cppNameComponent.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // Filename: cppNameComponent.cxx
  2. // Created by: drose (12Nov99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #include "cppNameComponent.h"
  15. #include "cppTemplateParameterList.h"
  16. ////////////////////////////////////////////////////////////////////
  17. // Function: CPPNameComponent::Constructor
  18. // Access: Public
  19. // Description:
  20. ////////////////////////////////////////////////////////////////////
  21. CPPNameComponent::
  22. CPPNameComponent(const string &name) :
  23. _name(name)
  24. {
  25. _templ = (CPPTemplateParameterList *)NULL;
  26. }
  27. ////////////////////////////////////////////////////////////////////
  28. // Function: CPPNameComponent::Equivalence Operator
  29. // Access: Public
  30. // Description:
  31. ////////////////////////////////////////////////////////////////////
  32. bool CPPNameComponent::
  33. operator == (const CPPNameComponent &other) const {
  34. if (_name != other._name) {
  35. return false;
  36. }
  37. if (_templ == NULL && other._templ == NULL) {
  38. return true;
  39. }
  40. if (_templ == NULL || other._templ == NULL) {
  41. return false;
  42. }
  43. if (*_templ != *other._templ) {
  44. return false;
  45. }
  46. return true;
  47. }
  48. ////////////////////////////////////////////////////////////////////
  49. // Function: CPPNameComponent::Nonequivalence Operator
  50. // Access: Public
  51. // Description:
  52. ////////////////////////////////////////////////////////////////////
  53. bool CPPNameComponent::
  54. operator != (const CPPNameComponent &other) const {
  55. return !(*this == other);
  56. }
  57. ////////////////////////////////////////////////////////////////////
  58. // Function: CPPNameComponent::Ordering Operator
  59. // Access: Public
  60. // Description:
  61. ////////////////////////////////////////////////////////////////////
  62. bool CPPNameComponent::
  63. operator < (const CPPNameComponent &other) const {
  64. if (_name != other._name) {
  65. return _name < other._name;
  66. }
  67. if (_templ == NULL && other._templ == NULL) {
  68. return false;
  69. }
  70. if (_templ == NULL || other._templ == NULL) {
  71. return _templ < other._templ;
  72. }
  73. return (*_templ) < (*other._templ);
  74. }
  75. ////////////////////////////////////////////////////////////////////
  76. // Function: CPPNameComponent::output
  77. // Access: Public
  78. // Description:
  79. ////////////////////////////////////////////////////////////////////
  80. string CPPNameComponent::
  81. get_name() const {
  82. return _name;
  83. }
  84. ////////////////////////////////////////////////////////////////////
  85. // Function: CPPNameComponent::get_name_with_templ
  86. // Access: Public
  87. // Description:
  88. ////////////////////////////////////////////////////////////////////
  89. string CPPNameComponent::
  90. get_name_with_templ(CPPScope *scope) const {
  91. ostringstream strm;
  92. strm << _name;
  93. if (_templ != NULL) {
  94. strm << "< ";
  95. _templ->output(strm, scope);
  96. strm << " >";
  97. }
  98. return strm.str();
  99. }
  100. ////////////////////////////////////////////////////////////////////
  101. // Function: CPPNameComponent::get_templ
  102. // Access: Public
  103. // Description:
  104. ////////////////////////////////////////////////////////////////////
  105. CPPTemplateParameterList *CPPNameComponent::
  106. get_templ() const {
  107. return _templ;
  108. }
  109. ////////////////////////////////////////////////////////////////////
  110. // Function: CPPNameComponent::empty
  111. // Access: Public
  112. // Description:
  113. ////////////////////////////////////////////////////////////////////
  114. bool CPPNameComponent::
  115. empty() const {
  116. return _name.empty();
  117. }
  118. ////////////////////////////////////////////////////////////////////
  119. // Function: CPPNameComponent::has_templ
  120. // Access: Public
  121. // Description:
  122. ////////////////////////////////////////////////////////////////////
  123. bool CPPNameComponent::
  124. has_templ() const {
  125. return _templ != (CPPTemplateParameterList *)NULL;
  126. }
  127. ////////////////////////////////////////////////////////////////////
  128. // Function: CPPNameComponent::is_tbd
  129. // Access: Public
  130. // Description: Returns true if the name component includes a
  131. // template parameter list that includes some
  132. // not-yet-defined type.
  133. ////////////////////////////////////////////////////////////////////
  134. bool CPPNameComponent::
  135. is_tbd() const {
  136. if (_templ != (CPPTemplateParameterList *)NULL) {
  137. return _templ->is_tbd();
  138. }
  139. return false;
  140. }
  141. ////////////////////////////////////////////////////////////////////
  142. // Function: CPPNameComponent::set_name
  143. // Access: Public
  144. // Description:
  145. ////////////////////////////////////////////////////////////////////
  146. void CPPNameComponent::
  147. set_name(const string &name) {
  148. _name = name;
  149. }
  150. ////////////////////////////////////////////////////////////////////
  151. // Function: CPPNameComponent::append_name
  152. // Access: Public
  153. // Description:
  154. ////////////////////////////////////////////////////////////////////
  155. void CPPNameComponent::
  156. append_name(const string &name) {
  157. _name += name;
  158. }
  159. ////////////////////////////////////////////////////////////////////
  160. // Function: CPPNameComponent::set_templ
  161. // Access: Public
  162. // Description:
  163. ////////////////////////////////////////////////////////////////////
  164. void CPPNameComponent::
  165. set_templ(CPPTemplateParameterList *templ) {
  166. _templ = templ;
  167. }
  168. ////////////////////////////////////////////////////////////////////
  169. // Function: CPPNameComponent::output
  170. // Access: Public
  171. // Description:
  172. ////////////////////////////////////////////////////////////////////
  173. void CPPNameComponent::
  174. output(ostream &out) const {
  175. out << _name;
  176. if (_templ != NULL) {
  177. out << "< " << *_templ << " >";
  178. }
  179. }