ExpectedType.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00025 //----------------------------------------------------------------------
00026 #ifndef ICL_CORE_EXPECTED_TYPE_H_INCLUDED
00027 #define ICL_CORE_EXPECTED_TYPE_H_INCLUDED
00028 
00029 #include <boost/shared_ptr.hpp>
00030 
00031 namespace icl_core {
00032 
00033 template <typename T> struct ExpectedTypeIs;
00034 
00058 struct ExpectedType
00059 {
00060 public:
00061   typedef boost::shared_ptr<const ExpectedType> Ptr;
00062 
00063   virtual ~ExpectedType() { }
00064 
00066   template <typename T> bool is() const { return ExpectedTypeIs<T>().equals(this); }
00067 
00069   bool operator == (const ExpectedType& other) const
00070   {
00071     return this->equals(&other);
00072   }
00073 
00075   bool operator != (const ExpectedType& other) const
00076   {
00077     return !this->equals(&other);
00078   }
00079 
00080 protected:
00081   virtual bool equals(const ExpectedType *other) const = 0;
00082 };
00083 
00111 template <typename T>
00112 struct ExpectedTypeIs : public ExpectedType
00113 {
00114 protected:
00115   bool equals(const ExpectedType *other) const
00116   {
00117     return dynamic_cast<const ExpectedTypeIs<T> *>(other) != NULL;
00118   }
00119   friend struct ExpectedType;
00120 };
00121 
00122 }
00123 
00124 #endif


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:23