FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTtheme.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Québec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifndef FMTtheme_H_INCLUDED
9#define FMTtheme_H_INCLUDED
10
11#include <boost/dynamic_bitset_fwd.hpp>
12#include <boost/serialization/serialization.hpp>
13#include <string>
14#include <vector>
15#include <map>
16#include <boost/serialization/nvp.hpp>
17#include <boost/serialization/map.hpp>
18#include <boost/serialization/export.hpp>
19#include <boost/serialization/string.hpp>
21#include "FMTobject.hpp"
22#include <unordered_map>
23
24#if defined FMTWITHR
25 #include <Rcpp.h>
26#endif
27
28namespace Parser
29{
30 class FMTlandscapeparser;
31}
32
33
34
35
36namespace Core
37{
38class FMTmask;
39class FMTmaskfilter;
40// DocString: FMTtheme
47 {
48 friend class FMTmask;
50 protected:
51 // DocString: FMTtheme::id
53 size_t id;
54 // DocString: FMTtheme::start
56 size_t start;
57 private:
58 // DocString: FMTtheme::serialize
62 friend class boost::serialization::access;
63 template<class Archive>
64 void serialize(Archive& ar, const unsigned int version)
65 {
66 try{
67 ar & boost::serialization::make_nvp("FMTobject", boost::serialization::base_object<FMTobject>(*this));
68 ar & BOOST_SERIALIZATION_NVP(id);
69 ar & BOOST_SERIALIZATION_NVP(start);
70 ar & BOOST_SERIALIZATION_NVP(attributes);
71 ar & BOOST_SERIALIZATION_NVP(attributenames);
72 ar & BOOST_SERIALIZATION_NVP(aggregates);
73 ar & BOOST_SERIALIZATION_NVP(aggregatenames);
74 ar & BOOST_SERIALIZATION_NVP(indexes);
75 ar & BOOST_SERIALIZATION_NVP(name);
76 buildattributelocations();
77 }catch (...)
78 {
79 _exhandler->printexceptions("", "FMTtheme::serialize", __LINE__, __FILE__);
80 }
81 }
82 // DocString: FMTtheme::attributes
84 std::vector<std::string>attributes;
85 // DocString: FMTtheme::attributenames
87 std::vector<std::string>attributenames;
88 // DocString: FMTtheme::aggregates
90 std::vector<std::string>aggregates;
91 // DocString: FMTtheme::aggregates
93 std::vector<std::vector<std::string>>aggregatenames;
94 // DocString: FMTtheme::indexes
96 std::vector<std::map<std::string, double>>indexes;
97 // DocString: FMTtheme::attribute_locations
99 std::unordered_map<std::string, std::vector<size_t>>attribute_locations;
100 // DocString: FMTtheme::lookiterator
102 typedef typename std::unordered_map<std::string, std::vector<size_t>>::const_iterator lookiterator;
103 // DocString: FMTtheme::name
105 std::string name;
106 // DocString: FMTtheme::strtobits
110 boost::dynamic_bitset<> strtobits(const std::string& value) const;
111 // DocString: FMTtheme::bitstostr
115 std::string bitstostr(const boost::dynamic_bitset<>& bits) const;
116 // DocString: FMTtheme::getattribute
120 lookiterator getattribute(const std::string& value, bool raiseifnotfound = false) const;
121 // DocString: FMTtheme::buildattributelocations
126 void buildattributelocations();
127 // DocString: FMTtheme::fillupaggregates
131 void fillupaggregates(std::vector<int>& themeids, std::vector<std::string>& locattributes, std::vector<std::string>& locaggregates) const;
132 // DocString: FMTtheme::push_aggregate
136 void push_aggregate(const std::string& aggregatename);
137 // DocString: FMTtheme::push_aggregate
141 void push_aggregate_value(const std::string& aggregatename, const std::string& value);
142 public:
143 // DocString: FMTtheme()
147 FMTtheme() = default;
148 // DocString: ~FMTtheme()
152 ~FMTtheme() = default;
153 // DocString: FMTtheme(const std::vector<std::string>&,const std::vector<std::string>&,const std::vector<std::vector<std::string>>,const std::vector<std::map<std::string, double>>&,const size_t&, const size_t&, const std::string&)
157 FMTtheme(const std::vector<std::string>& lattributes,
158 const std::vector<std::string>& lattributenames,
159 const std::vector<std::string>& laggregates,
160 const std::vector<std::vector<std::string>>& laggregatenames,
161 const std::vector<std::map<std::string, double>>& lindexes,
162 const size_t& lid, const size_t& lstart, const std::string& lname);
163 // DocString: FMTtheme(const std::vector<std::string>&,const std::vector<std::string>&,const std::vector<std::vector<std::string>>,const size_t&, const size_t&, const std::string&)
167 FMTtheme(const std::vector<std::string>& lattributes,
168 const std::vector<std::string>& lattributenames,
169 const std::vector<std::string>& laggregates,
170 const std::vector<std::vector<std::string>>& laggregatenames,
171 const size_t& lid, const size_t& lstart, const std::string& lname);
172 // DocString: FMTtheme(const std::vector<std::string>& lattributes,const size_t&,const size_t&,const std::string&)
176 FMTtheme(const std::vector<std::string>& lattributes,
177 const size_t& lid, const size_t& lstart, const std::string& lname);
178 // DocString: FMTtheme(const FMTtheme&)
182 FMTtheme(const FMTtheme& rhs);
183 // DocString: FMTtheme::operator=
187 FMTtheme& operator = (const FMTtheme& rhs);
188 // DocString: FMTtheme::isattribute
192 inline bool isattribute(const std::string& value) const
193 {
194 return (getattribute(value) != attribute_locations.end());
195 }
196 // DocString: FMTtheme::isaggregate
200 inline bool isaggregate(const std::string& value) const
201 {
202 return (std::find(aggregates.begin(),aggregates.end(),value)!= aggregates.end());
203 }
204 // DocString: FMTtheme::isindex
208 bool isindex(const std::string& attribute, const std::string& value) const;
209 // DocString: FMTtheme::isindex
213 bool isindex(const std::string& value) const;
214 // DocString: FMTtheme::useindex
218 bool useindex() const;
219 // DocString: FMTtheme::getindex
223 double getindex(const std::string& attribute,const std::string& value) const;
224 // DocString: FMTtheme::inaggregate
228 bool inaggregate(const std::string& value,const std::string& aggregate);
229 // DocString: FMTtheme::isvalid
233 bool isvalid(const std::string& value) const;
234 // DocString: FMTtheme::operator==
238 bool operator == (const FMTtheme& rhs) const;
239 // DocString: FMTtheme::size
243 inline size_t size() const
244 {
245 return attributes.size();
246 }
247 // DocString: FMTtheme::getstart
251 inline const size_t& getstart() const
252 {
253 return start;
254 }
255 // DocString: FMTtheme::getid
259 inline const size_t& getid() const
260 {
261 return id;
262 }
263 // DocString: FMTtheme::getname
267 inline std::string getname() const
268 {
269 return name;
270 }
271 // DocString: FMTtheme::empty
275 inline bool empty() const
276 {
277 return attributes.empty();
278 }
279 // DocString: FMTtheme::getattributes
284 std::vector<std::string>getattributes(const std::string& value, bool aggregate_source = false) const;
285 // DocString: FMTtheme::getbaseattributes
289 inline const std::vector<std::string>& getbaseattributes() const
290 {
291 return attributes;
292 }
293 // DocString: FMTtheme::getattributenames
297 const std::vector<std::string>& getattributenames() const
298 {
299 return attributenames;
300 }
301 // DocString: FMTtheme::presolve
307 FMTtheme presolve(FMTmaskfilter& maskfilter, size_t& newid, size_t& newstart) const;
308 // DocString: FMTtheme::updatefrommask
313 std::string updatefrommask(const Core::FMTmask& globalmask);
314 // DocString: FMTtheme::operator std::string
318 operator std::string() const;
319 #if defined FMTWITHR
320 // DocString: FMTtheme::getaggregatesdataframe
324 Rcpp::DataFrame getaggregatesasdataframe() const;
325 // DocString: FMTtheme::getattributesasdataframe
329 Rcpp::DataFrame getattributesasdataframe() const;
330 #endif
331 // DocString: FMTtheme::validate
337 static bool validate(const std::vector<Core::FMTtheme>& themes,
338 std::string& mask, std::string otherinformation = std::string());
339 // DocString: FMTobject::theme
344 static bool checkmask(const std::vector<Core::FMTtheme>& themes,
345 const std::vector<std::string>& values, std::string& mask,
346 const std::string& otherinformation);
347 // DocString: FMTobject::getaggregates
351 std::vector<std::string>getaggregates() const;
352 };
353
354 // DocString: FMTthemecomparator
359 {
360 // DocString: FMTthemecomparator::base_theme
362 FMTtheme base_theme;
363 // DocString: FMTthemecomparator::comparedwithpresolved
365 bool comparedwithpresolved;
366 public:
367 // DocString: FMTthemecomparator(const FMTtheme&,const bool&)
371 FMTthemecomparator(const FMTtheme& lbase_theme,const bool& lcomparedwithpresolved=false);
372 // DocString: FMTthemecomparatorr::operator()(const FMTtheme&)
376 bool operator()(const FMTtheme& theme) const;
377
378 };
379
380
381
382}
383
384BOOST_CLASS_EXPORT_KEY(Core::FMTtheme)
385
386#endif // FMTtheme_H_INCLUDED
#define FMTEXPORT
Definition: FMTutility.hpp:92
Definition: FMTmask.hpp:96
Definition: FMTmaskfilter.hpp:27
Definition: FMTobject.hpp:50
Definition: FMTtheme.hpp:47
static bool checkmask(const std::vector< Core::FMTtheme > &themes, const std::vector< std::string > &values, std::string &mask, const std::string &otherinformation)
bool isaggregate(const std::string &value) const
Definition: FMTtheme.hpp:200
size_t id
Id is the id of the theme first theme in the landscape section is number 1.
Definition: FMTtheme.hpp:53
FMTtheme(const std::vector< std::string > &lattributes, const std::vector< std::string > &lattributenames, const std::vector< std::string > &laggregates, const std::vector< std::vector< std::string > > &laggregatenames, const size_t &lid, const size_t &lstart, const std::string &lname)
static bool validate(const std::vector< Core::FMTtheme > &themes, std::string &mask, std::string otherinformation=std::string())
size_t size() const
Definition: FMTtheme.hpp:243
bool isindex(const std::string &attribute, const std::string &value) const
~FMTtheme()=default
const std::vector< std::string > & getbaseattributes() const
Definition: FMTtheme.hpp:289
double getindex(const std::string &attribute, const std::string &value) const
FMTtheme(const std::vector< std::string > &lattributes, const std::vector< std::string > &lattributenames, const std::vector< std::string > &laggregates, const std::vector< std::vector< std::string > > &laggregatenames, const std::vector< std::map< std::string, double > > &lindexes, const size_t &lid, const size_t &lstart, const std::string &lname)
bool useindex() const
FMTtheme(const FMTtheme &rhs)
std::string getname() const
Definition: FMTtheme.hpp:267
bool isvalid(const std::string &value) const
FMTtheme()=default
bool inaggregate(const std::string &value, const std::string &aggregate)
size_t start
Start is the bit location in the FMTmask at which the attributes of the theme starts.
Definition: FMTtheme.hpp:56
const size_t & getid() const
Definition: FMTtheme.hpp:259
std::vector< std::string > getattributes(const std::string &value, bool aggregate_source=false) const
const std::vector< std::string > & getattributenames() const
Definition: FMTtheme.hpp:297
FMTtheme(const std::vector< std::string > &lattributes, const size_t &lid, const size_t &lstart, const std::string &lname)
bool isattribute(const std::string &value) const
Definition: FMTtheme.hpp:192
std::string updatefrommask(const Core::FMTmask &globalmask)
bool empty() const
Definition: FMTtheme.hpp:275
const size_t & getstart() const
Definition: FMTtheme.hpp:251
std::vector< std::string > getaggregates() const
bool isindex(const std::string &value) const
FMTtheme presolve(FMTmaskfilter &maskfilter, size_t &newid, size_t &newstart) const
Definition: FMTtheme.hpp:359
bool operator()(const FMTtheme &theme) const
FMTthemecomparator(const FMTtheme &lbase_theme, const bool &lcomparedwithpresolved=false)
Definition: FMTlandscapeparser.hpp:36
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTaction.hpp:31
Namespace handling all FMT's parsers. Everything related to I/O should be located in this namespace.
Definition: FMTactionparser.hpp:26