CHROMA
typeinfo.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! @file
3  * @brief Type info support
4  */
5 
6 #ifndef __typeinfo_h__
7 #define __typeinfo_h__
8 
9 #include <typeinfo>
10 #include <cassert>
11 #include "typelist.h"
12 
13 namespace Chroma
14 {
15 ////////////////////////////////////////////////////////////////////////////////
16 // class TypeInfo
17 // Purpose: offer a first-class, comparable wrapper over std::type_info
18 ////////////////////////////////////////////////////////////////////////////////
19 
20  class TypeInfo
21  {
22  public:
23  // Constructors
24  TypeInfo(); // needed for containers
25  TypeInfo(const std::type_info&); // non-explicit
26 
27  // Access for the wrapped std::type_info
28  const std::type_info& Get() const;
29  // Compatibility functions
30  bool before(const TypeInfo& rhs) const;
31  const char* name() const;
32 
33  private:
34  const std::type_info* pInfo_;
35  };
36 
37 // Implementation
38 
40  {
41  class Nil {};
42  pInfo_ = &typeid(Nil);
43  assert(pInfo_);
44  }
45 
46  inline TypeInfo::TypeInfo(const std::type_info& ti)
47  : pInfo_(&ti)
48  { assert(pInfo_); }
49 
50  inline bool TypeInfo::before(const TypeInfo& rhs) const
51  {
52  assert(pInfo_);
53  return pInfo_->before(*rhs.pInfo_);
54  }
55 
56  inline const std::type_info& TypeInfo::Get() const
57  {
58  assert(pInfo_);
59  return *pInfo_;
60  }
61 
62  inline const char* TypeInfo::name() const
63  {
64  assert(pInfo_);
65  return pInfo_->name();
66  }
67 
68 // Comparison operators
69 
70  inline bool operator==(const TypeInfo& lhs, const TypeInfo& rhs)
71  { return lhs.Get() == rhs.Get(); }
72 
73  inline bool operator<(const TypeInfo& lhs, const TypeInfo& rhs)
74  { return lhs.before(rhs); }
75 
76  inline bool operator!=(const TypeInfo& lhs, const TypeInfo& rhs)
77  { return !(lhs == rhs); }
78 
79  inline bool operator>(const TypeInfo& lhs, const TypeInfo& rhs)
80  { return rhs < lhs; }
81 
82  inline bool operator<=(const TypeInfo& lhs, const TypeInfo& rhs)
83  { return !(lhs > rhs); }
84 
85  inline bool operator>=(const TypeInfo& lhs, const TypeInfo& rhs)
86  { return !(lhs < rhs); }
87 }
88 
89 #endif
90 
const char * name() const
Definition: typeinfo.h:62
bool before(const TypeInfo &rhs) const
Definition: typeinfo.h:50
const std::type_info * pInfo_
Definition: typeinfo.h:34
const std::type_info & Get() const
Definition: typeinfo.h:56
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
bool operator<(const KeyDispColorVector_t &a, const KeyDispColorVector_t &b)
Support for the keys of smeared and displaced color vectors.
bool operator<=(const TypeInfo &lhs, const TypeInfo &rhs)
Definition: typeinfo.h:82
bool operator==(const TypeInfo &lhs, const TypeInfo &rhs)
Definition: typeinfo.h:70
bool operator>(const TypeInfo &lhs, const TypeInfo &rhs)
Definition: typeinfo.h:79
bool operator>=(const TypeInfo &lhs, const TypeInfo &rhs)
Definition: typeinfo.h:85
bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs)
Definition: typeinfo.h:76
Typelist support.