Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef ORO_STRUCT_TYPE_INFO_HPP
00040 #define ORO_STRUCT_TYPE_INFO_HPP
00041
00042 #include "TemplateTypeInfo.hpp"
00043 #include "PropertyDecomposition.hpp"
00044 #include "type_discovery.hpp"
00045 #include "MemberFactory.hpp"
00046
00047 namespace RTT
00048 {
00049 namespace types
00050 {
00061 template<typename T, bool has_ostream = false>
00062 class StructTypeInfo: public TemplateTypeInfo<T, has_ostream>, public MemberFactory
00063 {
00064 public:
00065 StructTypeInfo(std::string name) :
00066 TemplateTypeInfo<T, has_ostream> (name)
00067 {
00068 }
00069
00070 bool installTypeInfoObject(TypeInfo* ti) {
00071
00072 boost::shared_ptr< StructTypeInfo<T,has_ostream> > mthis = boost::dynamic_pointer_cast<StructTypeInfo<T,has_ostream> >( this->getSharedPtr() );
00073 assert(mthis);
00074
00075 TemplateTypeInfo<T,has_ostream>::installTypeInfoObject(ti);
00076
00077 ti->setMemberFactory( mthis );
00078
00079
00080 return false;
00081 }
00082
00083 virtual std::vector<std::string> getMemberNames() const {
00084
00085 type_discovery in;
00086 T t;
00087 in.discover( t );
00088 return in.mnames;
00089 }
00090
00091 virtual base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item,
00092 base::DataSourceBase::shared_ptr id) const {
00093
00094
00095
00096
00097 assert(false && "You're doing something new and exotic. Contact the Orocos-dev mailing list.");
00098 return base::DataSourceBase::shared_ptr();
00099 }
00100
00101 virtual base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string& name) const {
00102 typename internal::AssignableDataSource<T>::shared_ptr adata = boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >( item );
00103
00104 if ( !adata ) {
00105
00106 typename internal::DataSource<T>::shared_ptr data = boost::dynamic_pointer_cast< internal::DataSource<T> >( item );
00107 if ( data ) {
00108
00109 adata = new internal::ValueDataSource<T>( data->get() );
00110 }
00111 }
00112 if (adata) {
00113 type_discovery in( adata );
00114 return in.discoverMember( adata->set(), name );
00115 }
00116 log(Error) << "Wrong call to type info function " + this->getTypeName() << "'s getMember() can not process "<< item->getTypeName() <<endlog();
00117 return base::DataSourceBase::shared_ptr();
00118 }
00119
00120 virtual bool getMember(internal::Reference* ref, base::DataSourceBase::shared_ptr item, const std::string& name) const {
00121 typename internal::AssignableDataSource<T>::shared_ptr adata = boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >( item );
00122
00123 if ( !adata ) {
00124
00125 typename internal::DataSource<T>::shared_ptr data = boost::dynamic_pointer_cast< internal::DataSource<T> >( item );
00126 if ( data ) {
00127
00128 adata = new internal::ValueDataSource<T>( data->get() );
00129 }
00130 }
00131 if (adata) {
00132 type_discovery in( adata );
00133 return in.referenceMember( ref, adata->set(), name );
00134 }
00135 log(Error) << "Wrong call to type info function " + this->getTypeName() << "'s getMember() can not process "<< item->getTypeName() <<endlog();
00136 return false;
00137 }
00138
00139 virtual bool resize(base::DataSourceBase::shared_ptr arg, int size) const
00140 {
00141 return false;
00142 }
00143
00144
00150 virtual bool composeTypeImpl(const PropertyBag& source, typename internal::AssignableDataSource<T>::reference_t result) const {
00151
00152 TypeInfoRepository::shared_ptr tir = Types();
00153 internal::ReferenceDataSource<T> rds(result);
00154 rds.ref();
00155 PropertyBag decomp;
00156
00157
00158
00159
00160 return typeDecomposition( &rds, decomp, false) && ( tir->type(decomp.getType()) == tir->type(source.getType()) ) && refreshProperties(decomp, source);
00161 }
00162
00163
00164 };
00165 }
00166 }
00167
00168 #endif