cppNameComponent.cxx 5.9 KB

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