Go to the documentation of this file.00001
00002
00003 #include <<%= typekit.name %>/Types.hpp>
00004 #include <<%= typekit.name %>/type_info/BoostSerialization.hpp>
00005 #include <rtt/types/StructTypeInfo.hpp>
00006 #include <rtt/types/TypeInfoRepository.hpp>
00007 #include <<%= typekit.name %>/OpaqueConvertions.hpp>
00008
00009 <% base_class =
00010 if !Orocos::TypekitMarshallers::TypeInfo::Plugin.rtt_scripting?
00011 ["RTT::types::PrimitiveTypeInfo< #{type.cxx_name} >", "RTT::types::TemplateConnFactory< #{type.cxx_name} >"]
00012 else
00013 ["RTT::types::TemplateTypeInfo< #{type.cxx_name} >"]
00014 end
00015 %>
00016
00017 namespace orogen_typekits {
00018 struct <%= type.method_name(true) %>TypeInfo :
00019 public <%= base_class.join(", public ") %>
00020 {
00021 mutable RTT::types::TypeInfo* intermediate_type_info;
00022
00023 void getIntermediateTypeInfo() const
00024 {
00025 if (intermediate_type_info)
00026 return;
00027
00028 RTT::types::TypeInfoRepository::shared_ptr ti = RTT::types::TypeInfoRepository::Instance();
00029 intermediate_type_info = ti->type("<%= intermediate_type.name %>");
00030 if (!intermediate_type_info)
00031 throw std::runtime_error("cannot initialize TypeInfo for opaque <%= type.full_name %> as I cannot find the TypeInfo for the intermediate type <%= intermediate_type.name %>");
00032 }
00033
00034 typedef <%= type.cxx_name %> T;
00035
00036 <%= type.method_name(true) %>TypeInfo()
00037 : <%= base_class.first %>("<%= type.full_name %>")
00038 {
00039 }
00040
00041 <% if Orocos::TypekitMarshallers::TypeInfo::Plugin.rtt_scripting? %>
00042 virtual bool composeType(RTT::base::DataSourceBase::shared_ptr source, RTT::base::DataSourceBase::shared_ptr target) const
00043 {
00044 getIntermediateTypeInfo();
00045
00046 <% if needs_copy %>
00047 <%= intermediate_type.cxx_name %> intermediate;
00048 typedef RTT::internal::ReferenceDataSource< <%= intermediate_type.cxx_name %> > IntermediateSource;
00049 IntermediateSource::shared_ptr intermediate_ptr =
00050 new IntermediateSource(intermediate);
00051 if (!intermediate_type_info->getCompositionFactory()->composeType(source, intermediate_ptr))
00052 return false;
00053 <% else %>
00054 std::auto_ptr< <%= intermediate_type.cxx_name %> > intermediate(new <%= intermediate_type.cxx_name %>);
00055 typedef RTT::internal::ReferenceDataSource< <%= intermediate_type.cxx_name %> > IntermediateSource;
00056 IntermediateSource::shared_ptr intermediate_ptr =
00057 new IntermediateSource(*intermediate);
00058 if (!intermediate_type_info->getCompositionFactory()->composeType(source, intermediate_ptr))
00059 return false;
00060 <% end %>
00061
00062 RTT::internal::AssignableDataSource<T>::shared_ptr value_source =
00063 boost::dynamic_pointer_cast< RTT::internal::AssignableDataSource<T> >( target );
00064 <%= type.cxx_name %>& value = value_source->set();
00065 <%= typekit.code_fromIntermediate(intermediate_type, needs_copy, " " * 8) %>
00066 return true;
00067 }
00068
00069 virtual RTT::base::DataSourceBase::shared_ptr getMember(RTT::base::DataSourceBase::shared_ptr item, const std::string& name) const {
00070 getIntermediateTypeInfo();
00071
00072 RTT::internal::AssignableDataSource<T>::shared_ptr value_source =
00073 boost::dynamic_pointer_cast< RTT::internal::AssignableDataSource<T> >( item );
00074 if ( !value_source ) {
00075 log(RTT::Error) << "TypeInfo of type "<< this->getTypeName() <<" can't handle (non-assignable) types of type "<< item->getTypeInfo() <<RTT::endlog();
00076 return RTT::base::DataSourceBase::shared_ptr();
00077 }
00078
00079 <%= type.cxx_name %> const& value = (*value_source).get();
00080 <%= typekit.code_toIntermediate(intermediate_type, needs_copy, " " * 8) %>
00081
00082 typedef RTT::internal::ConstReferenceDataSource< <%= intermediate_type.cxx_name %> > IntermediateSource;
00083 IntermediateSource::shared_ptr intermediate_ptr =
00084 new IntermediateSource(intermediate);
00085 return intermediate_type_info->getMemberFactory()->getMember(intermediate_ptr, name);
00086 }
00087
00088 virtual RTT::base::DataSourceBase::shared_ptr getMember(RTT::base::DataSourceBase::shared_ptr item,
00089 RTT::base::DataSourceBase::shared_ptr id) const {
00090 getIntermediateTypeInfo();
00091
00092 RTT::internal::AssignableDataSource<T>::shared_ptr value_source =
00093 boost::dynamic_pointer_cast< RTT::internal::AssignableDataSource<T> >( item );
00094 if ( !value_source ) {
00095 log(RTT::Error) << "TypeInfo of type "<< this->getTypeName() <<" can't handle (non-assignable) types of type "<< item->getTypeInfo() <<RTT::endlog();
00096 return RTT::base::DataSourceBase::shared_ptr();
00097 }
00098
00099 <%= type.cxx_name %> const& value = (*value_source).get();
00100 <%= typekit.code_toIntermediate(intermediate_type, needs_copy, " " * 8) %>
00101 typedef RTT::internal::ConstReferenceDataSource< <%= intermediate_type.cxx_name %> > IntermediateSource;
00102 IntermediateSource::shared_ptr intermediate_ptr =
00103 new IntermediateSource(intermediate);
00104 return intermediate_type_info->getMemberFactory()->getMember(intermediate_ptr, id);
00105 }
00106 <% end %>
00107
00108 <% if !Orocos::TypekitMarshallers::TypeInfo::Plugin.rtt_scripting? %>
00109 bool installTypeInfoObject(RTT::types::TypeInfo* ti) {
00110
00111
00112
00113 boost::shared_ptr< <%= type.method_name(true) %>TypeInfo > mthis =
00114 boost::dynamic_pointer_cast< <%= type.method_name(true) %>TypeInfo >( this->getSharedPtr() );
00115
00116
00117 RTT::types::PrimitiveTypeInfo< <%= type.cxx_name %> >::installTypeInfoObject(ti);
00118
00119 ti->setPortFactory(mthis);
00120
00121 return false;
00122 }
00123 <% end %>
00124 };
00125
00126 RTT::types::TypeInfoGenerator* <%= type.method_name(true) %>_TypeInfo()
00127 { return new <%= type.method_name(true) %>TypeInfo(); }
00128 }
00129
00130 <%= Generation.render_template('typekit', 'TemplateInstanciation.cpp', binding) %>
00131
00132