8#ifndef FMTMASK_Hm_included
9#define FMTMASK_Hm_included
11#ifndef BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
12#define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
15#include <boost/dynamic_bitset.hpp>
16#include <boost/unordered_map.hpp>
17#include <boost/algorithm/string.hpp>
18#include <boost/algorithm/string/join.hpp>
19#include <boost/functional/hash.hpp>
20#include <boost/serialization/serialization.hpp>
21#include <boost/serialization/split_free.hpp>
22#include <boost/serialization/nvp.hpp>
23#include <boost/serialization/export.hpp>
24#include <boost/serialization/string.hpp>
25#include <boost/functional/hash.hpp>
26#include <boost/serialization/vector.hpp>
27#include <boost/dynamic_bitset/serialization.hpp>
35#if (BOOST_VERSION / 100 % 1000) < 71
40 namespace serialization {
42 template <
typename Ar,
typename Block,
typename Alloc>
43 void save(Ar& ar, dynamic_bitset<Block, Alloc>
const& bs,
unsigned) {
44 size_t num_bits = bs.size();
45 std::vector<Block> blocks(bs.num_blocks());
46 to_block_range(bs, blocks.begin());
48 ar& BOOST_SERIALIZATION_NVP(num_bits);
49 ar& BOOST_SERIALIZATION_NVP(blocks);
52 template <
typename Ar,
typename Block,
typename Alloc>
53 void load(Ar& ar, dynamic_bitset<Block, Alloc>& bs,
unsigned) {
55 std::vector<Block> blocks;
56 ar& BOOST_SERIALIZATION_NVP(num_bits);
57 ar& BOOST_SERIALIZATION_NVP(blocks);
60 from_block_range(blocks.begin(), blocks.end(), bs);
64 template <
typename Ar,
typename Block,
typename Alloc>
65 void serialize(Ar& ar, dynamic_bitset<Block, Alloc>& bs,
unsigned version) {
66 split_free(ar, bs, version);
75 template <
typename Block,
typename Alloc>
76 std::size_t
hash_value(
const boost::dynamic_bitset<Block, Alloc>& bs)
79 boost::hash_combine(hash, bs.m_bits);
139 FMTMask(
const boost::dynamic_bitset<uint8_t>& bits);
145 explicit operator bool()
const;
152 FMTMask(
const std::string& mask,
const boost::dynamic_bitset<uint8_t>& bits);
159 FMTMask(
const std::string& mask,
const std::vector<FMTTheme>& themes);
166 FMTMask(
const std::vector<std::string>& values,
const std::vector<FMTTheme>& themes);
196 std::string
get(
const std::vector<FMTTheme>& themes)
const;
224 void set(
const std::vector<FMTTheme>& themes,
const std::string& value);
259 std::vector<const Core::FMTTheme*>
getStaticThemes(
const std::vector<const Core::FMTTheme*>& themes)
const;
266 std::vector<const Core::FMTTheme*>
getSelectedThemes(
const std::vector<Core::FMTTheme>& themes)
const;
302 void update(
const std::vector<FMTTheme>& themes);
315 void append(
const boost::dynamic_bitset<uint8_t> &bits);
323 template <
class typetobinarize>
326 size_t location = m_data.size();
327 m_data.resize(m_data.size() + (
sizeof(typetobinarize) * 8));
328 const char* charelements =
reinterpret_cast<const char*
>(&element);
329 for (
size_t charit = 0; charit <
sizeof(typetobinarize); ++charit)
331 const char value = charelements[charit];
332 for (
int i = 7; i >= 0; --i)
334 m_data[location] = ((value & (1 << i)));
421 return boost::hash<boost::dynamic_bitset<uint8_t>>()(m_data);
434 inline operator std::string()
const
527 friend class boost::serialization::access;
528 template<
class Archive>
529 void serialize(Archive& ar,
const unsigned int version)
531 ar& boost::serialization::make_nvp(
"data", m_data);
532 ar& boost::serialization::make_nvp(
"name", m_name);
540 boost::dynamic_bitset<uint8_t> _subset(
const FMTTheme& theme)
const;
547 bool operator [](
int i)
const;
555 bool _anyIntersect(
const FMTMask& p_MASK,
const FMTTheme& p_THEME)
const;
562 size_t _countTheme(
const FMTTheme& p_Theme)
const;
570 boost::dynamic_bitset<uint8_t> _getPreSolveMask(
const FMTMaskFilter& p_filter,
571 const std::vector<FMTTheme>& p_presolvedThemes)
const;
578 void _setSubset(
const FMTTheme& theme,
const boost::dynamic_bitset<uint8_t>& subset);
584 boost::dynamic_bitset<uint8_t> m_data;
588template<>
inline void FMTMask::binarizedAppend<std::string>(
const std::string& element)
590 size_t location = m_data.size();
591 m_data.resize(m_data.size() + (element.size() * 8));
592 const char* charelements = element.c_str();
593 for (
size_t charit = 0; charit < element.size(); ++charit)
595 const char value = charelements[charit];
596 for (
int i = 7; i >= 0; --i)
598 m_data[location] = ((value & (1 << i)));
604template<>
inline void FMTMask::binarizedAppend<double>(
const double& element)
606 size_t location = m_data.size();
608 m_data.resize(m_data.size() + (
sizeof(int) * 8));
609 const char* charelements =
reinterpret_cast<const char*
>(&corrected);
610 for (
size_t charit = 0; charit <
sizeof(int); ++charit)
612 const char value = charelements[charit];
613 for (
int i = 7; i >= 0; --i)
615 m_data[location] = ((value & (1 << i)));
659 return (mask.
hash());
#define FMT_DBL_TOLERANCE
Definition: FMTutility.h:11
#define FMTEXPORT
Definition: FMTutility.h:125
Comparator used to check if a mask already exists in a std container.
Definition: FMTMask.h:626
FMTMaskComparator(const FMTMask &lbase_mask)
Construct the comparator from the mask to match.
bool operator()(const FMTMask &mask) const
Matching test operator for the comparator.
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
size_t count() const
Return the number of bits set.
bool isNotThemesSubset(const FMTMask &rhs, const std::vector< Core::FMTTheme > &themes) const
Return true if this mask is not part of rhs based on the sorted themes.
FMTMask preSolve(const FMTMaskFilter &filter, const std::vector< FMTTheme > &presolvedthemes) const
Return a presolved mask with potentially less data using a filter and a subset of the original themes...
FMTMask resume(const boost::dynamic_bitset< uint8_t > &rhs) const
Return a mask with the selected name and data using a bitset.
void setExclusiveBits(const FMTMask &p_mask, const FMTTheme &p_theme)
Flip only the theme subset and clear the mask of the intersection with another mask.
void unionWith(const FMTMask &rhs)
Performs an in-place union with another mask.
std::vector< const Core::FMTTheme * > getSelectedThemes(const std::vector< Core::FMTTheme > &themes) const
Return the themes that have any bit set in the mask.
std::string getBitsString() const
Return the binary representation of the bitset as a string.
FMTMask(FMTMask &&rhs) noexcept
Move copy constructor.
std::string get(const FMTTheme &theme) const
Get the attribute of the mask for a given theme.
FMTMask getPostSolveMask(const FMTMask &mask, const std::vector< FMTTheme > &themes) const
Turn off the bits of themes that are still active on a base postsolve mask.
std::string get(const std::vector< FMTTheme > &themes) const
Get the string mask name based on the bitset data and sorted themes.
FMTMask removeAggregates(const std::vector< FMTTheme > &themes, bool questionmarkonly=false) const
Return a new mask with the bits of aggregates or question marks unset for the given themes.
void setIntersect(const FMTMask &rhs)
set the intersect with this mask using rhs mask.
boost::dynamic_bitset< uint8_t > getBitsetIntersect(const FMTMask &rhs) const
Return the bitset of the intersection of this mask and another mask.
bool empty() const
Return true if the data member is empty.
void swap(FMTMask &rhs)
Swap this mask with another.
void preSolveRef(const FMTMaskFilter &p_filter, const std::vector< FMTTheme > &p_presolvedThemes, bool p_allowReallocation=true)
Presolve this mask in place with potentially less data using a filter and a subset of the original th...
FMTMask postSolve(const FMTMaskFilter &filter, const std::vector< FMTTheme > &basethemes) const
Return a postsolved mask using a filter and the original themes.
FMTMask(const std::string &mask, const boost::dynamic_bitset< uint8_t > &bits)
Construct a mask from an already set bitset and a string mask used as name.
bool isSubsetOf(const FMTMask &p_mask, const std::vector< size_t > &p_subset) const
Check if this mask is a subset of another mask by looking at a block subset.
FMTMask resume(const std::vector< size_t > &indexes) const
Return a mask with the selected name and data using mask indexes.
virtual ~FMTMask()=default
Default virtual destructor for FMTMask.
void append(const boost::dynamic_bitset< uint8_t > &bits)
Append a bitset to the bitset data member of the mask.
void set(const std::vector< FMTTheme > &themes, const std::string &value)
Set the bitset data for some themes from a mask string.
FMTMask getIntersect(const FMTMask &rhs) const
Return the intersection of this mask and another mask.
std::vector< size_t > getNonFullBlocks() const
Return the indexes of the blocks that contain a 0.
void update(const std::vector< FMTTheme > &themes)
Update the name member from the bitset data using a sorted list of themes.
void clear()
Clear the data and name members.
const std::string & getStringReference() const
Return a const reference to the name string member.
Definition: FMTMask.h:459
void set(const FMTTheme &theme, const std::string &value)
Set the bitset data for a given theme from an attribute.
size_t getSubsetCount(const FMTTheme &theme) const
Return the number of bits set for the given theme subset.
FMTMask getUnion(const FMTMask &rhs) const
Return the union of this mask and another mask.
FMTMask & operator=(FMTMask &&rhs) noexcept
Move assignment operator for FMTMask.
bool isNotThemesSubset(const FMTMask &rhs, const std::vector< const Core::FMTTheme * > &themes) const
Return true if this mask is not part of rhs based on the sorted themes.
FMTMask(const std::string &mask, const std::vector< FMTTheme > &themes)
Construct a complete mask from a string and sorted themes.
void binarizedAppend(const typetobinarize &element)
Binarize an element and append it to the mask.
Definition: FMTMask.h:324
FMTMask(const FMTMask &rhs)
Copy constructor for FMTMask.
bool canPreSolve(const FMTMaskFilter &p_filter, const std::vector< FMTTheme > &p_presolvedThemes) const
Return true if the mask can be presolved with the given filter and themes.
const std::string & getAttribute(const FMTTheme &p_theme) const
When you deal with FMTDevelopment you can directly call this to get a reference to the attribute stri...
bool isSubsetOf(const FMTMask &p_rhs) const
Check if this mask is a subset of another mask.
size_t size() const
Return the size of the bitset data member.
FMTMask refine(const FMTMask &mask, const std::vector< FMTTheme > &themes) const
Return a new mask where the question marks are completed with the attributes of another mask.
FMTMask()
Default constructor for FMTMask.
FMTMask(const std::vector< FMTTheme > &themes)
Construct an empty mask sized for the given themes.
FMTMask(const boost::dynamic_bitset< uint8_t > &bits)
Construct a mask setting only the bitset data member.
FMTMask(const std::vector< std::string > &values, const std::vector< FMTTheme > &themes)
Construct a mask from a vector of attribute strings and sorted themes.
std::vector< const Core::FMTTheme * > getStaticThemes(const std::vector< const Core::FMTTheme * > &themes) const
Return the themes that only use aggregates or a question mark for the mask.
std::vector< FMTMask > decompose(const FMTTheme &theme) const
Disaggregate the attribute of a theme from the mask into a vector of masks, one per possible attribut...
const boost::dynamic_bitset< uint8_t > & getBitsetReference() const
Return a const reference to the bitset data member.
Definition: FMTMask.h:450
void reserve(size_t p_size)
reserve memory for the boost dynamicbitset.
size_t hash() const
Return the hash of the mask.
Definition: FMTMask.h:419
Class holding the attributes and aggregates of a single theme, describing a part of a FMTMask.
Definition: FMTTheme.h:47
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
void load(Ar &ar, dynamic_bitset< Block, Alloc > &bs, unsigned)
Definition: FMTMask.h:53
void serialize(Ar &ar, dynamic_bitset< Block, Alloc > &bs, unsigned version)
Definition: FMTMask.h:65
void save(Ar &ar, dynamic_bitset< Block, Alloc > const &bs, unsigned)
Definition: FMTMask.h:43
Definition: FMTAction.h:463
std::size_t hash_value(const boost::dynamic_bitset< Block, Alloc > &bs)
Definition: FMTMask.h:76
std::size_t operator()(const Core::FMTMask &mask) const
Definition: FMTMask.h:657