Panda3D
interrogateType.cxx
1 // Filename: interrogateType.cxx
2 // Created by: drose (31Jul00)
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 
15 #include "interrogateType.h"
16 #include "indexRemapper.h"
17 #include "interrogate_datafile.h"
18 #include "interrogateDatabase.h"
19 
20 #include <algorithm>
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: InterrogateType::Constructor
24 // Access: Public
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 InterrogateType::
28 InterrogateType(InterrogateModuleDef *def) :
30 {
31  _flags = 0;
32  _outer_class = 0;
33  _atomic_token = AT_not_atomic;
34  _wrapped_type = 0;
35  _array_size = 1;
36  _destructor = 0;
37 
38  _cpptype = (CPPType *)NULL;
39  _cppscope = (CPPScope *)NULL;
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: InterrogateType::Copy Constructor
44 // Access: Public
45 // Description:
46 ////////////////////////////////////////////////////////////////////
47 InterrogateType::
48 InterrogateType(const InterrogateType &copy) {
49  (*this) = copy;
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: InterrogateType::Derivation::output
54 // Access: Public
55 // Description:
56 ////////////////////////////////////////////////////////////////////
57 void InterrogateType::Derivation::
58 output(ostream &out) const {
59  out << _flags << " " << _base << " " << _upcast << " " << _downcast;
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: InterrogateType::Derivation::input
64 // Access: Public
65 // Description:
66 ////////////////////////////////////////////////////////////////////
67 void InterrogateType::Derivation::
68 input(istream &in) {
69  in >> _flags >> _base >> _upcast >> _downcast;
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: InterrogateType::EnumValue::output
74 // Access: Public
75 // Description:
76 ////////////////////////////////////////////////////////////////////
77 void InterrogateType::EnumValue::
78 output(ostream &out) const {
79  idf_output_string(out, _name);
80  idf_output_string(out, _scoped_name);
81  idf_output_string(out, _comment, '\n');
82  out << _value;
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: InterrogateType::EnumValue::input
87 // Access: Public
88 // Description:
89 ////////////////////////////////////////////////////////////////////
90 void InterrogateType::EnumValue::
91 input(istream &in) {
92  idf_input_string(in, _name);
93  idf_input_string(in, _scoped_name);
95  idf_input_string(in, _comment);
96  }
97  in >> _value;
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: InterrogateType::Copy Assignment Operator
102 // Access: Public
103 // Description:
104 ////////////////////////////////////////////////////////////////////
105 void InterrogateType::
106 operator = (const InterrogateType &copy) {
107  InterrogateComponent::operator = (copy);
108  _flags = copy._flags;
109  _scoped_name = copy._scoped_name;
110  _true_name = copy._true_name;
111  _comment = copy._comment;
112  _outer_class = copy._outer_class;
113  _atomic_token = copy._atomic_token;
114  _wrapped_type = copy._wrapped_type;
115  _array_size = copy._array_size;
116  _constructors = copy._constructors;
117  _destructor = copy._destructor;
118  _elements = copy._elements;
119  _methods = copy._methods;
120  _make_seqs = copy._make_seqs;
121  _casts = copy._casts;
122  _derivations = copy._derivations;
123  _enum_values = copy._enum_values;
124  _nested_types = copy._nested_types;
125 
126  _cpptype = copy._cpptype;
127  _cppscope = copy._cppscope;
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: InterrogateType::merge_with
132 // Access: Public
133 // Description: Combines type with the other similar definition. If
134 // one type is "fully defined" and the other one isn't,
135 // the fully-defined type wins.
136 ////////////////////////////////////////////////////////////////////
139  // The only thing we care about copying from the non-fully-defined
140  // type right now is the global flag.
141 
142  if (is_fully_defined()) {
143  // We win.
144  _flags |= (other._flags & F_global);
145 
146  } else {
147  // They win.
148  int old_flags = (_flags & F_global);
149  (*this) = other;
150  _flags |= old_flags;
151  }
152 }
153 
154 ////////////////////////////////////////////////////////////////////
155 // Function: InterrogateType::output
156 // Access: Public
157 // Description: Formats the InterrogateType data for output to a data
158 // file.
159 ////////////////////////////////////////////////////////////////////
161 output(ostream &out) const {
163 
164  out << _flags << " ";
165  idf_output_string(out, _scoped_name);
166  idf_output_string(out, _true_name);
167  out << _outer_class << " "
168  << (int)_atomic_token << " "
169  << _wrapped_type << " ";
170 
171  if (is_array()) {
172  out << _array_size << " ";
173  }
174 
175  idf_output_vector(out, _constructors);
176  out << _destructor << " ";
177  idf_output_vector(out, _elements);
178  idf_output_vector(out, _methods);
179  idf_output_vector(out, _make_seqs);
180  idf_output_vector(out, _casts);
181  idf_output_vector(out, _derivations);
182  idf_output_vector(out, _enum_values);
183  idf_output_vector(out, _nested_types);
184  idf_output_string(out, _comment, '\n');
185 }
186 
187 ////////////////////////////////////////////////////////////////////
188 // Function: InterrogateType::input
189 // Access: Public
190 // Description: Reads the data file as previously formatted by
191 // output().
192 ////////////////////////////////////////////////////////////////////
194 input(istream &in) {
196 
197  in >> _flags;
198  idf_input_string(in, _scoped_name);
199  idf_input_string(in, _true_name);
200 
201  in >> _outer_class;
202  int token;
203  in >> token;
204  _atomic_token = (AtomicToken)token;
205  in >> _wrapped_type;
206 
207  if (is_array()) {
208  in >> _array_size;
209  }
210 
211  idf_input_vector(in, _constructors);
212  in >> _destructor;
213 
214  idf_input_vector(in, _elements);
215  idf_input_vector(in, _methods);
216  idf_input_vector(in, _make_seqs);
217  idf_input_vector(in, _casts);
218  idf_input_vector(in, _derivations);
219  idf_input_vector(in, _enum_values);
220  idf_input_vector(in, _nested_types);
221  idf_input_string(in, _comment);
222 }
223 
224 ////////////////////////////////////////////////////////////////////
225 // Function: InterrogateType::remap_indices
226 // Access: Public
227 // Description: Remaps all internal index numbers according to the
228 // indicated map. This called from
229 // InterrogateDatabase::remap_indices().
230 ////////////////////////////////////////////////////////////////////
233  _outer_class = remap.map_from(_outer_class);
234  _wrapped_type = remap.map_from(_wrapped_type);
235 
236  Functions::iterator fi;
237  for (fi = _constructors.begin(); fi != _constructors.end(); ++fi) {
238  (*fi) = remap.map_from(*fi);
239  }
240  _destructor = remap.map_from(_destructor);
241 
242  Elements::iterator ei;
243  for (ei = _elements.begin(); ei != _elements.end(); ++ei) {
244  (*ei) = remap.map_from(*ei);
245  }
246 
247  for (fi = _methods.begin(); fi != _methods.end(); ++fi) {
248  (*fi) = remap.map_from(*fi);
249  }
250  for (fi = _casts.begin(); fi != _casts.end(); ++fi) {
251  (*fi) = remap.map_from(*fi);
252  }
253 
254  MakeSeqs::iterator si;
255  for (si = _make_seqs.begin(); si != _make_seqs.end(); ++si) {
256  (*si) = remap.map_from(*si);
257  }
258 
259  Derivations::iterator di;
260  for (di = _derivations.begin(); di != _derivations.end(); ++di) {
261  (*di)._base = remap.map_from((*di)._base);
262  (*di)._upcast = remap.map_from((*di)._upcast);
263  (*di)._downcast = remap.map_from((*di)._downcast);
264  }
265 
266  Types::iterator ti;
267  for (ti = _nested_types.begin(); ti != _nested_types.end(); ++ti) {
268  (*ti) = remap.map_from(*ti);
269  }
270 
271 }
272 
273 
274 ////////////////////////////////////////////////////////////////////
275 // Function: GetRunTimeDictionary
276 ////////////////////////////////////////////////////////////////////
277 EXPCL_DTOOLCONFIG RunTimeTypeDictionary & GetRunTimeDictionary()
278 {
279  static RunTimeTypeDictionary dict;
280  return dict;
281 };
282 
283 ////////////////////////////////////////////////////////////////////
284 // Function: GetRunTimeTypeList
285 ////////////////////////////////////////////////////////////////////
286 EXPCL_DTOOLCONFIG RunTimeTypeList & GetRunTimeTypeList()
287 {
288  static RunTimeTypeList list;
289  return list;
290 };
291 
void remap_indices(const IndexRemapper &remap)
Remaps all internal index numbers according to the indicated map.
static int get_file_minor_version()
Returns the minor version number of the interrogate database file currently being read...
This class manages a mapping of integers to integers.
Definition: indexRemapper.h:33
void input(istream &in)
Reads the data file as previously formatted by output().
void output(ostream &out) const
Formats the component for output to a data file.
void input(istream &in)
Reads the data file as previously formatted by output().
An internal representation of a type.
The base class for things that are part of the interrogate database.
void output(ostream &out) const
Formats the InterrogateType data for output to a data file.
void merge_with(const InterrogateType &other)
Combines type with the other similar definition.
int map_from(int from) const
Returns the integer that the given &#39;from&#39; integer had been set to map to, or the same integer if noth...