Orocos Real-Time Toolkit  2.8.3
DataSource.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon May 10 19:10:37 CEST 2004 DataSource.cxx
3 
4  DataSource.cxx - description
5  -------------------
6  begin : Mon May 10 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
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 #include "DataSource.hpp"
38 #include "../types/TypeInfoName.hpp"
39 
40 #include "rtt-config.h"
41 #include "../types/Types.hpp"
42 #include "../types/TypeTransporter.hpp"
43 
44 namespace RTT {
45  namespace base {
46  std::ostream& operator<<(std::ostream& os, DataSourceBase::shared_ptr mobj)
47  {
48  return mobj->getTypeInfo()->write( os, mobj );
49  }
50 
52  {
53  p->ref();
54  }
55 
57  {
58  p->deref();
59  }
60 
61  }
62 
63  using namespace detail;
64  using namespace std;
65 
67  const char* bad_assignment::what() const throw() { return "Bad DataSource assignment: incompatible types."; }
68 
70  dsb->ref();
71  return DataSourceBase::shared_ptr(dsb);
72  }
73 
75  dsb->ref();
76  return DataSourceBase::const_ptr(dsb);
77  }
78 
79  DataSourceBase::DataSourceBase() : refcount(0) { }
80  void DataSourceBase::ref() const { refcount.inc(); }
81  void DataSourceBase::deref() const { if ( refcount.dec_and_test() ) delete this; }
82 
84  {
85  }
86 
88  {
89  }
90 
91  std::ostream& DataSourceBase::write(std::ostream& os)
92  {
93  DataSourceBase::shared_ptr mobj(this);
94  return mobj->getTypeInfo()->write( os, mobj );
95  }
96 
97 
99  {
100  DataSourceBase::shared_ptr mobj(this);
101  return mobj->getTypeInfo()->toString( mobj );
102  }
103 
105  return false;
106  }
107 
109  return false;
110  }
111 
113  {}
114 
116  { return 0; }
118  { return 0; }
119 
121  return 0;
122  }
123 
124  DataSourceBase::shared_ptr DataSourceBase::getMember( const std::string& part_name ) {
125  if ( part_name.empty() )
126  return DataSourceBase::shared_ptr(this);
127  return getTypeInfo()->getMember( this, part_name );
128  }
129 
131  return getTypeInfo()->getMember( this, part_id );
132  }
133 
134  vector<string> DataSourceBase::getMemberNames() const {
135  return getTypeInfo()->getMemberNames();
136  }
137 
139  return this;
140  }
141 
142  namespace internal {
143 
145 
148  const std::string& DataSourceTypeInfo<UnknownType>::getQualifier() { return noqual; }
150  if (!TypeInfoObject)
151  TypeInfoObject = new TypeInfo("unknown_t");
152  return TypeInfoObject;
153  }
154 
155  const std::string DataSourceTypeInfo<UnknownType>::noqual("");
156  const std::string DataSourceTypeInfo<UnknownType>::cqual(" const");
157  const std::string DataSourceTypeInfo<UnknownType>::refqual(" &");
158  const std::string DataSourceTypeInfo<UnknownType>::crefqual(" const&");
159  const std::string DataSourceTypeInfo<UnknownType>::ptrqual(" *");
160  const std::string DataSourceTypeInfo<UnknownType>::cptrqual(" const*");
161 
162  // (void) type info
164  const std::string DataSourceTypeInfo<void>::tname("void");
165 
166  const std::string& DataSourceTypeInfo<void>::getType() { return tname; }
167  const std::string& DataSourceTypeInfo<void>::getTypeName() { return tname; }
168  const std::string& DataSourceTypeInfo<void>::getQualifier() { return DataSourceTypeInfo<UnknownType>::noqual; }
170  if (!TypeInfoObject)
172  return TypeInfoObject;
173  }
174  }
175 }
176 
virtual void const * getRawConstPointer()
Returns a const pointer to the sample contained in this data source, if there is any.
Definition: DataSource.cpp:117
const std::string & getTypeName() const
Return the type name which was first registered.
Definition: TypeInfo.hpp:82
virtual std::vector< std::string > getMemberNames() const
Returns the names of all members of the structure contained in this data source, or an empty list if ...
Definition: DataSource.cpp:134
The base class for all internal data representations.
static const std::string & getQualifier()
Return the &#39;const&#39;, &#39;ref&#39;, &#39;pointer&#39; qualifier for this type.
std::ostream & write(std::ostream &os)
Stream the contents of this object.
Definition: DataSource.cpp:91
static shared_ptr stack_shared_ptr(DataSourceBase *dsb)
Returns a shared ptr to a DataSourceBase living on the stack.
Definition: DataSource.cpp:69
virtual ActionInterface * updateAction(DataSourceBase *other)
Generate a ActionInterface object which will update this internal::DataSource with the value of anoth...
Definition: DataSource.cpp:120
void RTT_API intrusive_ptr_add_ref(ChannelElementBase *e)
virtual ~DataSourceBase()
the destructor is private.
Definition: DataSource.cpp:83
STL namespace.
virtual const types::TypeInfo * getTypeInfo() const =0
Return the Orocos type info object.
os::AtomicInt refcount
We keep the refcount ourselves.
virtual void reset()
Reset the data to initial values.
Definition: DataSource.cpp:87
virtual void * getRawPointer()
Returns a pointer to the sample contained in this data source, if there is any, and if it is an lvalu...
Definition: DataSource.cpp:115
virtual const char * what() const
Definition: DataSource.cpp:67
virtual bool isAssignable() const
Returns true if this object can be cast to an AssignableDataSource.
Definition: DataSource.cpp:104
virtual bool update(DataSourceBase *other)
Update the value of this internal::DataSource with the value of an other DataSource.
Definition: DataSource.cpp:108
static const std::string & getType()
Return the qualified type.
std::vector< std::string > getMemberNames() const
Returns the list of struct member names of this type.
Definition: TypeInfo.hpp:323
bool dec_and_test()
Decrement and test if the result is zero.
Definition: Atomic.hpp:104
static const types::TypeInfo * getTypeInfo()
Return the typeinfo object.
base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string &name) const
Returns a member of a given data source struct identified by its name.
Definition: TypeInfo.hpp:335
RTT_API std::ostream & operator<<(std::ostream &os, DataSourceBase::shared_ptr dsb)
Stream the contents of this object.
Definition: DataSource.cpp:46
Based on the software pattern &#39;command&#39;, this interface allows execution of action objects...
A class for representing a user type, and which can build instances of that type. ...
Definition: TypeInfo.hpp:66
static const_ptr stack_const_ptr(const DataSourceBase *dsb)
Returns a const shared_ptr to a DataSourceBase living on the stack.
Definition: DataSource.cpp:74
virtual shared_ptr getMember(const std::string &member_name)
Get a (const) reference data source to a member of the structure of this data source.
Definition: DataSource.cpp:124
boost::intrusive_ptr< const DataSourceBase > const_ptr
Use this type to store a const pointer to a DataSourceBase.
Every DataSource of type T has a type info class which it can ask type information.
void RTT_API intrusive_ptr_release(ChannelElementBase *e)
std::string toString()
Get the contents of this object as a string.
Definition: DataSource.cpp:98
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
void ref() const
Increase the reference count by one.
Definition: DataSource.cpp:80
void deref() const
Decrease the reference count by one and delete this on zero.
Definition: DataSource.cpp:81
virtual void updated()
In case the internal::DataSource returns a &#39;reference&#39; type, call this method to notify it that the d...
Definition: DataSource.cpp:112
static const std::string & getTypeName()
Return the unqualified typename.
virtual shared_ptr getParent()
Returns the top level data source that contains the full data structure this data source refers to...
Definition: DataSource.cpp:138