TemplateCompositionFactory.hpp
Go to the documentation of this file.
00001 #ifndef RTT_TEMPLATE_COMPOSITION_FACTORY_HPP
00002 #define RTT_TEMPLATE_COMPOSITION_FACTORY_HPP
00003 
00004 #include "CompositionFactory.hpp"
00005 #include "../Property.hpp"
00006 #include "../PropertyBag.hpp"
00007 
00008 namespace RTT {
00009     namespace types {
00010         template<typename T>
00011         class TemplateCompositionFactory
00012             : public CompositionFactory
00013         {
00014         public:
00015 
00019         typedef T UserType;
00020 
00021         virtual bool composeType( base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr result) const {
00022             const internal::DataSource<PropertyBag>* pb = dynamic_cast< const internal::DataSource<PropertyBag>* > (source.get() );
00023             if ( !pb )
00024                 return false;
00025             typename internal::AssignableDataSource<UserType>::shared_ptr ads = boost::dynamic_pointer_cast< internal::AssignableDataSource<UserType> >( result );
00026             if ( !ads )
00027                 return false;
00028 
00029             // last fall-back: use user supplied function:
00030             if ( composeTypeImpl( pb->rvalue(), ads->set() ) )
00031                 ads->updated();
00032             else {
00033                 Logger::log() <<Logger::Debug<<"Failed to compose from "<< source->getTypeName() <<Logger::endl;
00034                 return false;
00035             }
00036             Logger::log() <<Logger::Debug<<"Successfuly composed type from "<< source->getTypeName() <<Logger::endl;
00037             return true;
00038         }
00039 
00046         virtual base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
00047         {
00048             // Extract typed values
00049             typename internal::DataSource<UserType>::shared_ptr ds = boost::dynamic_pointer_cast< internal::DataSource<UserType> >( source );
00050             if ( !ds )
00051                 return base::DataSourceBase::shared_ptr(); // happens in the case of 'unknown type'
00052             Property<PropertyBag> targetbag_p("targetbag");
00053             if (decomposeTypeImpl( ds->rvalue(), targetbag_p.value() ))
00054                 return targetbag_p.getDataSource();
00055             return base::DataSourceBase::shared_ptr();
00056         }
00057 
00061         virtual bool composeTypeImpl(const PropertyBag& source,  typename internal::AssignableDataSource<T>::reference_t result) const {
00062             return false;
00063         }
00064 
00069         virtual bool decomposeTypeImpl( typename internal::AssignableDataSource<T>::const_reference_t source, PropertyBag& targetbag ) const {
00070             return false;
00071         }
00072 
00073     };
00074     }
00075 }
00076 
00077 #endif


rtt
Author(s): RTT Developers
autogenerated on Sat Jun 8 2019 18:46:33