LLVM API Documentation

TypeInfo.h

Go to the documentation of this file.
00001 //===- llvm/Support/TypeInfo.h - Support for type_info objects -*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This class makes std::type_info objects behave like first class objects that
00011 // can be put in maps and hashtables.  This code is based off of code in the
00012 // Loki C++ library from the Modern C++ Design book.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_SUPPORT_TYPEINFO_H
00017 #define LLVM_SUPPORT_TYPEINFO_H
00018 
00019 #include <typeinfo>
00020 
00021 namespace llvm {
00022 
00023 struct TypeInfo {
00024   TypeInfo() {                     // needed for containers
00025     struct Nil {};  // Anonymous class distinct from all others...
00026     Info = &typeid(Nil);
00027   }
00028 
00029   TypeInfo(const std::type_info &ti) : Info(&ti) { // non-explicit
00030   }
00031 
00032   // Access for the wrapped std::type_info
00033   const std::type_info &get() const {
00034     return *Info;
00035   }
00036 
00037   // Compatibility functions
00038   bool before(const TypeInfo &rhs) const {
00039     return Info->before(*rhs.Info) != 0;
00040   }
00041   const char *getClassName() const {
00042     return Info->name();
00043   }
00044 
00045 private:
00046   const std::type_info *Info;
00047 };
00048 
00049 // Comparison operators
00050 inline bool operator==(const TypeInfo &lhs, const TypeInfo &rhs) {
00051   return lhs.get() == rhs.get();
00052 }
00053 
00054 inline bool operator<(const TypeInfo &lhs, const TypeInfo &rhs) {
00055   return lhs.before(rhs);
00056 }
00057 
00058 inline bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs) {
00059   return !(lhs == rhs);
00060 }
00061 
00062 inline bool operator>(const TypeInfo &lhs, const TypeInfo &rhs) {
00063   return rhs < lhs;
00064 }
00065 
00066 inline bool operator<=(const TypeInfo &lhs, const TypeInfo &rhs) {
00067   return !(lhs > rhs);
00068 }
00069 
00070 inline bool operator>=(const TypeInfo &lhs, const TypeInfo &rhs) {
00071   return !(lhs < rhs);
00072 }
00073 
00074 } // End llvm namespace
00075 
00076 #endif