Orocos Real-Time Toolkit  2.8.3
VectorTemplateComposition.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Tinne De Laet 2007 VectorTemplateComposition.hpp
3  2007 Ruben Smits
4  VectorTemplateComposition.hpp - description
5 
6  ***************************************************************************
7  * This library is free software; you can redistribute it and/or *
8  * modify it under the terms of the GNU General Public *
9  * License as published by the Free Software Foundation; *
10  * version 2 of the License. *
11  * *
12  * As a special exception, you may use this file as part of a free *
13  * software library without restriction. Specifically, if other files *
14  * instantiate templates or use macros or inline functions from this *
15  * file, or you compile this file and link it with other files to *
16  * produce an executable, this file does not by itself cause the *
17  * resulting executable to be covered by the GNU General Public *
18  * License. This exception does not however invalidate any other *
19  * reasons why the executable file might be covered by the GNU General *
20  * Public License. *
21  * *
22  * This library is distributed in the hope that it will be useful, *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
25  * Lesser General Public License for more details. *
26  * *
27  * You should have received a copy of the GNU General Public *
28  * License along with this library; if not, write to the Free Software *
29  * Foundation, Inc., 59 Temple Place, *
30  * Suite 330, Boston, MA 02111-1307 USA *
31  * *
32  ***************************************************************************/
33 
34 #ifndef VECTOR_TEMPLATE_COMPOSITION_HPP
35 #define VECTOR_TEMPLATE_COMPOSITION_HPP
36 
37 #include "../Property.hpp"
38 #include "../PropertyBag.hpp"
39 #include "Types.hpp"
40 #include "../Logger.hpp"
41 #include "../internal/DataSources.hpp"
42 #include <vector>
43 
44 namespace RTT
45 {
46  namespace types {
47 
48  template<class T>
49  bool composeTemplateProperty(const PropertyBag& bag, T& result)
50  {
52  if ( tir->type( bag.getType()) == tir->getTypeInfo< T >() ) {
54  int dimension = bag.size();
55  result.resize( dimension );
56 
57  // Get values
58  int size_correction = 0;
59  for (int i = 0; i < dimension ; i++) {
60  base::PropertyBase* element = bag.getItem( i );
61  comp = dynamic_cast< Property< typename T::value_type>* >( element );
62  if ( comp == 0 ) {
63  // detect LEGACY element:
64  if ( element->getName() == "Size" ) {
65  // oops, our result vector will be one smaller.
66  size_correction += 1;
67  continue;
68  }
69  Logger::log() << Logger::Error << "Aborting composition of Property< T > "
70  << ": Exptected data element "<< i << " to be of type " << internal::DataSourceTypeInfo< typename T::value_type>::getTypeName()
71  <<" got type " << element->getType()
72  <<Logger::endl;
73  return false;
74  }
75  result[ i - size_correction ] = comp->get();
76  }
77  result.resize( dimension - size_correction );
78  }
79  else {
80  Logger::log() << Logger::Error << "Composing Property< T > :"
81  << " type mismatch, got type '"<< bag.getType()
83  return false;
84  }
85  return true;
86  }
87  }
88 }
89 
90 #endif
91 
DataSourceType get() const
Get a copy of the value of the property.
Definition: Property.hpp:246
const std::string & getType() const
Base class for all properties.
A container for holding references to properties.
Definition: PropertyBag.hpp:96
A property represents a named value of any type with a description.
Definition: Property.hpp:76
static std::ostream & endl(std::ostream &__os)
Definition: Logger.cpp:383
virtual std::string getType() const =0
Returns the type of this PropertyBase.
TypeInfoRepository::shared_ptr Types()
Obtain a pointer to the global type system.
Definition: Types.cpp:48
base::PropertyBase * getItem(int i) const
Returns the i&#39;th Property, starting from 0.
static Logger & log()
As Instance(), but more userfriendly.
Definition: Logger.cpp:117
const std::string & getName() const
Get the name of the property.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
size_t size() const
Get the number of Properties in this bag.
boost::shared_ptr< TypeInfoRepository > shared_ptr
static const std::string & getTypeName()
Return the unqualified typename.
bool composeTemplateProperty(const PropertyBag &bag, T &result)