-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathShared_Vector.h
More file actions
67 lines (58 loc) · 1.67 KB
/
Shared_Vector.h
File metadata and controls
67 lines (58 loc) · 1.67 KB
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
// ===================
// Author: Peize Lin
// date: 2023.02.24
// ===================
#pragma once
#include <cereal/cereal.hpp>
#include <initializer_list>
#include <cassert>
namespace RI
{
class Shape_Vector
{
public:
Shape_Vector()=default;
Shape_Vector(const Shape_Vector &v_in)=default;
Shape_Vector(Shape_Vector &&v_in)=default;
Shape_Vector &operator=(const Shape_Vector &v_in)=default;
Shape_Vector &operator=(Shape_Vector &&v_in)=default;
Shape_Vector(const std::initializer_list<std::size_t> &v_in)
:size_(v_in.size())
{
assert(v_in.size()<=sizeof(v)/sizeof(*v));
std::size_t* ptr_this = this->v;
for(auto ptr_in=v_in.begin(); ptr_in<v_in.end(); )
*(ptr_this++) = *(ptr_in++);
}
Shape_Vector(const std::vector<std::size_t>& v_in)
:size_(v_in.size())
{
assert(v_in.size() <= sizeof(v) / sizeof(*v));
for (std::size_t i = 0;i < size_;++i) this->v[i] = v_in[i];
}
Shape_Vector(std::vector<std::size_t>&& v_in)
:size_(v_in.size())
{
assert(v_in.size() <= sizeof(v) / sizeof(*v));
for (std::size_t i = 0;i < size_;++i) this->v[i] = v_in[i];
}
const std::size_t* begin() const noexcept { return this->v; }
const std::size_t* end() const noexcept { return this->v+size_; }
std::size_t size() const noexcept { return size_; }
bool empty() const noexcept{ return !size_; }
std::size_t& operator[] (const std::size_t i)
{
assert(i<size_);
return this->v[i];
}
const std::size_t& operator[] (const std::size_t i) const
{
assert(i<size_);
return this->v[i];
}
template <class Archive> void serialize( Archive & ar ){ ar(cereal::binary_data(this->v,sizeof(v)), size_); } // for cereal
public: //private:
std::size_t v[4];
std::size_t size_=0;
};
}