8#ifndef FMTtheme_Hm_included
9#define FMTtheme_Hm_included
11#include <boost/dynamic_bitset_fwd.hpp>
12#include <boost/serialization/serialization.hpp>
16#include <boost/serialization/nvp.hpp>
17#include <boost/serialization/map.hpp>
18#include <boost/serialization/vector.hpp>
19#include <boost/serialization/export.hpp>
20#include <boost/serialization/string.hpp>
23#include <unordered_map>
31 class FMTLandscapeParser;
73 FMTTheme(
const std::vector<std::string>& p_attributes,
74 const std::vector<std::string>& p_attributenames,
75 const std::vector<std::string>& p_aggregates,
76 const std::vector<std::vector<std::string>>& p_aggregatenames,
77 const std::vector<std::map<std::string, double>>& p_indexes,
78 const size_t& p_id,
const size_t& p_start,
const std::string& p_name);
90 FMTTheme(
const std::vector<std::string>& p_attributes,
91 const std::vector<std::string>& p_attributenames,
92 const std::vector<std::string>& p_aggregates,
93 const std::vector<std::vector<std::string>>& p_aggregatenames,
94 const size_t& p_id,
const size_t& p_start,
const std::string& p_name);
103 FMTTheme(
const std::vector<std::string>& p_attributes,
104 const size_t& p_id,
const size_t& p_start,
const std::string& p_name);
126 if (!p_value.empty() && p_value.at(0) ==
'!')
128 return (_getAttribute(p_value.substr(1, p_value.size())) != m_attributem_locations.end());
130 return (_getAttribute(p_value) != m_attributem_locations.end());
142 if (!p_value.empty() && p_value.at(0) ==
'!')
144 return (std::find(m_aggregates.begin(), m_aggregates.end(), p_value.substr(1, p_value.size())) !=
147 return (std::find(m_aggregates.begin(), m_aggregates.end(), p_value) != m_aggregates.end());
158 bool isIndex(
const std::string& p_attribute,
const std::string& p_value)
const;
165 bool isIndex(
const std::string& p_value)
const;
179 double getIndex(
const std::string& p_attribute,
const std::string& p_value)
const;
187 bool inAggregate(
const std::string& p_value,
const std::string& p_aggregate);
194 bool isValid(
const std::string& p_value)
const;
209 return m_attributes.size();
245 return m_attributes.empty();
254 std::vector<std::string>
getAttributes(
const std::string& p_value,
bool p_aggregate_source =
false)
const;
271 return m_attributenames;
294 operator std::string()
const;
301 Rcpp::DataFrame getAggregatesAsDataFrame()
const;
307 Rcpp::DataFrame getAttributesAsDataFrame()
const;
317 static bool validate(
const std::vector<Core::FMTTheme>& p_themes,
318 std::string& p_mask, std::string p_otherinformation = std::string());
328 static bool checkMask(
const std::vector<Core::FMTTheme>& p_themes,
329 const std::vector<std::string>& p_values, std::string& p_mask,
330 const std::string& p_otherinformation);
352 friend class boost::serialization::access;
353 template<
class Archive>
354 void serialize(Archive& ar,
const unsigned int version)
357 ar & boost::serialization::make_nvp(
"FMTobject", boost::serialization::base_object<FMTObject>(*
this));
358 ar & BOOST_SERIALIZATION_NVP(m_id);
359 ar & BOOST_SERIALIZATION_NVP(m_start);
360 ar & BOOST_SERIALIZATION_NVP(m_attributes);
361 ar & BOOST_SERIALIZATION_NVP(m_attributenames);
362 ar & BOOST_SERIALIZATION_NVP(m_aggregates);
363 ar & BOOST_SERIALIZATION_NVP(m_aggregatenames);
364 ar & BOOST_SERIALIZATION_NVP(m_indexes);
365 ar & BOOST_SERIALIZATION_NVP(m_name);
366 _buildAttributeLocations();
369 _exhandler->printExceptions(
"",
"FMTTheme::serialize", __LINE__, __FILE__);
374 std::vector<std::string>m_attributes;
377 std::vector<std::string>m_attributenames;
380 std::vector<std::string>m_aggregates;
383 std::vector<std::vector<std::string>>m_aggregatenames;
386 std::vector<std::map<std::string, double>>m_indexes;
389 std::unordered_map<std::string, std::vector<size_t>>m_attributem_locations;
392 typedef typename std::unordered_map<std::string, std::vector<size_t>>::const_iterator lookiterator;
402 boost::dynamic_bitset<uint8_t> _strToBits(
const std::string& p_value)
const;
439 const boost::dynamic_bitset<uint8_t>& p_bits)
const;
448 const boost::dynamic_bitset<uint8_t>& p_bits)
const;
462 const std::string& _getAttribute(
size_t p_attributeId)
const;
470 lookiterator _getAttribute(
const std::string& p_value,
bool p_raiseifnotfound =
false)
const;
475 void _buildAttributeLocations();
483 void _fillupAggregates(std::vector<int>& p_themeids, std::vector<std::string>& p_locattributes, std::vector<std::string>& p_locaggregates)
const;
489 void _pushAggregate(
const std::string& p_aggregatename);
496 void _pushAggregateValue(
const std::string& p_aggregatename,
const std::string& p_value);
528 bool m_comparedwithpresolved;
#define FMTEXPORT
Definition: FMTutility.h:125
Filter built from masks used to preSolve and postsolve FMTMask objects.
Definition: FMTMaskFilter.h:31
Core class holding, as a boost dynamic bitset, which theme attributes are part of a mask.
Definition: FMTMask.h:96
Base class of multiple FMT classes holding a shared exception handler pointer and logger.
Definition: FMTObject.h:49
Comparator used to check if two themes are the same.
Definition: FMTTheme.h:506
FMTThemeComparator(const FMTTheme &p_lbase_theme, const bool &p_lcomparedwithpresolved=false)
Construct the comparator from the theme to match.
bool operator()(const FMTTheme &p_theme) const
Matching test operator for the comparator.
Class holding the attributes and aggregates of a single theme, describing a part of a FMTMask.
Definition: FMTTheme.h:47
FMTTheme(const std::vector< std::string > &p_attributes, const std::vector< std::string > &p_attributenames, const std::vector< std::string > &p_aggregates, const std::vector< std::vector< std::string > > &p_aggregatenames, const std::vector< std::map< std::string, double > > &p_indexes, const size_t &p_id, const size_t &p_start, const std::string &p_name)
Constructor used for theme indexing with indexes.
FMTTheme(const std::vector< std::string > &p_attributes, const size_t &p_id, const size_t &p_start, const std::string &p_name)
Simpler constructor for a theme without aggregates or indexing.
const std::vector< std::string > & getAttributeNames() const
Return the names of the attributes.
Definition: FMTTheme.h:269
const std::vector< std::string > & getBaseAttributes() const
Return a reference to the base attributes of the theme.
Definition: FMTTheme.h:260
const size_t & getStart() const
Return the bit location of the mask at which the theme starts.
Definition: FMTTheme.h:216
size_t m_start
Start is the bit location in the FMTMask at which the attributes of the theme starts.
Definition: FMTTheme.h:343
std::string updateFromMask(const Core::FMTMask &p_globalmask)
Update the theme with the aggregates in a global mask or with newly created aggregates and return the...
bool inAggregate(const std::string &p_value, const std::string &p_aggregate)
Check if a value is part of an aggregate.
static bool validate(const std::vector< Core::FMTTheme > &p_themes, std::string &p_mask, std::string p_otherinformation=std::string())
Validate the construction of a valid mask string based on the themes, trimming the mask if there are ...
FMTTheme preSolve(FMTMaskFilter &p_maskfilter, size_t &p_newid, size_t &p_newstart) const
Presolve the theme, removing unused attributes based on the filter and assigning a new id and start.
bool isIndex(const std::string &p_value) const
Return true if the value is an index of the theme (yields section only).
size_t m_id
Id is the id of the theme first theme in the landscape section is number 1.
Definition: FMTTheme.h:340
bool isAggregate(const std::string &p_value) const
Return true if the value is an aggregate of the theme.
Definition: FMTTheme.h:140
bool isValid(const std::string &p_value) const
Check if a value is a valid attribute, aggregate or question mark for the theme.
bool useIndex() const
Return true if the theme uses indexes.
std::vector< std::string > getAttributes(const std::string &p_value, bool p_aggregate_source=false) const
Get the attributes of an aggregate for the theme.
size_t size() const
Return the size of the theme, 0 if it has no attribute.
Definition: FMTTheme.h:207
bool empty() const
Return true if the theme has no attribute.
Definition: FMTTheme.h:243
static bool checkMask(const std::vector< Core::FMTTheme > &p_themes, const std::vector< std::string > &p_values, std::string &p_mask, const std::string &p_otherinformation)
Validate the mask string for a vector of themes and throw an exception if something is wrong,...
~FMTTheme()=default
Default destructor for FMTTheme.
FMTTheme(const std::vector< std::string > &p_attributes, const std::vector< std::string > &p_attributenames, const std::vector< std::string > &p_aggregates, const std::vector< std::vector< std::string > > &p_aggregatenames, const size_t &p_id, const size_t &p_start, const std::string &p_name)
Constructor used for theme indexing.
bool isAttribute(const std::string &p_value) const
Return true if the value is an attribute of the theme.
Definition: FMTTheme.h:124
double getIndex(const std::string &p_attribute, const std::string &p_value) const
Get the index value for a given attribute and index.
FMTTheme(const FMTTheme &rhs)
Copy constructor for FMTTheme.
FMTTheme()
Default constructor for FMTTheme.
std::vector< std::string > getAggregates() const
Return the aggregates of the theme.
std::string getName() const
Return the name of the theme.
Definition: FMTTheme.h:234
bool isIndex(const std::string &p_attribute, const std::string &p_value) const
Return true if the value is an index of the theme for a given attribute (yields section only).
const size_t & getId() const
Return the id of the theme.
Definition: FMTTheme.h:225
Parser reading and writing the landscape section, and generating themes from vector or raster files.
Definition: FMTLandscapeParser.h:34
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
Namespace handling all FMT's parsers. Everything related to I/O should be located in this namespace.
Definition: FMTActionParser.h:27