TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Declare_Inst.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_instanciable_sans_destructeur and
19// Implemente_instanciable_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_instanciable_sans_destructeur(A_base);
26// };
27// .SECTION Source description
28// Implemente_instanciable_sans_destructeur(A_base, "A_base", B);
29#include <arch.h>
30
31#ifdef LATATOOLS
32#define Declare_instanciable_sans_constructeur_ni_destructeur_ni_readon(_TYPE_) \
33 \
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#else
41
42#define Declare_instanciable_sans_constructeur_ni_destructeur_ni_readon(_TYPE_) \
43 public : \
44 static Objet_U* cree_instance() ; \
45 unsigned taille_memoire() const override; \
46 int duplique() const override; \
47 static const Type_info info_obj; \
48 static const Type_info* info(); \
49 const Type_info* get_info() const override; \
50 /* method added to cast in python */ \
51 static _TYPE_& self_cast( Objet_U&) ; \
52 static const _TYPE_& self_cast(const Objet_U&) ; \
53 protected : \
54 Sortie& printOn(Sortie& x) const override
55
56#endif
57
58/////////////////////////////////////////
59/////// Those are shared with LATATOOLS
60/////////////////////////////////////////
61
62#define Declare_instanciable_sans_constructeur_ni_destructeur(_TYPE_) \
63 Declare_instanciable_sans_constructeur_ni_destructeur_ni_readon(_TYPE_); \
64 Entree& readOn(Entree&) override
65
66#define Declare_instanciable_sans_constructeur(_TYPE_) \
67 public: \
68 ~_TYPE_(); \
69 Declare_instanciable_sans_constructeur_ni_destructeur(_TYPE_) \
70
71#define Declare_instanciable_sans_destructeur(_TYPE_) \
72 public: \
73 _TYPE_(); \
74 Declare_instanciable_sans_constructeur_ni_destructeur(_TYPE_) \
75
76#define Declare_instanciable(_TYPE_) \
77 public: \
78 _TYPE_(); \
79 ~_TYPE_(); \
80 Declare_instanciable_sans_constructeur_ni_destructeur(_TYPE_) \
81
82#define Declare_instanciable_sans_readon(_TYPE_) \
83 public: \
84 _TYPE_(); \
85 ~_TYPE_(); \
86 Declare_instanciable_sans_constructeur_ni_destructeur_ni_readon(_TYPE_) \
87
88#define Declare_instanciable_with_param(_TYPE_) \
89 Declare_instanciable_sans_readon(_TYPE_); \
90 protected: \
91 void set_param(Param&) const override
92
93#ifdef LATATOOLS
94#define Implemente_instanciable_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
95
96#else
97#include <Cast.h>
98#include <Type_info.h>
99#define Implemente_instanciable_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_) \
100 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"); \
101 \
102 const Type_info* name2(_TYPE_,bases)[1]={ \
103 &(_BASE_::info_obj)}; \
104 const Type_info _TYPE_::info_obj(_NOM_, _TYPE_::cree_instance, 1, name2(_TYPE_,bases)); \
105 \
106 \
107 int _TYPE_::duplique() const \
108 { \
109 _TYPE_* xxx = new _TYPE_(*this); \
110 if(!xxx){Cerr << "Not enough memory " << finl; Process::exit();} \
111 return xxx->numero(); \
112 } \
113 _TYPE_& _TYPE_::self_cast( Objet_U& r) { \
114 return ref_cast_non_const(_TYPE_,r); /* _non_const important otherwise recursion in ref_cast */ \
115 } \
116 const _TYPE_& _TYPE_::self_cast(const Objet_U& r) { \
117 return ref_cast_non_const(_TYPE_,r); /* _non_const important otherwise recursion in ref_cast */ \
118 } \
119 Objet_U* _TYPE_::cree_instance() \
120 { _TYPE_* xxx = new _TYPE_(); \
121 if(!xxx){Cerr << "Not enough memory " << finl; Process::exit();} \
122 return xxx ; \
123 } \
124 \
125 const Type_info* _TYPE_::get_info() const { \
126 return &info_obj; \
127 } \
128 \
129 const Type_info* _TYPE_::info() { \
130 return &info_obj; \
131 } \
132 \
133 unsigned _TYPE_::taille_memoire() const { \
134 return sizeof(_TYPE_); \
135 } \
136 class __dummy__
137#endif
138
139#define Implemente_instanciable_sans_constructeur(_TYPE_,_NOM_,_BASE_) \
140 _TYPE_::~_TYPE_() { } \
141 Implemente_instanciable_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
142
143#define Implemente_instanciable_sans_destructeur(_TYPE_,_NOM_,_BASE_) \
144 _TYPE_::_TYPE_() { } \
145 Implemente_instanciable_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
146
147#define Implemente_instanciable(_TYPE_,_NOM_,_BASE_) \
148 _TYPE_::_TYPE_() { } \
149 _TYPE_::~_TYPE_() { } \
150 Implemente_instanciable_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
151
152
153/////////////////////////////////////////
154/////// TEMPLATE VERSION for 32/64 bits !!! Oh yes baby!
155/////////////////////////////////////////
156
157// The declare remain identical but we create a new macro so that bin/KSH/mk_Instanciable spots it correctly:
158#define Declare_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_) Declare_instanciable_sans_constructeur_ni_destructeur(_TYPE_)
159#define Declare_instanciable_sans_constructeur_32_64(_TYPE_) Declare_instanciable_sans_constructeur(_TYPE_)
160#define Declare_instanciable_sans_destructeur_32_64(_TYPE_) Declare_instanciable_sans_destructeur(_TYPE_)
161#define Declare_instanciable_32_64(_TYPE_) Declare_instanciable(_TYPE_)
162#define Declare_instanciable_sans_readon_32_64(_TYPE_) Declare_instanciable_sans_readon(_TYPE_)
163#define Declare_instanciable_with_param_32_64(_TYPE_) Declare_instanciable_with_param(_TYPE_)
164
165// Helper macro for info_obj static variable definition:
166#if INT_is_64_ == 2
167# define info_obj_def_macro_inst(_NOM_, _TYPE_) \
168 template <> const Type_info _TYPE_<int>::info_obj(_NOM_, _TYPE_<int>::cree_instance, 1, name2(_TYPE_,bases)<int> ); \
169 template <> const Type_info _TYPE_<trustIdType>::info_obj(_NOM_ "_64", _TYPE_<trustIdType>::cree_instance, 1, name2(_TYPE_, bases)<trustIdType> );
170#else
171# define info_obj_def_macro_inst(_NOM_, _TYPE_) \
172 template <> const Type_info _TYPE_<int>::info_obj(_NOM_, _TYPE_<int>::cree_instance, 1, name2(_TYPE_,bases)<int> );
173#endif
174
175#ifdef LATATOOLS
176#define Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)
177#else
178// The implemente are of course different:
179#define Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_) \
180 \
181 template <typename _T_> const Type_info* name2(_TYPE_,bases)[1] = { &(_BASE_::info_obj) }; \
182 \
183 info_obj_def_macro_inst(_NOM_, _TYPE_) \
184 \
185 template <typename _T_> int _TYPE_<_T_>::duplique() const \
186 { \
187 _TYPE_<_T_>* xxx = new _TYPE_<_T_>(*this); \
188 if(!xxx){Cerr << "Not enough memory " << finl; Process::exit();} \
189 return xxx->numero(); \
190 } \
191 template <typename _T_> _TYPE_<_T_>& _TYPE_<_T_>::self_cast( Objet_U& r) { \
192 return ref_cast_non_const(_TYPE_<_T_>,r); /* _non_const important otherwise recursion in ref_cast */ \
193 } \
194 template <typename _T_> const _TYPE_<_T_>& _TYPE_<_T_>::self_cast(const Objet_U& r) { \
195 return ref_cast_non_const(_TYPE_<_T_>,r); /* _non_const important otherwise recursion in ref_cast */ \
196 } \
197 template <typename _T_> Objet_U* _TYPE_<_T_>::cree_instance() \
198 { _TYPE_<_T_>* xxx = new _TYPE_<_T_>(); \
199 if(!xxx){Cerr << "Not enough memory " << finl; Process::exit();} \
200 return xxx ; \
201 } \
202 \
203 template <typename _T_> const Type_info* _TYPE_<_T_>::get_info() const { \
204 return &info_obj; \
205 } \
206 \
207 template <typename _T_> const Type_info* _TYPE_<_T_>::info() { \
208 return &info_obj; \
209 } \
210 \
211 template <typename _T_> unsigned _TYPE_<_T_>::taille_memoire() const { \
212 return sizeof(_TYPE_<_T_>); \
213 } \
214 class __dummy__
215
216#endif // LATATOOLS
217
218#define Implemente_instanciable_sans_constructeur_32_64(_TYPE_,_NOM_,_BASE_) \
219 template <typename _T_> _TYPE_<_T_>::~_TYPE_() { } \
220 Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)
221
222#define Implemente_instanciable_sans_destructeur_32_64(_TYPE_,_NOM_,_BASE_) \
223 template <typename _T_> _TYPE_<_T_>::_TYPE_() { } \
224 Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)
225
226#define Implemente_instanciable_32_64(_TYPE_,_NOM_,_BASE_) \
227 template <typename _T_> _TYPE_<_T_>::_TYPE_() { } \
228 template <typename _T_> _TYPE_<_T_>::~_TYPE_() { } \
229 Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)