Go to the documentation of this file.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 #ifndef VECTOR_TEMPLATE_COMPOSITION_HPP
00035 #define VECTOR_TEMPLATE_COMPOSITION_HPP
00036
00037 #include "../Property.hpp"
00038 #include "../PropertyBag.hpp"
00039 #include "SequenceTypeInfo.hpp"
00040 #include "Types.hpp"
00041 #include "../Logger.hpp"
00042 #include "../internal/DataSources.hpp"
00043 #include <ostream>
00044 #include <sstream>
00045 #include <vector>
00046
00047 namespace RTT
00048 { namespace types {
00049 template <typename T, bool has_ostream>
00050 struct StdVectorTemplateTypeInfo
00051 : public SequenceTypeInfo<std::vector<T>, has_ostream >
00052 {
00053 StdVectorTemplateTypeInfo<T,has_ostream>( std::string name )
00054 : SequenceTypeInfo<std::vector<T>, has_ostream >(name)
00055 {
00056 }
00057 };
00058
00059 template<typename T>
00060 std::ostream& operator << (std::ostream& os, const std::vector<T>& vec)
00061 {
00062 os<<'[';
00063 for(unsigned int i=0;i<vec.size();i++){
00064 if(i>0)
00065 os<<',';
00066 os<<vec[i]<<' ';
00067 }
00068
00069 return os << ']';
00070 }
00071
00072 template<typename T>
00073 std::istream& operator >> (std::istream& is,std::vector<T>& vec)
00074 {
00075 return is;
00076 }
00077
00078 template<typename T>
00079 struct stdvector_ctor
00080 : public std::unary_function<int, const std::vector<T>&>
00081 {
00082 typedef const std::vector<T>& (Signature)( int );
00083 mutable boost::shared_ptr< std::vector<T> > ptr;
00084 stdvector_ctor()
00085 : ptr( new std::vector<T>() ) {}
00086 const std::vector<T>& operator()( int size ) const
00087 {
00088 ptr->resize( size );
00089 return *(ptr);
00090 }
00091 };
00092
00097 template<typename T>
00098 struct stdvector_varargs_ctor
00099 {
00100 typedef const std::vector<T>& result_type;
00101 typedef T argument_type;
00102 result_type operator()( const std::vector<T>& args ) const
00103 {
00104 return args;
00105 }
00106 };
00107
00112 template<typename T>
00113 struct StdVectorBuilder
00114 : public TypeConstructor
00115 {
00116 virtual base::DataSourceBase::shared_ptr build(const std::vector<base::DataSourceBase::shared_ptr>& args) const {
00117 if (args.size() == 0 )
00118 return base::DataSourceBase::shared_ptr();
00119 typename internal::NArityDataSource<stdvector_varargs_ctor<T> >::shared_ptr vds = new internal::NArityDataSource<stdvector_varargs_ctor<T> >();
00120 for(unsigned int i=0; i != args.size(); ++i) {
00121 typename internal::DataSource<T>::shared_ptr dsd = boost::dynamic_pointer_cast< internal::DataSource<T> >( args[i] );
00122 if (dsd)
00123 vds->add( dsd );
00124 else
00125 return base::DataSourceBase::shared_ptr();
00126 }
00127 return vds;
00128 }
00129 };
00130
00131 template<typename T>
00132 struct stdvector_ctor2
00133 : public std::binary_function<int, T, const std::vector<T>&>
00134 {
00135 typedef const std::vector<T>& (Signature)( int, T );
00136 mutable boost::shared_ptr< std::vector<T> > ptr;
00137 stdvector_ctor2()
00138 : ptr( new std::vector<T>() ) {}
00139 const std::vector<T>& operator()( int size, T value ) const
00140 {
00141 ptr->resize( size );
00142 ptr->assign( size, value );
00143 return *(ptr);
00144 }
00145 };
00146 }}
00147
00148 #ifdef __clang__
00149 namespace std {
00150 using RTT::types::operator<<;
00151 using RTT::types::operator>>;
00152 }
00153 #endif
00154
00155 #endif
00156