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


orogen
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Sat Jun 8 2019 19:52:17