TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Declare_Base.h
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 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.
8* 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.
9*
10* 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.
11* 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;
12* 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.
13*
14*****************************************************************************/
15
16
17// .SECTION Description
18// The macros Declare_base_sans_destructeur and
19// Implemente_base_sans_destructeur
20// allow simple creation of base classes
21// conforming to TRUST.
22
23// .SECTION Header description
24// class A_base : public B {
25// Declare_base_sans_destructeur(A_base);
26// };
27// .SECTION Source description
28// Implemente_base_sans_destructeur(A_base, "A_base", B);
29
30#include <arch.h>
31
32#ifdef LATATOOLS
33#define Declare_base_sans_constructeur_ni_destructeur_ni_readon(_TYPE_) \
34 public : \
35 unsigned taille_memoire() const override { return 0; }; \
36 int duplique() const override { return 0; }; \
37 protected : \
38 Sortie& printOn(Sortie& x) const override
39
40#define Implemente_base_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
41
42#else
43#include <Cast.h>
44#include <Type_info.h>
45#define Declare_base_sans_constructeur_ni_destructeur_ni_readon(_TYPE_) \
46 \
47 public : \
48 static const Type_info info_obj; \
49 static const Type_info* info(); \
50 const Type_info* get_info() const override; \
51 /* method added to cast in python */ \
52 static _TYPE_& self_cast( Objet_U&) ; \
53 static const _TYPE_& self_cast(const Objet_U&) ; \
54 protected : \
55 Sortie& printOn(Sortie& x) const override
56
57
58#define Implemente_base_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_) \
59 \
60 static_assert(std::is_base_of<_BASE_, _TYPE_>::value, "\n\n!!!!! Error in Implemente_base* macro usage: type '" #_TYPE_ "' does not inherit from '" #_BASE_ "' !!!!\n\n"); \
61 \
62 const Type_info* name2(_TYPE_,bases)[1]={ \
63 &(_BASE_::info_obj)}; \
64 const Type_info _TYPE_::info_obj(_NOM_, 1, name2(_TYPE_,bases)); \
65 \
66 _TYPE_& _TYPE_::self_cast( Objet_U& r) { \
67 return ref_cast_non_const(_TYPE_,r); /* _non_const important otherwise recursion in ref_cast */ \
68 } \
69 const _TYPE_& _TYPE_::self_cast(const Objet_U& r) { \
70 return ref_cast_non_const(_TYPE_,r); /* _non_const important otherwise recursion in ref_cast */ \
71 } \
72 const Type_info* _TYPE_::get_info() const { \
73 return &info_obj; \
74 } \
75 const Type_info* _TYPE_::info() { \
76 return &info_obj; \
77 } \
78 class __dummy__
79#endif
80
81/////////////////////////////////////////
82/////// Those are shared with LATATOOLS
83/////////////////////////////////////////
84
85#define Declare_base_sans_constructeur_ni_destructeur(_TYPE_) \
86 Declare_base_sans_constructeur_ni_destructeur_ni_readon(_TYPE_); \
87 Entree& readOn(Entree&) override
88
89#define Declare_base_sans_constructeur(_TYPE_) \
90 public: \
91 ~_TYPE_() override; \
92 Declare_base_sans_constructeur_ni_destructeur(_TYPE_)
93
94#define Declare_base_sans_destructeur(_TYPE_) \
95 public: \
96 _TYPE_(); \
97 Declare_base_sans_constructeur_ni_destructeur(_TYPE_)
98
99#define Declare_base(_TYPE_) \
100 public: \
101 _TYPE_(); \
102 ~_TYPE_() override; \
103 Declare_base_sans_constructeur_ni_destructeur(_TYPE_)
104
105#define Declare_base_sans_readon(_TYPE_) \
106 public: \
107 _TYPE_(); \
108 ~_TYPE_() override; \
109 Declare_base_sans_constructeur_ni_destructeur_ni_readon(_TYPE_)
110
111#define Declare_base_with_param(_TYPE_) \
112 Declare_base_sans_readon(_TYPE_); \
113 protected: \
114 void set_param(Param&) const override
115
116#define Implemente_base_sans_constructeur(_TYPE_,_NOM_,_BASE_) \
117 _TYPE_::~_TYPE_() { } \
118 Implemente_base_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
119
120#define Implemente_base_sans_destructeur(_TYPE_,_NOM_,_BASE_) \
121 _TYPE_::_TYPE_() { } \
122 Implemente_base_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
123
124#define Implemente_base(_TYPE_,_NOM_,_BASE_) \
125 _TYPE_::_TYPE_() { } \
126 _TYPE_::~_TYPE_() { } \
127 Implemente_base_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
128
129
130/////////////////////////////////////////
131/////// TEMPLATE VERSION for 32/64 bits !!! Oh yes baby!
132/////////////////////////////////////////
133
134// The declare remain identical but we create a new macro so that bin/KSH/mk_Instanciable spots it correctly:
135#define Declare_base_sans_constructeur_ni_destructeur_32_64(_TYPE_) Declare_base_sans_constructeur_ni_destructeur(_TYPE_>)
136#define Declare_base_sans_constructeur_32_64(_TYPE_) Declare_base_sans_constructeur(_TYPE_)
137#define Declare_base_sans_destructeur_32_64(_TYPE_) Declare_base_sans_destructeur(_TYPE_)
138#define Declare_base_32_64(_TYPE_) Declare_base(_TYPE_)
139#define Declare_base_sans_readon_32_64(_TYPE_) Declare_base_sans_readon(_TYPE_)
140#define Declare_base_with_param_32_64(_TYPE_) Declare_base_with_param(_TYPE_)
141
142// Helper macro for info_obj static variable definition:
143#if INT_is_64_ == 2
144# define info_obj_def_macro_base(_NOM_, _TYPE_) \
145 template <> const Type_info _TYPE_<int>::info_obj(_NOM_, 1, name2(_TYPE_,bases)<int> ); \
146 template <> const Type_info _TYPE_<trustIdType>::info_obj(_NOM_ "_64", 1, name2(_TYPE_, bases)<trustIdType> );
147#else
148# define info_obj_def_macro_base(_NOM_, _TYPE_) \
149 template <> const Type_info _TYPE_<int>::info_obj(_NOM_, 1, name2(_TYPE_,bases)<int> );
150#endif
151
152#ifdef LATATOOLS
153#define Implemente_base_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)
154
155#else
156// The implemente are of course different:
157#define Implemente_base_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_) \
158 \
159 template <typename _T_> const Type_info* name2(_TYPE_,bases)[1] = { &(_BASE_::info_obj) }; \
160 \
161 info_obj_def_macro_base(_NOM_, _TYPE_) \
162 \
163 template <typename _T_> _TYPE_<_T_>& _TYPE_<_T_>::self_cast( Objet_U& r) { \
164 return ref_cast_non_const(_TYPE_<_T_>,r); /* _non_const important otherwise recursion in ref_cast */ \
165 } \
166 template <typename _T_> const _TYPE_<_T_>& _TYPE_<_T_>::self_cast(const Objet_U& r) { \
167 return ref_cast_non_const(_TYPE_<_T_>,r); /* _non_const important otherwise recursion in ref_cast */ \
168 } \
169 template <typename _T_> const Type_info* _TYPE_<_T_>::get_info() const { \
170 return &info_obj; \
171 } \
172 template <typename _T_> const Type_info* _TYPE_<_T_>::info() { \
173 return &info_obj; \
174 } \
175 class __dummy__
176
177#endif // LATATOOLS
178
179#define Implemente_base_sans_constructeur_32_64(_TYPE_,_NOM_,_BASE_) \
180 template <typename _T_> _TYPE_<_T_>::~_TYPE_() { } \
181 Implemente_base_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)
182
183#define Implemente_base_sans_destructeur_32_64(_TYPE_,_NOM_,_BASE_) \
184 template <typename _T_> _TYPE_<_T_>::_TYPE_() { } \
185 Implemente_base_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)
186
187#define Implemente_base_32_64(_TYPE_,_NOM_,_BASE_) \
188 template <typename _T_> _TYPE_<_T_>::_TYPE_() { } \
189 template <typename _T_> _TYPE_<_T_>::~_TYPE_() { } \
190 Implemente_base_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)
191