StructTypeInfo.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 StructTypeInfo.hpp
3 
4  StructTypeInfo.hpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_STRUCT_TYPE_INFO_HPP
40 #define ORO_STRUCT_TYPE_INFO_HPP
41 
42 #include "TemplateTypeInfo.hpp"
44 #include "type_discovery.hpp"
45 #include "MemberFactory.hpp"
46 
47 namespace RTT
48 {
49  namespace types
50  {
61  template<typename T, bool has_ostream = false>
62  class StructTypeInfo: public TemplateTypeInfo<T, has_ostream>, public MemberFactory
63  {
64  public:
65  StructTypeInfo(std::string name) :
66  TemplateTypeInfo<T, has_ostream> (name)
67  {
68  }
69 
71  // aquire a shared reference to the this object
72  boost::shared_ptr< StructTypeInfo<T,has_ostream> > mthis = boost::dynamic_pointer_cast<StructTypeInfo<T,has_ostream> >( this->getSharedPtr() );
73  assert(mthis);
74  // Allow base to install first
76  // Install the factories for primitive types
77  ti->setMemberFactory( mthis );
78 
79  // Don't delete us, we're memory-managed.
80  return false;
81  }
82 
83  virtual std::vector<std::string> getMemberNames() const {
84  // only discover the part names of this struct:
85  type_discovery in;
86  T t; // boost can't work without a value.
87  in.discover( t );
88  return in.mnames;
89  }
90 
93  // user tried to pass the member name by data source, but we can't read out this datasource after getMember() returns.
94  // ie, we could only read out id as a string and then call the getMember below.
95  // type_discovery requires the name right now and does not allow to delay the name, unless we discover the whole type,
96  // keep all datasources and then use getMember using some functor data source.... Not going to do that !
97  assert(false && "You're doing something new and exotic. Contact the Orocos-dev mailing list.");
99  }
100 
101  virtual base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string& name) const {
102  typename internal::AssignableDataSource<T>::shared_ptr adata = boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >( item );
103  // Use a copy in case our parent is not assignable:
104  if ( !adata ) {
105  // is it non-assignable ?
106  typename internal::DataSource<T>::shared_ptr data = boost::dynamic_pointer_cast< internal::DataSource<T> >( item );
107  if ( data ) {
108  // create a copy
109  adata = new internal::ValueDataSource<T>( data->get() );
110  }
111  }
112  if (adata) {
113  type_discovery in( adata );
114  return in.discoverMember( adata->set(), name );
115  }
116  log(Error) << "Wrong call to type info function " + this->getTypeName() << "'s getMember() can not process "<< item->getTypeName() <<endlog();
118  }
119 
120  virtual bool getMember(internal::Reference* ref, base::DataSourceBase::shared_ptr item, const std::string& name) const {
121  typename internal::AssignableDataSource<T>::shared_ptr adata = boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >( item );
122  // Use a copy in case our parent is not assignable:
123  if ( !adata ) {
124  // is it non-assignable ?
125  typename internal::DataSource<T>::shared_ptr data = boost::dynamic_pointer_cast< internal::DataSource<T> >( item );
126  if ( data ) {
127  // create a copy -> this is the only place & case where we allocate -> how to fix ?
128  adata = new internal::ValueDataSource<T>( data->get() );
129  }
130  }
131  if (adata) {
132  type_discovery in( adata );
133  return in.referenceMember( ref, adata->set(), name );
134  }
135  log(Error) << "Wrong call to type info function " + this->getTypeName() << "'s getMember() can not process "<< item->getTypeName() <<endlog();
136  return false;
137  }
138 
139  virtual bool resize(base::DataSourceBase::shared_ptr arg, int size) const
140  {
141  return false;
142  }
143 
144 
150  virtual bool composeTypeImpl(const PropertyBag& source, typename internal::AssignableDataSource<T>::reference_t result) const {
151  // The default implementation decomposes result and refreshes it with source.
154  rds.ref(); // prevent dealloc.
155  PropertyBag decomp;
156  // only try refreshProperties if decomp's type is equal to source type.
157  // update vs refresh: since it is intentional that the decomposition leads to references to parts of result,
158  // only refreshProperties() is meaningful (ie we have a one-to-one mapping). In case of sequences, this would
159  // of course not match, so this is struct specific.
160  return typeDecomposition( &rds, decomp, false) && ( tir->type(decomp.getType()) == tir->type(source.getType()) ) && refreshProperties(decomp, source);
161  }
162 
163 
164  };
165  }
166 }
167 
168 #endif
virtual result_t get() const =0
boost::call_traits< value_t >::reference reference_t
Definition: DataSource.hpp:193
const std::string & getType() const
bool refreshProperties(const PropertyBag &target, const PropertyBag &source, bool allprops)
virtual void set(param_t t)=0
bool installTypeInfoObject(TypeInfo *ti)
virtual bool resize(base::DataSourceBase::shared_ptr arg, int size) const
A container for holding references to properties.
Definition: PropertyBag.hpp:96
base::DataSourceBase::shared_ptr discoverMember(T &t, const std::string name)
StructTypeInfo(std::string name)
virtual base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string &name) const
virtual const std::string & getTypeName() const
virtual std::vector< std::string > getMemberNames() const
void setMemberFactory(MemberFactoryPtr mf)
Definition: TypeInfo.hpp:461
virtual bool composeTypeImpl(const PropertyBag &source, typename internal::AssignableDataSource< T >::reference_t result) const
TypeInfoRepository::shared_ptr Types()
Definition: Types.cpp:48
bool typeDecomposition(base::DataSourceBase::shared_ptr dsb, PropertyBag &targetbag, bool recurse)
boost::intrusive_ptr< DataSource< T > > shared_ptr
Definition: DataSource.hpp:115
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Definition: DataSource.hpp:198
bool installTypeInfoObject(TypeInfo *ti)
virtual base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, base::DataSourceBase::shared_ptr id) const
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
boost::shared_ptr< TypeInfoRepository > shared_ptr
static Logger & log()
Definition: Logger.hpp:350
static Logger::LogFunction endlog()
Definition: Logger.hpp:362
bool referenceMember(internal::Reference *ref, T &t, const std::string name)
virtual bool getMember(internal::Reference *ref, base::DataSourceBase::shared_ptr item, const std::string &name) const
boost::shared_ptr< PrimitiveTypeInfo< T, use_ostream > > getSharedPtr()


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:44