LandscapeDNDC 1.37.0
Loading...
Searching...
No Matches
eventbase.h
1/*
2 * SPDX-FileCopyrightText: Karlsruhe Institute of Technology (KIT)
3 * SPDX-License-Identifier: LicenseRef-Crabmeat
4 * This file is part of Crabmeat. Redistribution or commercial use is
5 * prohibited without express written permission. See LICENCE.
6 */
7
18
19#ifndef LDNDC_INPUT_EVENTBASE_H_
20#define LDNDC_INPUT_EVENTBASE_H_
21
22#include "crabmeat-common.h"
23
24#include "string/cbm_string.h"
25#include "utils/cbm_utils.h"
26#include "memory/cbm_mem.h"
27
28namespace ldndc{ namespace event{
29#include "event.h.inc"
30
31struct event_attribute_t
32{
33 virtual ~event_attribute_t() = 0;
34};
35
91struct CBM_API event_trigger_t
92{
94
96 std::string species;
98 double dvs_min;
100 double dvs_max;
104 std::string water_management;
106 double agb_cut;
113 double stand_volume_min;
114 double top_height_min;
115 double dbh_min;
117 int forest_threshold_count() const;
121
122 bool have_trigger() const;
124 lerr_t check( char const * /*event name*/) const;
126 void drop();
127};
128
129#define LMANA_EVENT_TYPE(__ev_class__,__ev_attr_t__,__ev_type__) \
130 public: \
131 typedef __ev_attr_t__ attributes_type; \
132 enum \
133 { \
134 event_type_ = __ev_type__ \
135 }; \
136 event_type_e event_type() \
137 const \
138 { \
139 return static_cast< event_type_e >( event_type_); \
140 } \
141 char const * name() const \
142 { return EVENT_NAMES[event_type_]; } \
143 std::string to_string() const; \
144 public: \
145 __ev_class__( \
146 lid_t const & _id, __ev_attr_t__ const * _attribs) \
147 : Event( _id), attribs_( _attribs) { } \
148 ~__ev_class__() \
149 { \
150 if ( attribs_) \
151 { \
152 CBM_DefaultAllocator->destroy( attribs_); \
153 } \
154 } \
155 private: \
156 __ev_attr_t__ const * attribs_; \
157 /* hide copy constructor and assignment operator */ \
158 __ev_class__( __ev_class__ const &); \
159 __ev_class__ & operator=( __ev_class__ const &);
160
161
162#define EVENT_COMMON_DECL(__ev_name__) \
163 LMANA_EVENT_TYPE(__event_class_name(__ev_name__),__event_attrib_class_name(__ev_name__),TOKENPASTE(__EVENT_ENUM_,__ev_name__))
164
165#define LEVENT_WRITE_ATTRIB_TXT_(__ss__,__key__,__value_prefix__,__value__) \
166 /*if ( cbm::is_valid( __value__))*/ \
167 { \
168 __ss__ << ((cbm::is_empty( (__ss__).str())) ? "" : "; ") \
169 << __key__ \
170 << " = " \
171 << "\"" << __value_prefix__ << __value__ << "\""; \
172 } \
173 CRABMEAT_FIX_UNUSED(__ss__)/*;*/
174
175#define LEVENT_WRITE_ATTRIB_TXT(__ss__,__key__,__value__) \
176 LEVENT_WRITE_ATTRIB_TXT_(__ss__,__key__,"",this->attribs_->__value__)
177#define LEVENT_WRITE_ATTRIB_PREFIX_TXT(__ss__,__key__,__value_prefix__,__value__) \
178 LEVENT_WRITE_ATTRIB_TXT_(__ss__,__key__,__value_prefix__,this->attribs_->__value__)
179
180/* ldndc event base class */
181class CBM_API Event
182{
183 public:
184 enum lmana_flag_e
185 {
186 EVFLAG_NONE = 0u,
187 EVFLAG_ = 1u << 0
188 };
189 public:
190 virtual event_type_e event_type() const = 0;
191 virtual char const * name() const = 0;
192
193 public:
194 Event( lid_t const &);
195 virtual ~Event() = 0;
196
197 lid_t const & id()
198 const { return m_id; }
199
200 virtual std::string to_string() const = 0;
201
202 private:
203 lid_t m_id;
204
205 Event( Event const &);
206 Event & operator=( Event const &);
207};
208
209#define __event_class_name(__event_name__) TOKENPASTE(Event__,__event_name__)
210#define __event_attrib_class_name(__event_name__) TOKENPASTE3(event_,__event_name__,_attribute_t)
211
212
213#define EVENT_FACTORY_DECL(__event_name__) \
214 /* factory */ \
215 extern event_factory_t< __event_class_name(__event_name__), __event_attrib_class_name(__event_name__) > const TOKENPASTE(event_factory_,__event_name__);\
216 /* default attributes */ \
217 extern __event_attrib_class_name(__event_name__) const TOKENPASTE(event_attribute_default_,__event_name__);
218
219#define EVENT_FACTORY_DEFN(__event_name__) \
220 /* factory */ \
221 event_factory_t< __event_class_name(__event_name__), __event_attrib_class_name(__event_name__) > const TOKENPASTE(event_factory_,__event_name__);\
222 /* default attributes */ \
223 __event_attrib_class_name(__event_name__) const TOKENPASTE(event_attribute_default_,__event_name__);
224
225#include "eventbase.h.inc"
226
227}}
228
229#endif /* !LDNDC_INPUT_EVENTBASE_H_ */
230
Spatially explicit groundwater model.
Definition airchemistryput.h:21
int forest_threshold_count() const
Number of given forest thresholds (thin, harvest, regrow)
Definition eventbase.cpp:86
lerr_t check(char const *) const
Checks consistency of given thresholds, logs all problems.
Definition eventbase.cpp:103
double dvs_min
Definition eventbase.h:98
std::string water_management
Definition eventbase.h:104
bool have_trigger() const
True if any threshold condition is given.
Definition eventbase.cpp:68
event_trigger_t()
Thresholds triggering windowed events: no condition given.
Definition eventbase.cpp:45
double basal_area_min
Definition eventbase.h:112
double agb_cut
Definition eventbase.h:106
double fraction_field_capacity
Definition eventbase.h:102
bool dropped
Definition eventbase.h:120
std::string species
Definition eventbase.h:96
double dvs_max
Definition eventbase.h:100
void drop()
Removes all thresholds and marks them as dropped (invalid input)
Definition eventbase.cpp:179