datasource_fixture.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:54:57 CEST 2010 datasource_fixture.hpp
3 
4  datasource_fixture.hpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 #ifndef ORO_DATASOURCE_FIXTURE_HPP_
21 #define ORO_DATASOURCE_FIXTURE_HPP_
22 
23 #include <rtt-config.h>
24 #include "unit.hpp"
25 #include <iostream>
26 #include <RTT.hpp>
27 #include <boost/array.hpp>
28 #include <boost/serialization/vector.hpp>
29 
30 using namespace RTT;
31 using namespace RTT::detail;
32 using namespace boost;
33 using namespace std;
34 
41 struct AType
42 {
43  AType(bool ini) { if (ini) init(); else clear(); }
44  AType() { clear(); }
45 
46  void init() {
47  a = (3);
48  b = (9.9);
49  c =("hello");
50  ai.assign(0);
51  ai[3] = 99;
52  vd.resize(10, 5.0);
53  vd[3] = 101;
54  }
55 
56  void clear() {
57  a = 0;
58  b = 0;
59  c.clear();
60  ai[3] = 0;
61  vd.clear();
62  }
63 
64  int a;
65  double b;
66  string c;
67  boost::array<int, 5> ai;
68  vector<double> vd;
69 };
70 
71 typedef std::vector<AType> ATypes;
72 
73 
74 RTT_UNIT_API bool operator==(const AType& a, const AType& b);
75 
76 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const AType& a);
77 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const ATypes& as);
78 
85 struct BType
86 {
87  BType() { clear(); }
88  BType(bool ini) { if (ini) init(); else clear(); }
89  void init() {
90  a = (3);
91  b = (9.9);
92  for(int i = 0; i<10; ++i) c[i] = 0;
93  strcpy(c,"hello");
94  for(int i = 0; i<5; ++i) ai[i] = 3;
95  ai[3] = 99;
96  for(int i = 0; i<10; ++i) vd[i] = 5;
97  vd[3] = 101;
98  }
99  void clear() {
100  a = 0;
101  b = 0;
102  for(int i = 0; i<10; ++i) c[i] = 0;
103  for(int i = 0; i<5; ++i) ai[i] = 0;
104  for(int i = 0; i<10; ++i) vd[i] = 0;
105  }
106 
107  int a;
108  double b;
109  char c[10];
110  int ai[5];
111  double vd[10];
112  //int vvi[2][2];
113 };
114 typedef std::vector<BType> BTypes;
115 
116 RTT_UNIT_API bool operator==(const BType& a, const BType& b);
117 
118 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const BType& a);
119 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const BTypes& a);
120 
126 struct CType
127 {
128  CType() { clear(); }
129  CType(bool ini) { if (ini) init(); else clear(); }
130 
131  void init() {
132  a.init();
133  b.init();
134  av.resize(10, a);
135  bv.resize(10, b);
136  }
139  vector<AType> av;
140  vector<BType> bv;
141 
142  void clear() {
143  a.clear();
144  b.clear();
145  av.clear();
146  bv.clear();
147  }
148 };
149 
150 typedef std::vector<CType> CTypes;
151 
152 RTT_UNIT_API bool operator==(const CType& a, const CType& b);
153 
154 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const CType& a);
155 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const CTypes& a);
156 
157 namespace boost {
158 namespace serialization {
159 
160 template<class Archive>
161 void serialize(Archive & ar, AType & g, const unsigned int version)
162 {
163  ar & make_nvp("a", g.a);
164  ar & make_nvp("b", g.b);
165  ar & make_nvp("c", g.c );
166  ar & make_nvp("ai", g.ai );
167  ar & make_nvp("vd", g.vd );
168 }
169 
170 template<class Archive>
171 void serialize(Archive & ar, BType & g, const unsigned int version)
172 {
173  ar & make_nvp("a", g.a);
174  ar & make_nvp("b", g.b);
175  ar & make_nvp("c", make_array(g.c,10) );
176  ar & make_nvp("ai", make_array(g.ai,5) );
177  ar & make_nvp("vd", make_array(g.vd,10) );
178 
179  //ar & make_nvp("vvi", make_array( g.vvi, 4));
180 }
181 
182 template<class Archive>
183 void serialize(Archive & ar, CType & g, const unsigned int version)
184 {
185  ar & make_nvp("a", g.a);
186  ar & make_nvp("b", g.b);
187  ar & make_nvp("av", g.av );
188  ar & make_nvp("bv", g.bv );
189 }
190 
191 } // namespace serialization
192 } // namespace boost
193 
194 
199  template<typename T>
201  : public DataSource<T>
202  {
203  // a reference to a value_t
206  public:
211 
212  typedef boost::intrusive_ptr<UpdatedReferenceDataSource<T> > shared_ptr;
213 
214  UpdatedReferenceDataSource( typename AssignableDataSource<T>::reference_t ref ) : mref(ref), mcopy(ref) {}
215 
216  typename DataSource<T>::result_t get() const
217  {
218  return mcopy;
219  }
220 
222  {
223  return mcopy;
224  }
225 
227  {
228  return mcopy;
229  }
230 
231  void updated() { mcopy = mref; }
232 
233  virtual UpdatedReferenceDataSource<T>* clone() const { return new UpdatedReferenceDataSource(mref); }
234 
235  virtual UpdatedReferenceDataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const { return clone(); }
236 
237  };
238 
239 #endif /* ORO_DATASOURCE_FIXTURE_HPP_ */
virtual UpdatedReferenceDataSource< T > * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
boost::intrusive_ptr< UpdatedReferenceDataSource< T > > shared_ptr
double vd[10]
boost::call_traits< value_t >::reference reference_t
Definition: DataSource.hpp:193
DataSource< T >::result_t value() const
Definition: mystd.hpp:163
vector< AType > av
AType(bool ini)
#define RTT_UNIT_API
Definition: unit.hpp:77
BType(bool ini)
virtual UpdatedReferenceDataSource< T > * clone() const
CType(bool ini)
std::vector< BType > BTypes
std::vector< AType > ATypes
DataSource< T >::value_t mcopy
static bool operator==(const ConnPolicy &, const ConnPolicy &)
Definition: corba_test.cpp:227
std::ostream & operator<<(std::ostream &os, const BufferPolicy &bp)
vector< double > vd
std::vector< CType > CTypes
boost::array< int, 5 > ai
vector< BType > bv
DataSource< T >::const_reference_t rvalue() const
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
UpdatedReferenceDataSource(typename AssignableDataSource< T >::reference_t ref)
void serialize(Archive &ar, CType &g, const unsigned int version)
details::GetConstRef< T >::type const_reference_t
Definition: DataSource.hpp:107
AssignableDataSource< T >::reference_t mref


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