TRUST 1.9.8
HPC thermohydraulic platform
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// les macros Declare_instanciable_sans_destructeur et
19// Implemente_instanciable_sans_destructeur
20// permettent de creer simplement des classes
21// de bases conforme a TRUST.
22
23// .SECTION Description du header
24// class A_base : public B {
25// Declare_instanciable_sans_destructeur(A_base);
26// };
27// .SECTION Description du source
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 /* methode rajoutee pour caster en 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 \
101 const Type_info* name2(_TYPE_,bases)[1]={ \
102 &(_BASE_::info_obj)}; \
103 const Type_info _TYPE_::info_obj(_NOM_, _TYPE_::cree_instance, 1, name2(_TYPE_,bases)); \
104 \
105 \
106 int _TYPE_::duplique() const \
107 { \
108 _TYPE_* xxx = new _TYPE_(*this); \
109 if(!xxx){Cerr << "Not enough memory " << finl; Process::exit();} \
110 return xxx->numero(); \
111 } \
112 _TYPE_& _TYPE_::self_cast( Objet_U& r) { \
113 return ref_cast_non_const(_TYPE_,r); /* _non_const important sinon recursion dans ref_cast */ \
114 } \
115 const _TYPE_& _TYPE_::self_cast(const Objet_U& r) { \
116 return ref_cast_non_const(_TYPE_,r); /* _non_const important sinon recursion dans ref_cast */ \
117 } \
118 Objet_U* _TYPE_::cree_instance() \
119 { _TYPE_* xxx = new _TYPE_(); \
120 if(!xxx){Cerr << "Not enough memory " << finl; Process::exit();} \
121 return xxx ; \
122 } \
123 \
124 const Type_info* _TYPE_::get_info() const { \
125 return &info_obj; \
126 } \
127 \
128 const Type_info* _TYPE_::info() { \
129 return &info_obj; \
130 } \
131 \
132 unsigned _TYPE_::taille_memoire() const { \
133 return sizeof(_TYPE_); \
134 } \
135 class __dummy__
136#endif
137
138#define Implemente_instanciable_sans_constructeur(_TYPE_,_NOM_,_BASE_) \
139 _TYPE_::~_TYPE_() { } \
140 Implemente_instanciable_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
141
142#define Implemente_instanciable_sans_destructeur(_TYPE_,_NOM_,_BASE_) \
143 _TYPE_::_TYPE_() { } \
144 Implemente_instanciable_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
145
146#define Implemente_instanciable(_TYPE_,_NOM_,_BASE_) \
147 _TYPE_::_TYPE_() { } \
148 _TYPE_::~_TYPE_() { } \
149 Implemente_instanciable_sans_constructeur_ni_destructeur(_TYPE_,_NOM_,_BASE_)
150
151
152/////////////////////////////////////////
153/////// TEMPLATE VERSION for 32/64 bits !!! Oh yes baby!
154/////////////////////////////////////////
155
156// The declare remain identical but we create a new macro so that bin/KSH/mk_Instanciable spots it correctly:
157#define Declare_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_) Declare_instanciable_sans_constructeur_ni_destructeur(_TYPE_)
158#define Declare_instanciable_sans_constructeur_32_64(_TYPE_) Declare_instanciable_sans_constructeur(_TYPE_)
159#define Declare_instanciable_sans_destructeur_32_64(_TYPE_) Declare_instanciable_sans_destructeur(_TYPE_)
160#define Declare_instanciable_32_64(_TYPE_) Declare_instanciable(_TYPE_)
161#define Declare_instanciable_sans_readon_32_64(_TYPE_) Declare_instanciable_sans_readon(_TYPE_)
162#define Declare_instanciable_with_param_32_64(_TYPE_) Declare_instanciable_with_param(_TYPE_)
163
164// Helper macro for info_obj static variable definition:
165#if INT_is_64_ == 2
166# define info_obj_def_macro_inst(_NOM_, _TYPE_) \
167 template <> const Type_info _TYPE_<int>::info_obj(_NOM_, _TYPE_<int>::cree_instance, 1, name2(_TYPE_,bases)<int> ); \
168 template <> const Type_info _TYPE_<trustIdType>::info_obj(_NOM_ "_64", _TYPE_<trustIdType>::cree_instance, 1, name2(_TYPE_, bases)<trustIdType> );
169#else
170# define info_obj_def_macro_inst(_NOM_, _TYPE_) \
171 template <> const Type_info _TYPE_<int>::info_obj(_NOM_, _TYPE_<int>::cree_instance, 1, name2(_TYPE_,bases)<int> );
172#endif
173
174#ifdef LATATOOLS
175#define Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)
176#else
177// The implemente are of course different:
178#define Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_) \
179 \
180 template <typename _T_> const Type_info* name2(_TYPE_,bases)[1] = { &(_BASE_::info_obj) }; \
181 \
182 info_obj_def_macro_inst(_NOM_, _TYPE_) \
183 \
184 template <typename _T_> int _TYPE_<_T_>::duplique() const \
185 { \
186 _TYPE_<_T_>* xxx = new _TYPE_<_T_>(*this); \
187 if(!xxx){Cerr << "Not enough memory " << finl; Process::exit();} \
188 return xxx->numero(); \
189 } \
190 template <typename _T_> _TYPE_<_T_>& _TYPE_<_T_>::self_cast( Objet_U& r) { \
191 return ref_cast_non_const(_TYPE_<_T_>,r); /* _non_const important sinon recursion dans ref_cast */ \
192 } \
193 template <typename _T_> const _TYPE_<_T_>& _TYPE_<_T_>::self_cast(const Objet_U& r) { \
194 return ref_cast_non_const(_TYPE_<_T_>,r); /* _non_const important sinon recursion dans ref_cast */ \
195 } \
196 template <typename _T_> Objet_U* _TYPE_<_T_>::cree_instance() \
197 { _TYPE_<_T_>* xxx = new _TYPE_<_T_>(); \
198 if(!xxx){Cerr << "Not enough memory " << finl; Process::exit();} \
199 return xxx ; \
200 } \
201 \
202 template <typename _T_> const Type_info* _TYPE_<_T_>::get_info() const { \
203 return &info_obj; \
204 } \
205 \
206 template <typename _T_> const Type_info* _TYPE_<_T_>::info() { \
207 return &info_obj; \
208 } \
209 \
210 template <typename _T_> unsigned _TYPE_<_T_>::taille_memoire() const { \
211 return sizeof(_TYPE_<_T_>); \
212 } \
213 class __dummy__
214
215#endif // LATATOOLS
216
217#define Implemente_instanciable_sans_constructeur_32_64(_TYPE_,_NOM_,_BASE_) \
218 template <typename _T_> _TYPE_<_T_>::~_TYPE_() { } \
219 Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)
220
221#define Implemente_instanciable_sans_destructeur_32_64(_TYPE_,_NOM_,_BASE_) \
222 template <typename _T_> _TYPE_<_T_>::_TYPE_() { } \
223 Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)
224
225#define Implemente_instanciable_32_64(_TYPE_,_NOM_,_BASE_) \
226 template <typename _T_> _TYPE_<_T_>::_TYPE_() { } \
227 template <typename _T_> _TYPE_<_T_>::~_TYPE_() { } \
228 Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(_TYPE_,_NOM_,_BASE_)