orocos 的数据表示(模板template): DataObject (还有一条主线为 DataSource)
2015-12-07 15:14
501 查看
数据有不同的type(int,double,struct…),还有 c-v qualifier, 还可以是 reference、pointer、array等等。因此,在处理数据的时候要正确区分每一种数据类型的处理方法。
例如:不能对引用类型取引用,不能对右值取引用等等:
see Effective Modern C++ Deducing Types
c++11引入 universal reference( T&&, std::forward) 和 alias(using), 可以简化上述代码:
The forward template exists in C++11, in the
see link universal-references: http://eli.thegreenplace.net/2014/perfect-forwarding-and-universal-references-in-c/
orocos数据TypeInfo:
Orocos DataObject类的结构:
DataObjectLocked 和 DataObjectLockFree 分别继承自DataObjectInterface; 然后 DataOject再继承 DataObjectLocked 和 DataObjectLockFree
例如:不能对引用类型取引用,不能对右值取引用等等:
typedef typename boost::remove_const<typename boost::remove_reference<T>::type>::type value_t; typedef typename boost::call_traits<value_t>::param_type param_t; typedef typename boost::call_traits<value_t>::reference reference_t; typedef typename boost::call_traits<value_t>::const_reference const_reference_t;
see Effective Modern C++ Deducing Types
c++11引入 universal reference( T&&, std::forward) 和 alias(using), 可以简化上述代码:
The forward template exists in C++11, in the
<utility>header, as std::forward
see link universal-references: http://eli.thegreenplace.net/2014/perfect-forwarding-and-universal-references-in-c/
orocos数据TypeInfo:
struct RTT_API UnknownType {}; template< class T> struct DataSourceTypeInfo; template<> struct RTT_API DataSourceTypeInfo<UnknownType> { typedef UnknownType value_type; typedef DataSourceTypeInfo<UnknownType> value_type_info; static types::TypeInfo* TypeInfoObject; static const std::string noqual; // void static const std::string cqual; // const static const std::string refqual; // reference static const std::string crefqual; // const reference static const std::string ptrqual; // pointer static const std::string cptrqual; // const pointer static const std::string& getType(); // 都是 static 函数,包括下列各个特化模板,因此其他类只需要直接使用该模板即可得到其他类的数据类型信息 static const std::string& getTypeName(); static const std::string& getQualifier(); // we drop the const qualifier in this specialisation, since it is // not registered in the type repository (which returns a non const in type() ) static types::TypeInfo* getTypeInfo(); // type_name、 qualifier、std::type_info * etc. compiler dependent info }; template< class T> struct DataSourceTypeInfo<const T&> { typedef T value_type; typedef DataSourceTypeInfo<T> value_type_info; static std::string getType() { return getTypeName() + getQualifier(); } static const std::string& getTypeName() { return DataSourceTypeInfo< T >::getTypeName(); } // value_type 的类型 static const std::string& getQualifier() { return DataSourceTypeInfo<UnknownType>::crefqual; } //qualifier: 其他类型就换成别的字符串("const"、"&" 等等) static const types::TypeInfo* getTypeInfo() { return DataSourceTypeInfo< T >::getTypeInfo(); } }; // 以下类似 template< class T> struct DataSourceTypeInfo<T&> {...} template< class T> struct DataSourceTypeInfo<const T> {...} template< class T> struct DataSourceTypeInfo<T*> {...} template< class T> struct DataSourceTypeInfo<const T*> {...} template<> struct RTT_API DataSourceTypeInfo<void> {...} /** * Specialisation for a types::carray<T> type info object. * All RTT internal primitives should use carray references * to (boost) arrays such that run-time size checks can be done. * For example, Property<carray<double> > holds a * ValueDataSource<carray<double> >( carray<double>( data.c_array(), 6 ) ) * where data is a boost::array<double,6> or equivalent */ template< class T> struct DataSourceTypeInfo<types::carray<T> > {...}
Orocos DataObject类的结构:
DataObjectInterface | / \ / \ DataObjectLocked DataObjectLockFree \ / \ / DataOjbect
DataObjectLocked 和 DataObjectLockFree 分别继承自DataObjectInterface; 然后 DataOject再继承 DataObjectLocked 和 DataObjectLockFree
相关文章推荐
- 开源机器人控制软件OROCOS
- GetObject() SelectObject()
- Objective-C 编译器
- IOS之Objectivc-c获取本地存储路径
- Object.defineProperty
- 多线程操作之NSObject
- 圣思园java se培训总结(28-32)(Object类,String类,包装类,数组)
- Class.isAssignableFrom(Class clz)与instanceof与Class.isInstance(Object obj) 的区别和联系
- 2015.12.7 Objective-c CoreGraphic
- Java中关于先有鸡还是先有蛋的问题----Class&Object
- 【Objective-C学习记录】第五天
- OC-随便看看
- 转载:Objective-C中的 instancetype 和 id 关键字
- Objective-C消息模式
- Objective-C:运行时runtime
- Conclusion for Inheritance and Object Oriented Design
- runtime理解
- Objective-C初学者速查表
- Objective-C 零散知识笔记 by STP
- 函数对象(function object)的简单讲解