Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
#define JTEST(__A__)
Test macro.
Definition: JTest.hh:45
static derived_type getReference()
static JFalse test(...)
default false
static const bool is_same
Definition: JConversion.hh:41
Template class test for polymorphism.
Definition: JConversion.hh:21
static JTrue test(const base_type &)
Auxialiary class to assert type conversion.
Definition: JConversion.hh:66
Test convertibility of two classes.
Definition: JConversion.hh:30
static const bool is_derived
true, if JDerived_t derives from JBase_t
Definition: JConversion.hh:46
Auxiliary base class for compile time evaluation of test.
Definition: JTest.hh:21
definition of true
Definition: JTest.hh:24
do set_variable OUTPUT_DIRECTORY $WORKDIR T
static const bool is_same
true, if JDerived_t is equal to JBase_t
Definition: JConversion.hh:47
static const bool is_derived
Definition: JConversion.hh:40