18 #include <utl_identifier.h> 26 #define OPENDDS_IDL_STR(X) #X 34 const string RtpsNamespace =
" ::OpenDDS::RTPS::", DdsNamespace =
" ::DDS::";
36 typedef bool (*gen_special_case)(
const string& cxx);
37 typedef std::map<std::string, gen_special_case> SpecialCases;
38 SpecialCases special_struct_cases;
39 SpecialCases special_seq_cases;
41 typedef bool (*gen_special_union)(
const string& cxx,
43 AST_Type* discriminator,
44 const std::vector<AST_UnionBranch*>& branches);
45 typedef std::map<std::string, gen_special_union> SpecialUnionCases;
46 SpecialUnionCases special_union_cases;
48 bool genRtpsSpecialSequence(
const string& cxx);
49 bool genPropertySpecialSequence(
const string& cxx);
50 bool genRtpsSpecialStruct(
const string& cxx);
51 bool genRtpsParameter(
const string& cxx,
53 AST_Type* discriminator,
54 const std::vector<AST_UnionBranch*>& branches);
55 bool genRtpsSubmessage(
const string& cxx,
57 AST_Type* discriminator,
58 const std::vector<AST_UnionBranch*>& branches);
59 bool genProperty_t(
const string& cxx);
60 bool genBinaryProperty_t(
const string& cxx);
61 bool genPropertyQosPolicy(
const string& cxx);
62 bool genSecuritySubmessage(
const string& cxx);
64 void init_special_cases()
66 if (special_seq_cases.empty()) {
67 special_seq_cases[
"ParameterList"] = genRtpsSpecialSequence;
68 special_seq_cases[
"prop_seq"] = genPropertySpecialSequence;
70 if (special_struct_cases.empty()) {
71 special_struct_cases[
"rtps_set"] = genRtpsSpecialStruct;
72 special_struct_cases[
"Property_t"] = genProperty_t;
73 special_struct_cases[
"BinaryProperty_t"] = genBinaryProperty_t;
74 special_struct_cases[
"PropertyQosPolicy"] = genPropertyQosPolicy;
75 special_struct_cases[
"SecuritySubmessage"] = genSecuritySubmessage;
77 if (special_union_cases.empty()) {
78 special_union_cases[
"Parameter"] = genRtpsParameter;
79 special_union_cases[
"Submessage"] = genRtpsSubmessage;
83 bool generate_special_sequence(
84 AST_Typedef* typedef_node,
const std::string& cpp_name,
bool& result)
86 std::string template_name;
87 if (!
be_global->special_serialization(typedef_node, template_name)) {
92 SpecialCases::iterator it = special_seq_cases.find(template_name);
93 if (it == special_seq_cases.end()) {
95 std::string(
"Invalid special case sequence template name \"") +
96 template_name +
"\"", typedef_node);
99 result = (it->second)(cpp_name);
104 bool generate_special_struct(AST_Structure* node,
const std::string& cpp_name,
bool& result)
106 std::string template_name;
107 if (!
be_global->special_serialization(node, template_name)) {
111 init_special_cases();
112 SpecialCases::iterator it = special_struct_cases.find(template_name);
113 if (it == special_struct_cases.end()) {
115 std::string(
"Invalid special case struct template name \"") +
116 template_name +
"\"", node);
119 result = (it->second)(cpp_name);
124 bool generate_special_union(
const std::string& cpp_name, AST_Union* node,
125 AST_Type* disc_type,
const std::vector<AST_UnionBranch*>& branches,
bool& result)
127 std::string template_name;
128 if (!
be_global->special_serialization(node, template_name)) {
132 init_special_cases();
133 SpecialUnionCases::iterator it = special_union_cases.find(template_name);
134 if (it == special_union_cases.end()) {
136 std::string(
"Invalid special case struct template name \"") +
137 template_name +
"\"", node);
140 result = (it->second)(cpp_name, node, disc_type, branches);
145 string streamCommon(
const std::string& indent, AST_Decl* node,
const string&
name,
146 AST_Type* type,
const string& prefix,
bool wrap_nested_key_only,
147 Intro& intro,
const string& stru =
"");
149 const std::string construct_bound_fail =
150 "strm.get_construction_status() == Serializer::BoundConstructionFailure";
151 const std::string construct_elem_fail =
152 "strm.get_construction_status() == Serializer::ElementConstructionFailure";
156 const std::vector<AST_EnumVal*>& vals,
const char*)
159 be_global->add_include(
"dds/DCPS/Serializer.h");
160 string cxx =
scoped(name);
162 Function insertion(
"operator<<",
"bool");
163 insertion.
addArg(
"strm",
"Serializer&");
164 insertion.
addArg(
"enumval",
"const " + cxx +
"&");
168 " if (CORBA::ULong(enumval) >= " << vals.size() <<
") {\n" 169 " if (OpenDDS::DCPS::log_level >= OpenDDS::DCPS::LogLevel::Warning) {\n" 170 " ACE_ERROR((LM_WARNING, \"(%P|%t) WARNING: " 171 "%u is an invalid enumerated value for " << idl_name <<
"\\n\", enumval));\n" 175 " return strm << static_cast<CORBA::ULong>(enumval);\n";
178 Function extraction(
"operator>>",
"bool");
179 extraction.
addArg(
"strm",
"Serializer&");
180 extraction.
addArg(
"enumval", cxx +
"&");
183 " CORBA::ULong temp = 0;\n" 184 " if (strm >> temp) {\n" 185 " if (temp >= " << vals.size() <<
") {\n" 186 " strm.set_construction_status(Serializer::ElementConstructionFailure);\n" 189 " enumval = static_cast<" << cxx <<
">(temp);\n" 198 string getSizeExprPrimitive(AST_Type* type,
199 const string& count_expr =
"count",
const string& size_expr =
"size",
200 const string& encoding_expr =
"encoding")
202 if (type->node_type() != AST_Decl::NT_pre_defined) {
205 AST_PredefinedType* pt =
dynamic_cast<AST_PredefinedType*
>(type);
206 const string first_args = encoding_expr +
", " + size_expr;
208 case AST_PredefinedType::PT_octet:
209 return "primitive_serialized_size_octet(" + first_args +
", " + count_expr +
")";
210 case AST_PredefinedType::PT_char:
211 return "primitive_serialized_size_char(" + first_args +
", " + count_expr +
")";
212 case AST_PredefinedType::PT_wchar:
213 return "primitive_serialized_size_wchar(" + first_args +
", " + count_expr +
")";
214 case AST_PredefinedType::PT_boolean:
215 return "primitive_serialized_size_boolean(" + first_args +
", " + count_expr +
")";
216 #if OPENDDS_HAS_EXPLICIT_INTS 217 case AST_PredefinedType::PT_uint8:
218 return "primitive_serialized_size_uint8(" + first_args +
", " + count_expr +
")";
219 case AST_PredefinedType::PT_int8:
220 return "primitive_serialized_size_int8(" + first_args +
", " + count_expr +
")";
223 return "primitive_serialized_size(" + first_args +
", " +
224 scoped(type->name()) +
"(), " + count_expr +
")";
228 string getSerializerName(AST_Type* type)
230 switch (dynamic_cast<AST_PredefinedType*>(type)->pt()) {
231 case AST_PredefinedType::PT_long:
233 case AST_PredefinedType::PT_ulong:
235 case AST_PredefinedType::PT_short:
237 case AST_PredefinedType::PT_ushort:
239 #if OPENDDS_HAS_EXPLICIT_INTS 240 case AST_PredefinedType::PT_int8:
242 case AST_PredefinedType::PT_uint8:
245 case AST_PredefinedType::PT_octet:
247 case AST_PredefinedType::PT_char:
249 case AST_PredefinedType::PT_wchar:
251 case AST_PredefinedType::PT_float:
253 case AST_PredefinedType::PT_double:
255 case AST_PredefinedType::PT_longlong:
257 case AST_PredefinedType::PT_ulonglong:
259 case AST_PredefinedType::PT_longdouble:
261 case AST_PredefinedType::PT_boolean:
268 string nameOfSeqHeader(AST_Type* elem)
270 string ser = getSerializerName(elem);
272 ser[0] =
static_cast<char>(std::toupper(ser[0]));
274 if (ser[0] ==
'U' || ser[0] ==
'W') {
275 ser[1] =
static_cast<char>(std::toupper(ser[1]));
277 const size_t fourthLast = ser.size() - 4;
278 if (ser.size() > 7 && ser.substr(fourthLast) ==
"long") {
279 ser[fourthLast] =
static_cast<char>(std::toupper(ser[fourthLast]));
281 if (ser ==
"Longdouble")
return "LongDouble";
285 string streamAndCheck(
const string& expr,
size_t indent = 2)
287 string idt(indent,
' ');
288 return idt +
"if (!(strm " + expr +
")) {\n" +
289 idt +
" return false;\n" +
293 string checkAlignment(AST_Type* elem)
298 switch (dynamic_cast<AST_PredefinedType*>(elem)->pt()) {
299 case AST_PredefinedType::PT_longlong:
300 case AST_PredefinedType::PT_ulonglong:
301 case AST_PredefinedType::PT_double:
302 case AST_PredefinedType::PT_longdouble:
303 return " encoding.align(size, 8);\n";
309 bool genRtpsSpecialSequence(
const string& cxx)
313 serialized_size.
addArg(
"encoding",
"const Encoding&");
314 serialized_size.
addArg(
"size",
"size_t&");
315 serialized_size.
addArg(
"seq",
"const " + cxx +
"&");
318 " for (CORBA::ULong i = 0; i < seq.length(); ++i) {\n" 319 " if (seq[i]._d() == OpenDDS::RTPS::PID_SENTINEL) continue;\n" 320 " serialized_size(encoding, size, seq[i]);\n" 323 " size += 4; /* PID_SENTINEL */\n";
326 Function insertion(
"operator<<",
"bool");
327 insertion.
addArg(
"strm",
"Serializer&");
328 insertion.
addArg(
"seq",
"const " + cxx +
"&");
331 " for (CORBA::ULong i = 0; i < seq.length(); ++i) {\n" 332 " if (seq[i]._d() == OpenDDS::RTPS::PID_SENTINEL) continue;\n" 333 " if (!(strm << seq[i])) {\n" 337 " return (strm << OpenDDS::RTPS::PID_SENTINEL)\n" 338 " && (strm << OpenDDS::RTPS::PID_PAD);\n";
341 Function extraction(
"operator>>",
"bool");
342 extraction.
addArg(
"strm",
"Serializer&");
343 extraction.
addArg(
"seq", cxx +
"&");
347 " const CORBA::ULong idx = OpenDDS::DCPS::grow(seq) - 1;\n" 348 " if (!(strm >> seq[idx])) {\n" 351 " if (seq[idx]._d() == OpenDDS::RTPS::PID_SENTINEL) {\n" 352 " seq.length(idx);\n" 360 bool genPropertySpecialSequence(
const string& cxx)
364 serialized_size.
addArg(
"encoding",
"const Encoding&");
365 serialized_size.
addArg(
"size",
"size_t&");
366 serialized_size.
addArg(
"seq",
"const " + cxx +
"&");
369 " primitive_serialized_size_ulong(encoding, size);\n" 370 " for (CORBA::ULong i = 0; i < seq.length(); ++i) {\n" 371 " serialized_size(encoding, size, seq[i]);\n" 375 Function insertion(
"operator<<",
"bool");
376 insertion.
addArg(
"strm",
"Serializer&");
377 insertion.
addArg(
"seq",
"const " + cxx +
"&");
380 " CORBA::ULong serlen = 0;\n" 381 " for (CORBA::ULong i = 0; i < seq.length(); ++i) {\n" 382 " if (seq[i].propagate) {\n" 386 " if (!(strm << serlen)) {\n" 389 " for (CORBA::ULong i = 0; i < seq.length(); ++i) {\n" 390 " if (!(strm << seq[i])) {\n" 397 Function extraction(
"operator>>",
"bool");
398 extraction.
addArg(
"strm",
"Serializer&");
399 extraction.
addArg(
"seq", cxx +
"&");
402 " CORBA::ULong length;\n" 403 " if (!(strm >> length)) {\n" 406 " if (length > strm.length()) {\n" 409 " seq.length(length);\n" 410 " for (CORBA::ULong i = 0; i < length; ++i) {\n" 411 " if (!(strm >> seq[i])) {\n" 420 void skip_to_end_sequence(
const std::string indent,
421 std::string start, std::string end, std::string seq_type_name,
424 std::string elem_type_name = seq_type_name +
"::value_type";
428 elem_type_name = use_cxx11 ?
"std::wstring" :
"CORBA::WString_var";
430 elem_type_name = use_cxx11 ?
"std::string" :
"CORBA::String_var";
434 std::string tempvar =
"tempvar";
436 indent <<
"if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2) {\n" <<
437 indent <<
" strm.skip(end_of_seq - strm.rpos());\n" <<
438 indent <<
"} else {\n";
440 const bool classic_array_copy = !use_cxx11 && (cls &
CL_ARRAY);
442 if (!classic_array_copy) {
444 indent <<
" " << elem_type_name <<
" " << tempvar <<
";\n";
447 std::string stream_to = tempvar;
448 if (cls & CL_STRING) {
451 const string args = stream_to + (use_cxx11 ?
", " :
".out(), ") +
bounded_arg(elem);
457 classic_array_copy ? tempvar : stream_to,
false);
459 wrapper.
done(&intro);
460 stream_to = wrapper.
ref();
465 indent <<
" for (CORBA::ULong j = " << start <<
" + 1; j < " << end <<
"; ++j) {\n" <<
466 indent <<
" strm >> " << stream_to <<
";\n" <<
471 void skip_to_end_array(
const std::string& indent)
474 indent <<
"if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2) {\n" <<
475 indent <<
" strm.set_construction_status(Serializer::ElementConstructionFailure);\n" <<
476 indent <<
" strm.skip(end_of_arr - strm.rpos());\n" <<
477 indent <<
" return false;\n" <<
478 indent <<
"} else {\n" <<
479 indent <<
" strm.set_construction_status(Serializer::ConstructionSuccessful);\n" <<
480 indent <<
" discard_flag = true;\n" <<
485 UTL_ScopedName* tdname, AST_Sequence* seq,
bool nested_key_only, AST_Typedef* typedef_node = 0,
488 be_global->add_include(
"dds/DCPS/Util.h");
489 be_global->add_include(
"dds/DCPS/Serializer.h");
491 seq =
dynamic_cast<AST_Sequence*
>(anonymous->type_);
493 const std::string named_as = anonymous ? anonymous->scoped_type_ :
scoped(tdname);
494 RefWrapper base_wrapper(seq, named_as,
"seq");
502 if (generate_special_sequence(typedef_node, base_wrapper.
type_name_, special_result)) {
512 if (!elem->in_main_file()) {
513 if (elem->node_type() == AST_Decl::NT_pre_defined) {
514 if (
be_global->language_mapping() != BE_GlobalData::LANGMAP_FACE_CXX &&
515 be_global->language_mapping() != BE_GlobalData::LANGMAP_SP_CXX) {
516 const std::string hdr =
"dds/CorbaSeq/" + nameOfSeqHeader(elem) +
"SeqTypeSupportImpl.h";
517 be_global->conditional_include(hdr.c_str(), BE_GlobalData::STREAM_CPP,
518 "#ifndef OPENDDS_SAFETY_PROFILE");
521 be_global->add_referenced(elem->file_name().c_str());
525 const std::string cxx_elem =
527 const bool use_cxx11 =
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
534 wrapper.
done(&intro);
535 const std::string value_access = wrapper.
value_access();
539 serialized_size.
addArg(
"encoding",
"const Encoding&");
540 serialized_size.
addArg(
"size",
"size_t&");
550 " primitive_serialized_size_ulong(encoding, size);\n" 551 " if (" << check_empty <<
") {\n" 558 " primitive_serialized_size_ulong(encoding, size, " + get_length +
");\n";
559 }
else if (elem_cls & CL_PRIMITIVE) {
560 be_global->impl_ << checkAlignment(elem) <<
561 " " + getSizeExprPrimitive(elem, get_length) <<
";\n";
562 }
else if (elem_cls & CL_INTERFACE) {
564 " // sequence of objrefs is not marshaled\n";
567 " // sequence of unknown/unsupported type\n";
570 " for (CORBA::ULong i = 0; i < " << get_length <<
"; ++i) {\n";
573 " primitive_serialized_size_ulong(encoding, size);\n";
574 const string strlen_suffix = (elem_cls &
CL_WIDE)
575 ?
" * char16_cdr_size;\n" :
" + 1;\n";
578 " size += " + value_access +
"[i].size()" << strlen_suffix;
581 " if (" + value_access +
"[i]) {\n" 582 " size += ACE_OS::strlen(" + value_access +
"[i])" << strlen_suffix <<
586 RefWrapper elem_wrapper(elem, cxx_elem, value_access +
"[i]");
589 elem_wrapper.
done(&intro);
590 const std::string indent =
" ";
593 indent <<
"serialized_size(encoding, size, " << elem_wrapper.
ref() <<
");\n";
603 wrapper.
done(&intro);
604 const std::string value_access = wrapper.
value_access();
608 Function insertion(
"operator<<",
"bool");
609 insertion.
addArg(
"strm",
"Serializer&");
615 " const Encoding& encoding = strm.encoding();\n" 616 " ACE_UNUSED_ARG(encoding);\n";
618 " serialized_size(encoding, total_size, seq);\n" 619 " if (!strm.write_delimiter(total_size)) {\n" 626 " const CORBA::ULong length = " << get_length <<
";\n";
627 if (!seq->unbounded()) {
634 streamAndCheck(
"<< length") <<
635 " if (length == 0) {\n" 640 if (elem_cls & CL_PRIMITIVE) {
641 AST_PredefinedType* predef =
dynamic_cast<AST_PredefinedType*
>(elem);
642 if (use_cxx11 && predef->pt() == AST_PredefinedType::PT_boolean) {
644 " for (CORBA::ULong i = 0; i < length; ++i) {\n" <<
645 streamAndCheck(
"<< ACE_OutputCDR::from_boolean(" + value_access +
"[i])", 4) <<
650 " return strm.write_" << getSerializerName(elem)
651 <<
"_array(" << get_buffer <<
", length);\n";
653 }
else if (elem_cls & CL_INTERFACE) {
655 " return false; // sequence of objrefs is not marshaled\n";
658 " return false; // sequence of unknown/unsupported type\n";
661 " for (CORBA::ULong i = 0; i < length; ++i) {\n";
663 const string args = value_access +
"[i], " +
bounded_arg(elem);
667 RefWrapper elem_wrapper(elem, cxx_elem, value_access +
"[i]");
670 elem_wrapper.
done(&intro);
672 be_global->impl_ << streamAndCheck(
"<< " + elem_wrapper.
ref(), 4);
684 wrapper.
done(&intro);
685 const std::string value_access = wrapper.
value_access();
689 Function extraction(
"operator>>",
"bool");
690 extraction.
addArg(
"strm",
"Serializer&");
696 " const Encoding& encoding = strm.encoding();\n" 697 " ACE_UNUSED_ARG(encoding);\n";
699 " if (!strm.read_delimiter(total_size)) {\n" 704 be_global->impl_ <<
" const size_t end_of_seq = strm.rpos() + total_size;\n";
707 " CORBA::ULong length;\n" 708 << streamAndCheck(
">> length");
711 " if (length > strm.length()) {\n" 712 " if (DCPS_debug_level >= 8) {\n" 713 " ACE_DEBUG((LM_DEBUG, ACE_TEXT(\"(%P|%t) Invalid sequence length (%u)\\n\"), length));\n" 719 AST_PredefinedType* predef =
dynamic_cast<AST_PredefinedType*
>(elem);
721 if (!seq->unbounded()) {
722 bound = use_cxx11 ?
bounded_arg(seq) : value_access +
".maximum()";
728 if ((elem_cls & CL_INTERFACE) == 0) {
729 be_global->impl_ <<
" CORBA::ULong new_length = length;\n";
732 if (elem_cls & CL_PRIMITIVE) {
734 if (!seq->unbounded()) {
736 " if (length > " << bound <<
") {\n" 737 " new_length = " << bound <<
";\n" 740 if (use_cxx11 && predef->pt() == AST_PredefinedType::PT_boolean) {
742 " for (CORBA::ULong i = 0; i < new_length; ++i) {\n" 744 streamAndCheck(
">> ACE_InputCDR::to_boolean(b)", 4) <<
745 " " + value_access +
"[i] = b;\n" 749 " strm.read_" << getSerializerName(elem) <<
"_array(" << get_buffer <<
", new_length);\n";
752 " if (new_length != length) {\n" 753 " size_t skip_length = 0;\n" 754 " " << getSizeExprPrimitive(elem,
"(length - new_length)",
"skip_length",
"encoding") <<
";\n" 755 " strm.set_construction_status(Serializer::BoundConstructionFailure);\n" 756 " strm.skip(skip_length);\n" 762 if (use_cxx11 && predef->pt() == AST_PredefinedType::PT_boolean) {
764 " for (CORBA::ULong i = 0; i < length; ++i) {\n" 766 streamAndCheck(
">> ACE_InputCDR::to_boolean(b)", 4) <<
767 " " << value_access <<
"[i] = b;\n" 772 " if (length == 0) {\n" 775 " return strm.read_" << getSerializerName(elem)
776 <<
"_array(" << get_buffer <<
", length);\n";
779 }
else if (elem_cls & CL_INTERFACE) {
781 " return false; // sequence of objrefs is not marshaled\n";
785 " return false; // sequence of unknown/unsupported type\n";
788 const std::string elem_access = value_access +
"[i]";
789 if (!seq->unbounded()) {
791 " if (length > " << (use_cxx11 ?
bounded_arg(seq) : value_access +
".maximum()") <<
") {\n" 792 " new_length = " << bound <<
";\n" 800 " for (CORBA::ULong i = 0; i < new_length; ++i) {\n";
803 std::string stream_to;
804 std::string classic_array_copy;
805 if (!use_cxx11 && (elem_cls &
CL_ARRAY)) {
809 classic_array_wrapper.
done(&intro);
811 stream_to = classic_array_wrapper.
ref();
814 const string args = elem_access + (use_cxx11 ?
", " :
".out(), ") +
bounded_arg(elem);
817 const string getbuffer =
818 (
be_global->language_mapping() == BE_GlobalData::LANGMAP_NONE)
819 ?
".get_buffer()" :
"";
820 stream_to = value_access + getbuffer +
"[i]";
823 RefWrapper elem_wrapper(elem, cxx_elem, value_access +
"[i]",
false);
825 elem_wrapper.
done(&intro);
826 stream_to = elem_wrapper.
ref();
828 const std::string indent =
" ";
831 indent <<
" if (!(strm >> " << stream_to <<
")) {\n";
836 " strm.set_construction_status(Serializer::ConstructionSuccessful);\n";
839 if (elem_cls & CL_STRING){
840 const std::string check_not_empty =
841 use_cxx11 ?
"!" + elem_access +
".empty()" : elem_access +
".in()";
842 const std::string get_length =
843 use_cxx11 ? elem_access +
".length()" :
"ACE_OS::strlen(" + elem_access +
".in())";
844 const string inout = use_cxx11 ?
"" :
".inout()";
846 " if (" + construct_bound_fail +
" && " << check_not_empty <<
" && (" <<
847 bounded_arg(elem) <<
" < " << get_length <<
")) {\n" 848 " " << elem_access << inout <<
850 " strm.set_construction_status(Serializer::ConstructionSuccessful);\n" 852 " strm.set_construction_status(Serializer::ElementConstructionFailure);\n";
853 skip_to_end_sequence(
" ",
"i",
"length", named_as, use_cxx11, elem_cls, seq);
859 " if (" + construct_elem_fail +
") {\n";
860 skip_to_end_sequence(
" ",
"i",
"length", named_as, use_cxx11, elem_cls, seq);
864 " strm.set_construction_status(Serializer::ConstructionSuccessful);\n";
869 " strm.set_construction_status(Serializer::ElementConstructionFailure);\n";
870 skip_to_end_sequence(
" ",
"i",
"length", named_as, use_cxx11, elem_cls, seq);
876 if (classic_array_copy.size()) {
878 " " << classic_array_copy <<
"\n";
884 " if (new_length != length) {\n";
885 skip_to_end_sequence(
" ",
"new_length",
"length", named_as, use_cxx11, elem_cls, seq);
887 " strm.set_construction_status(Serializer::BoundConstructionFailure);\n" 896 void gen_sequence(UTL_ScopedName*
name, AST_Typedef* typedef_node, AST_Sequence* seq)
898 gen_sequence_i(name, seq,
false, typedef_node);
900 gen_sequence_i(name, seq,
true, typedef_node);
904 void gen_anonymous_sequence(
const FieldInfo& sf)
906 gen_sequence_i(0, 0,
false, 0, &sf);
908 gen_sequence_i(0, 0,
true, 0, &sf);
913 UTL_ScopedName* name, AST_Array* arr,
bool nested_key_only,
const FieldInfo* anonymous = 0)
915 be_global->add_include(
"dds/DCPS/Serializer.h");
917 arr =
dynamic_cast<AST_Array*
>(anonymous->type_);
919 const std::string named_as = anonymous ? anonymous->scoped_type_ :
scoped(name);
920 RefWrapper base_wrapper(arr, named_as,
"arr");
924 const bool use_cxx11 =
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
930 if (!elem->in_main_file()
931 && elem->node_type() != AST_Decl::NT_pre_defined) {
932 be_global->add_referenced(elem->file_name().c_str());
934 const std::string cxx_elem =
940 if (!nested_key_only) {
956 serialized_size.
addArg(
"encoding",
"const Encoding&");
957 serialized_size.
addArg(
"size",
"size_t&");
965 " primitive_serialized_size_ulong(encoding, size, " << n_elems <<
");\n";
966 }
else if (elem_cls & CL_PRIMITIVE) {
967 std::ostringstream n_elems_ss;
968 n_elems_ss << n_elems;
970 " " << getSizeExprPrimitive(elem, n_elems_ss.str()) <<
";\n";
976 indent <<
"primitive_serialized_size_ulong(encoding, size);\n" <<
982 << nfl.
index_ <<
".in())";
984 be_global->impl_ << ((elem_cls &
CL_WIDE) ?
" * char16_cdr_size;\n" :
" + 1;\n");
989 elem_wrapper.done(&intro);
992 indent <<
"serialized_size(encoding, size, " << elem_wrapper.ref() <<
");\n";
1000 Function insertion(
"operator<<",
"bool");
1001 insertion.
addArg(
"strm",
"Serializer&");
1006 " const Encoding& encoding = strm.encoding();\n" 1007 " ACE_UNUSED_ARG(encoding);\n";
1010 "serialized_size(encoding, total_size, arr);" 1011 "if (!strm.write_delimiter(total_size)) {" 1014 const std::string accessor = wrapper.
value_access() + (use_cxx11 ?
".data()" :
".in()");
1015 if (elem_cls & CL_PRIMITIVE) {
1017 for (
unsigned int i = 1; i < arr->n_dims(); ++i)
1018 suffix += use_cxx11 ?
"->data()" :
"[0]";
1020 " return strm.write_" << getSerializerName(elem)
1021 <<
"_array(" << accessor << suffix <<
", " << n_elems <<
");\n";
1024 string indent =
" ";
1029 elem_wrapper.done(&intro);
1031 be_global->impl_ << streamAndCheck(
"<< " + elem_wrapper.ref(), indent.size());
1041 Function extraction(
"operator>>",
"bool");
1042 extraction.
addArg(
"strm",
"Serializer&");
1047 be_global->impl_ <<
" bool discard_flag = false;\n";
1050 " const Encoding& encoding = strm.encoding();\n" 1051 " ACE_UNUSED_ARG(encoding);\n";
1053 " if (!strm.read_delimiter(total_size)) {\n" 1055 " }\n", !primitive);
1058 be_global->impl_ <<
" const size_t end_of_arr = strm.rpos() + total_size;\n";
1061 const std::string accessor = wrapper.
value_access() + (use_cxx11 ?
".data()" :
".out()");
1064 for (
unsigned int i = 1; i < arr->n_dims(); ++i)
1065 suffix += use_cxx11 ?
"->data()" :
"[0]";
1067 " return strm.read_" << getSerializerName(elem)
1068 <<
"_array(" << accessor << suffix <<
", " << n_elems <<
");\n";
1071 string indent =
" ";
1077 std::string classic_array_copy;
1078 if (!use_cxx11 && (elem_cls &
CL_ARRAY)) {
1083 classic_array_wrapper.done(&intro);
1084 classic_array_copy = classic_array_wrapper.classic_array_copy();
1085 stream =
"(strm >> " + classic_array_wrapper.ref() +
")";
1087 stream = streamCommon(
1088 indent, 0,
"", arr->base_type(),
">> " + elem_access, nested_key_only, intro);
1092 indent <<
"if (!" << stream <<
") {\n";
1098 indent <<
"strm.set_construction_status(Serializer::ConstructionSuccessful);\n";
1102 const std::string check_not_empty =
1103 use_cxx11 ?
"!" + elem_access +
".empty()" : elem_access +
".in()";
1104 const std::string get_length =
1105 use_cxx11 ? elem_access +
".length()" :
"ACE_OS::strlen(" + elem_access +
".in())";
1106 const string inout = use_cxx11 ?
"" :
".inout()";
1108 indent <<
"if (" << construct_bound_fail <<
" && " <<
1109 check_not_empty <<
" && (" <<
bounded_arg(elem) <<
" < " << get_length <<
")) {\n" <<
1112 indent <<
" strm.set_construction_status(Serializer::ConstructionSuccessful);\n" <<
1113 indent <<
"} else {\n";
1114 skip_to_end_array(indent);
1119 indent <<
"if (" + construct_elem_fail +
") {\n";
1120 skip_to_end_array(indent);
1122 indent <<
"} else {\n" <<
1123 indent <<
" strm.set_construction_status(Serializer::ConstructionSuccessful);\n" <<
1128 skip_to_end_array(indent);
1130 if (classic_array_copy.size()) {
1132 indent <<
"} else {\n" <<
1133 indent <<
" " << classic_array_copy <<
"\n";
1140 " if (discard_flag) {\n" 1141 " strm.set_construction_status(Serializer::ElementConstructionFailure);\n" 1149 void gen_array(UTL_ScopedName* name, AST_Array* arr)
1151 gen_array_i(name, arr,
false);
1153 gen_array_i(name, arr,
true);
1157 void gen_anonymous_array(
const FieldInfo& af)
1159 gen_array_i(0, 0,
false, &af);
1161 gen_array_i(0, 0,
true, &af);
1169 AST_Type* find_type_i(AST_Structure* struct_node,
const string&
key)
1171 string key_base = key;
1173 bool is_array =
false;
1174 size_t pos = key.find_first_of(
".[");
1175 if (pos != string::npos) {
1176 key_base = key.substr(0, pos);
1177 if (key[pos] ==
'[') {
1179 size_t l_brack = key.find(
"]");
1180 if (l_brack == string::npos) {
1181 throw string(
"Missing right bracket");
1182 }
else if (l_brack != key.length()) {
1183 key_rem = key.substr(l_brack+1);
1186 key_rem = key.substr(pos+1);
1190 const Fields fields(struct_node);
1193 AST_Field*
const field = *i;
1194 if (key_base == field->local_name()->get_string()) {
1196 if (!is_array && key_rem.empty()) {
1200 AST_Structure* sub_struct =
dynamic_cast<AST_Structure*
>(field_type);
1201 if (sub_struct != 0) {
1202 throw string(
"Structs not allowed as keys");
1204 AST_Array* array_node =
dynamic_cast<AST_Array*
>(field_type);
1205 if (array_node != 0) {
1206 throw string(
"Arrays not allowed as keys");
1209 }
else if (is_array) {
1211 AST_Array* array_node =
dynamic_cast<AST_Array*
>(field_type);
1212 if (array_node == 0) {
1213 throw string(
"Indexing for non-array type");
1215 if (array_node->n_dims() > 1) {
1216 throw string(
"Only single dimension arrays allowed in keys");
1218 if (key_rem ==
"") {
1219 return array_node->base_type();
1222 if ((key_rem[0] !=
'.') || (key_rem.length() == 1)) {
1223 throw string(
"Unexpected characters after array index");
1227 key_rem = key_rem.substr(1);
1228 field_type = array_node->base_type();
1234 AST_Structure* sub_struct =
dynamic_cast<AST_Structure*
>(field_type);
1235 if (sub_struct == 0) {
1236 throw string(
"Expected structure field for ") + key_base;
1240 return find_type_i(sub_struct, key_rem);
1243 throw string(
"Field not found.");
1246 AST_Type* find_type(AST_Structure* struct_node,
const string& key)
1249 return find_type_i(struct_node, key);
1250 }
catch (
const string& error) {
1251 const std::string struct_name =
scoped(struct_node->name());
1253 "Invalid key specification for " + struct_name +
" (" + key +
"): " + error,
1261 bool bounded =
true;
1262 static std::vector<AST_Type*> type_stack;
1264 for (
size_t i = 0; i < type_stack.size(); ++i) {
1266 if (type == type_stack[i])
return false;
1268 type_stack.push_back(type);
1281 const Fields fields(dynamic_cast<AST_Structure*>(type));
1284 if (!is_bounded_type((*i)->field_type(),
encoding)) {
1291 if (fld_cls & CL_BOUNDED) {
1292 AST_Sequence* seq_node =
dynamic_cast<AST_Sequence*
>(type);
1293 if (!is_bounded_type(seq_node->base_type(),
encoding)) bounded =
false;
1298 AST_Array* array_node =
dynamic_cast<AST_Array*
>(type);
1299 if (!is_bounded_type(array_node->base_type(),
encoding)) bounded =
false;
1309 const Fields fields(dynamic_cast<AST_Union*>(type));
1312 if (!is_bounded_type((*i)->field_type(),
encoding)) {
1319 type_stack.pop_back();
1326 static std::vector<AST_Type*> type_stack;
1329 for (
size_t i = 0; i < type_stack.size(); ++i) {
1333 type_stack.push_back(type);
1339 type_stack.pop_back();
1343 const Fields fields(fld_cls &
CL_STRUCTURE ? dynamic_cast<AST_Structure*>(type) : dynamic_cast<AST_Union*>(type));
1348 type_stack.pop_back();
1351 if (exten < this_exten) {
1355 type_stack.pop_back();
1358 type_stack.pop_back();
1359 return max_extensibility_kind(dynamic_cast<AST_Array*>(type)->base_type());
1361 type_stack.pop_back();
1362 return max_extensibility_kind(dynamic_cast<AST_Sequence*>(type)->base_type());
1364 type_stack.pop_back();
1376 case Encoding::KIND_XCDR1:
1377 return "Encoding::XCDR_VERSION_1";
1378 case Encoding::KIND_XCDR2:
1379 return "Encoding::XCDR_VERSION_2";
1381 return "Encoding::XCDR_VERSION_NONE";
1392 case Encoding::KIND_XCDR1:
1393 return "Encoding::KIND_XCDR1";
1394 case Encoding::KIND_XCDR2:
1395 return "Encoding::KIND_XCDR2";
1397 return "Encoding::KIND_UNALIGNED_CDR";
1404 enc.
align(value, by);
1407 void idl_max_serialized_size_dheader(
1411 align(encoding, size, 4);
1416 void idl_max_serialized_size(
Encoding::Kind encoding,
size_t& size, AST_Type* type);
1420 void idl_max_serialized_size_repeating(
1425 idl_max_serialized_size(encoding, size, type);
1430 const size_t prev_size = size;
1431 idl_max_serialized_size(encoding, size, type);
1432 size += (n - 2) * (size - prev_size);
1437 void idl_max_serialized_size(
Encoding::Kind encoding,
size_t& size, AST_Type* type)
1441 switch (type->node_type()) {
1442 case AST_Decl::NT_pre_defined: {
1443 AST_PredefinedType* p =
dynamic_cast<AST_PredefinedType*
>(type);
1445 case AST_PredefinedType::PT_char:
1446 case AST_PredefinedType::PT_boolean:
1447 case AST_PredefinedType::PT_octet:
1448 #if OPENDDS_HAS_EXPLICIT_INTS 1449 case AST_PredefinedType::PT_uint8:
1450 case AST_PredefinedType::PT_int8:
1454 case AST_PredefinedType::PT_short:
1455 case AST_PredefinedType::PT_ushort:
1456 align(encoding, size, 2);
1459 case AST_PredefinedType::PT_wchar:
1460 align(encoding, size, 2);
1463 case AST_PredefinedType::PT_long:
1464 case AST_PredefinedType::PT_ulong:
1465 case AST_PredefinedType::PT_float:
1466 align(encoding, size, 4);
1469 case AST_PredefinedType::PT_longlong:
1470 case AST_PredefinedType::PT_ulonglong:
1471 case AST_PredefinedType::PT_double:
1472 align(encoding, size, 8);
1475 case AST_PredefinedType::PT_longdouble:
1476 align(encoding, size, 16);
1485 case AST_Decl::NT_enum:
1486 align(encoding, size, 4);
1489 case AST_Decl::NT_string:
1490 case AST_Decl::NT_wstring: {
1491 AST_String* string_node =
dynamic_cast<AST_String*
>(type);
1492 align(encoding, size, 4);
1494 const int width = (string_node->width() == 1) ? 1 : 2 ;
1495 size += width * string_node->max_size()->ev()->u.ulval;
1496 if (type->node_type() == AST_Decl::NT_string) {
1501 case AST_Decl::NT_struct: {
1502 const Fields fields(dynamic_cast<AST_Structure*>(type));
1504 idl_max_serialized_size_dheader(encoding, exten, size);
1507 idl_max_serialized_size(encoding, size, (*i)->field_type());
1511 case AST_Decl::NT_sequence: {
1512 AST_Sequence* seq_node =
dynamic_cast<AST_Sequence*
>(type);
1513 AST_Type* base_node = seq_node->base_type();
1514 idl_max_serialized_size_dheader(encoding, exten, size);
1515 size_t bound = seq_node->max_size()->ev()->u.ulval;
1516 align(encoding, size, 4);
1518 idl_max_serialized_size_repeating(encoding, size, base_node, bound);
1521 case AST_Decl::NT_array: {
1522 AST_Array* array_node =
dynamic_cast<AST_Array*
>(type);
1523 AST_Type* base_node = array_node->base_type();
1524 idl_max_serialized_size_dheader(encoding, exten, size);
1525 idl_max_serialized_size_repeating(
1529 case AST_Decl::NT_union: {
1530 AST_Union* union_node =
dynamic_cast<AST_Union*
>(type);
1531 idl_max_serialized_size_dheader(encoding, exten, size);
1533 idl_max_serialized_size(encoding, size, union_node->disc_type());
1534 size_t largest_field_size = 0;
1535 const size_t starting_size = size;
1536 const Fields fields(union_node);
1539 idl_max_serialized_size(encoding, size, (*i)->field_type());
1540 size_t field_size = size - starting_size;
1541 if (field_size > largest_field_size) {
1542 largest_field_size = field_size;
1545 size = starting_size;
1547 size += largest_field_size;
1559 switch (base->node_type()) {
1560 case AST_Decl::NT_sequence:
1561 gen_sequence(name, node, dynamic_cast<AST_Sequence*>(base));
1563 case AST_Decl::NT_array:
1564 gen_array(name, dynamic_cast<AST_Array*>(base));
1574 string findSizeCommon(
const std::string& indent, AST_Decl*field,
const string&
name,
1575 AST_Type* type,
const string& prefix,
bool wrap_nested_key_only,
1576 Intro& intro,
const string& =
"")
1578 const bool use_cxx11 =
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
1579 const bool is_union_member = prefix ==
"uni";
1587 return indent +
"primitive_serialized_size_ulong(encoding, size);\n";
1589 const string suffix = is_union_member ?
"" :
".in()";
1590 const string get_size = use_cxx11 ? (qual +
".size()")
1591 : (
"ACE_OS::strlen(" + qual + suffix +
")");
1592 return indent +
"primitive_serialized_size_ulong(encoding, size);\n" +
1593 indent +
"size += " + get_size
1594 + ((fld_cls &
CL_WIDE) ?
" * char16_cdr_size;\n" 1597 AST_PredefinedType*
const p =
dynamic_cast<AST_PredefinedType*
>(actual_type);
1598 if (p->pt() == AST_PredefinedType::PT_longdouble) {
1601 "primitive_serialized_size(encoding, size, ACE_CDR::LongDouble());\n";
1603 return indent +
"primitive_serialized_size(encoding, size, " +
1611 wrapper.
done(&intro);
1612 return indent +
"serialized_size(encoding, size, " + wrapper.
ref() +
");\n";
1616 string findSizeMutableUnion(
const string& indent, AST_Decl* node,
const string& name, AST_Type* type,
1617 const string& prefix,
bool wrap_nested_key_only,
Intro& intro,
1618 const string & =
"")
1620 return indent +
"serialized_size_parameter_id(encoding, size, mutable_running_total);\n" 1621 + findSizeCommon(indent, node, name, type, prefix, wrap_nested_key_only, intro);
1624 std::string generate_field_serialized_size(
1625 const std::string& indent, AST_Field* field,
const std::string& prefix,
1626 bool wrap_nested_key_only,
Intro& intro)
1633 wrapper.
done(&intro);
1634 return indent +
"serialized_size(encoding, size, " + wrapper.
ref() +
");\n";
1636 return findSizeCommon(
1637 indent, field, field->local_name()->get_string(), field->field_type(), prefix,
1638 wrap_nested_key_only, intro);
1642 string streamCommon(
const std::string& , AST_Decl* field,
const string& name,
1643 AST_Type* type,
const string& prefix,
bool wrap_nested_key_only,
Intro& intro,
1646 const bool use_cxx11 =
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
1647 const bool is_union_member = prefix.substr(3) ==
"uni";
1654 if (qual[qual.length() - 1] ==
'.') {
1655 qual.erase(qual.length() - 1);
1657 const string shift = prefix.substr(0, 2),
1658 expr = qual.substr(3);
1663 const string args = expr + (use_cxx11 ?
", " :
".out(), ") +
bounded_arg(actual_type);
1666 return "(strm " + qual + (use_cxx11 ?
"" :
".out()") +
')';
1668 return "(strm " + shift +
' ' +
getWrapper(expr, actual_type, dir) +
')';
1671 std::cerr <<
"WARNING: field " << name <<
" can not be serialized. " 1672 "The struct or union it belongs to (" << stru <<
1673 ") can not be used in an OpenDDS topic type." << std::endl;
1678 const bool accessor = local.size() > 2 && local.substr(local.size() - 2) ==
"()";
1679 if (fld_cls & CL_STRING) {
1680 if (!accessor && !use_cxx11) {
1684 const string args = (fieldref +
'.' + local).substr(3) +
", " +
bounded_arg(actual_type);
1691 wrapper.
done(&intro);
1692 return "(strm " + shift +
" " + wrapper.
ref() +
")";
1696 std::string generate_field_stream(
1697 const std::string& indent, AST_Field* field,
const std::string& prefix,
1698 bool wrap_nested_key_only,
Intro& intro)
1705 wrapper.
done(&intro);
1706 return "(strm " + wrapper.
stream() +
")";
1708 return streamCommon(
1709 indent, field, field->local_name()->get_string(), field->field_type(), prefix,
1710 wrap_nested_key_only, intro);
1713 bool genBinaryProperty_t(
const string& cxx)
1717 serialized_size.
addArg(
"encoding",
"const Encoding&");
1718 serialized_size.
addArg(
"size",
"size_t&");
1719 serialized_size.
addArg(
"stru",
"const " + cxx +
"&");
1722 " if (stru.propagate) {\n" 1723 " primitive_serialized_size_ulong(encoding, size);\n" 1724 " size += ACE_OS::strlen(stru.name.in()) + 1;\n" 1725 " serialized_size(encoding, size, stru.value);\n" 1729 Function insertion(
"operator<<",
"bool");
1730 insertion.
addArg(
"strm",
"Serializer&");
1731 insertion.
addArg(
"stru",
"const " + cxx +
"&");
1734 " if (stru.propagate) {\n" 1735 " return (strm << stru.name.in()) && (strm << stru.value);\n" 1740 Function extraction(
"operator>>",
"bool");
1741 extraction.
addArg(
"strm",
"Serializer&");
1742 extraction.
addArg(
"stru", cxx +
"&");
1745 " stru.propagate = true;\n" 1746 " return (strm >> stru.name.out()) && (strm >> stru.value);\n";
1751 bool genProperty_t(
const string& cxx)
1755 serialized_size.
addArg(
"encoding",
"const Encoding&");
1756 serialized_size.
addArg(
"size",
"size_t&");
1757 serialized_size.
addArg(
"stru",
"const " + cxx +
"&");
1760 " if (stru.propagate) {\n" 1761 " primitive_serialized_size_ulong(encoding, size);\n" 1762 " size += ACE_OS::strlen(stru.name.in()) + 1;\n" 1763 " primitive_serialized_size_ulong(encoding, size);\n" 1764 " size += ACE_OS::strlen(stru.value.in()) + 1;\n" 1768 Function insertion(
"operator<<",
"bool");
1769 insertion.
addArg(
"strm",
"Serializer&");
1770 insertion.
addArg(
"stru",
"const " + cxx +
"&");
1773 " if (stru.propagate) {\n" 1774 " return (strm << stru.name.in()) && (strm << stru.value.in());\n" 1779 Function extraction(
"operator>>",
"bool");
1780 extraction.
addArg(
"strm",
"Serializer&");
1781 extraction.
addArg(
"stru", cxx +
"&");
1784 " stru.propagate = true;\n" 1785 " return (strm >> stru.name.out()) && (strm >> stru.value.out());\n";
1790 bool genPropertyQosPolicy(
const string& cxx)
1794 serialized_size.
addArg(
"encoding",
"const Encoding&");
1795 serialized_size.
addArg(
"size",
"size_t&");
1796 serialized_size.
addArg(
"stru",
"const " + cxx +
"&");
1799 " serialized_size(encoding, size, stru.value);\n" 1800 " serialized_size(encoding, size, stru.binary_value);\n";
1803 Function insertion(
"operator<<",
"bool");
1804 insertion.
addArg(
"strm",
"Serializer&");
1805 insertion.
addArg(
"stru",
"const " + cxx +
"&");
1808 " return (strm << stru.value)\n" 1809 " && (strm << stru.binary_value);\n";
1812 Function extraction(
"operator>>",
"bool");
1813 extraction.
addArg(
"strm",
"Serializer&");
1814 extraction.
addArg(
"stru", cxx +
"&");
1817 " if (!(strm >> stru.value)) {\n" 1820 " if (!strm.length() || !strm.skip(0, 4) || !strm.length()) {\n" 1821 " return true; // optional member missing\n" 1823 " return strm >> stru.binary_value;\n";
1828 bool genSecuritySubmessage(
const string& cxx)
1832 serialized_size.
addArg(
"encoding",
"const Encoding&");
1833 serialized_size.
addArg(
"size",
"size_t&");
1834 serialized_size.
addArg(
"stru",
"const " + cxx +
"&");
1837 " serialized_size(encoding, size, stru.smHeader);\n" 1838 " primitive_serialized_size_octet(encoding, size, stru.content.length());\n";
1841 Function insertion(
"operator<<",
"bool");
1842 insertion.
addArg(
"strm",
"Serializer&");
1843 insertion.
addArg(
"stru",
"const " + cxx +
"&");
1846 " return (strm << stru.smHeader)\n" 1847 " && strm.write_octet_array(stru.content.get_buffer(), " 1848 "stru.content.length());\n";
1851 Function extraction(
"operator>>",
"bool");
1852 extraction.
addArg(
"strm",
"Serializer&");
1853 extraction.
addArg(
"stru", cxx +
"&");
1856 " if (strm >> stru.smHeader) {\n" 1857 " stru.content.length(stru.smHeader.submessageLength);\n" 1858 " if (strm.read_octet_array(stru.content.get_buffer(),\n" 1859 " stru.smHeader.submessageLength)) {\n" 1868 bool genRtpsSpecialStruct(
const string& cxx)
1872 serialized_size.
addArg(
"encoding",
"const Encoding&");
1873 serialized_size.
addArg(
"size",
"size_t&");
1874 serialized_size.
addArg(
"stru",
"const " + cxx +
"&");
1878 << ((cxx == RtpsNamespace +
"SequenceNumberSet") ?
"12" :
"8")
1879 <<
" + 4 * ((stru.numBits + 31) / 32); // RTPS Custom\n";
1882 Function insertion(
"operator<<",
"bool");
1883 insertion.
addArg(
"strm",
"Serializer&");
1884 insertion.
addArg(
"stru",
"const " + cxx +
"&");
1887 " if ((strm << stru.bitmapBase) && (strm << stru.numBits)) {\n" 1888 " const CORBA::ULong M = (stru.numBits + 31) / 32;\n" 1889 " if (stru.bitmap.length() < M) {\n" 1892 " for (CORBA::ULong i = 0; i < M; ++i) {\n" 1893 " if (!(strm << stru.bitmap[i])) {\n" 1902 Function extraction(
"operator>>",
"bool");
1903 extraction.
addArg(
"strm",
"Serializer&");
1904 extraction.
addArg(
"stru", cxx +
"&");
1907 " if ((strm >> stru.bitmapBase) && (strm >> stru.numBits)) {\n" 1908 " const CORBA::ULong M = (stru.numBits + 31) / 32;\n" 1912 " stru.bitmap.length(M);\n" 1913 " for (CORBA::ULong i = 0; i < M; ++i) {\n" 1914 " if (!(strm >> stru.bitmap[i])) {\n" 1925 struct RtpsFieldCustomizer {
1927 explicit RtpsFieldCustomizer(
const string& cxx)
1929 if (cxx == RtpsNamespace +
"DataSubmessage") {
1930 cst_[
"inlineQos"] =
"stru.smHeader.flags & 2";
1933 }
else if (cxx == RtpsNamespace +
"DataFragSubmessage") {
1934 cst_[
"inlineQos"] =
"stru.smHeader.flags & 2";
1937 }
else if (cxx == RtpsNamespace +
"InfoReplySubmessage") {
1938 cst_[
"multicastLocatorList"] =
"stru.smHeader.flags & 2";
1940 }
else if (cxx == RtpsNamespace +
"InfoTimestampSubmessage") {
1941 cst_[
"timestamp"] =
"!(stru.smHeader.flags & 2)";
1943 }
else if (cxx == RtpsNamespace +
"InfoReplyIp4Submessage") {
1944 cst_[
"multicastLocator"] =
"stru.smHeader.flags & 2";
1946 }
else if (cxx == RtpsNamespace +
"SubmessageHeader") {
1947 intro_.insert(
"strm.swap_bytes(ACE_CDR_BYTE_ORDER != (stru.flags & 1));");
1951 string getConditional(
const string& field_name)
const 1956 std::map<string, string>::const_iterator it = cst_.find(field_name);
1957 if (it != cst_.end()) {
1963 string preFieldRead(
const string& field_name)
const 1965 if (cst_.empty() || field_name !=
"inlineQos" || iQosOffset_.empty()) {
1968 return "strm.skip(stru.octetsToInlineQos - " + iQosOffset_ +
")\n" 1972 std::map<string, string> cst_;
1977 typedef void (*KeyIterationFn)(
1978 const std::string& indent,
1980 const string& key_name, AST_Type* ast_type,
1982 string* expr,
Intro* intro);
1986 const std::string& indent,
1988 AST_Structure* node,
1989 const std::string& struct_name,
1990 IDL_GlobalData::DCPS_Data_Type_Info* info,
1994 string* expr,
Intro* intro)
1999 string key_access = i.
path();
2000 AST_Type* straight_ast_type = i.get_ast_type();
2003 AST_Union* union_type =
dynamic_cast<AST_Union*
>(straight_ast_type);
2005 std::cerr <<
"ERROR: Invalid key iterator for: " << struct_name;
2008 ast_type =
dynamic_cast<AST_Type*
>(union_type->disc_type());
2009 key_access.append(
"._d()");
2011 ast_type = straight_ast_type;
2013 fn(indent, encoding, key_access, ast_type, size, expr, intro);
2019 IDL_GlobalData::DCPS_Data_Type_Info_Iter iter(info->key_list_);
2020 for (
ACE_TString* kp = 0; iter.next(kp) != 0; iter.advance()) {
2022 fn(indent, encoding, key_name, find_type(node, key_name), size, expr, intro);
2030 void idl_max_serialized_size_iteration(
2031 const std::string&,
Encoding::Kind encoding,
const string&, AST_Type* ast_type,
2032 size_t* size,
string*,
Intro*)
2034 idl_max_serialized_size(encoding, *size, ast_type);
2037 void serialized_size_iteration(
2038 const std::string& indent,
Encoding::Kind,
const string& key_name, AST_Type* ast_type,
2039 size_t*,
string* expr,
Intro* intro)
2041 *expr += findSizeCommon(indent, 0, key_name, ast_type,
"stru.value",
false, *intro);
2044 std::string fill_datareprseq(
2046 const std::string& name,
2047 const std::string& indent)
2049 std::vector<std::string> values;
2051 values.push_back(
"DDS::XCDR_DATA_REPRESENTATION");
2054 values.push_back(
"DDS::XCDR2_DATA_REPRESENTATION");
2057 values.push_back(
"DDS::XML_DATA_REPRESENTATION");
2060 values.push_back(
"OpenDDS::DCPS::UNALIGNED_CDR_DATA_REPRESENTATION");
2063 std::ostringstream ss;
2064 ss << indent << name <<
".length(" << values.size() <<
");\n";
2065 for (
size_t i = 0; i < values.size(); ++i) {
2066 ss << indent << name <<
"[" << i <<
"] = " << values[i] <<
";\n";
2071 bool is_bounded_topic_struct(AST_Type* type,
Encoding::Kind encoding,
bool key_only,
2072 TopicKeys& keys, IDL_GlobalData::DCPS_Data_Type_Info* info = 0)
2083 bool bounded =
true;
2086 IDL_GlobalData::DCPS_Data_Type_Info_Iter iter(info->key_list_);
2087 AST_Structure*
const struct_type =
dynamic_cast<AST_Structure*
>(type);
2088 for (
ACE_TString* kp = 0; iter.next(kp) != 0; iter.advance()) {
2090 AST_Type*
const field_type = find_type(struct_type, key_name);
2091 if (!is_bounded_type(field_type, encoding)) {
2099 if (!is_bounded_type(i.get_ast_type(),
encoding)) {
2106 bounded = is_bounded_type(type, encoding);
2111 bool generate_marshal_traits_struct_bounds_functions(AST_Structure* node,
2112 TopicKeys& keys, IDL_GlobalData::DCPS_Data_Type_Info* info,
bool key_only)
2114 const char* function_prefix = key_only ?
"key_only_" :
"";
2115 AST_Type*
const type_node =
dynamic_cast<AST_Type*
>(node);
2116 const Fields fields(node);
2118 const std::string name =
scoped(node->name());
2122 " static SerializedSizeBound " << function_prefix <<
2123 "serialized_size_bound(const Encoding& encoding)\n" 2125 " switch (encoding.kind()) {\n";
2126 for (
unsigned e = 0; e <= Encoding::KIND_UNALIGNED_CDR; ++e) {
2129 " case " << encoding_to_encoding_kind(encoding) <<
":\n" 2130 " return SerializedSizeBound(";
2131 if (is_bounded_topic_struct(type_node, encoding, key_only, keys, info)) {
2134 idl_max_serialized_size_dheader(encoding, exten, size);
2135 if (!iterate_over_keys(
"", encoding, node, name, info, &keys,
2136 idl_max_serialized_size_iteration, &size, 0, 0)) {
2141 idl_max_serialized_size(encoding, size, (*i)->field_type());
2150 " OPENDDS_ASSERT(false);\n" 2151 " return SerializedSizeBound();\n" 2159 bool generate_marshal_traits_struct(AST_Structure* node,
2160 TopicKeys& keys, IDL_GlobalData::DCPS_Data_Type_Info* info = 0)
2163 generate_marshal_traits_struct_bounds_functions(node, keys, info,
false) &&
2164 generate_marshal_traits_struct_bounds_functions(node, keys, info,
true);
2167 bool generate_marshal_traits_union(AST_Union* node,
bool has_key,
ExtensibilityKind exten)
2170 " static SerializedSizeBound serialized_size_bound(const Encoding& encoding)\n" 2172 " switch (encoding.kind()) {\n";
2173 for (
unsigned e = 0; e <= Encoding::KIND_UNALIGNED_CDR; ++e) {
2176 " case " << encoding_to_encoding_kind(encoding) <<
":\n" 2177 " return SerializedSizeBound(";
2178 if (is_bounded_type(node, encoding)) {
2180 idl_max_serialized_size(encoding, size, node);
2187 " OPENDDS_ASSERT(false);\n" 2188 " return SerializedSizeBound();\n" 2194 " static SerializedSizeBound key_only_serialized_size_bound(const Encoding& encoding)\n" 2196 " switch (encoding.kind()) {\n";
2197 for (
unsigned e = 0; e <= Encoding::KIND_UNALIGNED_CDR; ++e) {
2200 " case " << encoding_to_encoding_kind(encoding) <<
":\n" 2201 " return SerializedSizeBound(";
2209 idl_max_serialized_size(encoding, size, node->disc_type());
2217 " OPENDDS_ASSERT(false);\n" 2218 " return SerializedSizeBound();\n" 2226 bool generate_marshal_traits(
2228 TopicKeys& keys, IDL_GlobalData::DCPS_Data_Type_Info* info = 0)
2230 AST_Structure*
const struct_node =
2231 node->node_type() == AST_Decl::NT_struct ?
dynamic_cast<AST_Structure*
>(node) : 0;
2232 AST_Union*
const union_node =
2233 node->node_type() == AST_Decl::NT_union ?
dynamic_cast<AST_Union*
>(node) : 0;
2234 if (!struct_node && !union_node) {
2235 idl_global->err()->misc_error(
"Can't generate MarshalTraits for this node", node);
2239 std::string octetSeqOnly;
2240 if (struct_node && struct_node->nfields() == 1) {
2245 AST_Sequence*
const seq =
dynamic_cast<AST_Sequence*
>(type);
2248 AST_PredefinedType*
const pt =
dynamic_cast<AST_PredefinedType*
>(base);
2249 if (pt->pt() == AST_PredefinedType::PT_octet) {
2250 octetSeqOnly = field->local_name()->get_string();
2256 std::string export_string;
2257 if (octetSeqOnly.size()) {
2259 if (exporter !=
"") {
2260 export_string = string(
" ") + exporter.
c_str();
2264 be_global->add_include(
"dds/DCPS/TypeSupportImpl.h");
2268 "struct" << export_string <<
" MarshalTraits<" << cxx <<
"> {\n" 2269 " static void representations_allowed_by_type(DDS::DataRepresentationIdSeq& seq)\n" 2271 << fill_datareprseq(
be_global->data_representations(node),
"seq",
" ") <<
2276 if (!generate_marshal_traits_struct(struct_node, keys, info)) {
2279 }
else if (union_node) {
2280 if (!generate_marshal_traits_union(union_node, keys.
count(), exten)) {
2285 const char* msg_block_fn_decl_end =
" { return false; }";
2286 if (octetSeqOnly.size()) {
2287 const char* get_len;
2288 const char* set_len;
2289 const char* get_buffer;
2290 const char* buffer_pre =
"";
2291 if (
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11) {
2296 octetSeqOnly +=
"()";
2298 get_len = set_len =
"length";
2299 get_buffer =
".get_buffer()";
2303 "bool MarshalTraits<" << cxx <<
">::to_message_block(ACE_Message_Block& mb, " 2304 "const " << cxx <<
"& stru)\n" 2306 " if (mb.size(stru." << octetSeqOnly <<
"." << get_len <<
"()) != 0) {\n" 2309 " return mb.copy(reinterpret_cast<const char*>(" << buffer_pre <<
"stru." 2310 << octetSeqOnly << get_buffer <<
"), stru." << octetSeqOnly <<
"." << get_len
2313 "bool MarshalTraits<" << cxx <<
">::from_message_block(" << cxx <<
"& stru, " 2314 "const ACE_Message_Block& mb)\n" 2316 " stru." << octetSeqOnly <<
"." << set_len <<
"(static_cast<unsigned>(mb.total_length()));\n" 2317 " ACE_CDR::Octet* dst = " << buffer_pre <<
"stru." << octetSeqOnly << get_buffer <<
";\n" 2318 " for (const ACE_Message_Block* m = &mb; m; m = m->cont()) {\n" 2319 " std::memcpy(dst, m->rd_ptr(), m->length());\n" 2320 " dst += m->length();\n" 2325 msg_block_fn_decl_end =
";";
2328 " static bool to_message_block(ACE_Message_Block&, const " << cxx <<
"&)" 2329 << msg_block_fn_decl_end <<
"\n" 2330 " static bool from_message_block(" << cxx <<
"&, const ACE_Message_Block&)" 2331 << msg_block_fn_decl_end <<
"\n";
2339 " static Extensibility extensibility() { return ";
2351 idl_global->err()->misc_error(
2352 "Unexpected extensibility while generating MarshalTraits", node);
2360 const ExtensibilityKind ek = max_extensibility_kind(dynamic_cast<AST_Type*>(node));
2362 " static Extensibility max_extensibility_level() { return ";
2374 idl_global->err()->misc_error(
2375 "Unexpected extensibility level while generating MarshalTraits", node);
2384 bool generate_struct_deserialization(
2387 const std::string actual_cpp_name =
scoped(node->name());
2388 std::string cpp_name = actual_cpp_name;
2389 std::string const_cpp_name;
2390 switch (field_type) {
2392 const_cpp_name =
"const" + actual_cpp_name +
"&";
2395 cpp_name =
"const NestedKeyOnly<" + actual_cpp_name +
">";
2396 const_cpp_name =
"const NestedKeyOnly<const" + actual_cpp_name +
">&";
2399 cpp_name =
"const KeyOnly<" + actual_cpp_name +
">";
2400 const_cpp_name =
"const KeyOnly<const" + actual_cpp_name +
">&";
2403 const std::string value_access = field_type ==
FieldFilter_All ?
"" :
".value";
2405 const Fields fields(node, field_type);
2407 RtpsFieldCustomizer rtpsCustom(cpp_name);
2409 const bool use_cxx11 =
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
2417 Function extraction(
"operator>>",
"bool");
2418 extraction.
addArg(
"strm",
"Serializer&");
2419 extraction.
addArg(
"stru", cpp_name +
"&");
2423 const std::string indent =
" ";
2426 " const Encoding& encoding = strm.encoding();\n" 2427 " ACE_UNUSED_ARG(encoding);\n";
2428 if (is_appendable) {
2430 " bool reached_end_of_struct = false;\n" 2431 " ACE_UNUSED_ARG(reached_end_of_struct);\n";
2434 " if (!strm.read_delimiter(total_size)) {\n" 2440 " const size_t end_of_struct = strm.rpos() + total_size;\n" 2446 " if (encoding.xcdr_version() != Encoding::XCDR_VERSION_NONE) {\n" 2447 " set_default(stru" << (wrap_nested_key_only ?
".value" :
"") <<
");\n" 2449 " unsigned member_id;\n" 2450 " size_t field_size;\n" 2451 " while (true) {\n";
2461 " if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2 && strm.rpos() >= end_of_struct) {\n" 2464 " bool must_understand = false;\n" 2465 " if (!strm.read_parameter_id(member_id, field_size, must_understand)) {\n" 2468 " if (encoding.xcdr_version() == Encoding::XCDR_VERSION_1 && member_id == Serializer::pid_list_end) {\n" 2471 " const size_t end_of_field = strm.rpos() + field_size;\n" 2472 " ACE_UNUSED_ARG(end_of_field);\n" 2475 std::ostringstream cases;
2477 AST_Field*
const field = *i;
2480 string(
"stru") + value_access +
"." + field->local_name()->get_string();
2482 " case " <<
id <<
": {\n" 2483 " if (!" << generate_field_stream(
2484 indent, field,
">> stru" + value_access, wrap_nested_key_only, intro) <<
") {\n";
2494 type_to_default(
" ", field_type, field_name, field->field_type()->anonymous()) <<
2495 " strm.set_construction_status(Serializer::ConstructionSuccessful);\n";
2496 if (!(fld_cls &
CL_STRING)) cases <<
" strm.skip(end_of_field - strm.rpos());\n";
2500 const std::string check_not_empty = use_cxx11 ?
"!" + field_name +
".empty()" : field_name +
".in()";
2501 const std::string get_length = use_cxx11 ? field_name +
".length()" :
"ACE_OS::strlen(" + field_name +
".in())";
2502 const std::string inout = use_cxx11 ?
"" :
".inout()";
2504 " if (" + construct_bound_fail +
" && " << check_not_empty <<
" && (" 2505 <<
bounded_arg(field_type) <<
" < " << get_length <<
")) {\n" 2506 " " << field_name << inout;
2516 " strm.set_construction_status(Serializer::ElementConstructionFailure);\n" 2521 " if (" + construct_elem_fail +
") {\n" 2524 " strm.set_construction_status(Serializer::ConstructionSuccessful);\n" 2525 " strm.skip(end_of_field - strm.rpos());\n";
2530 " strm.set_construction_status(Serializer::ElementConstructionFailure);\n";
2533 " strm.skip(end_of_field - strm.rpos());\n";
2544 const string switch_cases = cases.str();
2545 string sw_indent =
" ";
2546 if (switch_cases.empty()) {
2550 " switch (member_id) {\n" 2556 sw_indent <<
"if (must_understand) {\n" <<
2557 sw_indent <<
" if (DCPS_debug_level >= 8) {\n" <<
2558 sw_indent <<
" ACE_DEBUG((LM_DEBUG, ACE_TEXT(\"(%P|%t) unknown must_understand field(%u) in " 2559 << cpp_name <<
"\\n\"), member_id));\n" <<
2560 sw_indent <<
" }\n" <<
2561 sw_indent <<
" return false;\n" <<
2562 sw_indent <<
"}\n" <<
2563 sw_indent <<
"strm.skip(field_size);\n";
2565 if (!switch_cases.empty()) {
2580 AST_Field*
const field = *i;
2584 if (is_appendable) {
2586 " reached_end_of_struct |= (encoding.xcdr_version() == Encoding::XCDR_VERSION_2 && strm.rpos() >= end_of_struct);\n";
2588 const string field_name = field->local_name()->get_string();
2589 const string cond = rtpsCustom.getConditional(field_name);
2590 if (!cond.empty()) {
2591 string prefix = rtpsCustom.preFieldRead(field_name);
2592 if (is_appendable) {
2593 if (!prefix.empty()) {
2594 prefix = prefix.substr(0, prefix.length() - 8);
2596 " if (!" + prefix +
") {\n" 2600 expr +=
" if ((" + cond +
") && !";
2602 expr += prefix +
"(!(" + cond +
") || ";
2604 }
else if (is_appendable) {
2605 AST_Type*
const type = field->field_type();
2606 string stru_field_name =
"stru" + value_access +
"." + field_name;
2608 stru_field_name +=
"()";
2611 " if (reached_end_of_struct) {\n" +
2616 expr += generate_field_stream(
2617 indent, field,
">> stru" + value_access, wrap_nested_key_only, intro);
2618 if (is_appendable) {
2626 }
else if (!cond.empty()) {
2631 if (is_appendable) {
2633 " if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2 && strm.rpos() < end_of_struct) {\n" 2634 " strm.skip(end_of_struct - strm.rpos());\n" 2638 }
else if (expr.empty()) {
2641 be_global->impl_ <<
" return " << expr <<
";\n";
2647 bool generate_struct_serialization_functions(AST_Structure* node,
FieldFilter field_type)
2649 const std::string actual_cpp_name =
scoped(node->name());
2650 std::string cpp_name = actual_cpp_name;
2651 std::string const_cpp_name;
2652 switch (field_type) {
2654 const_cpp_name =
"const" + actual_cpp_name +
"&";
2657 cpp_name =
"const NestedKeyOnly<" + actual_cpp_name +
">";
2658 const_cpp_name =
"const NestedKeyOnly<const" + actual_cpp_name +
">&";
2661 cpp_name =
"const KeyOnly<" + actual_cpp_name +
">";
2662 const_cpp_name =
"const KeyOnly<const" + actual_cpp_name +
">&";
2665 const std::string value_access = field_type ==
FieldFilter_All ?
"" :
".value";
2667 const Fields fields(node, field_type);
2669 RtpsFieldCustomizer rtpsCustom(cpp_name);
2677 serialized_size.
addArg(
"encoding",
"const Encoding&");
2678 serialized_size.
addArg(
"size",
"size_t&");
2679 serialized_size.
addArg(
"stru", const_cpp_name);
2688 " size_t mutable_running_total = 0;\n";
2695 const std::string indent =
" ";
2697 AST_Field*
const field = *i;
2699 if (!field_type->in_main_file() && field_type->node_type() != AST_Decl::NT_pre_defined) {
2700 be_global->add_referenced(field_type->file_name().c_str());
2702 const string field_name = field->local_name()->get_string(),
2703 cond = rtpsCustom.getConditional(field_name);
2704 if (!cond.empty()) {
2705 expr +=
" if (" + cond +
") {\n ";
2709 " serialized_size_parameter_id(encoding, size, mutable_running_total);\n";
2711 expr += generate_field_serialized_size(
2712 indent, field,
"stru" + value_access, wrap_nested_key_only, intro);
2713 if (!cond.empty()) {
2722 " serialized_size_list_end_parameter_id(encoding, size, mutable_running_total);\n";
2727 Function insertion(
"operator<<",
"bool");
2728 insertion.
addArg(
"strm",
"Serializer&");
2729 insertion.
addArg(
"stru", const_cpp_name);
2732 " const Encoding& encoding = strm.encoding();\n" 2733 " ACE_UNUSED_ARG(encoding);\n";
2735 " serialized_size(encoding, total_size, stru);\n" 2736 " if (!strm.write_delimiter(total_size)) {\n" 2741 std::ostringstream mutable_fields;
2742 Intro intro = rtpsCustom.intro_;
2743 const std::string indent =
" ";
2745 const std::string mutable_indent = indent +
" ";
2747 " if (encoding.xcdr_version() != Encoding::XCDR_VERSION_NONE) {\n" 2748 " size_t size = 0;\n" 2749 " ACE_UNUSED_ARG(size);\n";
2751 AST_Field*
const field = *i;
2753 const bool must_understand =
be_global->is_effectively_must_understand(field);
2756 << generate_field_serialized_size(
2757 mutable_indent, field,
"stru" + value_access, wrap_nested_key_only, intro)
2759 " if (!strm.write_parameter_id(" 2760 <<
id <<
", size" << (must_understand ?
", true" :
"") <<
")) {\n" 2764 " if (!" << generate_field_stream(
2765 mutable_indent, field,
"<< stru" + value_access, wrap_nested_key_only, intro)
2770 mutable_fields <<
"\n" 2771 " if (!strm.write_list_end_parameter_id()) {\n" 2781 AST_Field*
const field = *i;
2782 if (expr.size()) expr +=
"\n && ";
2783 const string field_name = field->local_name()->get_string(),
2784 cond = rtpsCustom.getConditional(field_name);
2785 if (!cond.empty()) {
2786 expr +=
"(!(" + cond +
") || ";
2788 expr += generate_field_stream(
2789 indent, field,
"<< stru" + value_access, wrap_nested_key_only, intro);
2790 if (!cond.empty()) {
2799 be_global->impl_ << mutable_fields.str() <<
" return " << expr <<
";\n";
2802 return generate_struct_deserialization(node, field_type);
2812 if (dheader_required) {
2814 be_global->impl_ <<
" size_t total_size = 0;\n";
2816 be_global->impl_ <<
" if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2) {\n" 2823 UTL_ScopedName*
name,
2824 const std::vector<AST_Field*>& fields,
2825 AST_Type::SIZE_TYPE ,
2829 be_global->add_include(
"dds/DCPS/Serializer.h");
2830 const string cxx =
scoped(name);
2831 const bool use_cxx11 =
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
2835 set_default.
addArg(
"stru", cxx +
"&");
2837 std::ostringstream contents;
2839 for (
size_t i = 0; i < fields.size(); ++i) {
2840 AST_Field*
const field = fields[i];
2841 AST_Type*
const type = field->field_type();
2842 string field_name = string(
"stru.") + field->local_name()->get_string();
2846 contents <<
type_to_default(
" ", type, field_name, type->anonymous());
2852 bool special_result;
2853 if (generate_special_struct(node, cxx, special_result)) {
2854 return special_result;
2858 for (
size_t i = 0; i < fields.size(); ++i) {
2859 if (fields[i]->field_type()->anonymous()) {
2862 gen_anonymous_array(af);
2863 }
else if (af.
seq_ && af.
is_new(anonymous_seq_generated)) {
2864 gen_anonymous_sequence(af);
2869 if (!generate_struct_serialization_functions(node,
FieldFilter_All) ||
2874 IDL_GlobalData::DCPS_Data_Type_Info* info = idl_global->is_dcps_type(name);
2875 const bool is_topic_type =
be_global->is_topic_type(node);
2877 if (is_topic_type) {
2886 if ((info || is_topic_type) &&
2887 !generate_marshal_traits(node, cxx,
be_global->extensibility(node), keys, info)) {
2891 if (info && !is_topic_type) {
2894 serialized_size.
addArg(
"encoding",
"const Encoding&");
2895 serialized_size.
addArg(
"size",
"size_t&");
2896 serialized_size.
addArg(
"stru",
"const KeyOnly<const " + cxx +
">");
2900 " switch (encoding.xcdr_version()) {\n";
2901 const char* indent =
" ";
2902 for (
unsigned e = 0; e <= Encoding::KIND_UNALIGNED_CDR; ++e) {
2906 if (!iterate_over_keys(indent, encoding, node, cxx, info, 0,
2907 serialized_size_iteration, 0, &expr, &intro)) {
2911 " case " << encoding_to_xcdr_version(encoding) <<
":\n" 2924 Function insertion(
"operator<<",
"bool");
2925 insertion.
addArg(
"strm",
"Serializer&");
2926 insertion.
addArg(
"stru",
"KeyOnly<const " + cxx +
">");
2932 const char* indent =
" ";
2934 IDL_GlobalData::DCPS_Data_Type_Info_Iter iter(info->key_list_);
2935 for (
ACE_TString* kp = 0; iter.next(kp) != 0; iter.advance()) {
2937 AST_Type*
const field_type = find_type(node, key_name);
2943 expr += streamCommon(indent, 0, key_name, field_type,
"<< stru.value",
false, intro);
2947 be_global->impl_ <<
" return " << (first ?
"true" : expr) <<
";\n";
2951 Function extraction(
"operator>>",
"bool");
2952 extraction.
addArg(
"strm",
"Serializer&");
2953 extraction.
addArg(
"stru",
"KeyOnly<" + cxx +
">");
2959 const std::string indent =
" ";
2961 IDL_GlobalData::DCPS_Data_Type_Info_Iter iter(info->key_list_);
2962 for (
ACE_TString* kp = 0; iter.next(kp) != 0; iter.advance()) {
2964 AST_Type*
const field_type = find_type(node, key_name);
2970 expr += streamCommon(indent, 0, key_name, field_type,
">> stru.value",
false, intro);
2974 be_global->impl_ <<
" return " << (first ?
"true" : expr) <<
";\n";
2988 const bool use_cxx11 =
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
2993 const std::string actual_cpp_name =
scoped(node->name());
2994 std::string cpp_name = actual_cpp_name;
2995 const Fields fields(node);
2997 RtpsFieldCustomizer rtpsCustom(cpp_name);
3000 " Value getValue(Serializer& strm, const char* field, const TypeSupportImpl* = 0) const\n" 3002 " const Encoding& encoding = strm.encoding();\n" 3003 " ACE_UNUSED_ARG(encoding);\n";
3005 " if (!strm.read_delimiter(total_size)) {\n" 3006 " throw std::runtime_error(\"Unable to reader delimiter in getValue\");\n" 3009 " std::string base_field = field;\n" 3010 " const size_t index = base_field.find('.');\n" 3011 " std::string subfield;\n" 3012 " if (index != std::string::npos) {\n" 3013 " subfield = base_field.substr(index + 1);\n" 3014 " base_field = base_field.substr(0, index);\n" 3019 " if (encoding.xcdr_version() != Encoding::XCDR_VERSION_NONE) {\n" 3020 " unsigned field_id = map_name_to_id(base_field.c_str());\n" 3021 " ACE_UNUSED_ARG(field_id);\n" 3022 " unsigned member_id;\n" 3023 " size_t field_size;\n" 3024 " const size_t end_of_struct = strm.rpos() + total_size;\n" 3026 " if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2 &&\n" 3027 " strm.rpos() >= end_of_struct) {\n" 3030 " bool must_understand = false;\n" 3031 " if (!strm.read_parameter_id(member_id, field_size, must_understand)) {\n" 3032 " throw std::runtime_error(\"Field \" + OPENDDS_STRING(field) + \" Deserialization " 3033 "Error for struct " << clazz <<
"\");\n" 3035 " if (encoding.xcdr_version() == Encoding::XCDR_VERSION_1 &&\n" 3036 " member_id == Serializer::pid_list_end) {\n" 3037 " throw std::runtime_error(\"Field \" + OPENDDS_STRING(field) + \" not " 3038 "valid for struct " << clazz <<
"\");\n" 3040 " const size_t end_of_field = strm.rpos() + field_size;\n" 3041 " ACE_UNUSED_ARG(end_of_field);\n" 3044 std::ostringstream cases;
3046 AST_Field*
const field = *i;
3049 std::string field_name = field->local_name()->get_string();
3053 cases <<
" case " <<
id <<
": {\n";
3055 const std::string cxx_type =
to_cxx_type(field_type, size);
3056 const std::string val = (fld_cls &
CL_STRING) ? (use_cxx11 ?
"val" :
"val.out()")
3058 std::string boundsCheck, transformPrefix, transformSuffix;
3061 boundsCheck =
" if (val >= gen_" + enumName +
"_names_size) {\n" 3062 " throw std::runtime_error(\"Enum value out of bounds\");\n" 3064 transformPrefix =
"gen_" + enumName +
"_names[";
3065 transformSuffix =
"]";
3068 " if (field_id == member_id) {\n" 3069 " " << cxx_type <<
" val;\n" <<
3070 " if (!(strm >> " << val <<
")) {\n" 3071 " throw std::runtime_error(\"Field '" << field_name <<
"' could not be deserialized\");\n" <<
3074 " return " << transformPrefix <<
"val" << transformSuffix <<
";\n" 3076 " strm.skip(field_size);\n" 3082 " if (field_id == member_id) {\n" 3083 " return getMetaStruct<" <<
scoped(field_type->name()) <<
">().getValue(strm, subfield.c_str());\n" 3085 " strm.skip(field_size);\n" 3091 " strm.skip(field_size);\n" 3096 const std::string switch_cases = cases.str();
3097 std::string sw_indent =
" ";
3098 if (switch_cases.empty()) {
3102 " switch (member_id) {\n" 3107 sw_indent <<
"if (must_understand) {\n" <<
3108 sw_indent <<
" if (DCPS_debug_level >= 8) {\n" <<
3109 sw_indent <<
" ACE_DEBUG((LM_DEBUG, ACE_TEXT(\"(%P|%t) unknown must_understand field(%u) in " 3110 << cpp_name <<
"\\n\"), member_id));\n" <<
3111 sw_indent <<
" }\n" <<
3112 sw_indent <<
" throw std::runtime_error(\"member id did not exist in getValue\");\n" <<
3113 sw_indent <<
"}\n" <<
3114 sw_indent <<
"strm.skip(field_size);\n";
3115 if (!switch_cases.empty()) {
3122 " if (!field[0]) {\n" 3125 " throw std::runtime_error(\"Did not find field in getValue\");\n" 3132 AST_Field*
const field = *i;
3138 const std::string cxx_type =
to_cxx_type(field_type, size);
3139 const std::string val = (fld_cls &
CL_STRING) ? (use_cxx11 ?
"val" :
"val.out()")
3141 std::string boundsCheck, transformPrefix, transformSuffix;
3144 boundsCheck =
" if (val >= gen_" + enumName +
"_names_size) {\n" 3145 " throw std::runtime_error(\"Enum value out of bounds\");\n" 3147 transformPrefix =
"gen_" + enumName +
"_names[";
3148 transformSuffix =
"]";
3151 " if (base_field == \"" + idl_name +
"\") {\n" 3152 " " + cxx_type +
" val;\n" 3153 " if (!(strm >> " + val +
")) {\n" 3154 " throw std::runtime_error(\"Field '" + idl_name +
"' could " 3155 "not be deserialized\");\n" 3158 " return " + transformPrefix +
"val" + transformSuffix +
";\n" 3162 " ACE_CDR::ULong len;\n" 3163 " if (!(strm >> len)) {\n" 3164 " throw std::runtime_error(\"String '" + idl_name +
3165 "' length could not be deserialized\");\n" 3167 " if (!strm.skip(len)) {\n" 3168 " throw std::runtime_error(\"String '" + idl_name +
3169 "' contents could not be skipped\");\n" 3175 " throw std::runtime_error(\"Field '" + idl_name +
3176 "' could not be skipped\");\n" 3182 " if (base_field == \"" + idl_name +
"\") {\n" 3183 " return getMetaStruct<" +
scoped(field_type->name()) +
">().getValue(strm, subfield.c_str());\n" 3185 " if (!gen_skip_over(strm, static_cast<" +
scoped(field_type->name()) +
"*>(0))) {\n" 3186 " throw std::runtime_error(\"Field '" + idl_name +
"' could not be skipped\");\n" 3190 std::string pre, post;
3191 if (!use_cxx11 && (fld_cls &
CL_ARRAY)) {
3193 }
else if (use_cxx11 && (fld_cls & (CL_ARRAY |
CL_SEQUENCE))) {
3194 pre =
"IDL::DistinctType<";
3197 const std::string ptr = field->field_type()->anonymous() ?
3200 " if (!gen_skip_over(strm, static_cast<" + ptr +
">(0))) {\n" 3201 " throw std::runtime_error(\"Field \" + OPENDDS_STRING(field) + \" could not be skipped\");\n" 3207 " if (!field[0]) {\n" 3210 " throw std::runtime_error(\"Did not find field in getValue\");\n" 3215 bool genRtpsParameter(
const string&, AST_Union* u, AST_Type* discriminator,
3216 const std::vector<AST_UnionBranch*>& branches)
3218 const string cxx = RtpsNamespace +
"Parameter";
3221 serialized_size.
addArg(
"encoding",
"const Encoding&");
3222 serialized_size.
addArg(
"size",
"size_t&");
3223 serialized_size.
addArg(
"uni",
"const " + cxx +
"&");
3226 discriminator,
"",
"", cxx.c_str());
3228 " if (uni._d() == RTPS::PID_XTYPES_TYPE_INFORMATION) {\n" 3229 " // Parameter union uses OctetSeq but this is not actually a sequence\n" 3232 " size += 4; // parameterId & length\n";
3235 Function insertion(
"operator<<",
"bool");
3236 insertion.
addArg(
"strm",
"Serializer&");
3237 insertion.
addArg(
"uni",
"const " + cxx +
"&");
3240 " if (!(strm << uni._d())) {\n" 3243 " size_t size = serialized_size(strm.encoding(), uni);\n" 3244 " size -= 4; // parameterId & length\n" 3245 " const size_t post_pad = 4 - (size % 4);\n" 3246 " const size_t total = size + ((post_pad < 4) ? post_pad : 0);\n" 3247 " if (size > ACE_UINT16_MAX || !(strm << ACE_CDR::UShort(total))) {\n" 3250 " const Serializer::ScopedAlignmentContext sac(strm);\n" 3251 " if (uni._d() == RTPS::PID_XTYPES_TYPE_INFORMATION) {\n" 3252 " if (!strm.write_octet_array(uni.type_information().get_buffer(), uni.type_information().length())) {\n" 3255 " } else if (!insertParamData(strm, uni)) {\n" 3258 " if (post_pad < 4 && strm.encoding().alignment() != Encoding::ALIGN_NONE) {\n" 3259 " static const ACE_CDR::Octet padding[3] = {0};\n" 3260 " return strm.write_octet_array(padding, ACE_CDR::ULong(post_pad));\n" 3265 Function insertData(
"insertParamData",
"bool");
3266 insertData.
addArg(
"strm",
"Serializer&");
3267 insertData.
addArg(
"uni",
"const " + cxx +
"&");
3270 "return",
"<< ", cxx.c_str());
3273 Function extraction(
"operator>>",
"bool");
3274 extraction.
addArg(
"strm",
"Serializer&");
3275 extraction.
addArg(
"uni", cxx +
"&");
3278 " ACE_CDR::UShort disc, size;\n" 3279 " if (!(strm >> disc) || !(strm >> size)) {\n" 3282 " if (disc == OpenDDS::RTPS::PID_SENTINEL) {\n" 3283 " uni._d(OpenDDS::RTPS::PID_SENTINEL);\n" 3286 " if (size == 0) {\n" 3290 " if (size > strm.length()) {\n" 3293 " if (disc == RTPS::PID_PROPERTY_LIST) {\n" 3294 " // support special case deserialization of DDS::PropertyQosPolicy\n" 3295 " Message_Block_Ptr param(strm.trim(size));\n" 3296 " strm.skip(size);\n" 3297 " Serializer strm2(param.get(), Encoding(Encoding::KIND_XCDR1, strm.swap_bytes()));\n" 3298 " ::DDS::PropertyQosPolicy tmp;\n" 3299 " if (strm2 >> tmp) {\n" 3300 " uni.property(tmp);\n" 3306 " const Serializer::ScopedAlignmentContext sac(strm, size);\n" 3307 " if (disc == RTPS::PID_XTYPES_TYPE_INFORMATION) {\n" 3308 " DDS::OctetSeq type_info(size);\n" 3309 " type_info.length(size);\n" 3310 " if (!strm.read_octet_array(type_info.get_buffer(), size)) {\n" 3313 " uni.type_information(type_info);\n" 3316 " switch (disc) {\n";
3318 "",
">> ", cxx.c_str(),
true);
3322 " uni.unknown_data(DDS::OctetSeq(size));\n" 3323 " uni.unknown_data().length(size);\n" 3324 " if (!strm.read_octet_array(uni.unknown_data().get_buffer(), size)) {\n" 3335 bool genRtpsSubmessage(
const string&, AST_Union* u, AST_Type* discriminator,
3336 const std::vector<AST_UnionBranch*>& branches)
3338 const string cxx = RtpsNamespace +
"Submessage";
3341 serialized_size.
addArg(
"encoding",
"const Encoding&");
3342 serialized_size.
addArg(
"size",
"size_t&");
3343 serialized_size.
addArg(
"uni",
"const " + cxx +
"&");
3346 discriminator,
"",
"", cxx.c_str());
3349 Function insertion(
"operator<<",
"bool");
3350 insertion.
addArg(
"strm",
"Serializer&");
3351 insertion.
addArg(
"uni",
"const " + cxx +
"&");
3354 discriminator,
"return",
"<< ", cxx.c_str());
3357 Function insertion(
"operator>>",
"bool");
3358 insertion.
addArg(
"strm",
"Serializer&");
3359 insertion.
addArg(
"uni", cxx +
"&");
3361 be_global->impl_ <<
" // unused\n return false;\n";
3366 void gen_union_key_serializers(AST_Union* node,
FieldFilter kind)
3368 const string cxx =
scoped(node->name());
3369 AST_Type*
const discriminator = node->disc_type();
3376 : nested_key_only ?
"NestedKeyOnly" 3378 const bool has_key =
be_global->union_discriminator_is_key(node) || nested_key_only;
3382 serialized_size.
addArg(
"encoding",
"const Encoding&");
3383 serialized_size.
addArg(
"size",
"size_t&");
3384 serialized_size.
addArg(
"uni",
"const " + wrapper +
"<const " + cxx +
">");
3392 " size_t mutable_running_total = 0;\n" 3393 " serialized_size_parameter_id(encoding, size, mutable_running_total);\n";
3398 " primitive_serialized_size_ulong(encoding, size);\n";
3401 " primitive_serialized_size(encoding, size, " << key_only_wrap_out <<
");\n";
3406 " serialized_size_list_end_parameter_id(encoding, size, mutable_running_total);\n";
3412 Function insertion(
"operator<<",
"bool");
3413 insertion.
addArg(
"strm",
"Serializer&");
3414 insertion.
addArg(
"uni", wrapper +
"<const " + cxx +
">");
3419 " const Encoding& encoding = strm.encoding();\n" 3420 " ACE_UNUSED_ARG(encoding);\n";
3422 " serialized_size(encoding, total_size, uni);\n" 3423 " if (!strm.write_delimiter(total_size)) {\n" 3430 " size_t size = 0;\n";
3434 " primitive_serialized_size_ulong(encoding, size);\n";
3437 " primitive_serialized_size(encoding, size, " << key_only_wrap_out <<
");\n";
3441 " if (!strm.write_parameter_id(0, size)) {\n" 3447 be_global->impl_ << streamAndCheck(
"<< " + key_only_wrap_out);
3451 <<
" return true;\n";
3455 Function extraction(
"operator>>",
"bool");
3456 extraction.
addArg(
"strm",
"Serializer&");
3457 extraction.
addArg(
"uni", wrapper +
"<" + cxx +
">");
3463 " const Encoding& encoding = strm.encoding();\n" 3464 " ACE_UNUSED_ARG(encoding);\n";
3466 " if (!strm.read_delimiter(total_size)) {\n" 3473 " unsigned member_id;\n" 3474 " size_t field_size;\n" 3475 " bool must_understand = false;\n" 3476 " if (!strm.read_parameter_id(member_id, field_size, must_understand)) {\n" 3482 <<
" " <<
scoped(discriminator->name()) <<
" disc;\n" 3484 <<
" uni.value._d(disc);\n";
3488 <<
" return true;\n";
3494 const std::vector<AST_UnionBranch*>& branches, AST_Type* discriminator,
3498 be_global->add_include(
"dds/DCPS/Serializer.h");
3499 string cxx =
scoped(name);
3503 for (
size_t i = 0; i < branches.size(); ++i) {
3504 if (branches[i]->field_type()->anonymous()) {
3507 gen_anonymous_array(af);
3508 }
else if (af.
seq_ && af.
is_new(anonymous_seq_generated)) {
3509 gen_anonymous_sequence(af);
3519 const std::string varname(
"uni");
3521 set_default.
addArg(varname.c_str(), cxx +
"&");
3527 if (!disc_type->in_main_file() && disc_type->node_type() != AST_Decl::NT_pre_defined) {
3528 be_global->add_referenced(disc_type->file_name().c_str());
3534 AST_Enum* enu =
dynamic_cast<AST_Enum*
>(disc_type);
3535 UTL_ScopeActiveIterator i(enu, UTL_Scope::IK_decls);
3536 AST_EnumVal *item =
dynamic_cast<AST_EnumVal*
>(i.item());
3537 default_enum_val = item->constant_value()->ev()->u.eval;
3543 for (std::vector<AST_UnionBranch*>::const_iterator itr = branches.begin(); itr < branches.end() && !found; ++itr) {
3544 AST_UnionBranch* branch = *itr;
3545 for (
unsigned i = 0; i < branch->label_list_length(); ++i) {
3546 AST_UnionLabel* ul = branch->label(i);
3547 if (ul->label_kind() != AST_UnionLabel::UL_default) {
3548 AST_Expression::AST_ExprValue* ev = branch->label(i)->label_val()->ev();
3549 if ((ev->et == AST_Expression::EV_enum && ev->u.eval == default_enum_val) ||
3551 (ev->et == AST_Expression::EV_uint8 && ev->u.uint8val == 0) ||
3552 (ev->et == AST_Expression::EV_int8 && ev->u.int8val == 0) ||
3554 (ev->et == AST_Expression::EV_short && ev->u.sval == 0) ||
3555 (ev->et == AST_Expression::EV_ushort && ev->u.usval == 0) ||
3556 (ev->et == AST_Expression::EV_long && ev->u.lval == 0) ||
3557 (ev->et == AST_Expression::EV_ulong && ev->u.ulval == 0) ||
3558 (ev->et == AST_Expression::EV_longlong && ev->u.llval == 0) ||
3559 (ev->et == AST_Expression::EV_ulonglong && ev->u.ullval == 0) ||
3560 (ev->et == AST_Expression::EV_float && ev->u.fval == 0) ||
3561 (ev->et == AST_Expression::EV_double && ev->u.dval == 0) ||
3562 (ev->et == AST_Expression::EV_longdouble && ev->u.sval == 0) ||
3563 (ev->et == AST_Expression::EV_char && ev->u.cval == 0) ||
3564 (ev->et == AST_Expression::EV_wchar && ev->u.wcval == 0) ||
3565 (ev->et == AST_Expression::EV_octet && ev->u.oval == 0) ||
3566 (ev->et == AST_Expression::EV_bool && ev->u.bval == 0))
3568 gen_union_default(branch, varname);
3580 " " <<
scoped(discriminator->name()) <<
" temp;\n" <<
3582 " " << varname <<
"._d(temp);\n";
3586 bool special_result;
3587 if (generate_special_union(cxx, node, discriminator, branches, special_result)) {
3588 return special_result;
3594 serialized_size.
addArg(
"encoding",
"const Encoding&");
3595 serialized_size.
addArg(
"size",
"size_t&");
3596 serialized_size.
addArg(
"uni",
"const " + cxx +
"&");
3603 " size_t mutable_running_total = 0;\n" 3604 " serialized_size_parameter_id(encoding, size, mutable_running_total);\n";
3609 " primitive_serialized_size_ulong(encoding, size);\n";
3612 " primitive_serialized_size(encoding, size, " << wrap_out <<
");\n";
3617 branches, discriminator,
"",
"", cxx.c_str());
3623 " serialized_size_list_end_parameter_id(encoding, size, mutable_running_total);\n";
3627 Function insertion(
"operator<<",
"bool");
3628 insertion.
addArg(
"strm",
"Serializer&");
3629 insertion.
addArg(
"uni",
"const " + cxx +
"&");
3633 " const Encoding& encoding = strm.encoding();\n" 3634 " ACE_UNUSED_ARG(encoding);\n";
3636 " serialized_size(encoding, total_size, uni);\n" 3637 " if (!strm.write_delimiter(total_size)) {\n" 3644 " size_t size = 0;\n";
3648 " primitive_serialized_size_ulong(encoding, size);\n";
3651 " primitive_serialized_size(encoding, size, " << wrap_out <<
");\n";
3655 " if (!strm.write_parameter_id(0, size)) {\n" 3662 streamAndCheck(
"<< " + wrap_out);
3664 discriminator,
"return",
"<< ", cxx.c_str(),
3672 Function extraction(
"operator>>",
"bool");
3673 extraction.
addArg(
"strm",
"Serializer&");
3674 extraction.
addArg(
"uni", cxx +
"&");
3678 " const Encoding& encoding = strm.encoding();\n" 3679 " ACE_UNUSED_ARG(encoding);\n";
3681 " if (!strm.read_delimiter(total_size)) {\n" 3688 " unsigned member_id;\n" 3689 " size_t field_size;\n" 3690 " bool must_understand = false;\n" 3691 " if (!strm.read_parameter_id(member_id, field_size, must_understand)) {\n" 3696 " " <<
scoped(discriminator->name()) <<
" disc;\n" 3697 " if (!(strm >> disc)) {\n";
3700 " set_default(uni);\n" 3701 " if (!strm.read_parameter_id(member_id, field_size, must_understand)) {\n" 3704 " strm.skip(field_size);\n" 3705 " strm.set_construction_status(Serializer::ConstructionSuccessful);\n" 3709 " if (!strm.read_parameter_id(member_id, field_size, must_understand)) {\n" 3712 " strm.skip(field_size);\n" 3713 " strm.set_construction_status(Serializer::ElementConstructionFailure);\n" 3720 " field_size = 0;\n" 3721 " must_understand = false;\n";
3723 const char prefix[] =
3724 " if (!strm.read_parameter_id(member_id, field_size, must_understand)) {\n" 3728 discriminator, prefix,
">> ", cxx.c_str())) {
3734 " " <<
scoped(discriminator->name()) <<
" disc;\n" <<
3737 discriminator,
"",
">> ", cxx.c_str())) {
3748 return generate_marshal_traits(node, cxx, exten, keys);
3755 const std::string tmpname =
"tmp";
3758 be_global->impl_ <<
" " <<
scoped(branch->field_type()->name()) <<
" " 3764 be_global->impl_ <<
" " << varname <<
"." << branch->local_name()->get_string() <<
"(tmp);\n";
3767 varname +
"." + branch->local_name()->get_string(),
std::string bounded_arg(AST_Type *type)
std::string to_cxx_type(AST_Type *type, std::size_t &size)
bool is_new(EleLenSet &el_set) const
Classification classify(AST_Type *type)
static std::string scoped_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
void join(std::ostream &os, const std::string &indent)
const char * c_str(void) const
const LogLevel::Value value
const Classification CL_STRING
string type_to_default(const std::string &indent, AST_Type *type, const string &name, bool is_anonymous, bool is_union)
AST_Typedef * typedef_node_
const std::string type_name_
static void gen_field_getValueFromSerialized(AST_Structure *node, const std::string &clazz)
const Classification CL_SCALAR
bool gen_struct(AST_Structure *node, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE size, const char *repoid)
const Classification CL_WIDE
std::string field_type_name(AST_Field *field, AST_Type *field_type)
String to_dds_string(unsigned short to_convert)
const Classification CL_PRIMITIVE
std::string seq_get_length() const
size_t array_count(Type(&)[count])
#define ACE_TEXT_ALWAYS_CHAR(STRING)
static RootType root_type(AST_Type *type)
static std::string get_tag_name(const std::string &base_name, const std::string &qualifier="")
std::string seq_get_buffer() const
Christopher Diggins *renamed files *fixing compilation errors *adding Visual C project file *removed make Max Lybbert *removed references to missing and unused as reported by Andy Elvey and Dan Kosecki *resynced with Christopher Diggins s branch as it exists in tree building code is back Christopher Diggins *resynced codebase with Chris s branch *removed tree building code
AST_Type * deepest_named_type(AST_Type *type)
const Classification CL_BOUNDED
void serialized_size(const Encoding &encoding, size_t &size, const SequenceNumber &)
const Classification CL_ARRAY
#define OPENDDS_HAS_EXPLICIT_INTS
void gen_union_default(AST_UnionBranch *branch, const std::string &varname)
bool generateSwitchBody(AST_Union *, CommonFn commonFn, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator, const char *statementPrefix, const char *namePrefix="", const char *uni="", bool forceDisableDefault=false, bool parens=true, bool breaks=true, CommonFn commonFn2=0)
bool generateSwitchForUnion(AST_Union *u, const char *switchExpr, CommonFn commonFn, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator, const char *statementPrefix, const char *namePrefix="", const char *uni="", bool forceDisableDefault=false, bool parens=true, bool breaks=true, CommonFn commonFn2=0)
returns true if a default: branch was generated (no default: label in IDL)
std::string canonical_name(UTL_ScopedName *sn)
bool gen_enum(AST_Enum *node, UTL_ScopedName *name, const std::vector< AST_EnumVal *> &contents, const char *repoid)
std::string wrapped_type_name() const
bool gen_union(AST_Union *node, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator, const char *repoid)
const std::string scoped_type_
std::string getWrapper(const std::string &name, AST_Type *type, WrapDirection wd)
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_UNKNOWN
std::string classic_array_copy() const
static void generate_dheader_code(const std::string &code, bool dheader_required, bool is_ser_func=true)
std::string insert_cxx11_accessor_parens(const std::string &full_var_name_, bool is_union_member=false)
std::string seq_check_empty() const
std::string value_access(const std::string &var_name="") const
OpenDDS_Dcps_Export void align(size_t &value, size_t by)
Align "value" by "by" if it's not already.
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
#define OPENDDS_IDL_STR(X)
std::string seq_resize(const std::string &new_size) const
std::string stream() const
std::set< EleLen > EleLenSet
const Classification CL_STRUCTURE
void addArg(const char *name, const std::string &type)
BE_GlobalData * be_global
ACE_CDR::ULong array_element_count(AST_Array *arr)
void generate_tag() const
const Classification CL_INTERFACE
RefWrapper & done(Intro *intro=0)
void misc_error_and_abort(const std::string &message, AST_Decl *node=0)
Report a miscellaneous error and abort.
bool gen_typedef(AST_Typedef *node, UTL_ScopedName *name, AST_Type *base, const char *repoid)
const DCPS::Encoding encoding(DCPS::Encoding::KIND_UNALIGNED_CDR, DCPS::ENDIAN_BIG)
const Classification CL_ENUM
const Classification CL_SEQUENCE
bool needs_nested_key_only(AST_Type *type)
const Classification CL_UNION
AST_Field * get_struct_field(AST_Structure *struct_node, unsigned index)
void align(size_t &value, size_t by=(std::numeric_limits< size_t >::max)()) const
Align "value" to "by" and according to the stream's alignment.