#include <ts_generator.h>
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_global, ACE_String_Base< ACE_CHAR_T >::c_str(), java_ts_generator::generate(), idl_template_, ACE_String_Base< ACE_CHAR_T >::is_empty(), and scoped().
00068 { 00069 IDL_GlobalData::DCPS_Data_Type_Info* info = idl_global->is_dcps_type(name); 00070 00071 if (!info) { 00072 // no #pragma DCPS_DATA_TYPE, so nothing to generate 00073 return true; 00074 } 00075 00076 const std::string cxxName = scoped(name); 00077 const std::string short_name = name->last_component()->get_string(); 00078 00079 static const char* idl_includes[] = { 00080 "dds/DdsDcpsInfrastructure.idl", "dds/DdsDcpsTopic.idl", 00081 "dds/DdsDcpsPublication.idl", "dds/DdsDcpsSubscriptionExt.idl", 00082 "dds/DdsDcpsTypeSupportExt.idl" 00083 }; 00084 add_includes(idl_includes, BE_GlobalData::STREAM_IDL); 00085 00086 std::string dc = be_global->header_name_.c_str(); 00087 dc.replace(dc.end() - 6, dc.end() - 2, "C"); // s/Impl.h$/C.h/ 00088 be_global->add_include(dc.c_str()); 00089 00090 static const char* h_includes[] = { 00091 "dds/DCPS/TypeSupportImpl.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", "dds/DCPS/DataWriterImpl_T.h", 00104 "dds/DCPS/DataReaderImpl_T.h" 00105 }; 00106 add_includes(cpp_includes, BE_GlobalData::STREAM_CPP); 00107 00108 std::map<std::string, std::string> replacements; 00109 replacements["SCOPED"] = cxxName; 00110 replacements["TYPE"] = short_name; 00111 replacements["EXPORT"] = be_global->export_macro().c_str(); 00112 replacements["SEQ"] = be_global->sequence_suffix().c_str(); 00113 00114 ScopedNamespaceGuard idlGuard(name, be_global->idl_, "module"); 00115 std::string idl = idl_template_; 00116 replaceAll(idl, replacements); 00117 be_global->idl_ << idl; 00118 00119 be_global->header_ << be_global->versioning_begin() << "\n"; 00120 { 00121 ScopedNamespaceGuard hGuard(name, be_global->header_); 00122 00123 be_global->header_ << 00124 "class " << short_name << "TypeSupportImpl;\n"; 00125 } 00126 be_global->header_ << be_global->versioning_end() << "\n"; 00127 00128 const bool has_keys = info->key_list_.is_empty(); 00129 00130 be_global->header_ << 00131 "OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL\n" 00132 "namespace OpenDDS { namespace DCPS {\n" 00133 "template <>\n" 00134 "struct DDSTraits<" << cxxName << "> {\n" 00135 " typedef " << cxxName << " MessageType;\n" 00136 " typedef " << cxxName << "Seq MessageSequenceType;\n" 00137 " typedef " << cxxName << "TypeSupport TypeSupportType;\n" 00138 " typedef " << cxxName << "TypeSupportImpl TypeSupportTypeImpl;\n" 00139 " typedef " << cxxName << "DataWriter DataWriterType;\n" 00140 " typedef " << cxxName << "DataReader DataReaderType;\n" 00141 " typedef " << cxxName << "_OpenDDS_KeyLessThan LessThanType;\n" 00142 "\n" 00143 " static const char* type_name () { return \"" << cxxName << "\"; }\n" 00144 " static bool gen_has_key () { return " << (has_keys ? "false" : "true") << "; }\n" 00145 "\n" 00146 " static size_t gen_max_marshaled_size(const MessageType& x, bool align) { return ::OpenDDS::DCPS::gen_max_marshaled_size(x, align); }\n" 00147 " static void gen_find_size(const MessageType& arr, size_t& size, size_t& padding) { ::OpenDDS::DCPS::gen_find_size(arr, size, padding); }\n" 00148 "\n" 00149 " 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" 00150 " 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" 00151 "};\n} }\nOPENDDS_END_VERSIONED_NAMESPACE_DECL\n\n"; 00152 00153 be_global->header_ << be_global->versioning_begin() << "\n"; 00154 { 00155 ScopedNamespaceGuard hGuard(name, be_global->header_); 00156 00157 be_global->header_ << 00158 "class " << be_global->export_macro() << " " << short_name << "TypeSupportImpl\n" 00159 " : public virtual OpenDDS::DCPS::LocalObject<" << short_name << "TypeSupport>\n" 00160 " , public virtual OpenDDS::DCPS::TypeSupportImpl\n" 00161 "{\n" 00162 "public:\n" 00163 " typedef OpenDDS::DCPS::DDSTraits<" << short_name << "> TraitsType;\n" 00164 " typedef " << short_name << "TypeSupport TypeSupportType;\n" 00165 " typedef " << short_name << "TypeSupport::_var_type _var_type;\n" 00166 " typedef " << short_name << "TypeSupport::_ptr_type _ptr_type;\n" 00167 "\n" 00168 " " << short_name << "TypeSupportImpl() {}\n" 00169 " virtual ~" << short_name << "TypeSupportImpl() {}\n" 00170 "\n" 00171 " virtual " << be_global->versioning_name() << "::DDS::DataWriter_ptr create_datawriter();\n" 00172 " virtual " << be_global->versioning_name() << "::DDS::DataReader_ptr create_datareader();\n" 00173 "#ifndef OPENDDS_NO_MULTI_TOPIC\n" 00174 " virtual " << be_global->versioning_name() << "::DDS::DataReader_ptr create_multitopic_datareader();\n" 00175 "#endif /* !OPENDDS_NO_MULTI_TOPIC */\n" 00176 "#ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE\n" 00177 " virtual const OpenDDS::DCPS::MetaStruct& getMetaStructForType();\n" 00178 "#endif /* !OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE */\n" 00179 " virtual bool has_dcps_key();\n" 00180 " const char* default_type_name() const;\n" 00181 " static " << short_name << "TypeSupport::_ptr_type _narrow(CORBA::Object_ptr obj);\n" 00182 "};\n"; 00183 } 00184 be_global->header_ << be_global->versioning_end() << "\n"; 00185 00186 be_global->impl_ << be_global->versioning_begin() << "\n"; 00187 { 00188 ScopedNamespaceGuard cppGuard(name, be_global->impl_); 00189 be_global->impl_ << 00190 "::DDS::DataWriter_ptr " << short_name << "TypeSupportImpl::create_datawriter()\n" 00191 "{\n" 00192 " typedef OpenDDS::DCPS::DataWriterImpl_T<" << short_name << "> DataWriterImplType;\n" 00193 " ::DDS::DataWriter_ptr writer_impl = ::DDS::DataWriter::_nil();\n" 00194 " ACE_NEW_NORETURN(writer_impl,\n" 00195 " DataWriterImplType());\n" 00196 " return writer_impl;\n" 00197 "}\n\n" 00198 "::DDS::DataReader_ptr " << short_name << "TypeSupportImpl::create_datareader()\n" 00199 "{\n" 00200 " typedef OpenDDS::DCPS::DataReaderImpl_T<" << short_name << "> DataReaderImplType;\n" 00201 " ::DDS::DataReader_ptr reader_impl = ::DDS::DataReader::_nil();\n" 00202 " ACE_NEW_NORETURN(reader_impl,\n" 00203 " DataReaderImplType());\n" 00204 " return reader_impl;\n" 00205 "}\n\n" 00206 "#ifndef OPENDDS_NO_MULTI_TOPIC\n" 00207 "::DDS::DataReader_ptr " << short_name << "TypeSupportImpl::create_multitopic_datareader()\n" 00208 "{\n" 00209 " typedef OpenDDS::DCPS::DataReaderImpl_T<" << short_name << "> DataReaderImplType;\n" 00210 " typedef OpenDDS::DCPS::MultiTopicDataReader_T<" << short_name << ", DataReaderImplType> MultiTopicDataReaderImplType;\n" 00211 " ::DDS::DataReader_ptr multitopic_reader_impl = ::DDS::DataReader::_nil();\n" 00212 " ACE_NEW_NORETURN(multitopic_reader_impl,\n" 00213 " MultiTopicDataReaderImplType());\n" 00214 " return multitopic_reader_impl;\n" 00215 "}\n" 00216 "#endif /* !OPENDDS_NO_MULTI_TOPIC */\n\n" 00217 "#ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE\n" 00218 "const OpenDDS::DCPS::MetaStruct& " << short_name << "TypeSupportImpl::getMetaStructForType()\n" 00219 "{\n" 00220 " return OpenDDS::DCPS::getMetaStruct<" << short_name << ">();\n" 00221 "}\n" 00222 "#endif /* !OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE */\n\n" 00223 "bool " << short_name << "TypeSupportImpl::has_dcps_key()\n" 00224 "{\n" 00225 " return TraitsType::gen_has_key ();\n" 00226 "}\n\n" 00227 "const char* " << short_name << "TypeSupportImpl::default_type_name() const\n" 00228 "{\n" 00229 " return TraitsType::type_name();\n" 00230 "}\n\n" 00231 << short_name << "TypeSupport::_ptr_type " << short_name << "TypeSupportImpl::_narrow(CORBA::Object_ptr obj)\n" 00232 "{\n" 00233 " return TypeSupportType::_narrow(obj);\n" 00234 "}\n"; 00235 } 00236 be_global->impl_ << be_global->versioning_end() << "\n"; 00237 00238 if (be_global->face_ts()) { 00239 face_ts_generator::generate(name); 00240 } 00241 00242 return true; 00243 }
bool ts_generator::gen_typedef | ( | AST_Typedef * | , | |
UTL_ScopedName * | , | |||
AST_Type * | , | |||
const char * | ||||
) | [inline, virtual] |
bool ts_generator::gen_union | ( | AST_Union * | , | |
UTL_ScopedName * | name, | |||
const std::vector< AST_UnionBranch * > & | , | |||
AST_Type * | , | |||
const char * | ||||
) | [virtual] |
Implements dds_generator.
Definition at line 245 of file ts_generator.cpp.
References scoped().
00247 { 00248 if (idl_global->is_dcps_type(name)) { 00249 std::cerr << "ERROR: union " << scoped(name) << " can not be used as a " 00250 "DCPS_DATA_TYPE (only structs can be Topic types)" << std::endl; 00251 return false; 00252 } 00253 return true; 00254 }
std::string ts_generator::idl_template_ [private] |
Definition at line 38 of file ts_generator.h.
Referenced by gen_struct().