@@ -526,7 +526,7 @@ operator<<(std::ostream& out, const OpenDDS::XTypes::TypeIdentifier& ti)
526526 return out;
527527}
528528
529- void dump_bytes (const OpenDDS::XTypes::TypeObject& to)
529+ void dump_bytes (const OpenDDS::XTypes::TypeObject& to, std::ostream& stream = be_global->impl_ )
530530{
531531 ACE_Message_Block buffer (OpenDDS::DCPS::serialized_size (OpenDDS::XTypes::get_typeobject_encoding (), to));
532532 OpenDDS::DCPS::Serializer ser (&buffer, OpenDDS::XTypes::get_typeobject_encoding ());
@@ -536,9 +536,9 @@ void dump_bytes(const OpenDDS::XTypes::TypeObject& to)
536536
537537 for (const char * ptr = buffer.rd_ptr (); ptr != buffer.wr_ptr (); ++ptr) {
538538 if (ptr != buffer.rd_ptr ()) {
539- be_global-> impl_ << " , " ;
539+ stream << " , " ;
540540 }
541- be_global-> impl_ << int (*reinterpret_cast <const unsigned char *>(ptr));
541+ stream << int (*reinterpret_cast <const unsigned char *>(ptr));
542542 }
543543}
544544
@@ -606,24 +606,17 @@ typeobject_generator::use_old_typeobject_encoding()
606606}
607607
608608void
609- typeobject_generator::gen_epilogue ()
609+ typeobject_generator::gen_epilogue_type_map (const std::string& label,
610+ const OpenDDS::XTypes::TypeMap& type_map,
611+ const std::string& file)
610612{
611- be_global->add_include (" dds/DCPS/Service_Participant.h" );
612-
613- if (!produce_output_ || !get_type_map_declared_) {
614- return ;
615- }
616-
617- NamespaceGuard ng;
618-
619- be_global->impl_ <<
620- " namespace {\n " ;
621-
613+ std::ostream* const stream = be_global->typeobject_stream ();
622614 size_t idx = 0 ;
623- for (OpenDDS::XTypes::TypeMap::const_iterator pos = minimal_type_map_.begin ();
624- pos != minimal_type_map_.end (); ++pos, ++idx) {
615+ std::vector<std::string> names;
616+ for (OpenDDS::XTypes::TypeMap::const_iterator pos = type_map.begin ();
617+ pos != type_map.end (); ++pos, ++idx) {
625618 be_global->impl_ <<
626- " XTypes::TypeObject OPENDDS_IDL_FILE_SPECIFIC(minimal_to , " << idx << " )()\n "
619+ " XTypes::TypeObject OPENDDS_IDL_FILE_SPECIFIC(" << label << " _to , " << idx << " )()\n "
627620 " {\n "
628621 " static const unsigned char to_bytes[] = { " ;
629622 dump_bytes (pos->second );
@@ -632,63 +625,73 @@ typeobject_generator::gen_epilogue()
632625 " };\n "
633626 " XTypes::TypeObject to;\n "
634627 " if (!to_type_object(to_bytes, sizeof(to_bytes), to)) {\n "
635- " throw std::runtime_error(\" Could not deserialize minimal Type Object " << idx << " \" );\n "
628+ " throw std::runtime_error(\" Could not deserialize " << label << " Type Object " << idx << " \" );\n "
636629 " }\n "
637630 " return to;\n "
638631 " }\n\n " ;
632+ if (stream) {
633+ const std::map<OpenDDS::XTypes::TypeIdentifier, std::string>::const_iterator iter = type_identifier_index_.find (pos->first );
634+ const std::string name = (iter == type_identifier_index_.end ())
635+ ? (file + OpenDDS::DCPS::to_dds_string (idx))
636+ : iter->second ;
637+ names.push_back (name);
638+ *stream << " const unsigned char to_" << label << " _bytes_" << name << " [] = {" ;
639+ dump_bytes (pos->second , *stream);
640+ *stream << " };\n " ;
641+ }
642+ }
643+ if (stream) {
644+ *stream << " const Span all_" << label << " _type_objects_" << file << " [] = {" ;
645+ for (size_t i = 0 ; i < names.size (); ++i) {
646+ *stream << " {to_" << label << " _bytes_" << names[i] << " , "
647+ " sizeof to_" << label << " _bytes_" << names[i] << " }, " ;
648+ }
649+ *stream << " {0, 0}};\n " ;
639650 }
640651
641652 be_global->impl_ <<
642- " XTypes::TypeMap OPENDDS_IDL_FILE_SPECIFIC(get_minimal_type_map_private , 0)()\n "
653+ " XTypes::TypeMap OPENDDS_IDL_FILE_SPECIFIC(get_ " << label << " _type_map_private , 0)()\n "
643654 " {\n "
644655 " XTypes::TypeMap tm;\n " ;
645656
646657 idx = 0 ;
647- for (OpenDDS::XTypes::TypeMap::const_iterator pos = minimal_type_map_ .begin ();
648- pos != minimal_type_map_ .end (); ++pos, ++idx) {
649- be_global->impl_ << " tm[" << pos->first << " ] = OPENDDS_IDL_FILE_SPECIFIC(minimal_to , " << idx << " )();\n " ;
658+ for (OpenDDS::XTypes::TypeMap::const_iterator pos = type_map .begin ();
659+ pos != type_map .end (); ++pos, ++idx) {
660+ be_global->impl_ << " tm[" << pos->first << " ] = OPENDDS_IDL_FILE_SPECIFIC(" << label << " _to , " << idx << " )();\n " ;
650661 }
651662
652663 be_global->impl_ <<
653664 " return tm;\n "
654665 " }\n\n " ;
666+ }
655667
656- if (produce_xtypes_complete_) {
657- idx = 0 ;
658- for (OpenDDS::XTypes::TypeMap::const_iterator pos = complete_type_map_.begin ();
659- pos != complete_type_map_.end (); ++pos, ++idx) {
660- be_global->impl_ <<
661- " XTypes::TypeObject OPENDDS_IDL_FILE_SPECIFIC(complete_to, " << idx << " )()\n "
662- " {\n "
663- " const unsigned char to_bytes[] = {\n " ;
664- dump_bytes (pos->second );
665- be_global->add_include (" <stdexcept>" , BE_GlobalData::STREAM_CPP);
666- be_global->impl_ <<
667- " };\n "
668- " XTypes::TypeObject to;\n "
669- " if (!to_type_object(to_bytes, sizeof(to_bytes), to)) {\n "
670- " throw std::runtime_error(\" Could not deserialize complete Type Object " << idx << " \" );\n "
671- " }\n "
672- " return to;\n "
673- " }\n\n " ;
674- }
668+ void
669+ typeobject_generator::gen_epilogue ()
670+ {
671+ be_global->add_include (" dds/DCPS/Service_Participant.h" );
675672
676- be_global->impl_ <<
677- " XTypes::TypeMap OPENDDS_IDL_FILE_SPECIFIC(get_complete_type_map_private, 0)()\n "
678- " {\n "
679- " XTypes::TypeMap tm;\n " ;
673+ if (!produce_output_ || !get_type_map_declared_) {
674+ return ;
675+ }
680676
681- idx = 0 ;
682- for (OpenDDS::XTypes::TypeMap::const_iterator pos = complete_type_map_. begin ();
683- pos != complete_type_map_. end (); ++pos, ++idx) {
684- be_global-> impl_ << " tm[ " << pos-> first << " ] = OPENDDS_IDL_FILE_SPECIFIC(complete_to, " <<
685- idx << " )(); // " << get_type_name (pos-> second . complete ) << " \n " ;
686- }
677+ std::ostream* const stream = be_global-> typeobject_stream () ;
678+ std::string file = idl_global-> filename ()-> get_string ();
679+ file. resize (file. find ( ' . ' ));
680+ if (stream && stream-> tellp () == 0 ) {
681+ *stream << " #include <cstddef> \n struct Span { const unsigned char* bytes_; std::size_t size_; }; \n " ;
682+ }
687683
688- be_global->impl_ <<
689- " return tm;\n "
690- " }\n " ;
684+ NamespaceGuard ng;
685+
686+ be_global->impl_ <<
687+ " namespace {\n " ;
688+
689+ gen_epilogue_type_map (" minimal" , minimal_type_map_, file);
690+
691+ if (produce_xtypes_complete_) {
692+ gen_epilogue_type_map (" complete" , complete_type_map_, file);
691693 }
694+
692695 be_global->impl_ << " }\n\n " ;
693696
694697 const std::string common = " {\n "
@@ -1789,6 +1792,7 @@ typeobject_generator::generate(AST_Type* node, UTL_ScopedName* name)
17891792 " ti = " << ti << " ;\n "
17901793 " }\n "
17911794 " return ti;\n " ;
1795+ type_identifier_index_[ti] = clazz;
17921796 }
17931797
17941798 declare_get_type_map ();
@@ -1812,6 +1816,7 @@ typeobject_generator::generate(AST_Type* node, UTL_ScopedName* name)
18121816 " ti = " << ti << " ;\n "
18131817 " }\n "
18141818 " return ti;\n " ;
1819+ type_identifier_index_[ti] = clazz;
18151820 } else {
18161821 be_global->impl_ <<
18171822 " static XTypes::TypeIdentifier ti;\n "
0 commit comments