kdlTypekitJntArray.cpp
Go to the documentation of this file.
1 #include "kdlTypekit.hpp"
2 
13 
14 
15 namespace KDL{
16  using namespace std;
17  using namespace RTT;
18 
19 
20  double& get_item(JntArray& v, int index)
21  {
22  if (index >= (int) (v.rows()) || index < 0)
24  return v(index);
25  }
26 
27  double get_item_copy(const JntArray& v, int index)
28  {
29  if (index >= (int) (v.rows()) || index < 0)
31  return v(index);
32  }
33 
34 
35  int get_size(const JntArray& v)
36  {
37  return v.rows();
38  }
39 
41 #if (RTT_VERSION_MAJOR*100+RTT_VERSION_MINOR) >= 206
42  , public MemberFactory
43 #endif
44  {
45  JntArrayTypeInfo():TemplateTypeInfo<JntArray, true >("KDL.JntArray")
46  {
47  }
48 
49 #if (RTT_VERSION_MAJOR*100+RTT_VERSION_MINOR) >= 206
50  bool installTypeInfoObject(TypeInfo* ti) {
51  // aquire a shared reference to the this object
52  boost::shared_ptr< JntArrayTypeInfo > mthis = boost::dynamic_pointer_cast<JntArrayTypeInfo >( this->getSharedPtr() );
53  assert(mthis);
54  // Allow base to install first
56  // Install the factories for primitive types
57  ti->setMemberFactory( mthis );
58  // Don't delete us, we're memory-managed.
59  return false;
60  }
61 #endif
62 
67  const internal::DataSource<PropertyBag>* pb = dynamic_cast< const internal::DataSource<PropertyBag>* > (dssource.get() );
68  if ( !pb )
69  return false;
71  if ( !ads )
72  return false;
73 
74  PropertyBag const& source = pb->rvalue();
76 
77  // take into account sequences:
78  base::PropertyBase* sz = source.find("Size");
79  if (!sz)
80  sz = source.find("size");
81  if (sz)
82  {
84  if (sz_ds)
85  result.resize( sz_ds->get() );
86  }
87  else
88  {
89  // no size found, inform parent of number of elements to come:
90  result.resize( source.size() );
91  }
92  // recurse into items of this sequence:
93  PropertyBag target( source.getType() );
94  PropertyBag decomp;
96  rds.ref(); // prevent dealloc.
97  // we compose each item in this sequence and then update result with target's result.
98  // 1. each child is composed into target (this is a recursive thing)
99  // 2. we decompose result one-level deep and 'refresh' it with the composed children of step 1.
100  if ( composePropertyBag(source, target) && typeDecomposition( &rds, decomp, false) && ( decomp.getType() == target.getType() ) && refreshProperties(decomp, target, true) ) {
101  assert(result.rows() == source.size());
102  assert(source.size() == target.size());
103  assert(source.size() == decomp.size());
104  ads->updated();
105  Logger::log() <<Logger::Debug<<"Successfuly composed type from "<< source.getType() <<Logger::endl;
106  return true;
107  }
108  return false;
109  }
110 
115  {
117  }
118 
119 
120  bool resize(base::DataSourceBase::shared_ptr arg, int size) const
121  {
122  if (arg->isAssignable()) {
124  asarg->set().resize( size );
125  asarg->updated();
126  return true;
127  }
128  return false;
129  }
130 
131  virtual std::vector<std::string> getMemberNames() const {
132  // only discover the parts of this struct:
133  std::vector<std::string> result;
134  result.push_back("size");
135  result.push_back("capacity");
136  return result;
137  }
138 
140  // the only thing we do is to check for an integer in name, otherwise, assume a part (size) is accessed:
141  try {
142  unsigned int indx = boost::lexical_cast<unsigned int>(name);
143  // @todo could also return a direct reference to item indx using another DS type that respects updated().
144  return getMember( item, new RTT::internal::ConstantDataSource<int>(indx));
145  } catch(...) {}
146 
147  return getMember( item, new RTT::internal::ConstantDataSource<std::string>(name) );
148  }
149 
152  // discover if user gave us a part name or index:
155  if ( id_name ) {
156  if ( id_name->get() == "size" || id_name->get() == "capacity") {
157  try {
159  } catch(...) {}
160  }
161  }
162 
163  if ( id_indx ) {
164  try {
165  if ( item->isAssignable() )
167  else
169  } catch(...) {}
170  }
171  if (id_name) {
172  log(Error) << "JntArrayTypeInfo: No such member : " << id_name->get() << endlog();
173  }
174  if (id_indx) {
175  log(Error) << "JntArrayTypeInfo: Invalid index : " << id_indx->get() <<":"<< id_indx->getTypeName() << endlog();
176  }
177  if ( !id_name && ! id_indx)
178  log(Error) << "JntArrayTypeInfo: Not a member or index : " << id <<":"<< id->getTypeName() << endlog();
180  }
181 
182  };
183 
185  RTT::types::Types()->addType( new JntArrayTypeInfo() );
186  RTT::types::Types()->addType( new SequenceTypeInfo<std::vector< JntArray > >("KDL.JntArray[]") );
187  RTT::types::Types()->addType( new CArrayTypeInfo<RTT::types::carray< JntArray > >("KDL.cJntArray[]") );
188  }
189 }
base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string &name) const
virtual result_t get() const =0
unsigned int rows() const
bool resize(base::DataSourceBase::shared_ptr arg, int size) const
boost::call_traits< value_t >::reference reference_t
INLINE Rall1d< T, V, S > log(const Rall1d< T, V, S > &arg)
const std::string & getType() const
bool refreshProperties(const PropertyBag &target, const PropertyBag &source, bool allprops)
virtual void set(param_t t)=0
bool RTT_API composePropertyBag(PropertyBag const &sourcebag, PropertyBag &target)
base::DataSourceBase * newFunctorDataSource(Function f, const std::vector< base::DataSourceBase::shared_ptr > &args)
double get_item_copy(const JntArray &v, int index)
bool composeType(base::DataSourceBase::shared_ptr dssource, base::DataSourceBase::shared_ptr dsresult) const
base::PropertyBase * find(const std::string &name) const
virtual const_reference_t rvalue() const =0
base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, base::DataSourceBase::shared_ptr id) const
virtual std::vector< std::string > getMemberNames() const
static AssignableDataSource< T > * narrow(base::DataSourceBase *db)
TypeInfoRepository::shared_ptr Types()
bool typeDecomposition(base::DataSourceBase::shared_ptr dsb, PropertyBag &targetbag, bool recurse)
boost::intrusive_ptr< DataSource< T > > shared_ptr
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
static DataSource< T > * narrow(base::DataSourceBase *db)
base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
virtual std::string getTypeName() const
void loadJntArrayTypes()
double & get_item(JntArray &v, int index)
boost::intrusive_ptr< DataSourceBase > shared_ptr
size_t size() const
virtual DataSourceBase::shared_ptr getDataSource() const =0


kdl_typekit
Author(s): Steven Bellens, Ruben Smits
autogenerated on Wed Jul 3 2019 19:39:45