CorbaEigenConversion.hpp
Go to the documentation of this file.
1 #ifndef ORO_EIGEN_CORBAEIGENCONVERSION_HPP
2 #define ORO_EIGEN_CORBAEIGENCONVERSION_HPP 1
3 
4 #include <Eigen/Dense>
5 #include <eigen_typekit/transports/corba/EigenTypesC.h>
6 
7 namespace RTT
8 {
9  namespace corba{
10 
11  template<>
12  struct AnyConversion< Eigen::VectorXd >
13  {
14  typedef Eigen::corba::DoubleSequence CorbaType;
15  typedef Eigen::VectorXd StdType;
16 
17  static CorbaType* toAny(const StdType& tp) {
18  CorbaType* cb = new CorbaType();
19  toCorbaType(*cb, tp);
20  return cb;
21  }
22 
23  static bool update(const CORBA::Any& any, StdType& _value) {
24  CorbaType* result;
25  if ( any >>= result ) {
26  return toStdType(_value, *result);
27  }
28  return false;
29  }
30 
31  static CORBA::Any_ptr createAny( const StdType& t ) {
32  CORBA::Any_ptr ret = new CORBA::Any();
33  *ret <<= toAny( t );
34  return ret;
35  }
36 
37  static bool updateAny( StdType const& t, CORBA::Any& any ) {
38  any <<= toAny( t );
39  return true;
40  }
41 
42  static bool toCorbaType(CorbaType& cb, const StdType& tp){
43  if(!tp.size()){
44  return true;
45  }
46  cb.length( (CORBA::ULong)(tp.size()) );
47  Eigen::Map<Eigen::VectorXd>(cb.get_buffer() , cb.length()) = tp;
48  return true;
49  }
50 
51  static bool toStdType(StdType& tp, const CorbaType& cb){
52  if(!cb.length()){
53  return false;
54  }
55  tp.resize( cb.length() );
56  tp = Eigen::VectorXd::Map(cb.get_buffer() , cb.length());
57  return true;
58  }
59 
60  };
61 
62  template<>
63  struct AnyConversion< Eigen::MatrixXd >
64  {
65  typedef Eigen::corba::DoubleSequence CorbaType;
66  typedef Eigen::MatrixXd StdType;
67 
68  static CorbaType* toAny(const StdType& tp) {
69  CorbaType* cb = new CorbaType();
70  toCorbaType(*cb, tp);
71  return cb;
72  }
73 
74  static bool update(const CORBA::Any& any, StdType& _value) {
75  CorbaType* result;
76  if ( any >>= result ) {
77  return toStdType(_value, *result);
78  }
79  return false;
80  }
81 
82  static CORBA::Any_ptr createAny( const StdType& t ) {
83  CORBA::Any_ptr ret = new CORBA::Any();
84  *ret <<= toAny( t );
85  return ret;
86  }
87 
88  static bool updateAny( StdType const& t, CORBA::Any& any ) {
89  any <<= toAny( t );
90  return true;
91  }
92 
93  static bool toCorbaType(CorbaType& cb, const StdType& tp){
94  if(!tp.size()){
95  return false;
96  }
97 
98  size_t rows = static_cast<size_t>(tp.rows());
99  size_t cols = static_cast<size_t>(tp.cols());
100 
101  cb.length( (CORBA::ULong)(tp.size() + 2) );
102 
103  cb[0] = static_cast<double>(rows);
104  cb[1] = static_cast<double>(cols);
105 
106  Eigen::Map<Eigen::MatrixXd>(cb.get_buffer() + 2 , rows, cols) = tp;
107 
108  return true;
109  }
110 
111  static bool toStdType(StdType& tp, const CorbaType& cb){
112  if(!cb.length() || cb.length() < 2){
113  return false;
114  }
115 
116  size_t rows = static_cast<size_t>(cb[0]);
117  size_t cols = static_cast<size_t>(cb[1]);
118 
119  tp.resize(rows,cols);
120 
121  tp = Eigen::MatrixXd::Map(cb.get_buffer()+2,rows,cols);
122 
123  return true;
124  }
125 
126  };
127 
128  } //namespace corba
129 } //namespace RTT
130 
131 #endif // ORO_EIGEN_CORBAEIGENCONVERSION_HPP
static bool update(const CORBA::Any &any, StdType &_value)
static bool toStdType(StdType &tp, const CorbaType &cb)
Any * Any_ptr
static CorbaType * toAny(const StdType &tp)
static bool updateAny(StdType const &t, CORBA::Any &any)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
static CORBA::Any_ptr createAny(const StdType &t)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
static CorbaType * toAny(const StdType &tp)
static CORBA::Any_ptr createAny(const StdType &t)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
static bool toStdType(StdType &tp, const CorbaType &cb)
static bool toStdType(StdType &tp, const CorbaType &cb)
static bool updateAny(StdType const &t, CORBA::Any &any)
static bool update(const CORBA::Any &any, StdType &_value)


eigen_typekit
Author(s): Ruben Smits
autogenerated on Wed Jul 3 2019 19:39:42