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

Function array_helper

dds/idl/value_reader_generator.cpp:68–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66 }
67
68 void array_helper(const std::string& expression, AST_Array* array, size_t dim_idx,
69 const std::string& idx, int level, FieldFilter filter_kind)
70 {
71 const bool use_cxx11 = be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
72 const std::string indent(size_t(level) * 2, ' ');
73 const Classification c = classify(array->base_type());
74 const bool primitive = c & CL_PRIMITIVE;
75 // When we have a primitive type the last dimension is read using the read_*_array
76 // operation, when we have a not primitive type the last dimension is read element by element
77 // in a loop in the generated code
78 const std::string elem_kind = type_kind(array->base_type());
79 if ((primitive && (dim_idx < array->n_dims() - 1)) || (!primitive && (dim_idx < array->n_dims()))) {
80 const size_t dim = array->dims()[dim_idx]->ev()->u.ulval;
81 be_global->impl_ <<
82 indent << "if (!value_reader.begin_array(" << elem_kind << ")) return false;\n" <<
83 indent << "for (" << (use_cxx11 ? "size_t " : "unsigned int ") << idx << " = 0; "
84 << idx << " != " << dim << "; ++" << idx << ") {\n" <<
85 indent << " if (!value_reader.begin_element()) return false;\n";
86 array_helper(expression + "[" + idx + "]", array, dim_idx + 1, idx + "i", level + 1, filter_kind);
87 be_global->impl_ <<
88 indent << " if (!value_reader.end_element()) return false;\n" <<
89 indent << "}\n" <<
90 indent << "if (!value_reader.end_array()) return false;\n";
91 } else {
92 if (primitive) {
93 const size_t dim = array->dims()[dim_idx]->ev()->u.ulval;
94 AST_Type* const actual = resolveActualType(array->base_type());
95 const AST_PredefinedType::PredefinedType pt =
96 dynamic_cast<AST_PredefinedType*>(actual)->pt();
97 be_global->impl_ <<
98 indent << "if (!value_reader.begin_array(" << elem_kind << ")) return false;\n";
99 be_global->impl_ << indent <<
100 "if (!value_reader.read_" << primitive_type(pt) << "_array (" << expression << (use_cxx11 ? ".data()" : "") << ", " << dim << ")) return false;\n";
101 be_global->impl_ <<
102 indent << "if (!value_reader.end_array()) return false;\n";
103
104 } else {
105 generate_read(expression, "", "elem", array->base_type(), idx, level, nested(filter_kind));
106 }
107 }
108 }
109
110 void sequence_helper(const std::string& expression, AST_Sequence* sequence,
111 const std::string& idx, int level, FieldFilter filter_kind)

Callers 1

generate_readFunction · 0.70

Calls 7

classifyFunction · 0.85
type_kindFunction · 0.85
resolveActualTypeFunction · 0.85
generate_readFunction · 0.85
language_mappingMethod · 0.80
primitive_typeFunction · 0.70
nestedFunction · 0.70

Tested by

no test coverage detected