spla
Loading...
Searching...
No Matches
tdecoration.hpp
Go to the documentation of this file.
1/**********************************************************************************/
2/* This file is part of spla project */
3/* https://github.com/SparseLinearAlgebra/spla */
4/**********************************************************************************/
5/* MIT License */
6/* */
7/* Copyright (c) 2023 SparseLinearAlgebra */
8/* */
9/* Permission is hereby granted, free of charge, to any person obtaining a copy */
10/* of this software and associated documentation files (the "Software"), to deal */
11/* in the Software without restriction, including without limitation the rights */
12/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13/* copies of the Software, and to permit persons to whom the Software is */
14/* furnished to do so, subject to the following conditions: */
15/* */
16/* The above copyright notice and this permission notice shall be included in all */
17/* copies or substantial portions of the Software. */
18/* */
19/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25/* SOFTWARE. */
26/**********************************************************************************/
27
28#ifndef SPLA_T_DECORATION_HPP
29#define SPLA_T_DECORATION_HPP
30
31#include <spla/ref.hpp>
32
33#include <array>
34#include <bitset>
35
36namespace spla {
37
49 template<typename T>
50 class TDecoration : public RefCnt {
51 public:
52 ~TDecoration() override = default;
53
55 [[nodiscard]] virtual uint get_n_values() const { return values; }
56
57 public:
59 };
60
69 template<typename T, typename F, int capacity>
71 public:
72 ref_ptr<TDecoration<T>>& get_ref_i(int index) { return m_decorations[index]; }
73 TDecoration<T>* get_ptr_i(int index) { return m_decorations[index].get(); }
74 ref_ptr<TDecoration<T>>& get_ref(F format) { return get_ref_i(static_cast<int>(format)); }
75 TDecoration<T>* get_ptr(F format) { return get_ptr_i(static_cast<int>(format)); }
76
77 template<class DecorationClass>
78 DecorationClass* get() { return dynamic_cast<DecorationClass*>(get_ptr(DecorationClass::FORMAT)); }
79
80 [[nodiscard]] bool is_valid_any() const { return m_is_valid.any(); }
81 [[nodiscard]] bool is_valid_i(int index) const { return m_is_valid.test(index); }
82 [[nodiscard]] bool is_valid(F format) const { return is_valid_i(static_cast<int>(format)); }
83 void validate(F format) { m_is_valid.set(static_cast<int>(format), true); }
84 void invalidate() { m_is_valid.reset(); }
85
86 void set_fill_value(T value) { m_fill_value = value; }
87 T get_fill_value() const { return m_fill_value; }
88
89 [[nodiscard]] uint get_n_rows() const { return m_n_rows; }
90 [[nodiscard]] uint get_n_cols() const { return m_n_cols; }
91
92 void set_dims(uint n_rows, uint n_cols) {
93 m_n_rows = n_rows;
94 m_n_cols = n_cols;
95 }
96
97 private:
98 std::array<ref_ptr<TDecoration<T>>, capacity> m_decorations;
99 std::bitset<capacity> m_is_valid;
100 uint m_n_rows = 0;
101 uint m_n_cols = 0;
102 T m_fill_value = T();
103 };
104
109}// namespace spla
110
111#endif//SPLA_T_DECORATION_HPP
Base class for object with built-in reference counting mechanism.
Definition ref.hpp:55
Storage for decorators with data of a particular vector or matrix object.
Definition tdecoration.hpp:70
uint get_n_cols() const
Definition tdecoration.hpp:90
T get_fill_value() const
Definition tdecoration.hpp:87
DecorationClass * get()
Definition tdecoration.hpp:78
TDecoration< T > * get_ptr(F format)
Definition tdecoration.hpp:75
ref_ptr< TDecoration< T > > & get_ref_i(int index)
Definition tdecoration.hpp:72
void invalidate()
Definition tdecoration.hpp:84
void set_fill_value(T value)
Definition tdecoration.hpp:86
uint get_n_rows() const
Definition tdecoration.hpp:89
void validate(F format)
Definition tdecoration.hpp:83
bool is_valid(F format) const
Definition tdecoration.hpp:82
TDecoration< T > * get_ptr_i(int index)
Definition tdecoration.hpp:73
void set_dims(uint n_rows, uint n_cols)
Definition tdecoration.hpp:92
ref_ptr< TDecoration< T > > & get_ref(F format)
Definition tdecoration.hpp:74
bool is_valid_any() const
Definition tdecoration.hpp:80
bool is_valid_i(int index) const
Definition tdecoration.hpp:81
Base class for typed decoration for storage object.
Definition tdecoration.hpp:50
~TDecoration() override=default
uint values
Definition tdecoration.hpp:58
virtual uint get_n_values() const
Definition tdecoration.hpp:55
Automates reference counting and behaves as shared smart pointer.
Definition ref.hpp:117
std::uint32_t uint
Library index and size type.
Definition config.hpp:56
Definition algorithm.hpp:37