Be a bit more efficient when processing the active and inactive
[oota-llvm.git] / include / llvm / Support / TypeInfo.h
1 //===- Support/TypeInfo.h - Support class for type_info objects -*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This class makes std::type_info objects behave like first class objects that
11 // can be put in maps and hashtables.  This code is based off of code in the
12 // Loki C++ library from the Modern C++ Design book.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef SUPPORT_TYPEINFO_H
17 #define SUPPORT_TYPEINFO_H
18
19 #include <typeinfo>
20
21 namespace llvm {
22
23 struct TypeInfo {
24   TypeInfo() {                     // needed for containers
25     struct Nil {};  // Anonymous class distinct from all others...
26     Info = &typeid(Nil);
27   }
28
29   TypeInfo(const std::type_info &ti) : Info(&ti) { // non-explicit
30   }
31
32   // Access for the wrapped std::type_info
33   const std::type_info &get() const {
34     return *Info;
35   }
36
37   // Compatibility functions
38   bool before(const TypeInfo &rhs) const {
39     return Info->before(*rhs.Info) != 0;
40   }
41   const char *getClassName() const {
42     return Info->name();
43   }
44
45 private:
46   const std::type_info *Info;
47 };
48     
49 // Comparison operators
50 inline bool operator==(const TypeInfo &lhs, const TypeInfo &rhs) {
51   return lhs.get() == rhs.get();
52 }
53
54 inline bool operator<(const TypeInfo &lhs, const TypeInfo &rhs) {
55   return lhs.before(rhs);
56 }
57
58 inline bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs) {
59   return !(lhs == rhs);
60 }
61
62 inline bool operator>(const TypeInfo &lhs, const TypeInfo &rhs) {
63   return rhs < lhs;
64 }
65     
66 inline bool operator<=(const TypeInfo &lhs, const TypeInfo &rhs) {
67   return !(lhs > rhs);
68 }
69      
70 inline bool operator>=(const TypeInfo &lhs, const TypeInfo &rhs) {
71   return !(lhs < rhs);
72 }
73
74 } // End llvm namespace
75
76 #endif