[Cppunit-cvs] cppunit2/include/cpptl typeinfo.h,NONE,1.1
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-03-03 08:13:27
|
Update of /cvsroot/cppunit/cppunit2/include/cpptl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29667 Added Files: typeinfo.h Log Message: * TypeId is a std::type_info wrapper, and provides a mechanism to support RTTI when the compiler does not provide any support. --- NEW FILE: typeinfo.h --- #ifndef CPPTL_TYPEINFO_H_INCUDED # define CPPTL_TYPEINFO_H_INCUDED # include <string> // ///////////////////////////////////////////////////// // ///////////////////////////////////////////////////// // CTTI using std::type_info & typeid // ///////////////////////////////////////////////////// // ///////////////////////////////////////////////////// # ifndef CPPTL_NO_RTTI # include <typeinfo> namespace CppTL { class TypeId { public: TypeId( const std::type_info &typeId ) : type_( &typeId ) { } bool operator ==( const TypeId &other ) const { return *type_ == *(other.type_); } bool operator !=( const TypeId &other ) const { return !( *this == other ); } bool operator <( const TypeId &other ) const { return type_->before( *(other.type_) ); } private: const std::type_info *type_; }; // Compile Time Type Information functions // ////////////////////////////////////////////////////////////////// template<class AType> TypeId typeId( Type<AType> ) { return typeid( AType ); } } // namespace CppTL // ///////////////////////////////////////////////////// // ///////////////////////////////////////////////////// // CTTI using hande-made mecanism (template overload) // ///////////////////////////////////////////////////// // ///////////////////////////////////////////////////// # else namespace CppTL { class TypeId { public: TypeId( const char *type ) : type_( type ) { } bool operator <( const TypeId &other ) const { return strcmp( type_, other.type_) < 0; } bool operator ==( const TypeId &other ) const { return strcmp( type_, other.type_ ) == 0; } bool operator !=( const TypeId &other ) const { return !( *this == other ); } private: const char *type_; }; inline TypeId typeId( ... ) { return __error__typeId_function_not_overloaded; } #define CPPTL_DECLARE_TYPEINFO( AType ) \ namespace CppTL { \ inline TypeId typeId( Type<AType> ) \ { \ return TypeId( #AType ); \ } \ } CPPUTTOOLS_DECLARE_CTTI( char ); CPPUTTOOLS_DECLARE_CTTI( signed char ); CPPUTTOOLS_DECLARE_CTTI( unsigned char ); CPPUTTOOLS_DECLARE_CTTI( short ); CPPUTTOOLS_DECLARE_CTTI( unsigned short ); CPPUTTOOLS_DECLARE_CTTI( int ); CPPUTTOOLS_DECLARE_CTTI( unsigned int ); CPPUTTOOLS_DECLARE_CTTI( long ); CPPUTTOOLS_DECLARE_CTTI( unsigned long ); CPPUTTOOLS_DECLARE_CTTI( float ); CPPUTTOOLS_DECLARE_CTTI( double ); CPPUTTOOLS_DECLARE_CTTI( long double ); CPPUTTOOLS_DECLARE_CTTI( const char * ); CPPUTTOOLS_DECLARE_CTTI( const wchar_t * ); CPPUTTOOLS_DECLARE_CTTI( std::string ); CPPUTTOOLS_DECLARE_CTTI( std::wstring ); } // namespace CppTL # endif #endif // CPPTL_TYPEINFO_H_INCUDED |