SLIDE  3.0.0
A simulator for lithium-ion battery pack degradation
Loading...
Searching...
No Matches
SmallVector.hpp
Go to the documentation of this file.
1
2
3#pragma once
4
5#include <array>
6
7namespace slide {
8
9template <typename T, T Nmax>
11{
12 std::array<T, Nmax> data{};
13
14public:
15 T N{ 0 };
16
17 SmallVector() = default;
19 {
20 if (N > Nmax) {
21 std::cerr << "Array is very small! Please increase its size from settings!\n";
22 throw 1234;
23 }
24
25 for (T i = 0; i < N; i++)
26 data[i] = 0;
27 }
28
29 inline void push_back(const T &&elem)
30 {
31 if (N > Nmax) {
32 std::cerr << "Array is very small! Please increase its size from settings!\n";
33 throw 1234;
34 }
35
36 data[N] = elem;
37 N++;
38 }
39
40 inline auto &operator[](T idx)
41 {
42 if (idx < N)
43 return data[idx];
44 else {
45 std::cerr << "Array is very small! Please increase its size from settings!\n";
46 throw 1234;
47 }
48 }
49
50 inline auto empty() { return N == 0; }
51
52 [[nodiscard]] inline const auto &operator[](T idx) const noexcept { return data[idx]; }
53
54 [[nodiscard]] constexpr auto begin() noexcept { return data.begin(); }
55 [[nodiscard]] constexpr auto cbegin() const noexcept { return data.cbegin(); }
56
57 [[nodiscard]] constexpr auto end() { return data.begin() + N; }
58 [[nodiscard]] constexpr auto cend() const noexcept { return data.cbegin() + N; }
59};
60
61} // namespace slide
Definition: SmallVector.hpp:11
const auto & operator[](T idx) const noexcept
Definition: SmallVector.hpp:52
T N
number of degradation models to use (length of SEI_ID) #TODO if default should be 1 and array initial...
Definition: SmallVector.hpp:15
constexpr auto cbegin() const noexcept
Definition: SmallVector.hpp:55
void push_back(const T &&elem)
Definition: SmallVector.hpp:29
constexpr auto cend() const noexcept
Definition: SmallVector.hpp:58
constexpr auto end()
Definition: SmallVector.hpp:57
auto & operator[](T idx)
Definition: SmallVector.hpp:40
SmallVector()=default
SmallVector(T N)
Definition: SmallVector.hpp:18
constexpr auto begin() noexcept
Definition: SmallVector.hpp:54
auto empty()
Definition: SmallVector.hpp:50
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27