8#ifndef FMTlist_H_INCLUDED
9#define FMTlist_H_INCLUDED
11#include <boost/unordered_map.hpp>
18#include <boost/serialization/version.hpp>
19#include <boost/serialization/serialization.hpp>
20#include <boost/serialization/hash_collections_save_imp.hpp>
21#include <boost/serialization/hash_collections_load_imp.hpp>
22#include <boost/serialization/split_member.hpp>
23#include <boost/serialization/unordered_map.hpp>
24#include <boost/serialization/vector.hpp>
25#include <boost/serialization/nvp.hpp>
26#include <boost/serialization/export.hpp>
60 "FMTlist::operator::+=", __LINE__, __FILE__);
62 for (
const std::pair<FMTmask, T>& Object : OtherList.data)
67 _exhandler->raisefromcatch(
"",
"FMTlist::operator::+=", __LINE__, __FILE__);
80 filter.
swap(rhs.filter);
81 fastpass.swap(rhs.fastpass);
90 for (
const auto&
object : *
this)
92 const Core::FMTmask specificiermask(std::string(
object.first), themes);
93 testedmask = testedmask.
getunion(specificiermask);
114 fastpass(rhs.fastpass)
129 fastpass = rhs.fastpass;
139 return (data == rhs.data);
160 return filter.
empty();
168 boost::unordered_map<FMTmask, std::vector<int>>().
swap(fastpass);
195 std::vector<const T*>allhits;
196 boost::unordered_map<FMTmask, std::vector<int>>
::const_iterator fast_it = fastpass.find(newkey);
197 if (fast_it != fastpass.end())
199 allhits.reserve(fast_it->second.size());
200 for (
const int& location : fast_it->second)
202 allhits.push_back(&data.at(location).second);
206 fastpass[newkey] = std::vector<int>();
208 for (
const std::pair<FMTmask, T>&
object : data)
212 fastpass[newkey].push_back(location);
213 allhits.push_back(&
object.second);
217 fastpass[newkey].shrink_to_fit();
227 return filter.
filter(basemask);
237 std::vector<Core::FMTmask> filteredmasks;
238 for (
const std::pair<FMTmask, T>&
object : data)
240 filteredmasks.push_back(
object.first);
242 if (filteredmasks.empty())
247 for (std::pair<FMTmask, T>&
object : data)
249 object.first = filter.
filter(
object.first);
251 data.shrink_to_fit();
255 _exhandler->raisefromcatch(
"",
"FMTlist::shrink", __LINE__, __FILE__);
267 for (std::pair<FMTmask, T>&
object : data)
269 object.first =
FMTmask(std::string(
object.first), themes);
286 data.emplace_back(mask, value);
333 data.erase(data.begin() + location);
341 data.insert(data.begin() + location, std::pair<FMTmask, T>(mask, value));
402 std::vector<std::pair<FMTmask, T>>newvecdata;
403 std::list<std::pair<FMTmask, T>>newdata(data.begin(), data.end());
404 boost::dynamic_bitset<>selectedbits;
405 selectedbits.resize(data.begin()->first.size(),
true);
406 for (
size_t loc = thstart;loc < (theme.size()+ thstart);++loc)
408 selectedbits[loc] =
false;
410 while (!newdata.empty())
412 typename std::list<std::pair<FMTmask, T>>
::iterator baseit = newdata.begin();
413 typename std::list<std::pair<FMTmask, T>>
::iterator datait = newdata.begin();
415 std::vector<typename std::list<std::pair<FMTmask, T>>
::iterator>toremove;
417 const boost::dynamic_bitset<> selecinter = selectedbits & baseit->first.getbitsetreference();
418 boost::dynamic_bitset<> reverselect(selecinter);
419 for (
size_t loc = thstart; loc < (theme.size() + thstart); ++loc)
421 reverselect[loc] =
true;
425 while (datait!=newdata.end())
429 const boost::dynamic_bitset<>&dataref = datait->first.getbitsetreference();
430 if (dataref.is_subset_of(reverselect))
432 const boost::dynamic_bitset<> datainter = selectedbits & dataref;
433 if (datainter == selecinter &&
434 baseit->second == datait->second)
436 basemask = basemask.
getunion(datait->first);
437 toremove.push_back(datait);
442 std::pair<FMTmask, T>newelement(basemask,baseit->second);
443 newdata.erase(newdata.begin());
444 for (
typename std::list<std::pair<FMTmask, T>>
::iterator remove : toremove)
446 newdata.erase(remove);
448 if(!toremove.empty())
451 for (
const FMTtheme& subtheme : newthemes)
455 newmask +=theme.updatefrommask(basemask) +
" ";
457 newmask += basemask.
get(subtheme) +
" ";
463 newvecdata.push_back(newelement);
465 thstart += theme.size();
466 data.swap(newvecdata);
471 _exhandler->raisefromcatch(
"",
"compressmasks", __LINE__, __FILE__);
484 const std::vector<FMTtheme>& originalthemes,
485 const std::vector<FMTtheme>& newthemes)
492 const std::vector<FMTtheme>maskthemes = filter.
getselectedthemes(originalthemes);
493 std::vector<std::pair<FMTmask, T>>newdata;
494 for (
const std::pair<FMTmask, T>&
object : data)
501 mskkey = mskkey.
presolve(filter, newthemes);
503 pushtodata(newdata, mskkey,
object.second);
508 data.shrink_to_fit();
511 _exhandler->raisefromcatch(
"",
"FMTlist::presolvelist", __LINE__, __FILE__);
524 template<
class Archive>
525 void save(Archive& ar,
const unsigned int version)
const
528 ar& boost::serialization::make_nvp(
"FMTobject", boost::serialization::base_object<FMTobject>(*
this));
529 ar& BOOST_SERIALIZATION_NVP(data);
530 ar& BOOST_SERIALIZATION_NVP(filter);
531 std::vector<std::pair<FMTmask, std::vector<int>>>vecfastpass(fastpass.begin(), fastpass.end());
532 ar& BOOST_SERIALIZATION_NVP(vecfastpass);
536 _exhandler->printexceptions(
"",
"FMTlist::save", __LINE__, __FILE__);
543 template<
class Archive>
544 void load(Archive& ar,
const unsigned int version)
546 ar& BOOST_SERIALIZATION_NVP(data);
547 ar& BOOST_SERIALIZATION_NVP(filter);
548 std::vector<std::pair<FMTmask, std::vector<int>>>vecfastpass;
549 ar& BOOST_SERIALIZATION_NVP(vecfastpass);
550 for (
const std::pair<FMTmask, std::vector<int>>& values : vecfastpass)
552 fastpass[values.first] = values.second;
555 BOOST_SERIALIZATION_SPLIT_MEMBER()
558 std::vector<std::pair<FMTmask, T>>data;
561 FMTmaskfilter filter;
564 mutable
boost::unordered_map<FMTmask, std::vector<
int>>fastpass;
569 void pushtodata(std::vector<std::pair<FMTmask, T>>& datavector,
570 const FMTmask& mask, const T& maskdata)
const
572 datavector.push_back(std::pair<FMTmask, T>(mask, maskdata));
585 std::pair<Core::FMTmask, std::unique_ptr<Core::FMTyieldhandler>> newobject = std::make_pair(mask, std::move(value->clone()));
586 data.insert(data.begin() + location, std::move(newobject));
590 const FMTmask& mask,
const std::unique_ptr<Core::FMTyieldhandler>& maskdata)
const
592 std::pair<Core::FMTmask, std::unique_ptr<Core::FMTyieldhandler>> newobject = std::make_pair(mask, std::move(maskdata->clone()));
593 datavector.push_back(std::move(newobject));
598 pushtodata(data, mask, value);
604 data.reserve(rhs.data.size());
605 for (
const std::pair<
Core::FMTmask, std::unique_ptr<Core::FMTyieldhandler>>&
object : rhs.data)
607 pushtodata(data,
object.first,
object.second);
Definition: FMTlist.hpp:46
FMTlist()
Definition: FMTlist.hpp:101
const_iterator begin() const
Definition: FMTlist.hpp:364
size_t size() const
Definition: FMTlist.hpp:174
std::vector< std::pair< FMTmask, T > >::value_type value_type
Value typedef of the FMTlist.
Definition: FMTlist.hpp:345
Core::FMTlist< T > & operator+=(const Core::FMTlist< T > &OtherList)
append OtherList to this list actions both list had to be non shrinked, will throw exception if shrin...
Definition: FMTlist.hpp:54
void erase(const size_t &location)
Definition: FMTlist.hpp:331
void presolvelist(const FMTmaskfilter &filter, const std::vector< FMTtheme > &originalthemes, const std::vector< FMTtheme > &newthemes)
Definition: FMTlist.hpp:483
void APIpush_back(const FMTmask &mask, const T &value)
Definition: FMTlist.hpp:276
void shrink()
Definition: FMTlist.hpp:233
void push_back(const FMTlist< T > &rhs)
Definition: FMTlist.hpp:303
void pop_back()
Definition: FMTlist.hpp:323
void swap(Core::FMTlist< T > &rhs)
Definition: FMTlist.hpp:77
std::vector< std::pair< FMTmask, T > >::iterator iterator
Iterator typedef of the FMTlist.
Definition: FMTlist.hpp:348
FMTlist(const FMTlist< T > &rhs)
Definition: FMTlist.hpp:110
iterator end()
Definition: FMTlist.hpp:372
void compressmasks(std::vector< FMTtheme > &newthemes)
Definition: FMTlist.hpp:391
void unshrink(const std::vector< FMTtheme > &themes)
Definition: FMTlist.hpp:263
bool operator==(const FMTlist< T > &rhs) const
Definition: FMTlist.hpp:137
FMTmask getunion(const std::vector< FMTtheme > &themes) const
Definition: FMTlist.hpp:87
virtual void update()
Definition: FMTlist.hpp:292
std::vector< std::pair< FMTmask, T > >::const_iterator const_iterator
Const_Iterator typedef of the FMTlist.
Definition: FMTlist.hpp:351
friend class boost::serialization::access
Definition: FMTlist.hpp:523
void insert(const size_t &location, const FMTmask &mask, const T &value)
Definition: FMTlist.hpp:339
bool canshrink() const
Definition: FMTlist.hpp:158
FMTlist & operator=(const FMTlist< T > &rhs)
Definition: FMTlist.hpp:122
FMTmask filtermask(const FMTmask &basemask) const
Definition: FMTlist.hpp:225
std::vector< const T * > findsetswithfiltered(const FMTmask &newkey) const
Definition: FMTlist.hpp:193
virtual void clearcache()
Definition: FMTlist.hpp:166
bool empty() const
Definition: FMTlist.hpp:150
std::vector< const T * > findsets(const FMTmask &mask) const
Definition: FMTlist.hpp:183
void push_front(const FMTmask &mask, const T &value)
Definition: FMTlist.hpp:315
void copydata(const Core::FMTlist< T > &rhs)
Definition: FMTlist.hpp:514
const_iterator end() const
Definition: FMTlist.hpp:380
void push_back(const FMTmask &mask, const T &value)
Definition: FMTlist.hpp:284
iterator begin()
Definition: FMTlist.hpp:356
Definition: FMTmask.hpp:96
std::string get(const std::vector< FMTtheme > &themes) const
FMTmask presolve(const FMTmaskfilter &filter, const std::vector< FMTtheme > &presolvedthemes) const
FMTmask getunion(const FMTmask &rhs) const
bool issubsetof(const boost::dynamic_bitset<> &rhs) const
Definition: FMTmask.hpp:352
Definition: FMTmaskfilter.hpp:27
bool canpresolve(const FMTmask &mask, const std::vector< Core::FMTtheme > &themes) const
bool emptyflipped() const
Definition: FMTmaskfilter.hpp:58
FMTmask filter(const FMTmask &devmask) const
bool empty() const
Definition: FMTmaskfilter.hpp:62
std::vector< Core::FMTtheme > getselectedthemes(const std::vector< Core::FMTtheme > &themes) const
void swap(FMTmaskfilter &rhs)
Definition: FMTobject.hpp:50
FMTobject & operator=(const FMTobject &rhs)
static std::shared_ptr< Exception::FMTexceptionhandler > _exhandler
A shared pointer to the exception handler.
Definition: FMTobject.hpp:66
Definition: FMTtheme.hpp:47
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTaction.hpp:31
@ FMTinvalid_action
Definition: FMTexception.hpp:51
@ FMTinvalid_maskrange
Definition: FMTexception.hpp:49
Definition: FMTaction.hpp:364