AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Scalar.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGXDATA_SCALAR_H
18#define AGXDATA_SCALAR_H
19
20#include <agxData/Data.h>
21#include <agxData/Type.h>
22#include <agx/config/AGX_DEBUG_INTRUSIVE.h>
23
24namespace agxData
25{
29 class AbstractScalar : public Data
30 {
31 public:
35
37 template <typename T>
38 T& get();
39
41 template <typename T>
42 const T& get() const;
43
45 size_t size() const;
46
48 void setStorage(void *storage);
49 };
50
51 //---------------------------------------------------------------
52
54 template <typename T>
55 class Scalar : public AbstractScalar
56 {
57 public:
58 typedef T Type;
59 static const bool IsScalar = true;
60
61 public:
62 Scalar(const T& value = T());
63 Scalar(void *storage);
65
67 T& get();
68 const T& get() const;
69
70 operator T& ();
71 operator const T& () const;
72
73 Scalar<T>& operator= (const Scalar<T>& value);
74 Scalar<T>& operator= (const T& value);
75
77 T& operator[] (size_t index);
78 const T& operator[] (size_t index) const;
79
80 private:
81 T m_value;
82 };
83
84
85
86
87 /* Implementation */
88
89 //---------------------------------------------------------------
90
91 AGX_FORCE_INLINE AbstractScalar& Data::asScalar() { return *static_cast<AbstractScalar *>(this); }
92 AGX_FORCE_INLINE const AbstractScalar& Data::asScalar() const { return *static_cast<const AbstractScalar *>(this); }
93
94 template <typename T>
95 AGX_FORCE_INLINE Scalar<T>& Data::asScalar() { return *static_cast<Scalar<T> *>(this); }
96
97 template <typename T>
98 AGX_FORCE_INLINE const Scalar<T>& Data::asScalar() const { return *static_cast<const Scalar<T> *>(this); }
99
100 //---------------------------------------------------------------
101
102
105
108
111
112 AGX_FORCE_INLINE size_t AbstractScalar::size() const { return 1; }
113
114 // AGX_FORCE_INLINE void *AbstractScalar::get() { return m_ptr; }
115 // AGX_FORCE_INLINE const void *AbstractScalar::get() const { return m_ptr; }
116
117 template <typename T>
119 {
121 #if AGX_DEBUG_INTRUSIVE()
123 #endif
124
125 return *static_cast<T *>(m_ptr);
126 }
127
128 template <typename T>
130 {
132 #if AGX_DEBUG_INTRUSIVE()
134 #endif
135
136 return *static_cast<const T *>(m_ptr);
137 }
138
139
141
142 //---------------------------------------------------------------
143
144 template <typename T>
145 AGX_FORCE_INLINE Scalar<T>::Scalar(const T& value) : AbstractScalar(&m_value, agxData::getFormat<T>()), m_value(value) {}
146
147 template <typename T>
149
150 template <typename T>
154
155 template <typename T>
156 AGX_FORCE_INLINE T& Scalar<T>::get() { return *(T *)m_ptr; }
157
158 template <typename T>
159 AGX_FORCE_INLINE const T& Scalar<T>::get() const { return *(T *)m_ptr; }
160
161 template <typename T>
162 AGX_FORCE_INLINE T& Scalar<T>::operator[] (size_t /* index */) { return *(T *)m_ptr; }
163
164 template <typename T>
165 AGX_FORCE_INLINE const T& Scalar<T>::operator[] (size_t /* index */) const { return *(T *)m_ptr; }
166
167 template <typename T>
168 AGX_FORCE_INLINE Scalar<T>::operator T& () { return *(T *)m_ptr; }
169
170 template <typename T>
171 AGX_FORCE_INLINE Scalar<T>::operator const T& () const { return *(T *)m_ptr; }
172
173 template <typename T>
174 AGX_FORCE_INLINE Scalar<T>& Scalar<T>::operator= (const Scalar<T>& value) { *(T *)m_ptr = *(T *)value.m_ptr; return *this; }
175
176 template <typename T>
177 AGX_FORCE_INLINE Scalar<T>& Scalar<T>::operator= (const T& value) { *(T *)m_ptr = value; return *this; }
178
179}
180
182
183
184
185#endif /* AGXDATA_SCALAR_H */
#define AGX_TEMPLATED_TYPE_BINDING(_Type, _Name)
Definition Type.h:192
Abstract representation of a scalar variable.
Definition Scalar.h:30
size_t size() const
Definition Scalar.h:112
void setStorage(void *storage)
Set the memory area for the scalar.
Definition Scalar.h:140
Generic data.
Definition Data.h:40
void * m_ptr
Definition Data.h:72
const AbstractScalar & asScalar() const
Definition Scalar.h:92
Templated scalar.
Definition Scalar.h:56
T & operator[](size_t index)
Definition Scalar.h:162
static const bool IsScalar
Definition Scalar.h:59
Scalar< T > & operator=(const Scalar< T > &value)
Definition Scalar.h:174
Scalar(const T &value=T())
Definition Scalar.h:145
Only use as member allocated variable.
Definition Value.h:285
#define agxAssert(expr)
Definition debug.h:143
#define AGX_FORCE_INLINE
Definition macros.h:58
Contains classes for low level data storage for AGX.
Definition Container.h:23
Format * getFormat()
Definition Type.h:269