Made error message more comprehensible.
[oota-llvm.git] / include / Support / TypeInfo.h
1 //===- Support/TypeInfo.h - Support class for type_info objects -*- C++ -*-===//
2 //
3 // This class makes std::type_info objects behave like first class objects that
4 // can be put in maps and hashtables.  This code is based off of code in the
5 // Loki C++ library from the Modern C++ Design book.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef SUPPORT_TYPEINFO_H
10 #define SUPPORT_TYPEINFO_H
11
12 #include <typeinfo>
13
14 struct TypeInfo {
15   TypeInfo() {                     // needed for containers
16     struct Nil {};  // Anonymous class distinct from all others...
17     Info = &typeid(Nil);
18   }
19
20   TypeInfo(const std::type_info &ti) : Info(&ti) { // non-explicit
21   }
22
23   // Access for the wrapped std::type_info
24   const std::type_info &get() const {
25     return *Info;
26   }
27
28   // Compatibility functions
29   bool before(const TypeInfo &rhs) const {
30     return Info->before(*rhs.Info);
31   }
32   const char *getClassName() const {
33     return Info->name();
34   }
35
36 private:
37   const std::type_info *Info;
38 };
39     
40 // Comparison operators
41 inline bool operator==(const TypeInfo &lhs, const TypeInfo &rhs) {
42   return lhs.get() == rhs.get();
43 }
44
45 inline bool operator<(const TypeInfo &lhs, const TypeInfo &rhs) {
46   return lhs.before(rhs);
47 }
48
49 inline bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs) {
50   return !(lhs == rhs);
51 }
52
53 inline bool operator>(const TypeInfo &lhs, const TypeInfo &rhs) {
54   return rhs < lhs;
55 }
56     
57 inline bool operator<=(const TypeInfo &lhs, const TypeInfo &rhs) {
58   return !(lhs > rhs);
59 }
60      
61 inline bool operator>=(const TypeInfo &lhs, const TypeInfo &rhs) {
62   return !(lhs < rhs);
63 }
64
65 #endif