MUDA_APP
Loading...
Searching...
No Matches
dense_0d.h
1#pragma once
2#include <muda/viewer/viewer_base.h>
3
4namespace muda
5{
6template <bool IsConst, typename T>
7class DenseViewerBase : public ViewerBase<IsConst>
8{
10 MUDA_VIEWER_COMMON_NAME(DenseViewerBase);
11
12 public:
16
17 protected:
18 template <typename U>
19 using auto_const_t = typename Base::template auto_const_t<U>;
20 auto_const_t<T>* m_data;
21
22 public:
23 using value_type = T;
24
25 MUDA_GENERIC DenseViewerBase() MUDA_NOEXCEPT : m_data(nullptr) {}
26
27 MUDA_GENERIC explicit DenseViewerBase(auto_const_t<T>* p) MUDA_NOEXCEPT : m_data(p)
28 {
29 }
30
31 MUDA_GENERIC auto as_const() const MUDA_NOEXCEPT
32 {
33 return ConstViewer{m_data};
34 }
35
36 MUDA_GENERIC operator ConstViewer() const MUDA_NOEXCEPT
37 {
38 return as_const();
39 }
40
41 MUDA_GENERIC auto_const_t<T>& operator*() MUDA_NOEXCEPT
42 {
43 check();
44 return *m_data;
45 }
46
47 MUDA_GENERIC auto_const_t<T>* operator->() MUDA_NOEXCEPT
48 {
49 check();
50 return m_data;
51 }
52
53 MUDA_GENERIC auto_const_t<T>* data() MUDA_NOEXCEPT { return m_data; }
54
55 MUDA_GENERIC const T& operator*() const MUDA_NOEXCEPT
56 {
57 return remove_const(*this).operator*();
58 }
59
60 MUDA_GENERIC const T* operator->() const MUDA_NOEXCEPT
61 {
62 return remove_const(*this).operator->();
63 }
64
65 MUDA_GENERIC const T* data() const MUDA_NOEXCEPT { return m_data; }
66
67 MUDA_GENERIC operator const T&() const MUDA_NOEXCEPT { return *m_data; }
68
69 protected:
70 MUDA_INLINE MUDA_GENERIC void check() const MUDA_NOEXCEPT
71 {
72 if constexpr(DEBUG_VIEWER)
73 {
74 MUDA_KERNEL_ASSERT(m_data,
75 "Dense[%s:%s]: m_data is null",
76 this->name(),
77 this->kernel_name());
78 }
79 }
80};
81
82template <typename T>
83class Dense : public DenseViewerBase<false, T>
84{
85 MUDA_VIEWER_COMMON_NAME(Dense);
86
87 public:
89 using ConstViewer = typename Base::ConstViewer;
91 using ThisViewer = Dense<T>;
92
93 using Base::Base;
94
95 MUDA_GENERIC Dense(const Base& base) MUDA_NOEXCEPT : Base(base) {}
96
97 MUDA_GENERIC Dense& operator=(const T& base) MUDA_NOEXCEPT
98 {
99 Base::check();
100 *this->m_data = base;
101 return *this;
102 }
103
104 using Base::operator*;
105 using Base::operator->;
106 using Base::as_const;
107 using Base::data;
108
109 MUDA_GENERIC operator T&() MUDA_NOEXCEPT { return *this->m_data; }
110 MUDA_GENERIC operator const T&() const MUDA_NOEXCEPT
111 {
112 return *this->m_data;
113 }
114
115 MUDA_GENERIC operator ConstViewer() const MUDA_NOEXCEPT
116 {
117 return this->as_const();
118 }
119};
120
121template <typename T>
123
124// viewer traits
125template <typename T>
127{
128 using type = CDense<T>;
129};
130
131template <typename T>
133{
134 using type = Dense<T>;
135};
136
137// make functions
138template <typename T>
139MUDA_INLINE MUDA_GENERIC auto make_cdense(const T* data) MUDA_NOEXCEPT
140{
141 return CDense<T>{data};
142}
143
144template <typename T>
145MUDA_INLINE MUDA_GENERIC auto make_dense(T* data) MUDA_NOEXCEPT
146{
147 return Dense<T>{data};
148}
149
150//print convert
151template <typename T>
152MUDA_INLINE MUDA_GENERIC const T& print_convert(const Dense<T>& v) MUDA_NOEXCEPT
153{
154 return v.operator const T&();
155}
156
157template <typename T>
158MUDA_INLINE MUDA_GENERIC const T& print_convert(const CDense<T>& v) MUDA_NOEXCEPT
159{
160 return v.operator const T&();
161}
162
163} // namespace muda
Definition dense_0d.h:84
Definition dense_0d.h:8
Definition viewer_base.h:22
Definition type_modifier.h:22
Definition type_modifier.h:28