Panda3D
dcParameter.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 dcParameter.cxx
10  * @author drose
11  * @date 2004-06-15
12  */
13 
14 #include "dcParameter.h"
15 #include "dcArrayParameter.h"
16 #include "hashGenerator.h"
17 #include "dcindent.h"
18 #include "dcTypedef.h"
19 
20 using std::ostream;
21 using std::string;
22 
23 /**
24  *
25  */
26 DCParameter::
27 DCParameter() {
28  _typedef = nullptr;
29  _has_fixed_byte_size = false;
30  _has_fixed_structure = false;
31  _num_nested_fields = -1;
32 }
33 
34 /**
35  *
36  */
37 DCParameter::
38 DCParameter(const DCParameter &copy) :
39  DCField(copy),
40  _typedef(copy._typedef)
41 {
42 }
43 
44 /**
45  *
46  */
47 DCParameter::
48 ~DCParameter() {
49 }
50 
51 /**
52  *
53  */
54 DCParameter *DCParameter::
55 as_parameter() {
56  return this;
57 }
58 
59 /**
60  *
61  */
62 const DCParameter *DCParameter::
63 as_parameter() const {
64  return this;
65 }
66 
67 /**
68  *
69  */
70 DCSimpleParameter *DCParameter::
71 as_simple_parameter() {
72  return nullptr;
73 }
74 
75 /**
76  *
77  */
78 const DCSimpleParameter *DCParameter::
79 as_simple_parameter() const {
80  return nullptr;
81 }
82 
83 /**
84  *
85  */
86 DCClassParameter *DCParameter::
87 as_class_parameter() {
88  return nullptr;
89 }
90 
91 /**
92  *
93  */
94 const DCClassParameter *DCParameter::
95 as_class_parameter() const {
96  return nullptr;
97 }
98 
99 /**
100  *
101  */
102 DCSwitchParameter *DCParameter::
103 as_switch_parameter() {
104  return nullptr;
105 }
106 
107 /**
108  *
109  */
110 const DCSwitchParameter *DCParameter::
111 as_switch_parameter() const {
112  return nullptr;
113 }
114 
115 /**
116  *
117  */
118 DCArrayParameter *DCParameter::
119 as_array_parameter() {
120  return nullptr;
121 }
122 
123 /**
124  *
125  */
126 const DCArrayParameter *DCParameter::
127 as_array_parameter() const {
128  return nullptr;
129 }
130 
131 /**
132  * If this type has been referenced from a typedef, returns the DCTypedef
133  * instance, or NULL if the type was declared on-the-fly.
134  */
136 get_typedef() const {
137  return _typedef;
138 }
139 
140 /**
141  * Records the DCTypedef object that generated this parameter. This is
142  * normally called only from DCTypedef::make_new_parameter().
143  */
145 set_typedef(const DCTypedef *dtypedef) {
146  _typedef = dtypedef;
147 }
148 
149 /**
150  * Returns the type represented by this_type[size].
151  *
152  * In the case of a generic DCParameter, this means it returns a
153  * DCArrayParameter wrapped around this type.
154  */
157  return new DCArrayParameter(this, size);
158 }
159 
160 /**
161  *
162  */
163 void DCParameter::
164 output(ostream &out, bool brief) const {
165  string name;
166  if (!brief) {
167  name = get_name();
168  }
169  output_instance(out, brief, "", name, "");
170 }
171 
172 /**
173  *
174  */
175 void DCParameter::
176 write(ostream &out, bool brief, int indent_level) const {
177  // we must always output the name when the parameter occurs by itself within
178  // a class, so we pass get_name() even if brief is true.
179  write_instance(out, brief, indent_level, "", get_name(), "");
180 }
181 
182 /**
183  * Formats the parameter in the C++-like dc syntax as a typename and
184  * identifier.
185  */
187 write_instance(ostream &out, bool brief, int indent_level,
188  const string &prename, const string &name,
189  const string &postname) const {
190  indent(out, indent_level);
191  output_instance(out, brief, prename, name, postname);
192  output_keywords(out);
193  out << ";";
194  if (!brief && _number >= 0) {
195  out << " // field " << _number;
196  }
197  out << "\n";
198 }
199 
200 /**
201  * Formats the instance like output_instance, but uses the typedef name
202  * instead.
203  */
205 output_typedef_name(ostream &out, bool, const string &prename,
206  const string &name, const string &postname) const {
207  out << get_typedef()->get_name();
208  if (!prename.empty() || !name.empty() || !postname.empty()) {
209  out << " " << prename << name << postname;
210  }
211 }
212 
213 /**
214  * Formats the instance like write_instance, but uses the typedef name
215  * instead.
216  */
218 write_typedef_name(ostream &out, bool brief, int indent_level,
219  const string &prename, const string &name,
220  const string &postname) const {
221  indent(out, indent_level)
222  << get_typedef()->get_name();
223  if (!prename.empty() || !name.empty() || !postname.empty()) {
224  out << " " << prename << name << postname;
225  }
226  output_keywords(out);
227  out << ";";
228  if (!brief && _number >= 0) {
229  out << " // field " << _number;
230  }
231  out << "\n";
232 }
233 
234 /**
235  * Accumulates the properties of this type into the hash.
236  */
238 generate_hash(HashGenerator &hashgen) const {
239  // We specifically don't call up to DCField::generate_hash(), since the
240  // parameter name is not actually significant to the hash.
241 
242  if (get_num_keywords() != 0) {
244  }
245 }
This represents an array of some other kind of object, meaning this parameter type accepts an arbitra...
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:37
void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of these keywords into the hash.
int get_num_keywords() const
Returns the number of keywords in the list.
const std::string & get_name() const
Returns the name of this field, or empty string if the field is unnamed.
Represents the type specification for a single parameter within a field specification.
Definition: dcParameter.h:35
virtual void write_instance(std::ostream &out, bool brief, int indent_level, const std::string &prename, const std::string &name, const std::string &postname) const
Formats the parameter in the C++-like dc syntax as a typename and identifier.
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this type into the hash.
void write_typedef_name(std::ostream &out, bool brief, int indent_level, const std::string &prename, const std::string &name, const std::string &postname) const
Formats the instance like write_instance, but uses the typedef name instead.
const DCTypedef * get_typedef() const
If this type has been referenced from a typedef, returns the DCTypedef instance, or NULL if the type ...
void output_typedef_name(std::ostream &out, bool brief, const std::string &prename, const std::string &name, const std::string &postname) const
Formats the instance like output_instance, but uses the typedef name instead.
virtual DCParameter * append_array_specification(const DCUnsignedIntRange &size)
Returns the type represented by this_type[size].
void set_typedef(const DCTypedef *dtypedef)
Records the DCTypedef object that generated this parameter.
This is the most fundamental kind of parameter type: a single number or string, one of the DCSubatomi...
This represents a switch object used as a parameter itself, which packs the appropriate fields of the...
This represents a single typedef declaration in the dc file.
Definition: dcTypedef.h:26
const std::string & get_name() const
Returns the name of this typedef.
Definition: dcTypedef.cxx:68
This class generates an arbitrary hash number from a sequence of ints.
Definition: hashGenerator.h:23
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20