| 3090 | } |
| 3091 | |
| 3092 | bool generate_struct_serialization_functions(AST_Structure* node, FieldFilter field_filter) |
| 3093 | { |
| 3094 | const std::string actual_cpp_name = scoped(node->name()); |
| 3095 | std::string cpp_name = actual_cpp_name; |
| 3096 | std::string const_cpp_name; |
| 3097 | switch (field_filter) { |
| 3098 | case FieldFilter_All: |
| 3099 | const_cpp_name = "const" + actual_cpp_name + "&"; |
| 3100 | break; |
| 3101 | case FieldFilter_NestedKeyOnly: |
| 3102 | cpp_name = "const NestedKeyOnly<" + actual_cpp_name + ">"; |
| 3103 | const_cpp_name = "const NestedKeyOnly<const" + actual_cpp_name + ">&"; |
| 3104 | break; |
| 3105 | case FieldFilter_KeyOnly: |
| 3106 | cpp_name = "const KeyOnly<" + actual_cpp_name + ">"; |
| 3107 | const_cpp_name = "const KeyOnly<const" + actual_cpp_name + ">&"; |
| 3108 | break; |
| 3109 | } |
| 3110 | const std::string value_access = field_filter == FieldFilter_All ? "" : ".value"; |
| 3111 | const bool wrap_nested_key_only = field_filter != FieldFilter_All; |
| 3112 | const Fields fields(node, field_filter); |
| 3113 | const Fields::Iterator fields_end = fields.end(); |
| 3114 | RtpsFieldCustomizer rtpsCustom(cpp_name); |
| 3115 | |
| 3116 | const ExtensibilityKind exten = be_global->extensibility(node); |
| 3117 | const bool not_final = exten != extensibilitykind_final; |
| 3118 | const bool is_mutable = exten == extensibilitykind_mutable; |
| 3119 | |
| 3120 | { |
| 3121 | Function serialized_size("serialized_size", "void"); |
| 3122 | serialized_size.addArg("encoding", "const Encoding&"); |
| 3123 | serialized_size.addArg("size", "size_t&"); |
| 3124 | serialized_size.addArg("stru", const_cpp_name); |
| 3125 | serialized_size.endArgs(); |
| 3126 | |
| 3127 | if (is_mutable) { |
| 3128 | /* |
| 3129 | * For parameter lists this is used to hold the total size while |
| 3130 | * size is hijacked for field sizes because of alignment resets. |
| 3131 | */ |
| 3132 | be_global->impl_ << |
| 3133 | " size_t mutable_running_total = 0;\n"; |
| 3134 | } |
| 3135 | |
| 3136 | marshal_generator::generate_dheader_code(" serialized_size_delimiter(encoding, size);\n", not_final, false); |
| 3137 | |
| 3138 | std::string expr; |
| 3139 | Intro intro; |
| 3140 | const std::string indent = " "; |
| 3141 | for (Fields::Iterator i = fields.begin(); i != fields_end; ++i) { |
| 3142 | AST_Field* const field = *i; |
| 3143 | AST_Type* field_type = resolveActualType(field->field_type()); |
| 3144 | if (!field_type->in_main_file() && field_type->node_type() != AST_Decl::NT_pre_defined) { |
| 3145 | be_global->add_referenced(field_type->file_name().c_str()); |
| 3146 | } |
| 3147 | const string field_name = field->local_name()->get_string(), |
| 3148 | cond = rtpsCustom.getConditional(field_name); |
| 3149 | if (!cond.empty()) { |
no test coverage detected