PrimitiveTypeInfo.hpp
Go to the documentation of this file.
00001 #ifndef ORO_PRIMITIVE_TYPEINFO_HPP
00002 #define ORO_PRIMITIVE_TYPEINFO_HPP
00003 
00004 #include "Types.hpp"
00005 #include "../Property.hpp"
00006 #include "../Attribute.hpp"
00007 #include "../Logger.hpp"
00008 #include "TypeStreamSelector.hpp"
00009 #include "TypeInfoGenerator.hpp"
00010 #include "StreamFactory.hpp"
00011 #include "TemplateValueFactory.hpp"
00012 #include "../rtt-config.h"
00013 
00014 namespace RTT
00015 {
00016     namespace types {
00017 
00031     template<typename T, bool use_ostream = false>
00032     class PrimitiveTypeInfo :
00033             public TypeInfoGenerator,
00034             public TemplateValueFactory<T>,
00035             public StreamFactory
00036     {
00037     protected:
00038         const std::string tname;
00039         boost::shared_ptr<PrimitiveTypeInfo<T, use_ostream> > mshared;
00040     public:
00044         typedef T DataType;
00045 
00053         PrimitiveTypeInfo(std::string name)
00054             : tname(name)
00055         {
00056         }
00057 
00058         virtual ~PrimitiveTypeInfo()
00059         {
00060         }
00061 
00062         boost::shared_ptr<PrimitiveTypeInfo<T, use_ostream> > getSharedPtr() {
00063             if (!mshared)
00064                 mshared.reset(this);
00065             return mshared;
00066         }
00067 
00068         bool installTypeInfoObject(TypeInfo* ti) {
00069             // Install the factories for primitive types
00070             ti->setValueFactory( this->getSharedPtr() );
00071             if (use_ostream)
00072               ti->setStreamFactory( this->getSharedPtr() );
00073 
00074             // Install the type info object for T
00075             internal::DataSourceTypeInfo<T>::value_type_info::TypeInfoObject = ti;
00076             ti->setTypeId( &typeid(T) );
00077 
00078             // Clean up reference to ourselves.
00079             mshared.reset();
00080             // Don't delete us, we're memory-managed.
00081             return false;
00082         }
00083 
00084         TypeInfo* getTypeInfoObject() const {
00085             return TypeInfoRepository::Instance()->getTypeInfo<T>();
00086         }
00087 
00088         virtual const std::string& getTypeName() const { return tname; }
00089 
00090         virtual std::ostream& write( std::ostream& os, base::DataSourceBase::shared_ptr in ) const {
00091             typename internal::DataSource<T>::shared_ptr d = boost::dynamic_pointer_cast< internal::DataSource<T> >( in );
00092             if ( d ) {
00093                 types::TypeStreamSelector<T, use_ostream>::write( os, d->rvalue() );
00094             }
00095             return os;
00096         }
00097 
00098         virtual std::istream& read( std::istream& os, base::DataSourceBase::shared_ptr out ) const {
00099             typename internal::AssignableDataSource<T>::shared_ptr d = boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >( out );
00100             if ( d ) {
00101                 types::TypeStreamSelector<T, use_ostream>::read( os, d->set() );
00102                 d->updated(); // because use of set().
00103             }
00104             return os;
00105         }
00106 
00107         virtual bool isStreamable() const {
00108             return use_ostream;
00109         }
00110 
00111         virtual bool composeType( base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr result) const {
00112             return false;
00113         }
00114 
00118         virtual base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
00119         {
00120             return source;
00121         }
00122 
00123         virtual bool decomposeType( base::DataSourceBase::shared_ptr source, PropertyBag& targetbag ) const {
00124             return false;
00125         }
00126     };
00127 }}
00128 
00129 #endif


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