LandscapeDNDC 1.37.0
mbe_substate.h
1
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
174 private:
175 bool is_initialized_;
176};
177
178
179class MoBiLE_PlantVegetation;
180struct LDNDC_API substate_factory_base_t
181{
182 char const * name()
183 const
184 {
185 return SUBSTATE_NAMES[substate_type()];
186 }
187
188
189 substate_factory_base_t() {}
190 virtual ~substate_factory_base_t() = 0;
191
192 virtual substate_type_e substate_type() const = 0;
193
194 virtual size_t memsize() const = 0;
195
196 virtual MoBiLE_Substate * construct(
197 lid_t const &, MoBiLE_PlantVegetation *) const = 0;
198 virtual void destruct(
199 MoBiLE_Substate *) const = 0;
200};
201
202
203template < class _S >
204struct substate_factory_t : substate_factory_base_t
205{
206 substate_factory_t()
207 : substate_factory_base_t()
208 { }
209
210 substate_type_e substate_type() const
211 { return (substate_type_e)_S::substate_type; }
212
213 size_t memsize() const
214 { return sizeof( _S); }
215
216 MoBiLE_Substate * construct(
217 lid_t const & _id, MoBiLE_PlantVegetation * _pv)
218 const
219 {
220// sk:off return static_cast< MoBiLE_Substate * >( _S::new_instance( _id, _pv));
221 return static_cast< MoBiLE_Substate * >( new _S( _id, _pv));
222 }
223
224 void destruct( MoBiLE_Substate * _s) const
225 {
226 if ( _s)
227 {
228// sk:off _s->delete_instance();
229 delete _s;
230 }
231 }
232};
233
234#define LDNDC_INAME(__iclass__) (ldndc::__iclass__::input_class_ ## __iclass__ ## _t::iclassname())
235
236} /*namespace ldndc*/
237
238#include <containers/cbm_vector.h>
239
240
241#endif /* !LDNDC_SUBSTATE_H_ */
242
Spatially explicit groundwater model.
Definition: airchemistryput.h:15
@ LSUB_FLAG_NONE
Definition: mbe_substate.h:77