TemplateValueFactory.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Fri Mar 16 21:32:02 2012 +0100 TemplateValueFactory.hpp
3 
4  TemplateValueFactory.hpp - description
5  -------------------
6  begin : Fri Mar 16 2012
7  copyright : (C) 2012 Peter Soetens
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  * 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 RTT_TEMPLATE_TYPE_FACTORY
40 #define RTT_TEMPLATE_TYPE_FACTORY
41 
42 #include "ValueFactory.hpp"
43 #include "../Property.hpp"
44 #include "../Attribute.hpp"
45 #include "../Logger.hpp"
46 #include "../rtt-config.h"
47 
48 namespace RTT
49 {
50  namespace types {
51 
52  template<class T>
54  : public ValueFactory
55  {
56  public:
57  typedef T DataType;
59  {
62  if ( res ) {
63  res->get();
64  //Logger::log() << Logger::Info << "Building "<<tname<<" Constant '"<<name<<"' with value "<< dsb->getTypeInfo()->toString(dsb) <<Logger::endl;
65  return new Constant<DataType>( name, res->rvalue() );
66  }
67  else
68  return 0;
69  }
70 
71  base::AttributeBase* buildVariable(std::string name) const
72  {
73  // A variable starts its life as unbounded.
74  //Logger::log() << Logger::Debug << "Building variable '"<<name <<"' of type " << tname <<Logger::endl;
76  }
77 
79  {
81  if ( !in )
83  else
85  if (!ds)
86  return 0;
87  // An attribute is always bounded.
88  //Logger::log() << Logger::Debug << "Building Attribute '"<< name <<"' of type " << tname <<Logger::endl;
89  return new Attribute<DataType>( name, ds.get() );
90  }
91 
93  {
95  if ( ! ds )
96  return 0;
97  return new Alias( name, ds );
98  }
99 
101  {
102  typename internal::AssignableDataSource<T>::shared_ptr ads = boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >( in ); // no type conversion is done.
103  if ( ads )
104  return new internal::ActionAliasAssignableDataSource<T>(action, ads.get());
105 
106  typename internal::DataSource<T>::shared_ptr ds = boost::dynamic_pointer_cast< internal::DataSource<T> >( in ); // no type conversion is done.
107  if ( ! ds )
108  return 0;
109  return new internal::ActionAliasDataSource<T>(action, ds.get());
110  }
111 
112  virtual base::PropertyBase* buildProperty(const std::string& name, const std::string& desc, base::DataSourceBase::shared_ptr source = 0) const {
113  if (source) {
115  = boost::dynamic_pointer_cast< internal::AssignableDataSource<DataType> >( source );
116  if (ad)
117  return new Property<DataType>(name, desc, ad );
118  else {
119  //log(Error) <<"Failed to build 'Property<"<< this->tname <<"> "<<name<<"' from given DataSourceBase. Returning default."<<endlog();
120  }
121  }
122  return new Property<DataType>(name, desc, DataType());
123  }
124 
127  }
129  return new internal::ReferenceDataSource<DataType>(*static_cast<DataType*>(ptr));
130  }
131 
132  };
133 
134  }
135 }
136 
137 #endif
base::AttributeBase * buildConstant(std::string name, base::DataSourceBase::shared_ptr dsb) const
virtual result_t get() const =0
base::DataSourceBase::shared_ptr convert(base::DataSourceBase::shared_ptr arg) const
Definition: TypeInfo.cpp:118
virtual base::DataSourceBase::shared_ptr buildReference(void *ptr) const
virtual base::PropertyBase * buildProperty(const std::string &name, const std::string &desc, base::DataSourceBase::shared_ptr source=0) const
base::AttributeBase * buildVariable(std::string name) const
base::DataSourceBase::shared_ptr buildActionAlias(base::ActionInterface *action, base::DataSourceBase::shared_ptr in) const
virtual base::DataSourceBase::shared_ptr buildValue() const
virtual const_reference_t rvalue() const =0
A property represents a named value of any type with a description.
Definition: Property.hpp:76
Based on the software pattern &#39;command&#39;, this interface allows execution of action objects...
static AssignableDataSource< T > * narrow(base::DataSourceBase *db)
DataSource< T >::result_t get() const
boost::intrusive_ptr< DataSource< T > > shared_ptr
Definition: DataSource.hpp:115
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Definition: DataSource.hpp:198
static const types::TypeInfo * getTypeInfo()
DataSource< T >::result_t get() const
Definition: DataSources.hpp:78
base::AttributeBase * buildAttribute(std::string name, base::DataSourceBase::shared_ptr in) const
base::AttributeBase * buildAlias(std::string name, base::DataSourceBase::shared_ptr in) const
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53


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