LILAC
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vartype.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014, Sam Schetterer, Nathan Kutz, University of Washington
3 Authors: Sam Schetterer
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 
10 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11 
12 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 
16 */
17 #pragma once
18 #ifndef VARTYPE_HPP
19 #define VARTYPE_HPP
20 #include <typeinfo>
21 #include <string>
23 
32 class vartype{
33  public:
34  virtual const std::type_info& vtype() const = 0;
35  inline bool compare(const vartype* in) const{
36  return vtype() == in->vtype();
37  }
38  inline bool compare(const vartype& in) const{
39  return vtype() == in.vtype();
40  }
41  inline bool compare(const std::type_info& tinf){
42  return vtype() == tinf;
43  }
44  template<typename T> inline bool compare() const{
45  return vtype() == typeid(T);
46  }
47  template<typename T> inline bool compare(const T& in) const{
48  //could call typeid(T), but this plays more nicely with static analysis tools
49  //and unused input parameters
50  return vtype() == typeid(in);
51  }
52  inline std::string vname() const{
53  return vtype().name();
54  }
55  /*
56  * Functions that compare type internally used by the object
57  * By default this is equal to the external type, but can be made different
58  */
59  virtual const std::type_info& vtype_internal() const{
60  return vtype();
61  }
62  inline bool compare_internal(const vartype* in) const{
63  return vtype_internal() == in->vtype_internal();
64  }
65  inline bool compare_internal(const vartype& in) const{
66  return vtype_internal() == in.vtype_internal();
67  }
68  inline bool compare_internal(const std::type_info& tinf){
69  return vtype_internal() == tinf;
70  }
71  template<typename T> inline bool compare_internal() const{
72  return vtype_internal() == typeid(T);
73  }
74  template<typename T> inline bool compare_internal(const T& in) const{
75  //could call typeid(T), but this plays more nicely with static analysis tools
76  //and unused input parameters
77  return vtype_internal() == typeid(in);
78  }
79  inline std::string vname_internal() const{
80  return vtype_internal().name();
81  }
82 
83  virtual ~vartype(){};
84 };
85 
86 #endif