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
Definition: Property.hpp:246
const std::string & getType() const
A container for holding references to properties.
Definition: PropertyBag.hpp:96
static const std::string & getTypeName()
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
TypeInfoRepository::shared_ptr Types()
Definition: Types.cpp:48
base::PropertyBase * getItem(int i) const
static Logger & log()
Definition: Logger.cpp:117
const std::string & getName() const
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
size_t size() const
boost::shared_ptr< TypeInfoRepository > shared_ptr
bool composeTemplateProperty(const PropertyBag &bag, T &result)


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:38