00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "dcClassParameter.h"
00016 #include "dcClass.h"
00017 #include "dcArrayParameter.h"
00018 #include "hashGenerator.h"
00019
00020
00021
00022
00023
00024
00025 DCClassParameter::
00026 DCClassParameter(const DCClass *dclass) :
00027 _dclass(dclass)
00028 {
00029 set_name(dclass->get_name());
00030
00031 int num_fields = _dclass->get_num_inherited_fields();
00032
00033 _has_nested_fields = true;
00034 _pack_type = PT_class;
00035
00036 if (_dclass->has_constructor()) {
00037 DCField *field = _dclass->get_constructor();
00038 _nested_fields.push_back(field);
00039 _has_default_value = _has_default_value || field->has_default_value();
00040 }
00041 int i;
00042 for (i = 0 ; i < num_fields; i++) {
00043 DCField *field = _dclass->get_inherited_field(i);
00044 if (!field->as_molecular_field()) {
00045 _nested_fields.push_back(field);
00046 _has_default_value = _has_default_value || field->has_default_value();
00047 }
00048 }
00049 _num_nested_fields = _nested_fields.size();
00050
00051
00052
00053
00054 _has_fixed_byte_size = true;
00055 _fixed_byte_size = 0;
00056 _has_fixed_structure = true;
00057 for (i = 0; i < _num_nested_fields; i++) {
00058 DCPackerInterface *field = get_nested_field(i);
00059 _has_fixed_byte_size = _has_fixed_byte_size && field->has_fixed_byte_size();
00060 _fixed_byte_size += field->get_fixed_byte_size();
00061 _has_fixed_structure = _has_fixed_structure && field->has_fixed_structure();
00062
00063 _has_range_limits = _has_range_limits || field->has_range_limits();
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072 DCClassParameter::
00073 DCClassParameter(const DCClassParameter ©) :
00074 DCParameter(copy),
00075 _nested_fields(copy._nested_fields),
00076 _dclass(copy._dclass)
00077 {
00078 }
00079
00080
00081
00082
00083
00084
00085 DCClassParameter *DCClassParameter::
00086 as_class_parameter() {
00087 return this;
00088 }
00089
00090
00091
00092
00093
00094
00095 const DCClassParameter *DCClassParameter::
00096 as_class_parameter() const {
00097 return this;
00098 }
00099
00100
00101
00102
00103
00104
00105 DCParameter *DCClassParameter::
00106 make_copy() const {
00107 return new DCClassParameter(*this);
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117 bool DCClassParameter::
00118 is_valid() const {
00119 return !_dclass->is_bogus_class();
00120 }
00121
00122
00123
00124
00125
00126
00127 const DCClass *DCClassParameter::
00128 get_class() const {
00129 return _dclass;
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 DCPackerInterface *DCClassParameter::
00141 get_nested_field(int n) const {
00142 nassertr(n >= 0 && n < (int)_nested_fields.size(), NULL);
00143 return _nested_fields[n];
00144 }
00145
00146
00147
00148
00149
00150
00151
00152 void DCClassParameter::
00153 output_instance(ostream &out, bool brief, const string &prename,
00154 const string &name, const string &postname) const {
00155 if (get_typedef() != (DCTypedef *)NULL) {
00156 output_typedef_name(out, brief, prename, name, postname);
00157
00158 } else {
00159 _dclass->output_instance(out, brief, prename, name, postname);
00160 }
00161 }
00162
00163
00164
00165
00166
00167
00168
00169 void DCClassParameter::
00170 generate_hash(HashGenerator &hashgen) const {
00171 DCParameter::generate_hash(hashgen);
00172 _dclass->generate_hash(hashgen);
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 bool DCClassParameter::
00184 do_check_match(const DCPackerInterface *other) const {
00185 return other->do_check_match_class_parameter(this);
00186 }
00187
00188
00189
00190
00191
00192
00193
00194 bool DCClassParameter::
00195 do_check_match_class_parameter(const DCClassParameter *other) const {
00196 if (_nested_fields.size() != other->_nested_fields.size()) {
00197 return false;
00198 }
00199 for (size_t i = 0; i < _nested_fields.size(); i++) {
00200 if (!_nested_fields[i]->check_match(other->_nested_fields[i])) {
00201 return false;
00202 }
00203 }
00204
00205 return true;
00206 }
00207
00208
00209
00210
00211
00212
00213
00214 bool DCClassParameter::
00215 do_check_match_array_parameter(const DCArrayParameter *other) const {
00216 if ((int)_nested_fields.size() != other->get_array_size()) {
00217
00218
00219 return false;
00220 }
00221
00222 const DCPackerInterface *element_type = other->get_element_type();
00223 for (size_t i = 0; i < _nested_fields.size(); i++) {
00224 if (!_nested_fields[i]->check_match(element_type)) {
00225 return false;
00226 }
00227 }
00228
00229 return true;
00230 }