ionClass.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <ionConfig.h>
11 
12 #include <typeinfo>
13 
14 
15 namespace ion
16 {
17 
20  struct Type
21  {
22  Type(std::type_info const & value)
23  : Value(value)
24  {}
25 
26  bool operator <(Type const & other) const
27  {
28  return Value.before(other.Value);
29  }
30 
31  std::type_info const & Value;
32  };
33 
42  template <typename T, typename U>
43  bool InstanceOf(U * Object)
44  {
45  return dynamic_cast<T const *>(Object) != 0;
46  }
47 
56  template <typename T, typename U>
57  bool InstanceOf(U & Object)
58  {
59  return dynamic_cast<T const *>(& Object) != 0;
60  }
61 
67  template <typename T, typename U>
68  T * As(U * Object)
69  {
70  return dynamic_cast<T *>(Object);
71  }
72 
78  template <typename T, typename U>
79  T const * As(U const * Object)
80  {
81  return dynamic_cast<T const *>(Object);
82  }
83 
89  template <typename T, typename U>
90  T & As(U & Object)
91  {
92  return * dynamic_cast<T *>(& Object);
93  }
94 
100  template <typename T, typename U>
101  T const & As(U const & Object)
102  {
103  return * dynamic_cast<T const *>(& Object);
104  }
105 
106 }
std::type_info const & Value
Definition: ionClass.h:31
bool operator<(Type const &other) const
Definition: ionClass.h:26
T * As(U *Object)
Casts an object as a different type, performing a validity check.
Definition: ionClass.h:68
bool InstanceOf(U *Object)
Check whether an object is an instance of a type.
Definition: ionClass.h:43
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
Type(std::type_info const &value)
Definition: ionClass.h:22
Lightweight wrapper for std::type_info that enables sorting (e.g. for use in a std::map) ...
Definition: ionClass.h:20