47 #define SPATIAL_STORAGE_H
56 template<
typename BIN,
typename STORAGE,
typename CONFIG>
59 using storage_t = STORAGE;
66 template<
typename T>
void operator()(
T& t ){
67 T& rhs = storage_cast<T&>(st);
68 t.insert(t.end(), std::make_move_iterator(rhs.begin()), std::make_move_iterator(rhs.end()));
73 template<
typename T>
void operator()(
T& t){ ::new(ptr) BIN(t); }
84 is_bin_.store(rhs.is_bin_.load());
88 is_bin_.store(rhs.is_bin_.load());
89 if( rhs.is_built() ) ::new(&
bin_) BIN(std::move(rhs.bin_));
90 rhs.destroy_if_bin_();
101 data_.swap(rhs.data_);
102 if( is_bin_ && rhs.is_bin_ )
bin_.swap(rhs.bin_);
103 else if( is_bin_ && !rhs.is_bin_ ) {
104 ::new(&(rhs.bin_)) BIN(std::move(
bin_));
107 }
else if( !is_bin_ && rhs.is_bin_ ) {
108 ::new(&(
bin_)) BIN(std::move(rhs.bin_));
110 rhs.destroy_if_bin_();
116 template<
typename REGION,
typename FOCUS,
typename SAMPLER,
typename ... ADDITIONAL>
117 typename SAMPLER::OTYPE
118 query(
const REGION& reg,
const FOCUS& f, SAMPLER& s, ADDITIONAL && ... additional)
const {
119 using vec = std::vector<std::pair<point_type,typename SAMPLER::ITYPE> >;
123 if( !
is_built() )
EXCEPTION(std::logic_error(
"MUI Error [spatial_storage.h]: Query error, "
124 "bin structure not built yet."));
126 const vec& st = storage_cast<const vec&>(data_);
132 if(
is_built() )
EXCEPTION(std::logic_error(
"MUI Error [spatial_storage.h]: Build error, cannot build bin structure twice."));
133 if( !data_.empty() ) {
134 data_.apply_visitor(construct_{
static_cast<void*
>(&
bin_)});
139 template<
typename FOCUS,
typename SAMPLER,
typename ...ADDITIONAL>
140 typename SAMPLER::OTYPE
144 std::unique_lock<std::mutex> lock(mutex_);
148 return query(s.support(f,
bin_.domain_size()).bbox(), f, s, additional...);
154 if( !data_ ) data_ = std::move(
storage);
159 template<
typename TYPE>
161 return storage_cast<const std::vector<std::pair<point_type,TYPE> >& >(data_);
166 bool empty()
const {
return data_.empty(); }
168 void destroy_if_bin_() {
177 std::atomic<bool> is_bin_;
182 mutable std::mutex mutex_;
186 #define SPATIAL_STORAGE_H
Definition: spatial_storage.h:57
spatial_storage(storage_t rhs)
Definition: spatial_storage.h:92
SAMPLER::OTYPE query(const REGION ®, const FOCUS &f, SAMPLER &s, ADDITIONAL &&... additional) const
Definition: spatial_storage.h:118
typename CONFIG::point_type point_type
Definition: spatial_storage.h:61
bool is_built() const
Definition: spatial_storage.h:165
char nodata_
Definition: spatial_storage.h:179
typename CONFIG::EXCEPTION EXCEPTION
Definition: spatial_storage.h:62
~spatial_storage()
Definition: spatial_storage.h:80
void swap(spatial_storage &rhs) noexcept(noexcept(BIN(std::move(rhs.bin_))))
Definition: spatial_storage.h:100
spatial_storage(const spatial_storage &rhs)
Definition: spatial_storage.h:83
BIN bin_
Definition: spatial_storage.h:180
spatial_storage(spatial_storage &&rhs) noexcept
Definition: spatial_storage.h:87
spatial_storage & operator=(spatial_storage rhs)
Definition: spatial_storage.h:95
void insert(storage_t storage)
Definition: spatial_storage.h:151
void build()
Definition: spatial_storage.h:131
bool empty() const
Definition: spatial_storage.h:166
SAMPLER::OTYPE build_and_query_ts(const FOCUS &f, SAMPLER &s, ADDITIONAL &&... additional)
Definition: spatial_storage.h:141
spatial_storage() noexcept
Definition: spatial_storage.h:77
const std::vector< std::pair< point_type, TYPE > > & return_data()
Definition: spatial_storage.h:160
Definition: virtual_container.h:97
Implementation of a compound dynamic data structure used throughout MUI.
Definition: dynstorage.h:62
Definition: dynstorage.h:146
id_t which() const
Definition: dynstorage.h:208
Provides a virtual container interface that is used to wrap around data structures created by dynstor...