Panda3D
interrogateType.cxx
Go to the documentation of this file.
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 
14 #include "interrogateType.h"
15 #include "indexRemapper.h"
16 #include "interrogate_datafile.h"
17 #include "interrogateDatabase.h"
18 
19 #include <algorithm>
20 
21 using std::istream;
22 using std::ostream;
23 
24 /**
25  *
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 = nullptr;
39  _cppscope = nullptr;
40 }
41 
42 /**
43  *
44  */
45 InterrogateType::
46 InterrogateType(const InterrogateType &copy) {
47  (*this) = copy;
48 }
49 
50 /**
51  *
52  */
53 void InterrogateType::Derivation::
54 output(ostream &out) const {
55  out << _flags << " " << _base << " " << _upcast << " " << _downcast;
56 }
57 
58 /**
59  *
60  */
61 void InterrogateType::Derivation::
62 input(istream &in) {
63  in >> _flags >> _base >> _upcast >> _downcast;
64 }
65 
66 /**
67  *
68  */
69 void InterrogateType::EnumValue::
70 output(ostream &out) const {
71  idf_output_string(out, _name);
72  idf_output_string(out, _scoped_name);
73  idf_output_string(out, _comment, '\n');
74  out << _value;
75 }
76 
77 /**
78  *
79  */
80 void InterrogateType::EnumValue::
81 input(istream &in) {
82  idf_input_string(in, _name);
83  idf_input_string(in, _scoped_name);
84  idf_input_string(in, _comment);
85  in >> _value;
86 }
87 
88 /**
89  *
90  */
91 void InterrogateType::
92 operator = (const InterrogateType &copy) {
93  InterrogateComponent::operator = (copy);
94  _flags = copy._flags;
95  _scoped_name = copy._scoped_name;
96  _true_name = copy._true_name;
97  _comment = copy._comment;
98  _outer_class = copy._outer_class;
99  _atomic_token = copy._atomic_token;
100  _wrapped_type = copy._wrapped_type;
101  _array_size = copy._array_size;
102  _constructors = copy._constructors;
103  _destructor = copy._destructor;
104  _elements = copy._elements;
105  _methods = copy._methods;
106  _make_seqs = copy._make_seqs;
107  _casts = copy._casts;
108  _derivations = copy._derivations;
109  _enum_values = copy._enum_values;
110  _nested_types = copy._nested_types;
111 
112  _cpptype = copy._cpptype;
113  _cppscope = copy._cppscope;
114 }
115 
116 /**
117  * Combines type with the other similar definition. If one type is "fully
118  * defined" and the other one isn't, the fully-defined type wins. If both
119  * types are fully defined, whichever type is marked "global" wins.
120  */
123  // The only thing we care about copying from the non-fully-defined type
124  // right now is the global flag.
125 
126  if (is_fully_defined() &&
127  (!other.is_fully_defined() || (other._flags & F_global) == 0)) {
128  // We win.
129  _flags |= (other._flags & F_global);
130 
131  } else {
132  // They win.
133  int old_flags = (_flags & F_global);
134  (*this) = other;
135  _flags |= old_flags;
136  }
137 }
138 
139 /**
140  * Formats the InterrogateType data for output to a data file.
141  */
143 output(ostream &out) const {
145 
146  out << _flags << " ";
147  idf_output_string(out, _scoped_name);
148  idf_output_string(out, _true_name);
149  out << _outer_class << " "
150  << (int)_atomic_token << " "
151  << _wrapped_type << " ";
152 
153  if (is_array()) {
154  out << _array_size << " ";
155  }
156 
157  idf_output_vector(out, _constructors);
158  out << _destructor << " ";
159  idf_output_vector(out, _elements);
160  idf_output_vector(out, _methods);
161  idf_output_vector(out, _make_seqs);
162  idf_output_vector(out, _casts);
163  idf_output_vector(out, _derivations);
164  idf_output_vector(out, _enum_values);
165  idf_output_vector(out, _nested_types);
166  idf_output_string(out, _comment, '\n');
167 }
168 
169 /**
170  * Reads the data file as previously formatted by output().
171  */
173 input(istream &in) {
175 
176  in >> _flags;
177  idf_input_string(in, _scoped_name);
178  idf_input_string(in, _true_name);
179 
180  in >> _outer_class;
181  int token;
182  in >> token;
183  _atomic_token = (AtomicToken)token;
184  in >> _wrapped_type;
185 
186  if (is_array()) {
187  in >> _array_size;
188  }
189 
190  idf_input_vector(in, _constructors);
191  in >> _destructor;
192 
193  idf_input_vector(in, _elements);
194  idf_input_vector(in, _methods);
195  idf_input_vector(in, _make_seqs);
196  idf_input_vector(in, _casts);
197  idf_input_vector(in, _derivations);
198  idf_input_vector(in, _enum_values);
199  idf_input_vector(in, _nested_types);
200  idf_input_string(in, _comment);
201 }
202 
203 /**
204  * Remaps all internal index numbers according to the indicated map. This
205  * called from InterrogateDatabase::remap_indices().
206  */
209  _outer_class = remap.map_from(_outer_class);
210  _wrapped_type = remap.map_from(_wrapped_type);
211 
212  Functions::iterator fi;
213  for (fi = _constructors.begin(); fi != _constructors.end(); ++fi) {
214  (*fi) = remap.map_from(*fi);
215  }
216  _destructor = remap.map_from(_destructor);
217 
218  Elements::iterator ei;
219  for (ei = _elements.begin(); ei != _elements.end(); ++ei) {
220  (*ei) = remap.map_from(*ei);
221  }
222 
223  for (fi = _methods.begin(); fi != _methods.end(); ++fi) {
224  (*fi) = remap.map_from(*fi);
225  }
226  for (fi = _casts.begin(); fi != _casts.end(); ++fi) {
227  (*fi) = remap.map_from(*fi);
228  }
229 
230  MakeSeqs::iterator si;
231  for (si = _make_seqs.begin(); si != _make_seqs.end(); ++si) {
232  (*si) = remap.map_from(*si);
233  }
234 
235  Derivations::iterator di;
236  for (di = _derivations.begin(); di != _derivations.end(); ++di) {
237  (*di)._base = remap.map_from((*di)._base);
238  (*di)._upcast = remap.map_from((*di)._upcast);
239  (*di)._downcast = remap.map_from((*di)._downcast);
240  }
241 
242  Types::iterator ti;
243  for (ti = _nested_types.begin(); ti != _nested_types.end(); ++ti) {
244  (*ti) = remap.map_from(*ti);
245  }
246 
247 }
void idf_input_vector(std::istream &in, std::vector< Element > &vec)
Reads the given vector from the input file, as previously written by output_string().
void remap_indices(const IndexRemapper &remap)
Remaps all internal index numbers according to the indicated map.
void output(std::ostream &out) const
Formats the InterrogateType data for output to a data file.
This class manages a mapping of integers to integers.
Definition: indexRemapper.h:29
void idf_output_string(ostream &out, const string &str, char whitespace)
Writes the indicated string to the output file.
void idf_input_string(istream &in, string &str)
Reads the given string from the input file, as previously written by output_string().
void output(std::ostream &out) const
Formats the component for output to a data file.
An internal representation of a type.
void input(std::istream &in)
Reads the data file as previously formatted by output().
The base class for things that are part of the interrogate database.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void input(std::istream &in)
Reads the data file as previously formatted by output().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void merge_with(const InterrogateType &other)
Combines type with the other similar definition.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void idf_output_vector(std::ostream &out, const std::vector< Element > &vec)
Writes the indicated vector to the output file.
int map_from(int from) const
Returns the integer that the given 'from' integer had been set to map to, or the same integer if noth...