Jpp
JConversion.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JCONVERSION__
2 #define __JLANG__JCONVERSION__
3 
4 #include "JLang/JAssert.hh"
5 #include "JLang/JTest.hh"
6 
7 /**
8  * \author mdejong
9  */
10 
11 namespace JLANG {}
12 namespace JPP { using namespace JLANG; }
13 
14 namespace JLANG {
15 
16 
17  /**
18  * Template class test for polymorphism.
19  */
20  template<class JDerived_t, class JBase_t>
22  {
23  /**
24  * Test convertibility of two classes.
25  *
26  * Source code is taken from reference:
27  * A. Alexandrescu, Modern C++ Design, Addison Wesley.
28  */
29  template<class derived_type, class base_type>
30  class JLocal :
31  public JTest
32  {
33  using JTest::test;
34 
35  static JTrue test(const base_type&);
36 
37  static derived_type getReference();
38 
39  public:
40  static const bool is_derived = JTEST(test(getReference()));
41  static const bool is_same = false;
42  };
43 
44  public:
45 
46  static const bool is_derived = JLocal<const JDerived_t*, const JBase_t*>::is_derived; //!< true, if JDerived_t derives from JBase_t
47  static const bool is_same = JLocal<const JDerived_t*, const JBase_t*>::is_same; //!< true, if JDerived_t is equal to JBase_t
48  };
49 
50 
51  /**
52  * Specialisation of JConversion for identical types.
53  */
54  template<class T>
55  struct JConversion<T,T>
56  {
57  static const bool is_derived = true;
58  static const bool is_same = true;
59  };
60 
61 
62  /**
63  * Auxialiary class to assert type conversion.
64  */
65  template<class JDerived_t, class JBase_t, bool is_derived = JConversion<JDerived_t,JBase_t>::is_derived>
67 
68  /**
69  * Implementation of a valid type conversion.
70  */
71  template<class JDerived_t, class JBase_t>
72  class JAssertConversion<JDerived_t, JBase_t, true> {};
73 }
74 
75 #endif
JLANG::JTest::JTrue
definition of true
Definition: JTest.hh:24
JLANG::JTest::test
static JFalse test(...)
default false
JLANG::JConversion
Template class test for polymorphism.
Definition: JConversion.hh:21
JLANG::JConversion::JLocal::is_same
static const bool is_same
Definition: JConversion.hh:41
JLANG::JConversion::JLocal
Test convertibility of two classes.
Definition: JConversion.hh:30
JLANG::JTest
Auxiliary base class for compile time evaluation of test.
Definition: JTest.hh:21
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JConversion::JLocal::test
static JTrue test(const base_type &)
JTEST
#define JTEST(__A__)
Test macro.
Definition: JTest.hh:45
JLANG::JAssertConversion
Auxialiary class to assert type conversion.
Definition: JConversion.hh:66
JLANG::JConversion::is_derived
static const bool is_derived
true, if JDerived_t derives from JBase_t
Definition: JConversion.hh:46
JLANG::JConversion::is_same
static const bool is_same
true, if JDerived_t is equal to JBase_t
Definition: JConversion.hh:47
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10
JLANG::JConversion::JLocal::is_derived
static const bool is_derived
Definition: JConversion.hh:40
JLANG::JConversion::JLocal::getReference
static derived_type getReference()
JTest.hh
JAssert.hh