CbmRoot
Loading...
Searching...
No Matches
KfVector.h
Go to the documentation of this file.
1/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#pragma once
11
13
14#include <boost/serialization/access.hpp>
15#include <boost/serialization/base_object.hpp>
16#include <boost/serialization/vector.hpp>
17//#include <boost/stacktrace.hpp>
18
19#include <exception>
20#include <sstream>
21#include <vector>
22
23namespace cbm::algo::kf
24{
27 template<class T, class Allocator = std::allocator<T>>
28 class Vector : public std::vector<T, Allocator> {
29 public:
30 using BaseVector_t = std::vector<T, Allocator>;
31
33 template<typename... Args>
34 Vector(Args... values) : BaseVector_t(values...)
35 {
36 }
37
39 Vector(const Vector& other) : BaseVector_t(other) {}
40
42 Vector(Vector&& other) : BaseVector_t(std::move(other)) {}
43
45 //Vector& operator=(const Vector& other) { return BaseVector_t::operator=(other); }
46 Vector& operator=(const Vector& other) = default;
47
49 //Vector& operator=(Vector&& other) { return BaseVector_t::operator=(std::move(other)); }
50 Vector& operator=(Vector&& other) = default;
51
53 template<bool CheckBoundaries = false>
54 T& at(std::size_t pos)
55 {
56 if constexpr (CheckBoundaries) {
57 if (pos >= this->size()) {
58 std::stringstream msg;
59 msg << "kf::Vector::operator[]: accessing element with index out of boundaries (pos = " << pos
60 << ", size = " << this->size() << "). "
61 << "Stack trace:\n";
62 //<< boost::stacktrace::stacktrace();
63 throw std::runtime_error(msg.str());
64 }
65 }
66 return BaseVector_t::operator[](pos);
67 }
68
70 template<bool CheckBoundaries = false>
71 const T& at(std::size_t pos) const
72 {
73 if constexpr (CheckBoundaries) {
74 if (pos >= this->size()) {
75 std::stringstream msg;
76 msg << "kf::Vector::operator[]: accessing element with index out of boundaries (pos = " << pos
77 << ", size = " << this->size() << "). "
78 << "Stack trace:\n";
79 //<< boost::stacktrace::stacktrace();
80 throw std::runtime_error(msg.str());
81 }
82 }
83 return BaseVector_t::operator[](pos);
84 }
85
86 private:
89 template<class Archive>
90 void serialize(Archive& ar, const unsigned int /*version*/)
91 {
92 ar& boost::serialization::base_object<BaseVector_t>(*this);
93 }
94 };
95} // namespace cbm::algo::kf
static constexpr size_t size()
Definition KfSimdPseudo.h:2
A std::vector with additional debugging utility set.
Definition KfVector.h:28
Vector(const Vector &other)
Copy constructor.
Definition KfVector.h:39
const T & at(std::size_t pos) const
Constant access operator overload.
Definition KfVector.h:71
T & at(std::size_t pos)
Access operator overload.
Definition KfVector.h:54
std::vector< T, Allocator > BaseVector_t
Definition KfVector.h:30
Vector(Vector &&other)
Move constructor.
Definition KfVector.h:42
friend class boost::serialization::access
Serialization method.
Definition KfVector.h:88
Vector(Args... values)
Generic constructor from parameters.
Definition KfVector.h:34
Vector & operator=(Vector &&other)=default
Move assignment operator.
Vector & operator=(const Vector &other)=default
Copy assignment operator.
void serialize(Archive &ar, const unsigned int)
Definition KfVector.h:90
Hash for CbmL1LinkKey.