#include <ts_generator.h>
Inheritance diagram for ts_generator:
Public Member Functions | |
ts_generator () | |
bool | gen_struct (AST_Structure *node, UTL_ScopedName *name, const std::vector< AST_Field * > &fields, AST_Type::SIZE_TYPE size, const char *repoid) |
bool | gen_typedef (AST_Typedef *, UTL_ScopedName *, AST_Type *, const char *) |
bool | gen_union (AST_Union *, UTL_ScopedName *, const std::vector< AST_UnionBranch * > &, AST_Type *, const char *) |
Private Attributes | |
std::string | idl_template_ |
Definition at line 23 of file ts_generator.h.
ts_generator::ts_generator | ( | ) |
Definition at line 61 of file ts_generator.cpp.
00062 : idl_template_(read_template("IDL")) 00063 { 00064 }
bool ts_generator::gen_struct | ( | AST_Structure * | node, | |
UTL_ScopedName * | name, | |||
const std::vector< AST_Field * > & | fields, | |||
AST_Type::SIZE_TYPE | size, | |||
const char * | repoid | |||
) | [virtual] |
Implements dds_generator.
Definition at line 66 of file ts_generator.cpp.
References BE_GlobalData::add_include(), add_includes(), be_global, BE_GlobalData::export_macro(), BE_GlobalData::face_ts(), face_ts_generator::generate(), BE_GlobalData::header_, BE_GlobalData::header_name_, BE_GlobalData::idl_, idl_template_, BE_GlobalData::impl_, module_scope(), replaceAll(), scoped(), BE_GlobalData::sequence_suffix(), BE_GlobalData::STREAM_CPP, BE_GlobalData::STREAM_H, and BE_GlobalData::STREAM_IDL.
00068 { 00069 if (idl_global->is_dcps_type(name) == 0) { 00070 // no #pragma DCPS_DATA_TYPE, so nothing to generate 00071 return true; 00072 } 00073 00074 const std::string cxxName = scoped(name); 00075 const std::string short_name = name->last_component()->get_string(); 00076 00077 static const char* idl_includes[] = { 00078 "dds/DdsDcpsInfrastructure.idl", "dds/DdsDcpsTopic.idl", 00079 "dds/DdsDcpsPublication.idl", "dds/DdsDcpsSubscriptionExt.idl", 00080 "dds/DdsDcpsTypeSupportExt.idl" 00081 }; 00082 add_includes(idl_includes, BE_GlobalData::STREAM_IDL); 00083 00084 std::string dc = be_global->header_name_.c_str(); 00085 dc.replace(dc.end() - 6, dc.end() - 2, "C"); // s/Impl.h$/C.h/ 00086 be_global->add_include(dc.c_str()); 00087 00088 static const char* h_includes[] = { 00089 "dds/DCPS/DataWriterImpl_T.h", 00090 "dds/DCPS/DataReaderImpl_T.h", 00091 "dds/DCPS/TypeSupportImpl_T.h" 00092 }; 00093 add_includes(h_includes, BE_GlobalData::STREAM_H); 00094 00095 static const char* cpp_includes[] = { 00096 "dds/DCPS/debug.h", "dds/DCPS/Registered_Data_Types.h", 00097 "dds/DdsDcpsDomainC.h", "dds/DCPS/Service_Participant.h", 00098 "dds/DCPS/Qos_Helper.h", "dds/DCPS/PublicationInstance.h", 00099 "dds/DCPS/PublisherImpl.h", "dds/DCPS/SubscriberImpl.h", 00100 "dds/DCPS/ReceivedDataElementList.h", "dds/DCPS/RakeResults_T.h", 00101 "dds/DCPS/BuiltInTopicUtils.h", "dds/DCPS/Util.h", 00102 "dds/DCPS/ContentFilteredTopicImpl.h", "dds/DCPS/RakeData.h", 00103 "dds/DCPS/MultiTopicDataReader_T.h" 00104 }; 00105 add_includes(cpp_includes, BE_GlobalData::STREAM_CPP); 00106 00107 std::map<std::string, std::string> replacements; 00108 replacements["SCOPED"] = cxxName; 00109 replacements["TYPE"] = short_name; 00110 replacements["EXPORT"] = be_global->export_macro().c_str(); 00111 replacements["SEQ"] = be_global->sequence_suffix().c_str(); 00112 00113 ScopedNamespaceGuard idlGuard(name, be_global->idl_, "module"); 00114 std::string idl = idl_template_; 00115 replaceAll(idl, replacements); 00116 be_global->idl_ << idl; 00117 00118 be_global->header_ << 00119 "namespace OpenDDS { namespace DCPS {\n" 00120 "template <>\n" 00121 "struct DDSTraits<" << cxxName << "> {\n" 00122 " typedef " << cxxName << " MessageType;\n" 00123 " typedef " << cxxName << "Seq MessageSequenceType;\n" 00124 " typedef " << cxxName << "TypeSupport TypeSupportType;\n" 00125 " typedef " << cxxName << "DataWriter DataWriterType;\n" 00126 " typedef " << cxxName << "DataReader DataReaderType;\n" 00127 " typedef " << module_scope(name) << "OpenDDSGenerated::" << short_name << "_KeyLessThan LessThanType;\n" 00128 "\n" 00129 " inline static const char* type_name () { return \"" << cxxName << "\"; }\n" 00130 " inline static bool gen_has_key (const MessageType& x) { return ::OpenDDS::DCPS::gen_has_key(x); }\n" 00131 "\n" 00132 " inline static bool gen_is_bounded_size (const MessageType& x) { return ::OpenDDS::DCPS::gen_is_bounded_size(x); }\n" 00133 " inline static size_t gen_max_marshaled_size(const MessageType& x, bool align) { return ::OpenDDS::DCPS::gen_max_marshaled_size(x, align); }\n" 00134 " inline static void gen_find_size(const MessageType& arr, size_t& size, size_t& padding) { ::OpenDDS::DCPS::gen_find_size(arr, size, padding); }\n" 00135 "\n" 00136 " inline static bool gen_is_bounded_size (const OpenDDS::DCPS::KeyOnly<const MessageType>& x) { return ::OpenDDS::DCPS::gen_is_bounded_size(x); }\n" 00137 " inline static size_t gen_max_marshaled_size(const OpenDDS::DCPS::KeyOnly<const MessageType>& x, bool align) { return ::OpenDDS::DCPS::gen_max_marshaled_size(x, align); }\n" 00138 " inline static void gen_find_size(const OpenDDS::DCPS::KeyOnly<const MessageType>& arr, size_t& size, size_t& padding) { ::OpenDDS::DCPS::gen_find_size(arr, size, padding); }\n" 00139 "};\n} }\n\n"; 00140 00141 { 00142 ScopedNamespaceGuard hGuard(name, be_global->header_); 00143 be_global->header_ << 00144 " typedef OpenDDS::DCPS::DataWriterImpl_T<" << cxxName << "> " << short_name << "DataWriterImpl;\n" 00145 " typedef OpenDDS::DCPS::DataReaderImpl_T<" << cxxName << "> " << short_name << "DataReaderImpl;\n" 00146 " typedef OpenDDS::DCPS::TypeSupportImpl_T<" << cxxName << "> " << short_name << "TypeSupportImpl;\n"; 00147 } 00148 00149 ScopedNamespaceGuard cppGuard(name, be_global->impl_); 00150 00151 if (be_global->face_ts()) { 00152 face_ts_generator::generate(name); 00153 } 00154 00155 return true; 00156 }
bool ts_generator::gen_typedef | ( | AST_Typedef * | , | |
UTL_ScopedName * | , | |||
AST_Type * | , | |||
const char * | ||||
) | [inline, virtual] |
bool ts_generator::gen_union | ( | AST_Union * | , | |
UTL_ScopedName * | , | |||
const std::vector< AST_UnionBranch * > & | , | |||
AST_Type * | , | |||
const char * | ||||
) | [virtual] |
Implements dds_generator.
Definition at line 158 of file ts_generator.cpp.
References scoped().
00160 { 00161 if (idl_global->is_dcps_type(name)) { 00162 std::cerr << "ERROR: union " << scoped(name) << " can not be used as a " 00163 "DCPS_DATA_TYPE (only structs can be Topic types)" << std::endl; 00164 return false; 00165 } 00166 return true; 00167 }
std::string ts_generator::idl_template_ [private] |