00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "dcSwitchParameter.h"
00016 #include "dcSwitch.h"
00017 #include "hashGenerator.h"
00018
00019
00020
00021
00022
00023
00024 DCSwitchParameter::
00025 DCSwitchParameter(const DCSwitch *dswitch) :
00026 _dswitch(dswitch)
00027 {
00028 set_name(dswitch->get_name());
00029
00030 _has_fixed_byte_size = true;
00031 _fixed_byte_size = 0;
00032 _has_fixed_structure = false;
00033
00034
00035
00036
00037
00038 _has_nested_fields = true;
00039 _num_nested_fields = 1;
00040
00041 _pack_type = PT_switch;
00042
00043 DCField *key_parameter = dswitch->get_key_parameter();
00044 _has_fixed_byte_size = _has_fixed_byte_size && key_parameter->has_fixed_byte_size();
00045 _has_range_limits = _has_range_limits || key_parameter->has_range_limits();
00046 _has_default_value = _has_default_value || key_parameter->has_default_value();
00047
00048 int num_cases = _dswitch->get_num_cases();
00049 if (num_cases > 0) {
00050 _fixed_byte_size = _dswitch->get_case(0)->get_fixed_byte_size();
00051
00052
00053 for (int i = 0; i < num_cases; i++) {
00054 const DCSwitch::SwitchFields *fields =
00055 (const DCSwitch::SwitchFields *)_dswitch->get_case(i);
00056
00057 if (!fields->has_fixed_byte_size() ||
00058 fields->get_fixed_byte_size() != _fixed_byte_size) {
00059
00060
00061 _has_fixed_byte_size = false;
00062 }
00063
00064 _has_range_limits = _has_range_limits || fields->has_range_limits();
00065 _has_default_value = _has_default_value || fields->_has_default_value;
00066 }
00067 }
00068
00069
00070 const DCSwitch::SwitchFields *fields =
00071 (DCSwitch::SwitchFields *)_dswitch->get_default_case();
00072 if (fields != (DCSwitch::SwitchFields *)NULL) {
00073 if (!fields->has_fixed_byte_size() ||
00074 fields->get_fixed_byte_size() != _fixed_byte_size) {
00075 _has_fixed_byte_size = false;
00076 }
00077
00078 _has_range_limits = _has_range_limits || fields->has_range_limits();
00079 _has_default_value = _has_default_value || fields->_has_default_value;
00080 }
00081 }
00082
00083
00084
00085
00086
00087
00088 DCSwitchParameter::
00089 DCSwitchParameter(const DCSwitchParameter ©) :
00090 DCParameter(copy),
00091 _dswitch(copy._dswitch)
00092 {
00093 }
00094
00095
00096
00097
00098
00099
00100 DCSwitchParameter *DCSwitchParameter::
00101 as_switch_parameter() {
00102 return this;
00103 }
00104
00105
00106
00107
00108
00109
00110 const DCSwitchParameter *DCSwitchParameter::
00111 as_switch_parameter() const {
00112 return this;
00113 }
00114
00115
00116
00117
00118
00119
00120 DCParameter *DCSwitchParameter::
00121 make_copy() const {
00122 return new DCSwitchParameter(*this);
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132 bool DCSwitchParameter::
00133 is_valid() const {
00134 return true;
00135 }
00136
00137
00138
00139
00140
00141
00142 const DCSwitch *DCSwitchParameter::
00143 get_switch() const {
00144 return _dswitch;
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 DCPackerInterface *DCSwitchParameter::
00156 get_nested_field(int) const {
00157 return _dswitch->get_key_parameter();
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 const DCPackerInterface *DCSwitchParameter::
00169 apply_switch(const char *value_data, size_t length) const {
00170 return _dswitch->apply_switch(value_data, length);
00171 }
00172
00173
00174
00175
00176
00177
00178
00179 void DCSwitchParameter::
00180 output_instance(ostream &out, bool brief, const string &prename,
00181 const string &name, const string &postname) const {
00182 if (get_typedef() != (DCTypedef *)NULL) {
00183 output_typedef_name(out, brief, prename, name, postname);
00184
00185 } else {
00186 _dswitch->output_instance(out, brief, prename, name, postname);
00187 }
00188 }
00189
00190
00191
00192
00193
00194
00195
00196 void DCSwitchParameter::
00197 write_instance(ostream &out, bool brief, int indent_level,
00198 const string &prename, const string &name,
00199 const string &postname) const {
00200 if (get_typedef() != (DCTypedef *)NULL) {
00201 write_typedef_name(out, brief, indent_level, prename, name, postname);
00202
00203 } else {
00204 _dswitch->write_instance(out, brief, indent_level, prename, name, postname);
00205 }
00206 }
00207
00208
00209
00210
00211
00212
00213
00214 void DCSwitchParameter::
00215 generate_hash(HashGenerator &hashgen) const {
00216 DCParameter::generate_hash(hashgen);
00217 _dswitch->generate_hash(hashgen);
00218 }
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 bool DCSwitchParameter::
00230 pack_default_value(DCPackData &pack_data, bool &pack_error) const {
00231 if (has_default_value()) {
00232 return DCField::pack_default_value(pack_data, pack_error);
00233 }
00234
00235 return _dswitch->pack_default_value(pack_data, pack_error);
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 bool DCSwitchParameter::
00247 do_check_match(const DCPackerInterface *other) const {
00248 return other->do_check_match_switch_parameter(this);
00249 }
00250
00251
00252
00253
00254
00255
00256
00257 bool DCSwitchParameter::
00258 do_check_match_switch_parameter(const DCSwitchParameter *other) const {
00259 return _dswitch->do_check_match_switch(other->_dswitch);
00260 }