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