Go to the documentation of this file.00001 #include "kdlTypekit.hpp"
00002
00003 template class RTT::internal::DataSource< ::KDL::JntArray >;
00004 template class RTT::internal::AssignableDataSource< ::KDL::JntArray >;
00005 template class RTT::internal::ValueDataSource< ::KDL::JntArray >;
00006 template class RTT::internal::ConstantDataSource< ::KDL::JntArray >;
00007 template class RTT::internal::ReferenceDataSource< ::KDL::JntArray >;
00008 template class RTT::base::ChannelElement< ::KDL::JntArray >;
00009 template class RTT::OutputPort< ::KDL::JntArray >;
00010 template class RTT::InputPort< ::KDL::JntArray >;
00011 template class RTT::Property< ::KDL::JntArray >;
00012 template class RTT::Attribute< ::KDL::JntArray >;
00013
00014
00015 namespace KDL{
00016 using namespace std;
00017 using namespace RTT;
00018
00019
00020 double& get_item(JntArray& v, int index)
00021 {
00022 if (index >= (int) (v.rows()) || index < 0)
00023 return RTT::internal::NA<double&>::na();
00024 return v(index);
00025 }
00026
00027 double get_item_copy(const JntArray& v, int index)
00028 {
00029 if (index >= (int) (v.rows()) || index < 0)
00030 return RTT::internal::NA<double>::na();
00031 return v(index);
00032 }
00033
00034
00035 int get_size(const JntArray& v)
00036 {
00037 return v.rows();
00038 }
00039
00040 struct JntArrayTypeInfo : public types::TemplateTypeInfo<JntArray,true>
00041 #if (RTT_VERSION_MAJOR*100+RTT_VERSION_MINOR) >= 206
00042 , public MemberFactory
00043 #endif
00044 {
00045 JntArrayTypeInfo():TemplateTypeInfo<JntArray, true >("KDL.JntArray")
00046 {
00047 }
00048
00049 #if (RTT_VERSION_MAJOR*100+RTT_VERSION_MINOR) >= 206
00050 bool installTypeInfoObject(TypeInfo* ti) {
00051
00052 boost::shared_ptr< JntArrayTypeInfo > mthis = boost::dynamic_pointer_cast<JntArrayTypeInfo >( this->getSharedPtr() );
00053 assert(mthis);
00054
00055 TemplateTypeInfo<JntArray,true>::installTypeInfoObject(ti);
00056
00057 ti->setMemberFactory( mthis );
00058
00059 return false;
00060 }
00061 #endif
00062
00066 bool composeType( base::DataSourceBase::shared_ptr dssource, base::DataSourceBase::shared_ptr dsresult) const {
00067 const internal::DataSource<PropertyBag>* pb = dynamic_cast< const internal::DataSource<PropertyBag>* > (dssource.get() );
00068 if ( !pb )
00069 return false;
00070 internal::AssignableDataSource<JntArray>::shared_ptr ads = boost::dynamic_pointer_cast< internal::AssignableDataSource<JntArray> >( dsresult );
00071 if ( !ads )
00072 return false;
00073
00074 PropertyBag const& source = pb->rvalue();
00075 internal::AssignableDataSource<JntArray>::reference_t result = ads->set();
00076
00077
00078 base::PropertyBase* sz = source.find("Size");
00079 if (!sz)
00080 sz = source.find("size");
00081 if (sz)
00082 {
00083 internal::DataSource<int>::shared_ptr sz_ds = internal::DataSource<int>::narrow(sz->getDataSource().get());
00084 if (sz_ds)
00085 result.resize( sz_ds->get() );
00086 }
00087 else
00088 {
00089
00090 result.resize( source.size() );
00091 }
00092
00093 PropertyBag target( source.getType() );
00094 PropertyBag decomp;
00095 internal::ReferenceDataSource<JntArray> rds(result);
00096 rds.ref();
00097
00098
00099
00100 if ( composePropertyBag(source, target) && typeDecomposition( &rds, decomp, false) && ( decomp.getType() == target.getType() ) && refreshProperties(decomp, target, true) ) {
00101 assert(result.rows() == source.size());
00102 assert(source.size() == target.size());
00103 assert(source.size() == decomp.size());
00104 ads->updated();
00105 Logger::log() <<Logger::Debug<<"Successfuly composed type from "<< source.getType() <<Logger::endl;
00106 return true;
00107 }
00108 return false;
00109 }
00110
00114 base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
00115 {
00116 return base::DataSourceBase::shared_ptr();
00117 }
00118
00119
00120 bool resize(base::DataSourceBase::shared_ptr arg, int size) const
00121 {
00122 if (arg->isAssignable()) {
00123 RTT::internal::AssignableDataSource<JntArray>::shared_ptr asarg = RTT::internal::AssignableDataSource<JntArray>::narrow( arg.get() );
00124 asarg->set().resize( size );
00125 asarg->updated();
00126 return true;
00127 }
00128 return false;
00129 }
00130
00131 virtual std::vector<std::string> getMemberNames() const {
00132
00133 std::vector<std::string> result;
00134 result.push_back("size");
00135 result.push_back("capacity");
00136 return result;
00137 }
00138
00139 base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string& name) const {
00140
00141 try {
00142 unsigned int indx = boost::lexical_cast<unsigned int>(name);
00143
00144 return getMember( item, new RTT::internal::ConstantDataSource<int>(indx));
00145 } catch(...) {}
00146
00147 return getMember( item, new RTT::internal::ConstantDataSource<std::string>(name) );
00148 }
00149
00150 base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item,
00151 base::DataSourceBase::shared_ptr id) const {
00152
00153 RTT::internal::DataSource<int>::shared_ptr id_indx = RTT::internal::DataSource<int>::narrow( RTT::internal::DataSourceTypeInfo<int>::getTypeInfo()->convert(id).get() );
00154 RTT::internal::DataSource<string>::shared_ptr id_name = RTT::internal::DataSource<string>::narrow( id.get() );
00155 if ( id_name ) {
00156 if ( id_name->get() == "size" || id_name->get() == "capacity") {
00157 try {
00158 return RTT::internal::newFunctorDataSource(&get_size, RTT::internal::GenerateDataSource()(item.get()) );
00159 } catch(...) {}
00160 }
00161 }
00162
00163 if ( id_indx ) {
00164 try {
00165 if ( item->isAssignable() )
00166 return RTT::internal::newFunctorDataSource(&get_item, RTT::internal::GenerateDataSource()(item.get(), id_indx.get() ) );
00167 else
00168 return RTT::internal::newFunctorDataSource(&get_item_copy, RTT::internal::GenerateDataSource()(item.get(), id_indx.get() ) );
00169 } catch(...) {}
00170 }
00171 if (id_name) {
00172 log(Error) << "JntArrayTypeInfo: No such member : " << id_name->get() << endlog();
00173 }
00174 if (id_indx) {
00175 log(Error) << "JntArrayTypeInfo: Invalid index : " << id_indx->get() <<":"<< id_indx->getTypeName() << endlog();
00176 }
00177 if ( !id_name && ! id_indx)
00178 log(Error) << "JntArrayTypeInfo: Not a member or index : " << id <<":"<< id->getTypeName() << endlog();
00179 return base::DataSourceBase::shared_ptr();
00180 }
00181
00182 };
00183 void loadJntArrayTypes(){
00184 RTT::types::Types()->addType( new JntArrayTypeInfo() );
00185 RTT::types::Types()->addType( new SequenceTypeInfo<std::vector< JntArray > >("KDL.JntArray[]") );
00186 RTT::types::Types()->addType( new CArrayTypeInfo<RTT::types::carray< JntArray > >("KDL.cJntArray[]") );
00187 };
00188 }