CorbaEigenConversion.hpp
Go to the documentation of this file.
00001 #include <Eigen/Dense>
00002 #include <EigenTypesC.h>
00003 
00004 namespace RTT
00005 {
00006   namespace corba{
00007 
00008     template<>
00009     struct AnyConversion< Eigen::VectorXd >
00010     {
00011         typedef Eigen::corba::DoubleSequence CorbaType;
00012         typedef Eigen::VectorXd StdType;
00013 
00014       static CorbaType* toAny(const StdType& tp) {
00015         CorbaType* cb = new CorbaType();
00016         toCorbaType(*cb, tp);
00017         return cb;
00018       }
00019 
00020       static bool update(const CORBA::Any& any, StdType& _value) {
00021         CorbaType* result;
00022         if ( any >>= result ) {
00023           return toStdType(_value, *result);
00024         }
00025         return false;
00026       }
00027 
00028       static CORBA::Any_ptr createAny( const StdType& t ) {
00029         CORBA::Any_ptr ret = new CORBA::Any();
00030         *ret <<= toAny( t );
00031         return ret;
00032       }
00033 
00034       static bool updateAny( StdType const& t, CORBA::Any& any ) {
00035         any <<= toAny( t );
00036         return true;
00037       }
00038 
00039       static bool toCorbaType(CorbaType& cb, const StdType& tp){
00040         if(!tp.size()){
00041           return true;
00042         }
00043         cb.length( (CORBA::ULong)(tp.size()) );
00044         Eigen::Map<Eigen::VectorXd>(cb.get_buffer() , cb.length()) = tp;
00045         return true;
00046       }
00047 
00048       static bool toStdType(StdType& tp, const CorbaType& cb){
00049         if(!cb.length()){
00050           return false;
00051         }
00052         tp.resize( cb.length() );
00053         tp = Eigen::VectorXd::Map(cb.get_buffer() , cb.length());
00054               return true;
00055       }
00056 
00057     };
00058 
00059     template<>
00060     struct AnyConversion< Eigen::MatrixXd >
00061     {
00062       typedef Eigen::corba::DoubleSequence CorbaType;
00063       typedef Eigen::MatrixXd StdType;
00064 
00065       static CorbaType* toAny(const StdType& tp) {
00066         CorbaType* cb = new CorbaType();
00067         toCorbaType(*cb, tp);
00068         return cb;
00069       }
00070 
00071       static bool update(const CORBA::Any& any, StdType& _value) {
00072         CorbaType* result;
00073         if ( any >>= result ) {
00074           return toStdType(_value, *result);
00075         }
00076         return false;
00077       }
00078 
00079       static CORBA::Any_ptr createAny( const StdType& t ) {
00080         CORBA::Any_ptr ret = new CORBA::Any();
00081         *ret <<= toAny( t );
00082         return ret;
00083       }
00084 
00085       static bool updateAny( StdType const& t, CORBA::Any& any ) {
00086         any <<= toAny( t );
00087         return true;
00088       }
00089 
00090       static bool toCorbaType(CorbaType& cb, const StdType& tp){
00091         if(!tp.size()){
00092           return false;
00093         }
00094 
00095         size_t rows = static_cast<size_t>(tp.rows());
00096         size_t cols = static_cast<size_t>(tp.cols());
00097 
00098         cb.length( (CORBA::ULong)(tp.size() + 2) );
00099 
00100         cb[0] = static_cast<double>(rows);
00101         cb[1] = static_cast<double>(cols);
00102 
00103         Eigen::Map<Eigen::MatrixXd>(cb.get_buffer() + 2 , rows, cols) = tp;
00104 
00105         return true;
00106       }
00107 
00108       static bool toStdType(StdType& tp, const CorbaType& cb){
00109         if(!cb.length() || cb.length() < 2){
00110           return false;
00111         }
00112 
00113         size_t rows = static_cast<size_t>(cb[0]);
00114         size_t cols = static_cast<size_t>(cb[1]);
00115 
00116         tp.resize(rows,cols);
00117 
00118         tp = Eigen::MatrixXd::Map(cb.get_buffer()+2,rows,cols);
00119 
00120         return true;
00121       }
00122 
00123     };
00124 
00125   };//namespace corba
00126 };//namespace RTT
00127 


eigen_typekit
Author(s): Ruben Smits
autogenerated on Sat May 6 2017 02:43:51