MCPcopy Create free account
hub / github.com/OpenDDS/OpenDDS / generate_read

Function generate_read

dds/idl/value_reader_generator.cpp:166–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164 }
165
166 void generate_read(const std::string& expression, const std::string& accessor,
167 const std::string& field_name, AST_Type* type, const std::string& idx,
168 int level, FieldFilter filter_kind, bool optional)
169 {
170 const std::string indent(size_t(level) * 2 + (optional ? 2 : 0), ' ');
171
172 AST_Type* const actual = resolveActualType(type);
173 const Classification c = classify(actual);
174
175 if (optional) {
176 be_global->impl_ <<
177 indent.substr(0, indent.size() - 2) << "if (value_reader.member_has_value()) {\n";
178 }
179
180 // If the field is optional we need to create a temporary to read the value into before we can assign it to the optional
181 const bool create_tmp = optional && !(c & CL_STRING);
182 const std::string var_name = create_tmp ? "tmp" : expression + accessor;
183 if (create_tmp) {
184 std::string tmp_type = scoped(type->name());
185 if (c & (CL_ARRAY | CL_SEQUENCE | CL_MAP)) {
186 tmp_type = FieldInfo::scoped_type(*type, field_name);
187 }
188 be_global->impl_ <<
189 indent << tmp_type << " tmp;\n";
190 }
191 const bool use_cxx11 = be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
192
193 if (c & CL_SEQUENCE) {
194 AST_Sequence* const sequence = dynamic_cast<AST_Sequence*>(actual);
195 sequence_helper(var_name, sequence, idx, level, filter_kind);
196
197 } else if (c & CL_ARRAY) {
198 AST_Array* const array = dynamic_cast<AST_Array*>(actual);
199 array_helper(var_name, array, 0, idx, level, filter_kind);
200
201 } else if (c & CL_MAP) {
202 AST_Map* const map = dynamic_cast<AST_Map*>(actual);
203 map_helper(var_name, map, level, filter_kind);
204
205 } else if (c & CL_FIXED) {
206 be_global->impl_ <<
207 indent << "::ACE_CDR::Fixed fixed;\n" <<
208 indent << "if (!value_reader.read_fixed(fixed)) return false;\n" <<
209 indent << expression << " = ::OpenDDS::FaceTypes::Fixed(fixed);\n";
210
211 } else if (c & CL_STRING) {
212 be_global->impl_ <<
213 indent << "{\n" <<
214 indent << " " << ((c & CL_WIDE) ? "WString" : "String") << " x;\n" <<
215 indent << " if (!value_reader.read_" << ((c & CL_WIDE) ? "w" : "")
216 << "string(x)) return false;\n" <<
217 indent << " " << expression << accessor << " = x" << (use_cxx11 ? "" : ".c_str()")
218 << ";\n" <<
219 indent << "}\n";
220
221 } else if (c & CL_PRIMITIVE) {
222 const AST_PredefinedType::PredefinedType pt =
223 dynamic_cast<AST_PredefinedType*>(actual)->pt();

Callers 6

array_helperFunction · 0.85
sequence_helperFunction · 0.85
map_helperFunction · 0.85
branch_helperFunction · 0.85
gen_struct_iFunction · 0.85
gen_union_iFunction · 0.85

Calls 10

resolveActualTypeFunction · 0.85
classifyFunction · 0.85
scopedFunction · 0.85
language_mappingMethod · 0.80
sequence_helperFunction · 0.70
array_helperFunction · 0.70
map_helperFunction · 0.70
primitive_typeFunction · 0.70
sizeMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected