cppNamespace.cxx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file cppNamespace.cxx
  10. * @author drose
  11. * @date 1999-11-16
  12. */
  13. #include "cppNamespace.h"
  14. #include "cppIdentifier.h"
  15. #include "cppScope.h"
  16. #include "indent.h"
  17. /**
  18. *
  19. */
  20. CPPNamespace::
  21. CPPNamespace(CPPIdentifier *ident, CPPScope *scope, const CPPFile &file) :
  22. CPPDeclaration(file),
  23. _ident(ident),
  24. _scope(scope),
  25. _is_inline(false)
  26. {
  27. }
  28. /**
  29. *
  30. */
  31. std::string CPPNamespace::
  32. get_simple_name() const {
  33. if (_ident == nullptr) {
  34. return "";
  35. }
  36. return _ident->get_simple_name();
  37. }
  38. /**
  39. *
  40. */
  41. std::string CPPNamespace::
  42. get_local_name(CPPScope *scope) const {
  43. if (_ident == nullptr) {
  44. return "";
  45. }
  46. return _ident->get_local_name(scope);
  47. }
  48. /**
  49. *
  50. */
  51. std::string CPPNamespace::
  52. get_fully_scoped_name() const {
  53. if (_ident == nullptr) {
  54. return "";
  55. }
  56. return _ident->get_fully_scoped_name();
  57. }
  58. /**
  59. *
  60. */
  61. CPPScope *CPPNamespace::
  62. get_scope() const {
  63. return _scope;
  64. }
  65. /**
  66. *
  67. */
  68. void CPPNamespace::
  69. output(std::ostream &out, int indent_level, CPPScope *scope, bool complete) const {
  70. if (_is_inline) {
  71. out << "inline ";
  72. }
  73. if (!complete && _ident != nullptr) {
  74. // If we have a name, use it.
  75. out << "namespace " << _ident->get_local_name(scope);
  76. } else {
  77. if (_ident != nullptr) {
  78. out << "namespace " << _ident->get_local_name(scope) << " {\n";
  79. } else {
  80. out << "namespace {\n";
  81. }
  82. _scope->write(out, indent_level + 2, _scope);
  83. indent(out, indent_level) << "}";
  84. }
  85. }
  86. /**
  87. *
  88. */
  89. CPPDeclaration::SubType CPPNamespace::
  90. get_subtype() const {
  91. return ST_namespace;
  92. }
  93. /**
  94. *
  95. */
  96. CPPNamespace *CPPNamespace::
  97. as_namespace() {
  98. return this;
  99. }