ExpectedType.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
26 #ifndef ICL_CORE_EXPECTED_TYPE_H_INCLUDED
27 #define ICL_CORE_EXPECTED_TYPE_H_INCLUDED
28 
29 #include <boost/shared_ptr.hpp>
30 
31 namespace icl_core {
32 
33 template <typename T> struct ExpectedTypeIs;
34 
59 {
60 public:
61  typedef boost::shared_ptr<const ExpectedType> Ptr;
62 
63  virtual ~ExpectedType() { }
64 
66  template <typename T> bool is() const { return ExpectedTypeIs<T>().equals(this); }
67 
69  bool operator == (const ExpectedType& other) const
70  {
71  return this->equals(&other);
72  }
73 
75  bool operator != (const ExpectedType& other) const
76  {
77  return !this->equals(&other);
78  }
79 
80 protected:
81  virtual bool equals(const ExpectedType *other) const = 0;
82 };
83 
111 template <typename T>
112 struct ExpectedTypeIs : public ExpectedType
113 {
114 protected:
115  bool equals(const ExpectedType *other) const
116  {
117  return dynamic_cast<const ExpectedTypeIs<T> *>(other) != NULL;
118  }
119  friend struct ExpectedType;
120 };
121 
122 }
123 
124 #endif
bool is() const
Check if an actual type equals this expected type.
Definition: ExpectedType.h:66
virtual bool equals(const ExpectedType *other) const =0
boost::shared_ptr< const ExpectedType > Ptr
Definition: ExpectedType.h:61
bool operator!=(const ExpectedType &other) const
Directly compare two ExpectedType objects.
Definition: ExpectedType.h:75
bool equals(const ExpectedType *other) const
Definition: ExpectedType.h:115
bool operator==(const ExpectedType &other) const
Directly compare two ExpectedType objects.
Definition: ExpectedType.h:69


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58