Panda3D
 All Classes Functions Variables Enumerations
dcParameter.cxx
1 // Filename: dcParameter.cxx
2 // Created by: drose (15Jun04)
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 "dcParameter.h"
16 #include "dcArrayParameter.h"
17 #include "hashGenerator.h"
18 #include "dcindent.h"
19 #include "dcTypedef.h"
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: DCParameter::Constructor
23 // Access: Protected
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 DCParameter::
27 DCParameter() {
28  _typedef = NULL;
29  _has_fixed_byte_size = false;
30  _has_fixed_structure = false;
31  _num_nested_fields = -1;
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: DCParameter::Copy Constructor
36 // Access: Protected
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 DCParameter::
40 DCParameter(const DCParameter &copy) :
41  DCField(copy),
42  _typedef(copy._typedef)
43 {
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: DCParameter::Destructor
48 // Access: Public, Virtual
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 DCParameter::
52 ~DCParameter() {
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: DCParameter::as_parameter
57 // Access: Published, Virtual
58 // Description:
59 ////////////////////////////////////////////////////////////////////
60 DCParameter *DCParameter::
61 as_parameter() {
62  return this;
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: DCParameter::as_parameter
67 // Access: Published, Virtual
68 // Description:
69 ////////////////////////////////////////////////////////////////////
70 const DCParameter *DCParameter::
71 as_parameter() const {
72  return this;
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: DCParameter::as_simple_parameter
77 // Access: Published, Virtual
78 // Description:
79 ////////////////////////////////////////////////////////////////////
80 DCSimpleParameter *DCParameter::
81 as_simple_parameter() {
82  return NULL;
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: DCParameter::as_simple_parameter
87 // Access: Published, Virtual
88 // Description:
89 ////////////////////////////////////////////////////////////////////
90 const DCSimpleParameter *DCParameter::
91 as_simple_parameter() const {
92  return NULL;
93 }
94 
95 ////////////////////////////////////////////////////////////////////
96 // Function: DCParameter::as_class_parameter
97 // Access: Published, Virtual
98 // Description:
99 ////////////////////////////////////////////////////////////////////
100 DCClassParameter *DCParameter::
101 as_class_parameter() {
102  return NULL;
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: DCParameter::as_class_parameter
107 // Access: Published, Virtual
108 // Description:
109 ////////////////////////////////////////////////////////////////////
110 const DCClassParameter *DCParameter::
111 as_class_parameter() const {
112  return NULL;
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: DCParameter::as_switch_parameter
117 // Access: Published, Virtual
118 // Description:
119 ////////////////////////////////////////////////////////////////////
120 DCSwitchParameter *DCParameter::
121 as_switch_parameter() {
122  return NULL;
123 }
124 
125 ////////////////////////////////////////////////////////////////////
126 // Function: DCParameter::as_switch_parameter
127 // Access: Published, Virtual
128 // Description:
129 ////////////////////////////////////////////////////////////////////
130 const DCSwitchParameter *DCParameter::
131 as_switch_parameter() const {
132  return NULL;
133 }
134 
135 ////////////////////////////////////////////////////////////////////
136 // Function: DCParameter::as_array_parameter
137 // Access: Published, Virtual
138 // Description:
139 ////////////////////////////////////////////////////////////////////
140 DCArrayParameter *DCParameter::
141 as_array_parameter() {
142  return NULL;
143 }
144 
145 ////////////////////////////////////////////////////////////////////
146 // Function: DCParameter::as_array_parameter
147 // Access: Published, Virtual
148 // Description:
149 ////////////////////////////////////////////////////////////////////
150 const DCArrayParameter *DCParameter::
151 as_array_parameter() const {
152  return NULL;
153 }
154 
155 ////////////////////////////////////////////////////////////////////
156 // Function: DCParameter::get_typedef
157 // Access: Published
158 // Description: If this type has been referenced from a typedef,
159 // returns the DCTypedef instance, or NULL if the
160 // type was declared on-the-fly.
161 ////////////////////////////////////////////////////////////////////
163 get_typedef() const {
164  return _typedef;
165 }
166 
167 ////////////////////////////////////////////////////////////////////
168 // Function: DCParameter::set_typedef
169 // Access: Public
170 // Description: Records the DCTypedef object that generated this
171 // parameter. This is normally called only from
172 // DCTypedef::make_new_parameter().
173 ////////////////////////////////////////////////////////////////////
174 void DCParameter::
175 set_typedef(const DCTypedef *dtypedef) {
176  _typedef = dtypedef;
177 }
178 
179 ////////////////////////////////////////////////////////////////////
180 // Function: DCParameter::append_array_specification
181 // Access: Public, Virtual
182 // Description: Returns the type represented by this_type[size].
183 //
184 // In the case of a generic DCParameter, this means it
185 // returns a DCArrayParameter wrapped around this type.
186 ////////////////////////////////////////////////////////////////////
189  return new DCArrayParameter(this, size);
190 }
191 
192 ////////////////////////////////////////////////////////////////////
193 // Function: DCParameter::output
194 // Access: Public, Virtual
195 // Description:
196 ////////////////////////////////////////////////////////////////////
197 void DCParameter::
198 output(ostream &out, bool brief) const {
199  string name;
200  if (!brief) {
201  name = get_name();
202  }
203  output_instance(out, brief, "", name, "");
204 }
205 
206 ////////////////////////////////////////////////////////////////////
207 // Function: DCParameter::write
208 // Access: Public, Virtual
209 // Description:
210 ////////////////////////////////////////////////////////////////////
211 void DCParameter::
212 write(ostream &out, bool brief, int indent_level) const {
213  // we must always output the name when the parameter occurs by
214  // itself within a class, so we pass get_name() even if brief is
215  // true.
216  write_instance(out, brief, indent_level, "", get_name(), "");
217 }
218 
219 ////////////////////////////////////////////////////////////////////
220 // Function: DCParameter::write_instance
221 // Access: Public, Virtual
222 // Description: Formats the parameter in the C++-like dc syntax as a
223 // typename and identifier.
224 ////////////////////////////////////////////////////////////////////
225 void DCParameter::
226 write_instance(ostream &out, bool brief, int indent_level,
227  const string &prename, const string &name,
228  const string &postname) const {
229  indent(out, indent_level);
230  output_instance(out, brief, prename, name, postname);
231  output_keywords(out);
232  out << ";";
233  if (!brief && _number >= 0) {
234  out << " // field " << _number;
235  }
236  out << "\n";
237 }
238 
239 ////////////////////////////////////////////////////////////////////
240 // Function: DCParameter::output_typedef_name
241 // Access: Public
242 // Description: Formats the instance like output_instance, but uses
243 // the typedef name instead.
244 ////////////////////////////////////////////////////////////////////
245 void DCParameter::
246 output_typedef_name(ostream &out, bool, const string &prename,
247  const string &name, const string &postname) const {
248  out << get_typedef()->get_name();
249  if (!prename.empty() || !name.empty() || !postname.empty()) {
250  out << " " << prename << name << postname;
251  }
252 }
253 
254 ////////////////////////////////////////////////////////////////////
255 // Function: DCParameter::write_typedef_name
256 // Access: Public
257 // Description: Formats the instance like write_instance, but uses
258 // the typedef name instead.
259 ////////////////////////////////////////////////////////////////////
260 void DCParameter::
261 write_typedef_name(ostream &out, bool brief, int indent_level,
262  const string &prename, const string &name,
263  const string &postname) const {
264  indent(out, indent_level)
265  << get_typedef()->get_name();
266  if (!prename.empty() || !name.empty() || !postname.empty()) {
267  out << " " << prename << name << postname;
268  }
269  output_keywords(out);
270  out << ";";
271  if (!brief && _number >= 0) {
272  out << " // field " << _number;
273  }
274  out << "\n";
275 }
276 
277 ////////////////////////////////////////////////////////////////////
278 // Function: DCParameter::generate_hash
279 // Access: Public, Virtual
280 // Description: Accumulates the properties of this type into the
281 // hash.
282 ////////////////////////////////////////////////////////////////////
283 void DCParameter::
284 generate_hash(HashGenerator &hashgen) const {
285  // We specifically don't call up to DCField::generate_hash(), since
286  // the parameter name is not actually significant to the hash.
287 
288  if (get_num_keywords() != 0) {
290  }
291 }
This represents a single typedef declaration in the dc file.
Definition: dcTypedef.h:29
const string & get_name() const
Returns the name of this field, or empty string if the field is unnamed.
virtual void write_instance(ostream &out, bool brief, int indent_level, const string &prename, const string &name, const string &postname) const
Formats the parameter in the C++-like dc syntax as a typename and identifier.
int get_num_keywords() const
Returns the number of keywords in the list.
This represents a class (or struct) object used as a parameter itself.
A single field of a Distributed Class, either atomic or molecular.
Definition: dcField.h:40
This is the most fundamental kind of parameter type: a single number or string, one of the DCSubatomi...
void set_typedef(const DCTypedef *dtypedef)
Records the DCTypedef object that generated this parameter.
This represents a switch object used as a parameter itself, which packs the appropriate fields of the...
virtual DCParameter * append_array_specification(const DCUnsignedIntRange &size)
Returns the type represented by this_type[size].
const DCTypedef * get_typedef() const
If this type has been referenced from a typedef, returns the DCTypedef instance, or NULL if the type ...
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this type into the hash.
Represents the type specification for a single parameter within a field specification.
Definition: dcParameter.h:39
This represents an array of some other kind of object, meaning this parameter type accepts an arbitra...
const string & get_name() const
Returns the name of this typedef.
Definition: dcTypedef.cxx:79
This class generates an arbitrary hash number from a sequence of ints.
Definition: hashGenerator.h:26
void output_typedef_name(ostream &out, bool brief, const string &prename, const string &name, const string &postname) const
Formats the instance like output_instance, but uses the typedef name instead.
void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of these keywords into the hash.
void write_typedef_name(ostream &out, bool brief, int indent_level, const string &prename, const string &name, const string &postname) const
Formats the instance like write_instance, but uses the typedef name instead.