interrogateType.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 interrogateType.cxx
  10. * @author drose
  11. * @date 2000-07-31
  12. */
  13. #include "interrogateType.h"
  14. #include "indexRemapper.h"
  15. #include "interrogate_datafile.h"
  16. #include "interrogateDatabase.h"
  17. #include <algorithm>
  18. using std::istream;
  19. using std::ostream;
  20. /**
  21. *
  22. */
  23. InterrogateType::
  24. InterrogateType(InterrogateModuleDef *def) :
  25. InterrogateComponent(def)
  26. {
  27. _flags = 0;
  28. _outer_class = 0;
  29. _atomic_token = AT_not_atomic;
  30. _wrapped_type = 0;
  31. _array_size = 1;
  32. _destructor = 0;
  33. _cpptype = nullptr;
  34. _cppscope = nullptr;
  35. }
  36. /**
  37. *
  38. */
  39. InterrogateType::
  40. InterrogateType(const InterrogateType &copy) {
  41. (*this) = copy;
  42. }
  43. /**
  44. *
  45. */
  46. void InterrogateType::Derivation::
  47. output(ostream &out) const {
  48. out << _flags << " " << _base << " " << _upcast << " " << _downcast;
  49. }
  50. /**
  51. *
  52. */
  53. void InterrogateType::Derivation::
  54. input(istream &in) {
  55. in >> _flags >> _base >> _upcast >> _downcast;
  56. }
  57. /**
  58. *
  59. */
  60. void InterrogateType::EnumValue::
  61. output(ostream &out) const {
  62. idf_output_string(out, _name);
  63. idf_output_string(out, _scoped_name);
  64. idf_output_string(out, _comment, '\n');
  65. out << _value;
  66. }
  67. /**
  68. *
  69. */
  70. void InterrogateType::EnumValue::
  71. input(istream &in) {
  72. idf_input_string(in, _name);
  73. idf_input_string(in, _scoped_name);
  74. idf_input_string(in, _comment);
  75. in >> _value;
  76. }
  77. /**
  78. *
  79. */
  80. void InterrogateType::
  81. operator = (const InterrogateType &copy) {
  82. InterrogateComponent::operator = (copy);
  83. _flags = copy._flags;
  84. _scoped_name = copy._scoped_name;
  85. _true_name = copy._true_name;
  86. _comment = copy._comment;
  87. _outer_class = copy._outer_class;
  88. _atomic_token = copy._atomic_token;
  89. _wrapped_type = copy._wrapped_type;
  90. _array_size = copy._array_size;
  91. _constructors = copy._constructors;
  92. _destructor = copy._destructor;
  93. _elements = copy._elements;
  94. _methods = copy._methods;
  95. _make_seqs = copy._make_seqs;
  96. _casts = copy._casts;
  97. _derivations = copy._derivations;
  98. _enum_values = copy._enum_values;
  99. _nested_types = copy._nested_types;
  100. _cpptype = copy._cpptype;
  101. _cppscope = copy._cppscope;
  102. }
  103. /**
  104. * Combines type with the other similar definition. If one type is "fully
  105. * defined" and the other one isn't, the fully-defined type wins. If both
  106. * types are fully defined, whichever type is marked "global" wins.
  107. */
  108. void InterrogateType::
  109. merge_with(const InterrogateType &other) {
  110. // The only thing we care about copying from the non-fully-defined type
  111. // right now is the global flag.
  112. if (is_fully_defined() &&
  113. (!other.is_fully_defined() || (other._flags & F_global) == 0)) {
  114. // We win.
  115. _flags |= (other._flags & F_global);
  116. } else {
  117. // They win.
  118. int old_flags = (_flags & F_global);
  119. (*this) = other;
  120. _flags |= old_flags;
  121. }
  122. }
  123. /**
  124. * Formats the InterrogateType data for output to a data file.
  125. */
  126. void InterrogateType::
  127. output(ostream &out) const {
  128. InterrogateComponent::output(out);
  129. out << _flags << " ";
  130. idf_output_string(out, _scoped_name);
  131. idf_output_string(out, _true_name);
  132. out << _outer_class << " "
  133. << (int)_atomic_token << " "
  134. << _wrapped_type << " ";
  135. if (is_array()) {
  136. out << _array_size << " ";
  137. }
  138. idf_output_vector(out, _constructors);
  139. out << _destructor << " ";
  140. idf_output_vector(out, _elements);
  141. idf_output_vector(out, _methods);
  142. idf_output_vector(out, _make_seqs);
  143. idf_output_vector(out, _casts);
  144. idf_output_vector(out, _derivations);
  145. idf_output_vector(out, _enum_values);
  146. idf_output_vector(out, _nested_types);
  147. idf_output_string(out, _comment, '\n');
  148. }
  149. /**
  150. * Reads the data file as previously formatted by output().
  151. */
  152. void InterrogateType::
  153. input(istream &in) {
  154. InterrogateComponent::input(in);
  155. in >> _flags;
  156. idf_input_string(in, _scoped_name);
  157. idf_input_string(in, _true_name);
  158. in >> _outer_class;
  159. int token;
  160. in >> token;
  161. _atomic_token = (AtomicToken)token;
  162. in >> _wrapped_type;
  163. if (is_array()) {
  164. in >> _array_size;
  165. }
  166. idf_input_vector(in, _constructors);
  167. in >> _destructor;
  168. idf_input_vector(in, _elements);
  169. idf_input_vector(in, _methods);
  170. idf_input_vector(in, _make_seqs);
  171. idf_input_vector(in, _casts);
  172. idf_input_vector(in, _derivations);
  173. idf_input_vector(in, _enum_values);
  174. idf_input_vector(in, _nested_types);
  175. idf_input_string(in, _comment);
  176. }
  177. /**
  178. * Remaps all internal index numbers according to the indicated map. This
  179. * called from InterrogateDatabase::remap_indices().
  180. */
  181. void InterrogateType::
  182. remap_indices(const IndexRemapper &remap) {
  183. _outer_class = remap.map_from(_outer_class);
  184. _wrapped_type = remap.map_from(_wrapped_type);
  185. Functions::iterator fi;
  186. for (fi = _constructors.begin(); fi != _constructors.end(); ++fi) {
  187. (*fi) = remap.map_from(*fi);
  188. }
  189. _destructor = remap.map_from(_destructor);
  190. Elements::iterator ei;
  191. for (ei = _elements.begin(); ei != _elements.end(); ++ei) {
  192. (*ei) = remap.map_from(*ei);
  193. }
  194. for (fi = _methods.begin(); fi != _methods.end(); ++fi) {
  195. (*fi) = remap.map_from(*fi);
  196. }
  197. for (fi = _casts.begin(); fi != _casts.end(); ++fi) {
  198. (*fi) = remap.map_from(*fi);
  199. }
  200. MakeSeqs::iterator si;
  201. for (si = _make_seqs.begin(); si != _make_seqs.end(); ++si) {
  202. (*si) = remap.map_from(*si);
  203. }
  204. Derivations::iterator di;
  205. for (di = _derivations.begin(); di != _derivations.end(); ++di) {
  206. (*di)._base = remap.map_from((*di)._base);
  207. (*di)._upcast = remap.map_from((*di)._upcast);
  208. (*di)._downcast = remap.map_from((*di)._downcast);
  209. }
  210. Types::iterator ti;
  211. for (ti = _nested_types.begin(); ti != _nested_types.end(); ++ti) {
  212. (*ti) = remap.map_from(*ti);
  213. }
  214. }