[Cppunit-cvs] cppunit2/include/cpptl typetraits.h, 1.2, 1.3 value.h, 1.1, 1.2
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2008-07-08 20:42:05
|
Update of /cvsroot/cppunit/cppunit2/include/cpptl In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv11051/include/cpptl Modified Files: typetraits.h value.h Log Message: - Fixed bug in Registry::remove() when a suite had multiple child suites. - Added Registry suite removal tests Index: value.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/value.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** value.h 19 Aug 2007 20:13:24 -0000 1.1 --- value.h 8 Jul 2008 20:42:00 -0000 1.2 *************** *** 2,5 **** --- 2,6 ---- # define CPPTL_VALUE_H_INCLUDED # include "forwards.h" + # include "typetraits.h" *************** *** 14,17 **** --- 15,45 ---- - conversion between type (int, uint, const char *, std::string...) - type comparison + + Implemented: + - framework to expose any service for Value + - framework for comparison + + To do: + - type identification, comparison and hashing + - type to string + - conversion + + To think: + - pointer and cast support + - smart-pointer ? Notes: requires dynamic allocation of target object + + About type identification: + - we already force the creation of a static to identify type. + - it can be used to replace type_info and all its bug & portability issues. + - but still need to be able to identify that two types are similar + Problems: + dll / static linking: + type info are not shared. Solution: use a single registry held in a dll. + thread-safe registration: + static variable stored in getValueType is a pointer on type in the registry. + ValueType is copied by value in the registry ensuring a single pointer is always returned. + Registry is synchronized to ensure type safety. + + */ *************** *** 19,22 **** --- 47,52 ---- class Value; + class ValueType; + class ValueTypeRegistry; // ////////////////////////////////////////////////////////////////// *************** *** 259,264 **** template<class T> ! inline const ValueType &getValueTypeSelector( const ValueType &valueType, ! const Type<T> &type ) { return valueType; --- 289,294 ---- template<class T> ! inline const ValueType &getValueTypeHelper( const ValueType &valueType, ! const Type<T> &type ) { return valueType; *************** *** 268,272 **** inline const ValueType &getValueTypeSelector( const Type<T> &type ) { ! return getValueTypeHelper( getValueType(), type ); } --- 298,302 ---- inline const ValueType &getValueTypeSelector( const Type<T> &type ) { ! return getValueTypeHelper( getValueType(type), type ); } *************** *** 335,340 **** /// Allocate DataType dynamically. ! template<typename DataType,const bool> ! class StorageHelper { public: --- 365,370 ---- /// Allocate DataType dynamically. ! template<typename DataType> ! class LargeTypeStorageHelper { public: *************** *** 368,372 **** /// Store DataType in string buffer if it fit in. template<typename DataType> ! class StorageHelper<DataType,true> { public: --- 398,402 ---- /// Store DataType in string buffer if it fit in. template<typename DataType> ! class SmallTypeStorageHelper { public: *************** *** 402,410 **** /// Select storage strategy depending on size of DataType. template<typename DataType> ! class Storage { public: ! typedef StorageHelper<DataType, bool(sizeof(DataType) <= sizeof(ValueDataBuffer))> ! result_type; }; --- 432,442 ---- /// Select storage strategy depending on size of DataType. template<typename DataType> ! class StoragePolicySelector { public: ! typedef CPPTL_TYPENAME IfType<LargeTypeStorageHelper<DataType> ! ,SmallTypeStorageHelper<DataType> ! ,(sizeof(DataType) > sizeof(ValueDataBuffer)) ! >::type type; }; *************** *** 415,425 **** public: typedef CommonLifeCycle<DataType> SelfType; ! typedef CPPTL_TYPENAME Storage<DataType>::result_type Storage; static void registerFunctions( ValueType &type ) { ! type.initialize_ = &Storage::initialize; ! type.clone_ = &Storage::clone; ! type.destroy_ = &Storage::destroy; } }; --- 447,457 ---- public: typedef CommonLifeCycle<DataType> SelfType; ! typedef CPPTL_TYPENAME StoragePolicySelector<DataType>::type StoragePolicy; static void registerFunctions( ValueType &type ) { ! type.initialize_ = &StoragePolicy::initialize; ! type.clone_ = &StoragePolicy::clone; ! type.destroy_ = &StoragePolicy::destroy; } }; *************** *** 434,438 **** public: typedef Compare<DataType> SelfType; ! typedef CPPTL_TYPENAME Storage<DataType>::result_type Storage; static void registerFunctions( ValueType &type ) --- 466,470 ---- public: typedef Compare<DataType> SelfType; ! typedef CPPTL_TYPENAME StoragePolicySelector<DataType>::type StoragePolicy; static void registerFunctions( ValueType &type ) *************** *** 445,450 **** static int compare( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = Storage::data(aData); ! const DataType &b = Storage::data(bData); if ( a < b ) return -1; --- 477,482 ---- static int compare( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = StoragePolicy::data(aData); ! const DataType &b = StoragePolicy::data(bData); if ( a < b ) return -1; *************** *** 456,461 **** static bool less( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = Storage::data(aData); ! const DataType &b = Storage::data(bData); return a < b; } --- 488,493 ---- static bool less( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = StoragePolicy::data(aData); ! const DataType &b = StoragePolicy::data(bData); return a < b; } *************** *** 463,468 **** static bool equal( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = Storage::data(aData); ! const DataType &b = Storage::data(bData); return a == b; } --- 495,500 ---- static bool equal( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = StoragePolicy::data(aData); ! const DataType &b = StoragePolicy::data(bData); return a == b; } *************** *** 477,481 **** public: typedef Compare<DataType> SelfType; ! typedef CPPTL_TYPENAME Storage<DataType>::result_type Storage; static void registerFunctions( ValueType &type ) --- 509,513 ---- public: typedef Compare<DataType> SelfType; ! typedef CPPTL_TYPENAME StoragePolicySelector<DataType>::type StoragePolicy; static void registerFunctions( ValueType &type ) *************** *** 488,493 **** static int compare( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = Storage::data(aData); ! const DataType &b = Storage::data(bData); if ( a < b ) return -1; --- 520,525 ---- static int compare( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = StoragePolicy::data(aData); ! const DataType &b = StoragePolicy::data(bData); if ( a < b ) return -1; *************** *** 499,504 **** static bool less( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = Storage::data(aData); ! const DataType &b = Storage::data(bData); return a < b; } --- 531,536 ---- static bool less( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = StoragePolicy::data(aData); ! const DataType &b = StoragePolicy::data(bData); return a < b; } *************** *** 506,511 **** static bool equal( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = Storage::data(aData); ! const DataType &b = Storage::data(bData); return (a < b) && !(b < a); } --- 538,543 ---- static bool equal( const Value &aData, const Value &bData, bool &canCompare ) { ! const DataType &a = StoragePolicy::data(aData); ! const DataType &b = StoragePolicy::data(bData); return (a < b) && !(b < a); } Index: typetraits.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpptl/typetraits.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** typetraits.h 28 Feb 2005 20:36:34 -0000 1.2 --- typetraits.h 8 Jul 2008 20:42:00 -0000 1.3 *************** *** 4,27 **** # include <cpptl/forwards.h> namespace CppTL { ! template<class T> ! struct RemoveConst ! { ! typedef T type; ! }; ! #if !defined( CPPTL_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) - template<class T> - struct RemoveConst<const T> - { - typedef T type; - }; - #endif } // namespace CppTL --- 4,90 ---- # include <cpptl/forwards.h> + // @todo move this to a header dedicated to basic generic programming technics + + namespace CppTL { ! /** Remove const prefix of a type. ! * \Warning Older compiler such as VC 6.0 do not allow implementation of ! * this feature. Const will not be removed on such platform. ! */ ! template<class T> ! struct RemoveConst ! { ! typedef T type; ! }; ! #if !defined( CPPTL_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) ! ! template<class T> ! struct RemoveConst<const T> ! { ! typedef T type; ! }; ! ! #endif + + + //@todo BooleanType should be moved to a simple generic programming header. + template<const bool isTrue> + struct BooleanType + { + }; + + typedef BooleanType<false> FalseType; + typedef BooleanType<true> TrueType; + + + + + #if !defined(CPPTL_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + /** Returns type A if true, type B otherwise. + * \c true case, returns A + * \code + * CppTL::IfType< LargeTypePolicy,SmallTypePolicy,sizeof(T) > 128 > + * \endcode + */ + template<typename A, typename B, const bool condition> + struct IfType + { + typedef A type; + }; + + /// Returns type A if true, type B otherwise. + /// \c false case, returns B + template<typename A, typename B> + struct IfType<A,B,false> + { + typedef B type; + }; + #else // work-around lack of template partial specialization using template member + /// Returns type A if true, type B otherwise + template<typename A, typename B, const bool condition> + struct IfType + { + template<const bool condition> + struct Selector + { + typedef A type; + }; + template<> + struct Selector<false> + { + typedef B type; + }; + + typedef CPPTL_TYPENAME Selector<condition>::type type; + }; + #endif + } // namespace CppTL |