datasource_fixture.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:54:57 CEST 2010  datasource_fixture.hpp
00003 
00004                         datasource_fixture.hpp -  description
00005                            -------------------
00006     begin                : Tue September 07 2010
00007     copyright            : (C) 2010 The SourceWorks
00008     email                : peter@thesourceworks.com
00009 
00010  ***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 
00020 #ifndef ORO_DATASOURCE_FIXTURE_HPP_
00021 #define ORO_DATASOURCE_FIXTURE_HPP_
00022 
00023 #include <rtt-config.h>
00024 #include "unit.hpp"
00025 #include <iostream>
00026 #include <RTT.hpp>
00027 #include <boost/array.hpp>
00028 #include <boost/serialization/vector.hpp>
00029 
00030 using namespace RTT;
00031 using namespace RTT::detail;
00032 using namespace boost;
00033 using namespace std;
00034 
00041 struct AType
00042 {
00043     AType(bool ini) { if (ini) init(); else clear(); }
00044     AType() { clear(); }
00045 
00046     void init() {
00047         a = (3);
00048         b = (9.9);
00049         c =("hello");
00050         ai.assign(0);
00051         ai[3] = 99;
00052         vd.resize(10, 5.0);
00053         vd[3] = 101;
00054     }
00055 
00056     void clear() {
00057         a = 0;
00058         b = 0;
00059         c.clear();
00060         ai[3] = 0;
00061         vd.clear();
00062     }
00063 
00064     int a;
00065     double b;
00066     string c;
00067     boost::array<int, 5> ai;
00068     vector<double> vd;
00069 };
00070 
00071 typedef std::vector<AType> ATypes;
00072 
00073 
00074 RTT_UNIT_API bool operator==(const AType& a, const AType& b);
00075 
00076 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const AType& a);
00077 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const ATypes& as);
00078 
00085 struct BType
00086 {
00087     BType() { clear(); }
00088     BType(bool ini) { if (ini) init(); else clear(); }
00089     void init() {
00090         a = (3);
00091         b = (9.9);
00092         for(int i = 0; i<10; ++i) c[i] = 0;
00093         strcpy(c,"hello");
00094         for(int i = 0; i<5; ++i) ai[i] = 3;
00095         ai[3] = 99;
00096         for(int i = 0; i<10; ++i) vd[i] = 5;
00097         vd[3] = 101;
00098     }
00099     void clear() {
00100         a = 0;
00101         b = 0;
00102         for(int i = 0; i<10; ++i) c[i] = 0;
00103         for(int i = 0; i<5; ++i) ai[i] = 0;
00104         for(int i = 0; i<10; ++i) vd[i] = 0;
00105     }
00106 
00107     int    a;
00108     double b;
00109     char   c[10];
00110     int    ai[5];
00111     double vd[10];
00112     //int    vvi[2][2];
00113 };
00114 typedef std::vector<BType> BTypes;
00115 
00116 RTT_UNIT_API bool operator==(const BType& a, const BType& b);
00117 
00118 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const BType& a);
00119 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const BTypes& a);
00120 
00126 struct CType
00127 {
00128     CType() { clear(); }
00129     CType(bool ini) { if (ini) init(); else clear(); }
00130 
00131     void init() {
00132         a.init();
00133         b.init();
00134         av.resize(10, a);
00135         bv.resize(10, b);
00136     }
00137     AType a;
00138     BType b;
00139     vector<AType> av;
00140     vector<BType> bv;
00141 
00142     void clear() {
00143         a.clear();
00144         b.clear();
00145         av.clear();
00146         bv.clear();
00147     }
00148 };
00149 
00150 typedef std::vector<CType> CTypes;
00151 
00152 RTT_UNIT_API bool operator==(const CType& a, const CType& b);
00153 
00154 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const CType& a);
00155 RTT_UNIT_API std::ostream& operator<<(std::ostream& os, const CTypes& a);
00156 
00157 namespace boost {
00158 namespace serialization {
00159 
00160 template<class Archive>
00161 void serialize(Archive & ar, AType & g, const unsigned int version)
00162 {
00163     ar & make_nvp("a", g.a);
00164     ar & make_nvp("b", g.b);
00165     ar & make_nvp("c", g.c );
00166     ar & make_nvp("ai", g.ai );
00167     ar & make_nvp("vd", g.vd );
00168 }
00169 
00170 template<class Archive>
00171 void serialize(Archive & ar, BType & g, const unsigned int version)
00172 {
00173     ar & make_nvp("a", g.a);
00174     ar & make_nvp("b", g.b);
00175     ar & make_nvp("c", make_array(g.c,10) );
00176     ar & make_nvp("ai", make_array(g.ai,5) );
00177     ar & make_nvp("vd", make_array(g.vd,10) );
00178 
00179     //ar & make_nvp("vvi", make_array( g.vvi, 4));
00180 }
00181 
00182 template<class Archive>
00183 void serialize(Archive & ar, CType & g, const unsigned int version)
00184 {
00185     ar & make_nvp("a", g.a);
00186     ar & make_nvp("b", g.b);
00187     ar & make_nvp("av", g.av );
00188     ar & make_nvp("bv", g.bv );
00189 }
00190 
00191 } // namespace serialization
00192 } // namespace boost
00193 
00194 
00199     template<typename T>
00200     class UpdatedReferenceDataSource
00201         : public DataSource<T>
00202     {
00203         // a reference to a value_t
00204         typename AssignableDataSource<T>::reference_t mref;
00205         typename DataSource<T>::value_t mcopy;
00206     public:
00210         ~UpdatedReferenceDataSource() {}
00211 
00212         typedef boost::intrusive_ptr<UpdatedReferenceDataSource<T> > shared_ptr;
00213 
00214         UpdatedReferenceDataSource( typename AssignableDataSource<T>::reference_t ref ) : mref(ref), mcopy(ref) {}
00215 
00216         typename DataSource<T>::result_t get() const
00217         {
00218             return mcopy;
00219         }
00220 
00221         typename DataSource<T>::result_t value() const
00222         {
00223             return mcopy;
00224         }
00225 
00226         typename DataSource<T>::const_reference_t rvalue() const
00227         {
00228             return mcopy;
00229         }
00230 
00231         void updated() { mcopy = mref; }
00232 
00233         virtual UpdatedReferenceDataSource<T>* clone() const { return new UpdatedReferenceDataSource(mref); }
00234 
00235         virtual UpdatedReferenceDataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const { return clone(); }
00236 
00237     };
00238 
00239 #endif /* ORO_DATASOURCE_FIXTURE_HPP_ */


rtt
Author(s): RTT Developers
autogenerated on Mon Oct 6 2014 03:13:34