LandscapeDNDC 1.37.0
Loading...
Searching...
No Matches
mbe_substate.h
1/*
2 * SPDX-FileCopyrightText: Karlsruhe Institute of Technology (KIT)
3 * SPDX-License-Identifier: LicenseRef-LandscapeDNDC
4 * This file is part of LandscapeDNDC. See LICENSE.
5 */
15
16#ifndef LDNDC_SUBSTATE_H_
17#define LDNDC_SUBSTATE_H_
18
19#include "ld_legacy.h"
20#include "state/mbe_substatetypes.h"
21
22#include <input/ecosystemtypes.h>
23#include <cbm_object.h>
24
25struct lreply_t;
26struct lrequest_t;
27
28#define __LDNDC_SUBSTATE_CLASS(__substate__) TOKENPASTE3(substate_,__substate__,_t)
29#define MOBILE_SUBSTATE_OBJECT(__type__,__flags__) \
30 LDNDC_OBJECT(__LDNDC_SUBSTATE_CLASS(__type__)) \
31 private: static char const * const ss_name; \
32 public: char const * name() const { return ss_name;} \
33 public: \
34 enum \
35 { \
36 substate_type = (__ldndc_substate_enum_##__type__) \
37 }; \
38 \
39 static lflags_t flags() \
40 { \
41 return (__flags__); \
42 } \
43 \
44 public: \
45 __LDNDC_SUBSTATE_CLASS(__type__)(); \
46 __LDNDC_SUBSTATE_CLASS(__type__)( \
47 lid_t const &, MoBiLE_PlantVegetation *); \
48 \
49 ~__LDNDC_SUBSTATE_CLASS(__type__)(); \
50 \
51 lerr_t initialize( \
52 cbm::io_kcomm_t *, \
53 void * = NULL); \
54 \
55 private: \
56 bool set_required_inputs_( \
57 cbm::io_kcomm_t *); \
58 bool has_required_inputs_( \
59 cbm::io_kcomm_t *) const; \
60 \
61 lerr_t resize_entities( \
62 cbm::io_kcomm_t *); \
63 \
64 /* hide these buggers for now */ \
65 __LDNDC_SUBSTATE_CLASS(__type__)( \
66 __LDNDC_SUBSTATE_CLASS(__type__) const &); \
67 __LDNDC_SUBSTATE_CLASS(__type__) & operator=( \
68 __LDNDC_SUBSTATE_CLASS(__type__) const &)/*;*/
69
70#define MOBILE_SUBSTATE_OBJECT_DEFN(__type__) \
71 LDNDC_OBJECT_DEFN(ldndc::__LDNDC_SUBSTATE_CLASS(__type__)) \
72 char const * const ldndc::__LDNDC_SUBSTATE_CLASS(__type__)::ss_name = \
73 SUBSTATE_NAMES[__ldndc_substate_enum_##__type__];
74
75
76namespace ldndc {
77struct substate_checkpoint_read_context_t;
78struct substate_checkpoint_write_context_t;
79enum
80{
83};
84
85/*
86 * Abstract base class for all simulation system state compartments
87 */
88class LDNDC_API MoBiLE_Substate : public cbm::object_t
89{
90 public:
91 MoBiLE_Substate();
92 MoBiLE_Substate( lid_t const &);
93 virtual ~MoBiLE_Substate() = 0;
94
95 virtual char const * name() const = 0;
96
106 virtual lerr_t initialize( cbm::io_kcomm_t *, void * = NULL) = 0;
107
112 virtual size_t member_cnt() const = 0;
113
121 virtual size_t alloc_size() const = 0;
122
127 virtual lerr_t resize_entities( cbm::io_kcomm_t *) = 0;
128
129
141 bool is_initialized() const
142 { return is_initialized_; }
143
144#ifdef _HAVE_SERIALIZE
145 virtual int create_checkpoint( substate_checkpoint_write_context_t *) = 0;
146 virtual int restore_checkpoint( substate_checkpoint_read_context_t *) = 0;
147#endif /* _HAVE_SERIALIZE */
148#ifdef _LDNDC_HAVE_ONLINECONTROL
149 virtual int process_request(
150 lreply_t * /*reply*/, lrequest_t const * /*request*/)
151 { return LDNDC_ERR_OK;}
152#endif /* _LDNDC_HAVE_ONLINECONTROL */
153
154 protected:
166 void set_initialized()
167 {
168 is_initialized_ = true;
169 }
170
171 /* hide copy construction and assignment operator */
172 MoBiLE_Substate( MoBiLE_Substate const &);
173
174 MoBiLE_Substate & operator=( MoBiLE_Substate const &);
175
176 public:
177 static cbm::string_t wr_type;
178 static cbm::string_t pt_type;
179
180 private:
181 bool is_initialized_;
182};
183
184
185class MoBiLE_PlantVegetation;
186struct LDNDC_API substate_factory_base_t
187{
188 char const * name()
189 const
190 {
191 return SUBSTATE_NAMES[substate_type()];
192 }
193
194
195 substate_factory_base_t() {}
196 virtual ~substate_factory_base_t() = 0;
197
198 virtual substate_type_e substate_type() const = 0;
199
200 virtual size_t memsize() const = 0;
201
202 virtual MoBiLE_Substate * construct(
203 lid_t const &, MoBiLE_PlantVegetation *) const = 0;
204 virtual void destruct(
205 MoBiLE_Substate *) const = 0;
206};
207
208
209template < class _S >
210struct substate_factory_t : substate_factory_base_t
211{
212 substate_factory_t()
213 : substate_factory_base_t()
214 { }
215
216 substate_type_e substate_type() const
217 { return (substate_type_e)_S::substate_type; }
218
219 size_t memsize() const
220 { return sizeof( _S); }
221
222 MoBiLE_Substate * construct(
223 lid_t const & _id, MoBiLE_PlantVegetation * _pv)
224 const
225 {
226// sk:off return static_cast< MoBiLE_Substate * >( _S::new_instance( _id, _pv));
227 return static_cast< MoBiLE_Substate * >( new _S( _id, _pv));
228 }
229
230 void destruct( MoBiLE_Substate * _s) const
231 {
232 if ( _s)
233 {
234// sk:off _s->delete_instance();
235 delete _s;
236 }
237 }
238};
239
240#define LDNDC_INAME(__iclass__) (ldndc::__iclass__::input_class_ ## __iclass__ ## _t::iclassname())
241
242} /*namespace ldndc*/
243
244#include <containers/cbm_vector.h>
245
246
247#endif /* !LDNDC_SUBSTATE_H_ */
248
Spatially explicit groundwater model.
Definition airchemistryput.h:21
@ LSUB_FLAG_NONE
Definition mbe_substate.h:82