1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/*!
@authors Andrei Novikov (pyclustering@yandex.ru)
@date 2014-2020
@copyright BSD-3-Clause
*/
#pragma once
#include <vector>
namespace pyclustering {
namespace container {
/**
*
* @brief Collection that stores dynamic of oscillatory network - state of each oscillator on
* each iteration.
*
*/
template <typename DynamicType>
class dynamic_data : public std::vector<DynamicType> {
public:
std::size_t m_oscillators = 0;
public:
dynamic_data() = default;
explicit dynamic_data(const std::size_t p_size) :
std::vector<DynamicType>(p_size),
m_oscillators(0)
{ }
dynamic_data(const std::size_t p_size, const DynamicType & p_value) :
std::vector<DynamicType>(p_size, p_value),
m_oscillators(0)
{ }
dynamic_data(const dynamic_data & p_dynamic) = default;
dynamic_data(dynamic_data && p_dynamic) = default;
virtual ~dynamic_data() = default;
public:
void push_back(const DynamicType & p_value) {
check_set_oscillators(p_value);
std::vector<DynamicType>::push_back(p_value);
}
void push_back(DynamicType && p_value) {
check_set_oscillators(p_value);
std::vector<DynamicType>::push_back(p_value);
}
void resize(const std::size_t p_size, const std::size_t p_oscillators) {
std::vector<DynamicType>::resize(p_size);
m_oscillators = p_oscillators;
}
void clear() {
std::vector<DynamicType>::clear();
m_oscillators = 0;
}
std::size_t oscillators() const {
return m_oscillators;
}
private:
void check_set_oscillators(const DynamicType & p_value) {
if (std::vector<DynamicType>::empty()) {
m_oscillators = p_value.size();
}
else if (m_oscillators != p_value.size()) {
throw std::range_error("Dynamic collection can consist of network states with the same size only");
}
}
private:
using std::vector<DynamicType>::assign;
using std::vector<DynamicType>::clear;
using std::vector<DynamicType>::emplace;
using std::vector<DynamicType>::erase;
using std::vector<DynamicType>::insert;
using std::vector<DynamicType>::push_back;
using std::vector<DynamicType>::pop_back;
using std::vector<DynamicType>::resize;
using std::vector<DynamicType>::data;
};
}
}
|