00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00015 #ifndef LOKI_LOKITYPEINFO_INC_
00016 #define LOKI_LOKITYPEINFO_INC_
00017
00018
00019
00020
00021 #include <typeinfo>
00022 #include <cassert>
00023 #include "Typelist.h"
00024
00025 namespace Loki
00026 {
00028
00029
00031
00032 class TypeInfo
00033 {
00034 public:
00035
00036 TypeInfo();
00037 TypeInfo(const std::type_info&);
00038
00039
00040 const std::type_info& Get() const;
00041
00042 bool before(const TypeInfo& rhs) const;
00043 const char* name() const;
00044
00045 private:
00046 const std::type_info* pInfo_;
00047 };
00048
00049
00050
00051 inline TypeInfo::TypeInfo()
00052 {
00053 class Nil {};
00054 pInfo_ = &typeid(Nil);
00055 assert(pInfo_);
00056 }
00057
00058 inline TypeInfo::TypeInfo(const std::type_info& ti)
00059 : pInfo_(&ti)
00060 { assert(pInfo_); }
00061
00062 inline bool TypeInfo::before(const TypeInfo& rhs) const
00063 {
00064 assert(pInfo_);
00065
00066 return pInfo_->before(*rhs.pInfo_) != 0;
00067 }
00068
00069 inline const std::type_info& TypeInfo::Get() const
00070 {
00071 assert(pInfo_);
00072 return *pInfo_;
00073 }
00074
00075 inline const char* TypeInfo::name() const
00076 {
00077 assert(pInfo_);
00078 return pInfo_->name();
00079 }
00080
00081
00082
00083 inline bool operator==(const TypeInfo& lhs, const TypeInfo& rhs)
00084
00085 { return (lhs.Get() == rhs.Get()) != 0; }
00086
00087 inline bool operator<(const TypeInfo& lhs, const TypeInfo& rhs)
00088 { return lhs.before(rhs); }
00089
00090 inline bool operator!=(const TypeInfo& lhs, const TypeInfo& rhs)
00091 { return !(lhs == rhs); }
00092
00093 inline bool operator>(const TypeInfo& lhs, const TypeInfo& rhs)
00094 { return rhs < lhs; }
00095
00096 inline bool operator<=(const TypeInfo& lhs, const TypeInfo& rhs)
00097 { return !(lhs > rhs); }
00098
00099 inline bool operator>=(const TypeInfo& lhs, const TypeInfo& rhs)
00100 { return !(lhs < rhs); }
00101 }
00102
00103 #endif // end file guardian