Panda3D

interrogateType.cxx

00001 // Filename: interrogateType.cxx
00002 // Created by:  drose (31Jul00)
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 "interrogateType.h"
00016 #include "indexRemapper.h"
00017 #include "interrogate_datafile.h"
00018 
00019 #include <algorithm>
00020 
00021 // This static string is just kept around as a handy bogus return
00022 // value for functions that must return a const string reference.
00023 string InterrogateType::_empty_string;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: InterrogateType::Constructor
00027 //       Access: Public
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 InterrogateType::
00031 InterrogateType(InterrogateModuleDef *def) :
00032   InterrogateComponent(def)
00033 {
00034   _flags = 0;
00035   _outer_class = 0;
00036   _atomic_token = AT_not_atomic;
00037   _wrapped_type = 0;
00038   _destructor = 0;
00039 
00040   _cpptype = (CPPType *)NULL;
00041   _cppscope = (CPPScope *)NULL;
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: InterrogateType::Copy Constructor
00046 //       Access: Public
00047 //  Description:
00048 ////////////////////////////////////////////////////////////////////
00049 InterrogateType::
00050 InterrogateType(const InterrogateType &copy) {
00051   (*this) = copy;
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: InterrogateType::Derivation::output
00056 //       Access: Public
00057 //  Description:
00058 ////////////////////////////////////////////////////////////////////
00059 void InterrogateType::Derivation::
00060 output(ostream &out) const {
00061   out << _flags << " " << _base << " " << _upcast << " " << _downcast;
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: InterrogateType::Derivation::input
00066 //       Access: Public
00067 //  Description:
00068 ////////////////////////////////////////////////////////////////////
00069 void InterrogateType::Derivation::
00070 input(istream &in) {
00071   in >> _flags >> _base >> _upcast >> _downcast;
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: InterrogateType::EnumValue::output
00076 //       Access: Public
00077 //  Description:
00078 ////////////////////////////////////////////////////////////////////
00079 void InterrogateType::EnumValue::
00080 output(ostream &out) const {
00081   idf_output_string(out, _name);
00082   idf_output_string(out, _scoped_name);
00083   out << _value;
00084 }
00085 
00086 ////////////////////////////////////////////////////////////////////
00087 //     Function: InterrogateType::EnumValue::input
00088 //       Access: Public
00089 //  Description:
00090 ////////////////////////////////////////////////////////////////////
00091 void InterrogateType::EnumValue::
00092 input(istream &in) {
00093   idf_input_string(in, _name);
00094   idf_input_string(in, _scoped_name);
00095   in >> _value;
00096 }
00097 
00098 ////////////////////////////////////////////////////////////////////
00099 //     Function: InterrogateType::Copy Assignment Operator
00100 //       Access: Public
00101 //  Description:
00102 ////////////////////////////////////////////////////////////////////
00103 void InterrogateType::
00104 operator = (const InterrogateType &copy) {
00105   InterrogateComponent::operator = (copy);
00106   _flags = copy._flags;
00107   _scoped_name = copy._scoped_name;
00108   _true_name = copy._true_name;
00109   _comment = copy._comment;
00110   _outer_class = copy._outer_class;
00111   _atomic_token = copy._atomic_token;
00112   _wrapped_type = copy._wrapped_type;
00113   _constructors = copy._constructors;
00114   _destructor = copy._destructor;
00115   _elements = copy._elements;
00116   _methods = copy._methods;
00117   _make_seqs = copy._make_seqs;
00118   _casts = copy._casts;
00119   _derivations = copy._derivations;
00120   _enum_values = copy._enum_values;
00121   _nested_types = copy._nested_types;
00122 
00123   _cpptype = copy._cpptype;
00124   _cppscope = copy._cppscope;
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: InterrogateType::merge_with
00129 //       Access: Public
00130 //  Description: Combines type with the other similar definition.  If
00131 //               one type is "fully defined" and the other one isn't,
00132 //               the fully-defined type wins.
00133 ////////////////////////////////////////////////////////////////////
00134 void InterrogateType::
00135 merge_with(const InterrogateType &other) {
00136   // The only thing we care about copying from the non-fully-defined
00137   // type right now is the global flag.
00138 
00139   if (is_fully_defined()) {
00140     // We win.
00141     _flags |= (other._flags & F_global);
00142 
00143   } else {
00144     // They win.
00145     int old_flags = (_flags & F_global);
00146     (*this) = other;
00147     _flags |= old_flags;
00148   }
00149 }
00150 
00151 ////////////////////////////////////////////////////////////////////
00152 //     Function: InterrogateType::output
00153 //       Access: Public
00154 //  Description: Formats the InterrogateType data for output to a data
00155 //               file.
00156 ////////////////////////////////////////////////////////////////////
00157 void InterrogateType::
00158 output(ostream &out) const {
00159   InterrogateComponent::output(out);
00160 
00161   out << _flags << " ";
00162   idf_output_string(out, _scoped_name);
00163   idf_output_string(out, _true_name);
00164   out << _outer_class << " "
00165       << (int)_atomic_token << " "
00166       << _wrapped_type << " ";
00167   idf_output_vector(out, _constructors);
00168   out << _destructor << " ";
00169   idf_output_vector(out, _elements);
00170   idf_output_vector(out, _methods);
00171   idf_output_vector(out, _make_seqs);
00172   idf_output_vector(out, _casts);
00173   idf_output_vector(out, _derivations);
00174   idf_output_vector(out, _enum_values);
00175   idf_output_vector(out, _nested_types);
00176   idf_output_string(out, _comment, '\n');
00177 }
00178 
00179 ////////////////////////////////////////////////////////////////////
00180 //     Function: InterrogateType::input
00181 //       Access: Public
00182 //  Description: Reads the data file as previously formatted by
00183 //               output().
00184 ////////////////////////////////////////////////////////////////////
00185 void InterrogateType::
00186 input(istream &in) {
00187   InterrogateComponent::input(in);
00188 
00189   in >> _flags;
00190   idf_input_string(in, _scoped_name);
00191   idf_input_string(in, _true_name);
00192 
00193   in >> _outer_class;
00194   int token;
00195   in >> token;
00196   _atomic_token = (AtomicToken)token;
00197   in >> _wrapped_type;
00198 
00199   idf_input_vector(in, _constructors);
00200   in >> _destructor;
00201 
00202   idf_input_vector(in, _elements);
00203   idf_input_vector(in, _methods);
00204   idf_input_vector(in, _make_seqs);
00205   idf_input_vector(in, _casts);
00206   idf_input_vector(in, _derivations);
00207   idf_input_vector(in, _enum_values);
00208   idf_input_vector(in, _nested_types);
00209   idf_input_string(in, _comment);
00210 }
00211 
00212 ////////////////////////////////////////////////////////////////////
00213 //     Function: InterrogateType::remap_indices
00214 //       Access: Public
00215 //  Description: Remaps all internal index numbers according to the
00216 //               indicated map.  This called from
00217 //               InterrogateDatabase::remap_indices().
00218 ////////////////////////////////////////////////////////////////////
00219 void InterrogateType::
00220 remap_indices(const IndexRemapper &remap) {
00221   _outer_class = remap.map_from(_outer_class);
00222   _wrapped_type = remap.map_from(_wrapped_type);
00223 
00224   Functions::iterator fi;
00225   for (fi = _constructors.begin(); fi != _constructors.end(); ++fi) {
00226     (*fi) = remap.map_from(*fi);
00227   }
00228   _destructor = remap.map_from(_destructor);
00229 
00230   Elements::iterator ei;
00231   for (ei = _elements.begin(); ei != _elements.end(); ++ei) {
00232     (*ei) = remap.map_from(*ei);
00233   }
00234 
00235   for (fi = _methods.begin(); fi != _methods.end(); ++fi) {
00236     (*fi) = remap.map_from(*fi);
00237   }
00238   for (fi = _casts.begin(); fi != _casts.end(); ++fi) {
00239     (*fi) = remap.map_from(*fi);
00240   }
00241 
00242   MakeSeqs::iterator si;
00243   for (si = _make_seqs.begin(); si != _make_seqs.end(); ++si) {
00244     (*si) = remap.map_from(*si);
00245   }
00246 
00247   Derivations::iterator di;
00248   for (di = _derivations.begin(); di != _derivations.end(); ++di) {
00249     (*di)._base = remap.map_from((*di)._base);
00250     (*di)._upcast = remap.map_from((*di)._upcast);
00251     (*di)._downcast = remap.map_from((*di)._downcast);
00252   }
00253 
00254   Types::iterator ti;
00255   for (ti = _nested_types.begin(); ti != _nested_types.end(); ++ti) {
00256     (*ti) = remap.map_from(*ti);
00257   }
00258 
00259 }
00260 
00261 
00262 ////////////////////////////////////////////////////////////////////
00263 //     Function: GetRunTimeDictionary
00264 ////////////////////////////////////////////////////////////////////
00265 EXPCL_DTOOLCONFIG RunTimeTypeDictionary & GetRunTimeDictionary()
00266 {
00267     static RunTimeTypeDictionary dict;
00268     return dict;
00269 };
00270 
00271 ////////////////////////////////////////////////////////////////////
00272 //     Function: GetRunTimeTypeList
00273 ////////////////////////////////////////////////////////////////////
00274 EXPCL_DTOOLCONFIG RunTimeTypeList & GetRunTimeTypeList()
00275 {
00276     static RunTimeTypeList list;
00277     return list;
00278 };
00279 
 All Classes Functions Variables Enumerations