cppClassTemplateParameter.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 cppClassTemplateParameter.cxx
  10. * @author drose
  11. * @date 1999-10-28
  12. */
  13. #include "cppClassTemplateParameter.h"
  14. #include "cppIdentifier.h"
  15. /**
  16. *
  17. */
  18. CPPClassTemplateParameter::
  19. CPPClassTemplateParameter(CPPIdentifier *ident, CPPType *default_type) :
  20. CPPType(CPPFile()),
  21. _ident(ident),
  22. _default_type(default_type),
  23. _packed(false)
  24. {
  25. }
  26. /**
  27. * Returns true if this declaration is an actual, factual declaration, or
  28. * false if some part of the declaration depends on a template parameter which
  29. * has not yet been instantiated.
  30. */
  31. bool CPPClassTemplateParameter::
  32. is_fully_specified() const {
  33. return false;
  34. }
  35. /**
  36. *
  37. */
  38. void CPPClassTemplateParameter::
  39. output(ostream &out, int indent_level, CPPScope *scope, bool complete) const {
  40. if (complete) {
  41. if (_ident != NULL) {
  42. out << "class ";
  43. _ident->output(out, scope);
  44. } else {
  45. out << "class";
  46. }
  47. if (_packed) {
  48. out << "...";
  49. }
  50. if (_default_type) {
  51. out << " = ";
  52. _default_type->output(out, indent_level, scope, false);
  53. }
  54. } else {
  55. _ident->output(out, scope);
  56. }
  57. }
  58. /**
  59. *
  60. */
  61. CPPDeclaration::SubType CPPClassTemplateParameter::
  62. get_subtype() const {
  63. return ST_class_template_parameter;
  64. }
  65. /**
  66. *
  67. */
  68. CPPClassTemplateParameter *CPPClassTemplateParameter::
  69. as_class_template_parameter() {
  70. return this;
  71. }
  72. /**
  73. * Called by CPPDeclaration() to determine whether this type is equivalent to
  74. * another type of the same type.
  75. */
  76. bool CPPClassTemplateParameter::
  77. is_equal(const CPPDeclaration *other) const {
  78. const CPPClassTemplateParameter *ot = ((CPPDeclaration *)other)->as_class_template_parameter();
  79. assert(ot != NULL);
  80. if (_default_type != ot->_default_type) {
  81. return false;
  82. }
  83. if (_packed != ot->_packed) {
  84. return false;
  85. }
  86. if (_ident == NULL || ot->_ident == NULL) {
  87. return _ident == ot->_ident;
  88. }
  89. return *_ident == *ot->_ident;
  90. }
  91. /**
  92. * Called by CPPDeclaration() to determine whether this type should be ordered
  93. * before another type of the same type, in an arbitrary but fixed ordering.
  94. */
  95. bool CPPClassTemplateParameter::
  96. is_less(const CPPDeclaration *other) const {
  97. const CPPClassTemplateParameter *ot = ((CPPDeclaration *)other)->as_class_template_parameter();
  98. assert(ot != NULL);
  99. if (_default_type != ot->_default_type) {
  100. return _default_type < ot->_default_type;
  101. }
  102. if (_packed != ot->_packed) {
  103. return _packed < ot->_packed;
  104. }
  105. if (_ident == NULL || ot->_ident == NULL) {
  106. return _ident < ot->_ident;
  107. }
  108. return *_ident < *ot->_ident;
  109. }