cppNameComponent.cxx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 cppNameComponent.cxx
  10. * @author drose
  11. * @date 1999-11-12
  12. */
  13. #include "cppNameComponent.h"
  14. #include "cppTemplateParameterList.h"
  15. using std::string;
  16. /**
  17. *
  18. */
  19. CPPNameComponent::
  20. CPPNameComponent(const string &name) :
  21. _name(name)
  22. {
  23. _templ = nullptr;
  24. }
  25. /**
  26. *
  27. */
  28. bool CPPNameComponent::
  29. operator == (const CPPNameComponent &other) const {
  30. if (_name != other._name) {
  31. return false;
  32. }
  33. if (_templ == nullptr && other._templ == nullptr) {
  34. return true;
  35. }
  36. if (_templ == nullptr || other._templ == nullptr) {
  37. return false;
  38. }
  39. if (*_templ != *other._templ) {
  40. return false;
  41. }
  42. return true;
  43. }
  44. /**
  45. *
  46. */
  47. bool CPPNameComponent::
  48. operator != (const CPPNameComponent &other) const {
  49. return !(*this == other);
  50. }
  51. /**
  52. *
  53. */
  54. bool CPPNameComponent::
  55. operator < (const CPPNameComponent &other) const {
  56. if (_name != other._name) {
  57. return _name < other._name;
  58. }
  59. if (_templ == nullptr && other._templ == nullptr) {
  60. return false;
  61. }
  62. if (_templ == nullptr || other._templ == nullptr) {
  63. return _templ < other._templ;
  64. }
  65. return (*_templ) < (*other._templ);
  66. }
  67. /**
  68. *
  69. */
  70. string CPPNameComponent::
  71. get_name() const {
  72. return _name;
  73. }
  74. /**
  75. *
  76. */
  77. string CPPNameComponent::
  78. get_name_with_templ(CPPScope *scope) const {
  79. std::ostringstream strm;
  80. strm << _name;
  81. if (_templ != nullptr) {
  82. strm << "< ";
  83. _templ->output(strm, scope);
  84. strm << " >";
  85. }
  86. return strm.str();
  87. }
  88. /**
  89. *
  90. */
  91. CPPTemplateParameterList *CPPNameComponent::
  92. get_templ() const {
  93. return _templ;
  94. }
  95. /**
  96. *
  97. */
  98. bool CPPNameComponent::
  99. empty() const {
  100. return _name.empty();
  101. }
  102. /**
  103. *
  104. */
  105. bool CPPNameComponent::
  106. has_templ() const {
  107. return _templ != nullptr;
  108. }
  109. /**
  110. * Returns true if the name component includes a template parameter list that
  111. * includes some not-yet-defined type.
  112. */
  113. bool CPPNameComponent::
  114. is_tbd() const {
  115. if (_templ != nullptr) {
  116. return _templ->is_tbd();
  117. }
  118. return false;
  119. }
  120. /**
  121. *
  122. */
  123. void CPPNameComponent::
  124. set_name(const string &name) {
  125. _name = name;
  126. }
  127. /**
  128. *
  129. */
  130. void CPPNameComponent::
  131. append_name(const string &name) {
  132. _name += name;
  133. }
  134. /**
  135. *
  136. */
  137. void CPPNameComponent::
  138. set_templ(CPPTemplateParameterList *templ) {
  139. _templ = templ;
  140. }
  141. /**
  142. *
  143. */
  144. void CPPNameComponent::
  145. output(std::ostream &out) const {
  146. out << _name;
  147. if (_templ != nullptr) {
  148. out << "< " << *_templ << " >";
  149. }
  150. }