Panda3D
|
00001 // Filename: dcParameter.cxx 00002 // Created by: drose (15Jun04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "dcParameter.h" 00016 #include "dcArrayParameter.h" 00017 #include "hashGenerator.h" 00018 #include "dcindent.h" 00019 #include "dcTypedef.h" 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: DCParameter::Constructor 00023 // Access: Protected 00024 // Description: 00025 //////////////////////////////////////////////////////////////////// 00026 DCParameter:: 00027 DCParameter() { 00028 _typedef = NULL; 00029 _has_fixed_byte_size = false; 00030 _has_fixed_structure = false; 00031 _num_nested_fields = -1; 00032 } 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Function: DCParameter::Copy Constructor 00036 // Access: Protected 00037 // Description: 00038 //////////////////////////////////////////////////////////////////// 00039 DCParameter:: 00040 DCParameter(const DCParameter ©) : 00041 DCField(copy), 00042 _typedef(copy._typedef) 00043 { 00044 } 00045 00046 //////////////////////////////////////////////////////////////////// 00047 // Function: DCParameter::Destructor 00048 // Access: Public, Virtual 00049 // Description: 00050 //////////////////////////////////////////////////////////////////// 00051 DCParameter:: 00052 ~DCParameter() { 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: DCParameter::as_parameter 00057 // Access: Published, Virtual 00058 // Description: 00059 //////////////////////////////////////////////////////////////////// 00060 DCParameter *DCParameter:: 00061 as_parameter() { 00062 return this; 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: DCParameter::as_parameter 00067 // Access: Published, Virtual 00068 // Description: 00069 //////////////////////////////////////////////////////////////////// 00070 const DCParameter *DCParameter:: 00071 as_parameter() const { 00072 return this; 00073 } 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function: DCParameter::as_simple_parameter 00077 // Access: Published, Virtual 00078 // Description: 00079 //////////////////////////////////////////////////////////////////// 00080 DCSimpleParameter *DCParameter:: 00081 as_simple_parameter() { 00082 return NULL; 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: DCParameter::as_simple_parameter 00087 // Access: Published, Virtual 00088 // Description: 00089 //////////////////////////////////////////////////////////////////// 00090 const DCSimpleParameter *DCParameter:: 00091 as_simple_parameter() const { 00092 return NULL; 00093 } 00094 00095 //////////////////////////////////////////////////////////////////// 00096 // Function: DCParameter::as_class_parameter 00097 // Access: Published, Virtual 00098 // Description: 00099 //////////////////////////////////////////////////////////////////// 00100 DCClassParameter *DCParameter:: 00101 as_class_parameter() { 00102 return NULL; 00103 } 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: DCParameter::as_class_parameter 00107 // Access: Published, Virtual 00108 // Description: 00109 //////////////////////////////////////////////////////////////////// 00110 const DCClassParameter *DCParameter:: 00111 as_class_parameter() const { 00112 return NULL; 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: DCParameter::as_switch_parameter 00117 // Access: Published, Virtual 00118 // Description: 00119 //////////////////////////////////////////////////////////////////// 00120 DCSwitchParameter *DCParameter:: 00121 as_switch_parameter() { 00122 return NULL; 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: DCParameter::as_switch_parameter 00127 // Access: Published, Virtual 00128 // Description: 00129 //////////////////////////////////////////////////////////////////// 00130 const DCSwitchParameter *DCParameter:: 00131 as_switch_parameter() const { 00132 return NULL; 00133 } 00134 00135 //////////////////////////////////////////////////////////////////// 00136 // Function: DCParameter::as_array_parameter 00137 // Access: Published, Virtual 00138 // Description: 00139 //////////////////////////////////////////////////////////////////// 00140 DCArrayParameter *DCParameter:: 00141 as_array_parameter() { 00142 return NULL; 00143 } 00144 00145 //////////////////////////////////////////////////////////////////// 00146 // Function: DCParameter::as_array_parameter 00147 // Access: Published, Virtual 00148 // Description: 00149 //////////////////////////////////////////////////////////////////// 00150 const DCArrayParameter *DCParameter:: 00151 as_array_parameter() const { 00152 return NULL; 00153 } 00154 00155 //////////////////////////////////////////////////////////////////// 00156 // Function: DCParameter::get_typedef 00157 // Access: Published 00158 // Description: If this type has been referenced from a typedef, 00159 // returns the DCTypedef instance, or NULL if the 00160 // type was declared on-the-fly. 00161 //////////////////////////////////////////////////////////////////// 00162 const DCTypedef *DCParameter:: 00163 get_typedef() const { 00164 return _typedef; 00165 } 00166 00167 //////////////////////////////////////////////////////////////////// 00168 // Function: DCParameter::set_typedef 00169 // Access: Public 00170 // Description: Records the DCTypedef object that generated this 00171 // parameter. This is normally called only from 00172 // DCTypedef::make_new_parameter(). 00173 //////////////////////////////////////////////////////////////////// 00174 void DCParameter:: 00175 set_typedef(const DCTypedef *dtypedef) { 00176 _typedef = dtypedef; 00177 } 00178 00179 //////////////////////////////////////////////////////////////////// 00180 // Function: DCParameter::append_array_specification 00181 // Access: Public, Virtual 00182 // Description: Returns the type represented by this_type[size]. 00183 // 00184 // In the case of a generic DCParameter, this means it 00185 // returns a DCArrayParameter wrapped around this type. 00186 //////////////////////////////////////////////////////////////////// 00187 DCParameter *DCParameter:: 00188 append_array_specification(const DCUnsignedIntRange &size) { 00189 return new DCArrayParameter(this, size); 00190 } 00191 00192 //////////////////////////////////////////////////////////////////// 00193 // Function: DCParameter::output 00194 // Access: Public, Virtual 00195 // Description: 00196 //////////////////////////////////////////////////////////////////// 00197 void DCParameter:: 00198 output(ostream &out, bool brief) const { 00199 string name; 00200 if (!brief) { 00201 name = get_name(); 00202 } 00203 output_instance(out, brief, "", name, ""); 00204 } 00205 00206 //////////////////////////////////////////////////////////////////// 00207 // Function: DCParameter::write 00208 // Access: Public, Virtual 00209 // Description: 00210 //////////////////////////////////////////////////////////////////// 00211 void DCParameter:: 00212 write(ostream &out, bool brief, int indent_level) const { 00213 // we must always output the name when the parameter occurs by 00214 // itself within a class, so we pass get_name() even if brief is 00215 // true. 00216 write_instance(out, brief, indent_level, "", get_name(), ""); 00217 } 00218 00219 //////////////////////////////////////////////////////////////////// 00220 // Function: DCParameter::write_instance 00221 // Access: Public, Virtual 00222 // Description: Formats the parameter in the C++-like dc syntax as a 00223 // typename and identifier. 00224 //////////////////////////////////////////////////////////////////// 00225 void DCParameter:: 00226 write_instance(ostream &out, bool brief, int indent_level, 00227 const string &prename, const string &name, 00228 const string &postname) const { 00229 indent(out, indent_level); 00230 output_instance(out, brief, prename, name, postname); 00231 output_keywords(out); 00232 out << ";"; 00233 if (!brief && _number >= 0) { 00234 out << " // field " << _number; 00235 } 00236 out << "\n"; 00237 } 00238 00239 //////////////////////////////////////////////////////////////////// 00240 // Function: DCParameter::output_typedef_name 00241 // Access: Public 00242 // Description: Formats the instance like output_instance, but uses 00243 // the typedef name instead. 00244 //////////////////////////////////////////////////////////////////// 00245 void DCParameter:: 00246 output_typedef_name(ostream &out, bool, const string &prename, 00247 const string &name, const string &postname) const { 00248 out << get_typedef()->get_name(); 00249 if (!prename.empty() || !name.empty() || !postname.empty()) { 00250 out << " " << prename << name << postname; 00251 } 00252 } 00253 00254 //////////////////////////////////////////////////////////////////// 00255 // Function: DCParameter::write_typedef_name 00256 // Access: Public 00257 // Description: Formats the instance like write_instance, but uses 00258 // the typedef name instead. 00259 //////////////////////////////////////////////////////////////////// 00260 void DCParameter:: 00261 write_typedef_name(ostream &out, bool brief, int indent_level, 00262 const string &prename, const string &name, 00263 const string &postname) const { 00264 indent(out, indent_level) 00265 << get_typedef()->get_name(); 00266 if (!prename.empty() || !name.empty() || !postname.empty()) { 00267 out << " " << prename << name << postname; 00268 } 00269 output_keywords(out); 00270 out << ";"; 00271 if (!brief && _number >= 0) { 00272 out << " // field " << _number; 00273 } 00274 out << "\n"; 00275 } 00276 00277 //////////////////////////////////////////////////////////////////// 00278 // Function: DCParameter::generate_hash 00279 // Access: Public, Virtual 00280 // Description: Accumulates the properties of this type into the 00281 // hash. 00282 //////////////////////////////////////////////////////////////////// 00283 void DCParameter:: 00284 generate_hash(HashGenerator &hashgen) const { 00285 // We specifically don't call up to DCField::generate_hash(), since 00286 // the parameter name is not actually significant to the hash. 00287 00288 if (get_num_keywords() != 0) { 00289 DCKeywordList::generate_hash(hashgen); 00290 } 00291 }