100 if (!node || !
name) {
104 AST_Structure* struct_node = 0;
105 AST_Union* union_node = 0;
106 AST_Type::SIZE_TYPE size_type;
107 if (node->node_type() == AST_Decl::NT_struct) {
108 struct_node =
dynamic_cast<AST_Structure*
>(node);
109 size_type = struct_node->size_type();
110 }
else if (node->node_type() == AST_Decl::NT_union) {
111 union_node =
dynamic_cast<AST_Union*
>(node);
112 size_type = union_node->size_type();
114 idl_global->err()->misc_error(
115 "Could not cast AST Nodes to valid types", node);
120 IDL_GlobalData::DCPS_Data_Type_Info* info = 0;
123 info = idl_global->is_dcps_type(
name);
124 if (
be_global->is_topic_type(struct_node)) {
126 key_count = keys.
count();
128 key_count = info->key_list_.size();
132 }
else if (
be_global->is_topic_type(union_node)) {
133 key_count =
be_global->union_discriminator_is_key(union_node) ? 1 : 0;
139 const std::string short_name =
name->last_component()->get_string();
141 const std::string ts_short_name =
to_string(
143 const std::string unescaped_name =
146 static const std::string ns(
"OpenDDS::DCPS::");
149 static const char* idl_includes[] = {
150 "dds/DdsDcpsInfrastructure.idl",
"dds/DdsDcpsTopic.idl",
151 "dds/DdsDcpsPublication.idl",
"dds/DdsDcpsSubscriptionExt.idl",
152 "dds/DdsDcpsTypeSupportExt.idl" 154 add_includes(idl_includes, BE_GlobalData::STREAM_IDL);
157 dc.replace(dc.end() - 6, dc.end() - 2,
"C");
160 static const char* h_includes[] = {
161 "dds/DCPS/TypeSupportImpl.h",
"dds/DCPS/ValueDispatcher.h" 163 add_includes(h_includes, BE_GlobalData::STREAM_H);
165 static const char* cpp_includes[] = {
166 "dds/DCPS/debug.h",
"dds/DCPS/Registered_Data_Types.h",
167 "dds/DdsDcpsDomainC.h",
"dds/DCPS/Service_Participant.h",
168 "dds/DCPS/Qos_Helper.h",
"dds/DCPS/PublicationInstance.h",
169 "dds/DCPS/PublisherImpl.h",
"dds/DCPS/SubscriberImpl.h",
170 "dds/DCPS/ReceivedDataElementList.h",
"dds/DCPS/RakeResults_T.h",
171 "dds/DCPS/BuiltInTopicUtils.h",
"dds/DCPS/Util.h",
172 "dds/DCPS/ContentFilteredTopicImpl.h",
"dds/DCPS/RakeData.h",
173 "dds/DCPS/MultiTopicDataReader_T.h",
"dds/DCPS/DataWriterImpl_T.h",
174 "dds/DCPS/DataReaderImpl_T.h",
"dds/DCPS/XTypes/TypeObject.h" 176 add_includes(cpp_includes, BE_GlobalData::STREAM_CPP);
178 std::map<std::string, std::string> replacements;
182 replacements[
"SCOPED_NOT_GLOBAL"] =
190 replaceAll(idl, replacements);
198 "class " << ts_short_name <<
"TypeSupportImpl;\n";
203 "OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL\n" 204 "namespace OpenDDS {\n" 207 "struct DDSTraits<" << cxx_name <<
"> {\n" 208 " typedef " << cxx_name <<
" MessageType;\n" 209 " typedef " << ts_name <<
be_global->sequence_suffix() <<
" MessageSequenceType;\n" 210 " typedef " << ts_name <<
be_global->sequence_suffix() <<
"::PrivateMemberAccess MessageSequenceAdapterType;\n" 211 " typedef " << ts_name <<
"TypeSupport TypeSupportType;\n" 212 " typedef " << ts_name <<
"TypeSupportImpl TypeSupportImplType;\n" 213 " typedef " << ts_name <<
"DataWriter DataWriterType;\n" 214 " typedef " << ts_name <<
"DataReader DataReaderType;\n" 215 " typedef " << cxx_name <<
"_OpenDDS_KeyLessThan LessThanType;\n" 216 " typedef OpenDDS::DCPS::KeyOnly<const " << cxx_name <<
"> KeyOnlyType;\n" 217 " typedef " << xtag <<
" XtagType;\n" 219 " static const char* type_name() { return \"" << unescaped_name <<
"\"; }\n" 220 " static size_t key_count() { return " << key_count <<
"; }\n" 221 " static bool is_key(const char*);\n" 223 "} // namespace DCPS\n" 224 "} // namespace OpenDDS\n" 225 "OPENDDS_END_VERSIONED_NAMESPACE_DECL\n\n";
228 "OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL\n" 229 "namespace OpenDDS {\n" 231 "bool DDSTraits<" << cxx_name <<
">::is_key(const char* field)\n" 233 " ACE_UNUSED_ARG(field);\n";
234 if (struct_node && key_count) {
244 "} // namespace DCPS\n" 245 "} // namespace OpenDDS\n" 246 "OPENDDS_END_VERSIONED_NAMESPACE_DECL\n\n";
253 "class " <<
be_global->export_macro() <<
" " << ts_short_name <<
"TypeSupportImpl\n" 254 " : public virtual OpenDDS::DCPS::LocalObject<" << ts_short_name <<
"TypeSupport>\n" 255 " , public virtual OpenDDS::DCPS::TypeSupportImpl_T<" << short_name <<
">\n" 256 " , public virtual OpenDDS::DCPS::ValueDispatcher_T<" << short_name <<
">\n" 259 " typedef " << ts_short_name <<
"TypeSupport TypeSupportType;\n" 260 " typedef " << ts_short_name <<
"TypeSupport::_var_type _var_type;\n" 261 " typedef " << ts_short_name <<
"TypeSupport::_ptr_type _ptr_type;\n" 263 " " << ts_short_name <<
"TypeSupportImpl() {}\n" 264 " virtual ~" << ts_short_name <<
"TypeSupportImpl() {}\n" 266 " virtual " <<
be_global->versioning_name() <<
"::DDS::DataWriter_ptr create_datawriter();\n" 267 " virtual " <<
be_global->versioning_name() <<
"::DDS::DataReader_ptr create_datareader();\n" 268 "#ifndef OPENDDS_NO_MULTI_TOPIC\n" 269 " virtual " <<
be_global->versioning_name() <<
"::DDS::DataReader_ptr create_multitopic_datareader();\n" 270 "#endif /* !OPENDDS_NO_MULTI_TOPIC */\n" 271 "#ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE\n" 272 " virtual const OpenDDS::DCPS::MetaStruct& getMetaStructForType() const;\n" 273 "#endif /* !OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE */\n" 275 " virtual const OpenDDS::XTypes::TypeIdentifier& getMinimalTypeIdentifier() const;\n" 276 " virtual const OpenDDS::XTypes::TypeMap& getMinimalTypeMap() const;\n" 278 " virtual const OpenDDS::XTypes::TypeIdentifier& getCompleteTypeIdentifier() const;\n" 279 " virtual const OpenDDS::XTypes::TypeMap& getCompleteTypeMap() const;\n" 281 " ::DDS::ReturnCode_t encode_to_string(const " << short_name <<
"& in, CORBA::String_out out, OpenDDS::DCPS::RepresentationFormat* format);\n" 282 " ::DDS::ReturnCode_t encode_to_bytes(const " << short_name <<
"& in, ::DDS::OctetSeq_out out, OpenDDS::DCPS::RepresentationFormat* format);\n" 283 " ::DDS::ReturnCode_t decode_from_string(const char* in, " << short_name <<
"_out out, OpenDDS::DCPS::RepresentationFormat* format);\n" 284 " ::DDS::ReturnCode_t decode_from_bytes(const ::DDS::OctetSeq& in, " << short_name <<
"_out out, OpenDDS::DCPS::RepresentationFormat* format);\n" 286 " static " << ts_short_name <<
"TypeSupport::_ptr_type _narrow(CORBA::Object_ptr obj);\n" 295 "::DDS::DataWriter_ptr " << ts_short_name <<
"TypeSupportImpl::create_datawriter()\n" 297 " typedef OpenDDS::DCPS::DataWriterImpl_T<" << short_name <<
"> DataWriterImplType;\n" 298 " ::DDS::DataWriter_ptr writer_impl = ::DDS::DataWriter::_nil();\n" 299 " ACE_NEW_NORETURN(writer_impl,\n" 300 " DataWriterImplType());\n" 301 " return writer_impl;\n" 303 "::DDS::DataReader_ptr " << ts_short_name <<
"TypeSupportImpl::create_datareader()\n" 305 " typedef OpenDDS::DCPS::DataReaderImpl_T<" << short_name <<
"> DataReaderImplType;\n" 306 " ::DDS::DataReader_ptr reader_impl = ::DDS::DataReader::_nil();\n" 307 " ACE_NEW_NORETURN(reader_impl,\n" 308 " DataReaderImplType());\n" 309 " return reader_impl;\n" 311 "#ifndef OPENDDS_NO_MULTI_TOPIC\n" 312 "::DDS::DataReader_ptr " << ts_short_name <<
"TypeSupportImpl::create_multitopic_datareader()\n" 314 " typedef OpenDDS::DCPS::DataReaderImpl_T<" << short_name <<
"> DataReaderImplType;\n" 315 " typedef OpenDDS::DCPS::MultiTopicDataReader_T<" << short_name <<
", DataReaderImplType> MultiTopicDataReaderImplType;\n" 316 " ::DDS::DataReader_ptr multitopic_reader_impl = ::DDS::DataReader::_nil();\n" 317 " ACE_NEW_NORETURN(multitopic_reader_impl,\n" 318 " MultiTopicDataReaderImplType());\n" 319 " return multitopic_reader_impl;\n" 321 "#endif /* !OPENDDS_NO_MULTI_TOPIC */\n\n" 322 "#ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE\n" 323 "const OpenDDS::DCPS::MetaStruct& " << ts_short_name <<
"TypeSupportImpl::getMetaStructForType() const\n" 325 " return OpenDDS::DCPS::getMetaStruct<" << short_name <<
">();\n" 327 "#endif /* !OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE */\n\n" 329 " OpenDDS::DCPS::TypeSupportInitializer<" << ts_short_name <<
"TypeSupportImpl> ts_init_" << name_underscores <<
";\n" 332 "const OpenDDS::XTypes::TypeIdentifier& " << ts_short_name <<
"TypeSupportImpl::getMinimalTypeIdentifier() const\n" 336 const bool generate_xtypes = !
be_global->suppress_xtypes() && !java_ts_only;
337 if (generate_xtypes) {
339 " return OpenDDS::DCPS::getMinimalTypeIdentifier<" << xtag <<
">();\n";
342 " static OpenDDS::XTypes::TypeIdentifier ti;\n" 347 "const OpenDDS::XTypes::TypeMap& " << ts_short_name <<
"TypeSupportImpl::getMinimalTypeMap() const\n" 350 if (generate_xtypes) {
352 " return OpenDDS::DCPS::getMinimalTypeMap<" << xtag <<
">();\n";
355 " static OpenDDS::XTypes::TypeMap tm;\n" 360 "const OpenDDS::XTypes::TypeIdentifier& " << ts_short_name <<
"TypeSupportImpl::getCompleteTypeIdentifier() const\n" 363 const bool generate_xtypes_complete = generate_xtypes &&
be_global->xtypes_complete();
364 if (generate_xtypes_complete) {
366 " return OpenDDS::DCPS::getCompleteTypeIdentifier<" << xtag <<
">();\n";
369 " static OpenDDS::XTypes::TypeIdentifier ti;\n" 374 "const OpenDDS::XTypes::TypeMap& " << ts_short_name <<
"TypeSupportImpl::getCompleteTypeMap() const\n" 377 if (generate_xtypes_complete) {
379 " return OpenDDS::DCPS::getCompleteTypeMap<" << xtag <<
">();\n";
382 " static OpenDDS::XTypes::TypeMap tm;\n" 385 be_global->add_cpp_include(
"dds/DCPS/JsonValueReader.h");
386 be_global->add_cpp_include(
"dds/DCPS/JsonValueWriter.h");
387 const bool alloc_out =
be_global->language_mapping() != BE_GlobalData::LANGMAP_CXX11 && size_type == AST_Type::VARIABLE;
390 "::DDS::ReturnCode_t " << ts_short_name <<
"TypeSupportImpl::encode_to_string(const " << short_name <<
"& in, CORBA::String_out out, OpenDDS::DCPS::RepresentationFormat* format)\n" 392 "#if OPENDDS_HAS_JSON_VALUE_WRITER\n" 393 " OpenDDS::DCPS::JsonRepresentationFormat_var jrf = OpenDDS::DCPS::JsonRepresentationFormat::_narrow(format);\n" 395 " rapidjson::StringBuffer buffer;\n" 396 " rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);\n" 397 " OpenDDS::DCPS::JsonValueWriter<rapidjson::Writer<rapidjson::StringBuffer> > jvw(writer);\n" 398 " vwrite(jvw, in);\n" 399 " out = buffer.GetString();\n" 400 " return ::DDS::RETCODE_OK;\n" 403 " ACE_UNUSED_ARG(in);\n" 404 " ACE_UNUSED_ARG(format);\n" 407 " return ::DDS::RETCODE_UNSUPPORTED;\n" 409 "::DDS::ReturnCode_t " << ts_short_name <<
"TypeSupportImpl::encode_to_bytes(const " << short_name <<
"& in, ::DDS::OctetSeq_out out, OpenDDS::DCPS::RepresentationFormat* format)\n" 411 "#if OPENDDS_HAS_JSON_VALUE_WRITER\n" 412 " OpenDDS::DCPS::JsonRepresentationFormat_var jrf = OpenDDS::DCPS::JsonRepresentationFormat::_narrow(format);\n" 414 " CORBA::String_var buffer;\n" 415 " const ::DDS::ReturnCode_t ret = encode_to_string(in, buffer, format);\n" 416 " if (ret == ::DDS::RETCODE_OK) {\n" 417 " const ::DDS::UInt32 len = static_cast< ::DDS::UInt32>(std::strlen(buffer));\n" 418 " out = new ::DDS::OctetSeq(len);\n" 419 " out->length(len);\n" 420 " std::memcpy(out->get_buffer(), buffer, len);\n" 421 " return ::DDS::RETCODE_OK;\n" 423 " out = new ::DDS::OctetSeq();\n" 428 " ACE_UNUSED_ARG(in);\n" 429 " ACE_UNUSED_ARG(format);\n" 431 " out = new ::DDS::OctetSeq();\n" 432 " return ::DDS::RETCODE_UNSUPPORTED;\n" 434 "::DDS::ReturnCode_t " << ts_short_name <<
"TypeSupportImpl::decode_from_string(const char* in, " << short_name <<
"_out " <<
435 (alloc_out ?
"out" :
"param") <<
", OpenDDS::DCPS::RepresentationFormat* format)\n" 439 be_global->impl_ <<
" out = new " << short_name <<
";\n";
441 be_global->impl_ <<
" " << short_name <<
"* out = ¶m;\n";
445 " OpenDDS::DCPS::set_default(*out);\n" 446 "#if OPENDDS_HAS_JSON_VALUE_READER\n" 447 " OpenDDS::DCPS::JsonRepresentationFormat_var jrf = OpenDDS::DCPS::JsonRepresentationFormat::_narrow(format);\n" 449 " rapidjson::StringStream buffer(in);\n" 450 " OpenDDS::DCPS::JsonValueReader<> jvr(buffer);\n" <<
451 " return vread(jvr, *out) ? ::DDS::RETCODE_OK : ::DDS::RETCODE_ERROR;\n" 454 " ACE_UNUSED_ARG(in);\n" 455 " ACE_UNUSED_ARG(format);\n" 457 " return ::DDS::RETCODE_UNSUPPORTED;\n" 459 "::DDS::ReturnCode_t " << ts_short_name <<
"TypeSupportImpl::decode_from_bytes(const ::DDS::OctetSeq& in, " << short_name <<
"_out out, OpenDDS::DCPS::RepresentationFormat* format)\n" 461 "#if OPENDDS_HAS_JSON_VALUE_READER\n" 462 " OpenDDS::DCPS::JsonRepresentationFormat_var jrf = OpenDDS::DCPS::JsonRepresentationFormat::_narrow(format);\n" 464 " return decode_from_string(reinterpret_cast<const char*>(in.get_buffer()), out, format);\n" 467 " ACE_UNUSED_ARG(in);\n" 468 " ACE_UNUSED_ARG(format);\n" 470 " out = " << (alloc_out ?
"new " :
"") << short_name <<
"();\n" 471 " return ::DDS::RETCODE_UNSUPPORTED;\n" 473 << ts_short_name <<
"TypeSupport::_ptr_type " << ts_short_name <<
"TypeSupportImpl::_narrow(CORBA::Object_ptr obj)\n" 475 " return TypeSupportType::_narrow(obj);\n" 481 if (node->node_type() == AST_Decl::NT_struct) {
484 idl_global->err()->misc_error(
485 "Generating FACE type support for Union topic types is not supported", node);
static std::string scoped_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
const char * c_str(void) const
static std::string get_xtag_name(UTL_ScopedName *name)
void generate(UTL_ScopedName *name)
std::string idl_template_
static std::string to_string(Identifier *id, EscapeContext ec=EscapeContext_Normal)
This is for generated IDL. (Like *TypeSupport.idl)
This is for a name coming from generated IDL. (Like *TypeSupportC.h)
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
BE_GlobalData * be_global
size_type length(void) const
DDS::ReturnCode_t key_count(DDS::DynamicType_ptr type, size_t &count)