00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef TYPE_DISCOVERY_HPP_
00040 #define TYPE_DISCOVERY_HPP_
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00064 #include <cassert>
00065 #include <boost/version.hpp>
00066 #include <boost/serialization/serialization.hpp>
00067 #include <boost/serialization/is_bitwise_serializable.hpp>
00068 #include <boost/serialization/vector.hpp>
00069 #include <boost/serialization/string.hpp>
00070 #include <boost/serialization/array.hpp>
00071 #include <boost/archive/detail/iserializer.hpp>
00072 #include <boost/archive/detail/oserializer.hpp>
00073 #include <boost/archive/archive_exception.hpp>
00074 #include <boost/config.hpp>
00075 #include <boost/mpl/bool.hpp>
00076
00077 #include <vector>
00078 #include <string>
00079 #include "../base/DataSourceBase.hpp"
00080 #include "../internal/PartDataSource.hpp"
00081 #include "../internal/DataSources.hpp"
00082 #include "carray.hpp"
00083
00084 namespace RTT
00085 {
00086 namespace types
00087 {
00092 class type_discovery
00093 {
00094 public:
00098 base::DataSourceBase::shared_ptr mparent;
00099
00100 typedef std::vector<base::DataSourceBase::shared_ptr> Parts;
00101 typedef std::vector<std::string> PartNames;
00105 Parts mparts;
00106
00111 Parts mcparts;
00112
00116 PartNames mnames;
00117
00118 typedef char Elem;
00122 typedef boost::mpl::bool_<true> is_loading;
00126 typedef boost::mpl::bool_<false> is_saving;
00127
00132 type_discovery(base::DataSourceBase::shared_ptr parent) :
00133 mparent(parent)
00134 {
00135 }
00136
00141 type_discovery() :
00142 mparent()
00143 {
00144 }
00145
00146 base::DataSourceBase::shared_ptr getMember(const std::string name) {
00147 PartNames::iterator it = find( mnames.begin(), mnames.end(), name);
00148 if ( it != mnames.end() && mparts.size() == mnames.size() )
00149 return mparts.at( it - mnames.begin() );
00150 return base::DataSourceBase::shared_ptr();
00151 }
00152
00153 base::DataSourceBase::shared_ptr getConstMember(const std::string name) {
00154 PartNames::iterator it = find( mnames.begin(), mnames.end(), name);
00155 if ( it != mnames.end() && mcparts.size() == mnames.size() )
00156 return mcparts.at( it - mnames.begin() );
00157 return base::DataSourceBase::shared_ptr();
00158 }
00159
00160 template<class T>
00161 void discover( T& t) {
00162 #if BOOST_VERSION >= 104100
00163 boost::archive::detail::load_non_pointer_type<type_discovery>::load_only::invoke(*this,t);
00164 #else
00165 boost::archive::detail::load_non_pointer_type<type_discovery,T>::load_only::invoke(*this,t);
00166 #endif
00167 }
00168
00173 unsigned int get_library_version() { return 0; }
00174
00180 void reset_object_address(const void * new_address, const void * old_address) {}
00181
00185 void delete_created_pointers() {}
00186
00192 template<class T>
00193 const boost::archive::detail::basic_pointer_iserializer *
00194 register_type(T * = NULL) {return 0;}
00195
00201 void load_object(void *x, const boost::archive::detail::basic_oserializer & bos)
00202 {
00203 assert(false);
00204 }
00205
00211 template<class T>
00212 type_discovery &operator>>(T &t)
00213 {
00214 return load_a_type(t, boost::mpl::bool_<boost::serialization::implementation_level<T>::value == boost::serialization::primitive_type>());
00215 }
00216
00222 template<class T>
00223 type_discovery &operator&(T &t)
00224 {
00225 return this->operator>>(t);
00226 }
00227
00233 template<class T>
00234 type_discovery &load_a_type(T &t, boost::mpl::true_)
00235 {
00236
00237 if (mparent) {
00238 mparts.push_back(new internal::PartDataSource<T> (t, mparent));
00239 mcparts.push_back(new internal::AliasDataSource<T>( new internal::PartDataSource<T> (t, mparent) ));
00240 }
00241 return *this;
00242 }
00243
00249 template<class T>
00250 type_discovery &load_a_type(T &t, boost::mpl::false_)
00251 {
00252 if (mparent) {
00253 mparts.push_back(new internal::PartDataSource<T> (t, mparent));
00254 mcparts.push_back(new internal::AliasDataSource<T>( new internal::PartDataSource<T> (t, mparent) ));
00255 }
00256 return *this;
00257 }
00258
00264 template<class T>
00265 type_discovery &load_a_type(const boost::serialization::array<T> &t, boost::mpl::false_)
00266 {
00267 if (mparent) {
00268 mparts.push_back(new internal::PartDataSource< carray<T> > ( carray<T>(t), mparent) );
00269 mcparts.push_back(new internal::AliasDataSource< carray<T> >( new internal::PartDataSource< carray<T> > ( carray<T>(t), mparent) ));
00270 }
00271
00272
00273 return *this;
00274 }
00275
00282 template<class T>
00283 type_discovery &load_a_type(T* &, boost::mpl::false_)
00284 {
00285
00286
00287 return *this;
00288 }
00289
00291 template<class T>
00292 type_discovery &load_a_type(const boost::serialization::nvp<T> & t, boost::mpl::false_)
00293 {
00294
00295 mnames.push_back( t.name() );
00296
00297
00298 *this & t.value();
00299
00300 return *this;
00301 }
00302 };
00303 }
00304 }
00305
00306 #endif