mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-11 12:27:14 +02:00
WIP
This commit is contained in:
@ -16,34 +16,28 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
|
||||
using const_iterator = typename std::array<T, Capacity>::const_iterator;
|
||||
|
||||
FixedCapacityContainer() = default;
|
||||
explicit FixedCapacityContainer(std::initializer_list<T> l) {
|
||||
current_size = l.size();
|
||||
|
||||
explicit FixedCapacityContainer(std::initializer_list<T> l)
|
||||
: current_size(l.size()) {
|
||||
size_check(l.size());
|
||||
std::copy(l.begin(), l.end(), data_.begin());
|
||||
}
|
||||
|
||||
/** Copy construct from another container */
|
||||
template <typename V,
|
||||
typename = typename std::enable_if<
|
||||
is_light_container<V>::value &&
|
||||
is_container<V>::value &&
|
||||
std::is_same<T, typename V::value_type>::value>::type>
|
||||
explicit FixedCapacityContainer(const V &v) {
|
||||
if (v.size() > Capacity) {
|
||||
throw std::runtime_error(
|
||||
"Capacity needs to be same size or larger than vector");
|
||||
}
|
||||
current_size = v.size();
|
||||
FixedCapacityContainer(const V &v) : current_size(v.size()) {
|
||||
size_check(v.size());
|
||||
std::copy(v.begin(), v.end(), data_.begin());
|
||||
}
|
||||
|
||||
template <size_t OtherCapacity>
|
||||
explicit FixedCapacityContainer(
|
||||
const FixedCapacityContainer<T, OtherCapacity> &other) noexcept {
|
||||
static_assert(Capacity >= OtherCapacity,
|
||||
"Container needs to be same size or larger");
|
||||
current_size = other.size();
|
||||
std::copy(other.cbegin(), other.cend(), data_.begin());
|
||||
}
|
||||
|
||||
FixedCapacityContainer &operator=(const std::vector<T> &other) {
|
||||
/** copy assignment from another container */
|
||||
template <typename V>
|
||||
typename std::enable_if<is_container<V>::value, FixedCapacityContainer &>::type
|
||||
operator=(const V &other) {
|
||||
size_check(other.size());
|
||||
std::copy(other.begin(), other.end(), data_.begin());
|
||||
current_size = other.size();
|
||||
return *this;
|
||||
@ -119,6 +113,13 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
|
||||
private:
|
||||
size_type current_size{};
|
||||
std::array<T, Capacity> data_;
|
||||
|
||||
void size_check(size_type s) const {
|
||||
if (s > Capacity) {
|
||||
throw std::runtime_error(
|
||||
"Capacity needs to be same size or larger than vector");
|
||||
}
|
||||
}
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Free function concerning FixedCapacityContainer */
|
||||
|
Reference in New Issue
Block a user