LandscapeDNDC 1.37.0
Loading...
Searching...
No Matches
speciesgroups.h
1
9
10#ifndef LDNDC_INPUT_SPECIESGROUPS_H_
11#define LDNDC_INPUT_SPECIESGROUPS_H_
12
13#include "crabmeat-common.h"
14
15
16namespace ldndc{ namespace species
17{
25enum species_group_e
26{
28 SPECIES_GROUP_NONE,
30 SPECIES_GROUP_ANY,
31
33 SPECIES_GROUP_CROP,
35 SPECIES_GROUP_GRASS,
36 //SPECIES_GROUP_HERB,
37 //SPECIES_GROUP_SHRUB,
39 SPECIES_GROUP_WOOD,
40
42 SPECIES_GROUP_CNT
43};
44extern CBM_API char const * SPECIES_GROUP_NAMES[SPECIES_GROUP_CNT];
45extern CBM_API char const * internal_SPECIES_GROUP_ANY;
46
55extern CBM_API char const * SPECIES_NAME_NONE;
56
61template < species_group_e _G >
63{
64 enum
65 {
66 select = 1 << _G,
67 deselect = ~select
68 };
69
70 static int fselect( species_group_e _g)
71 {
72 return 1 << _g;
73 }
74};
75
76template < species_group_e _g >
77struct CBM_API species_group_t
78{
79 enum
80 {
81 group_id = _g
82 };
83 static species_group_e group() { return _g; }
84 static char const * name() { return SPECIES_GROUP_NAMES[_g]; }
85};
86struct CBM_API none : public species_group_t< SPECIES_GROUP_NONE >
87{
88 enum
89 {
90 select = select_species_t< SPECIES_GROUP_NONE >::select,
91 deselect = ~0
92 };
93};
94struct CBM_API any : public species_group_t< SPECIES_GROUP_ANY >
95{
96 enum
97 {
98 select = select_species_t< SPECIES_GROUP_CROP >::select|select_species_t< SPECIES_GROUP_GRASS >::select|select_species_t< SPECIES_GROUP_WOOD >::select,
99 deselect = ~0
100 };
101};
102typedef any no_none;
103typedef none no_any;
104struct CBM_API crop : public species_group_t< SPECIES_GROUP_CROP >
105{
106 enum
107 {
108 select = select_species_t< SPECIES_GROUP_CROP >::select,
109 deselect = ~0
110 };
111};
112struct CBM_API no_crop : public species_group_t< SPECIES_GROUP_NONE >
113{
114 enum
115 {
116 select = 0,
117 deselect = select_species_t< SPECIES_GROUP_CROP >::deselect
118 };
119};
120struct CBM_API grass : public species_group_t< SPECIES_GROUP_GRASS >
121{
122 enum
123 {
124 select = select_species_t< SPECIES_GROUP_GRASS >::select,
125 deselect = ~0
126 };
127};
128struct CBM_API no_grass : public species_group_t< SPECIES_GROUP_NONE >
129{
130 enum
131 {
132 select = 0,
133 deselect = select_species_t< SPECIES_GROUP_GRASS >::deselect
134 };
135};
136struct CBM_API wood : public species_group_t< SPECIES_GROUP_WOOD >
137{
138 enum
139 {
140 select = select_species_t< SPECIES_GROUP_WOOD >::select,
141 deselect = ~0
142 };
143};
144struct CBM_API no_wood : public species_group_t< SPECIES_GROUP_NONE >
145{
146 enum
147 {
148 select = 0,
149 deselect = select_species_t< SPECIES_GROUP_WOOD >::deselect
150 };
151};
152
153
154
155template < species_group_e _G >
156struct species_group_from_enum_t
157{
158};
159template < >
160struct species_group_from_enum_t< SPECIES_GROUP_NONE >
161{
162 typedef none group;
163};
164template < >
165struct species_group_from_enum_t< SPECIES_GROUP_ANY >
166{
167 typedef any group;
168};
169template < >
170struct species_group_from_enum_t< SPECIES_GROUP_CROP >
171{
172 typedef crop group;
173};
174template < >
175struct species_group_from_enum_t< SPECIES_GROUP_GRASS >
176{
177 typedef grass group;
178};
179template < >
180struct species_group_from_enum_t< SPECIES_GROUP_WOOD >
181{
182 typedef wood group;
183};
184
185struct species_groups_selector_t
186{
187 virtual ~species_groups_selector_t() {}
188 virtual bool is_selected( species_group_e) const = 0;
189};
190template < typename _G1 = species::any, typename _G2 = species::none, typename _G3 = species::none,
191 typename _G4 = species::none, typename _G5 = species::none, typename _G6 = species::none, typename _G7 = species::none >
192struct species_groups_select_t : public species_groups_selector_t
193{
194 enum
195 {
196 select = (_G1::select|_G2::select|_G3::select|_G4::select|_G5::select|_G6::select|_G7::select) &
197 (_G1::deselect&_G2::deselect&_G3::deselect&_G4::deselect&_G5::deselect&_G6::deselect&_G7::deselect)
198 };
199 bool is_selected( species_group_e _group) const
200 {
201 return ( _group==SPECIES_GROUP_ANY && int(this->select)!=int(species::none::select)) ||
202 ( this->select & select_species_t< SPECIES_GROUP_ANY >::fselect( _group));
203 }
204};
205
206
207} /* namespace species */
208} /* namespace ldndc */
209
210
211#endif /* !LDNDC_INPUT_SPECIESGROUPS_H_ */
212
Spatially explicit groundwater model.
Definition airchemistryput.h:15
make species group number a bit mask for or'ing
Definition speciesgroups.h:63