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