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
00060 template<typename T>
00061 std::ostream& operator << (std::ostream& os, const std::vector<T>& vec)
00062 {
00063 os<<'[';
00064 for(unsigned int i=0;i<vec.size();i++){
00065 if(i>0)
00066 os<<',';
00067 os<<vec[i]<<' ';
00068 }
00069
00070 return os << ']';
00071 };
00072
00073 template<typename T>
00074 std::istream& operator >> (std::istream& is,std::vector<T>& vec)
00075 {
00076 return is;
00077 };
00078
00079 template<typename T>
00080 struct stdvector_ctor
00081 : public std::unary_function<int, const std::vector<T>&>
00082 {
00083 typedef const std::vector<T>& (Signature)( int );
00084 mutable boost::shared_ptr< std::vector<T> > ptr;
00085 stdvector_ctor()
00086 : ptr( new std::vector<T>() ) {}
00087 const std::vector<T>& operator()( int size ) const
00088 {
00089 ptr->resize( size );
00090 return *(ptr);
00091 }
00092 };
00093
00098 template<typename T>
00099 struct stdvector_varargs_ctor
00100 {
00101 typedef const std::vector<T>& result_type;
00102 typedef T argument_type;
00103 result_type operator()( const std::vector<T>& args ) const
00104 {
00105 return args;
00106 }
00107 };
00108
00113 template<typename T>
00114 struct StdVectorBuilder
00115 : public TypeBuilder
00116 {
00117 virtual base::DataSourceBase::shared_ptr build(const std::vector<base::DataSourceBase::shared_ptr>& args) const {
00118 if (args.size() == 0 )
00119 return base::DataSourceBase::shared_ptr();
00120 typename internal::NArityDataSource<stdvector_varargs_ctor<T> >::shared_ptr vds = new internal::NArityDataSource<stdvector_varargs_ctor<T> >();
00121 for(unsigned int i=0; i != args.size(); ++i) {
00122 typename internal::DataSource<T>::shared_ptr dsd = boost::dynamic_pointer_cast< internal::DataSource<T> >( args[i] );
00123 if (dsd)
00124 vds->add( dsd );
00125 else
00126 return base::DataSourceBase::shared_ptr();
00127 }
00128 return vds;
00129 }
00130 };
00131
00132 template<typename T>
00133 struct stdvector_ctor2
00134 : public std::binary_function<int, T, const std::vector<T>&>
00135 {
00136 typedef const std::vector<T>& (Signature)( int, T );
00137 mutable boost::shared_ptr< std::vector<T> > ptr;
00138 stdvector_ctor2()
00139 : ptr( new std::vector<T>() ) {}
00140 const std::vector<T>& operator()( int size, T value ) const
00141 {
00142 ptr->resize( size );
00143 ptr->assign( size, value );
00144 return *(ptr);
00145 }
00146 };
00147 }};
00148
00149 #ifdef __clang__
00150 namespace std {
00151 using RTT::types::operator<<;
00152 using RTT::types::operator>>;
00153 }
00154 #endif
00155
00156 #endif
00157