AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ParameterBinding.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
18#ifndef AGXFN_PARAMETERBINDING_H
19#define AGXFN_PARAMETERBINDING_H
20
21#include <agxData/Scalar.h>
22#include <agxData/Array.h>
23#include <agx/Parameter.h>
24
25namespace agx
26{
31 {
32 public:
34 ParameterBinding(agxData::Data *value, const agxData::Format *format, agx::Parameter::MetaType metaType, bool isWritable, bool allowFormatPromotion);
35
36 agxData::Data *getValue();
37 const agxData::Data *getValue() const;
38
39 const agxData::Format *getFormat() const;
40
41 void setValue(agxData::Data *value);
42 void setFormat(const agxData::Format *format);
43 void setAllowFormatPromotion(bool flag);
44 void setMetaType(agx::UInt metaType);
45 void setWritable(bool writable);
46
47
48 agx::UInt getMetaType() const;
49 bool isScalar() const;
50 bool isArray() const;
51 bool isPointer() const;
52
53 bool isWritable() const;
54 bool allowFormatPromotion() const;
55 bool isValid() const;
56
57
58
59 template <typename T>
60 T& getScalar();
61
62 template <typename T>
63 const T& getScalar() const;
64
65
66 template <typename T>
67 agxData::Array<T>& getArray();
68
69 template <typename T>
70 const agxData::Array<T>& getArray() const;
71
72
73 template <typename T>
74 T *& getPointer();
75
76 template <typename T>
77 const T *& getPointer() const;
78
79 private:
80 agxData::Data *m_value;
81 const agxData::Format *m_format;
82 agx::UInt m_metaType;
83 bool m_isWritable;
84 bool m_allowFormatPromotion;
85 };
86
88
89
90 /* Implementation */
91 AGX_FORCE_INLINE ParameterBinding::ParameterBinding() : m_value(nullptr), m_format(nullptr), m_metaType(agx::InvalidIndex), m_isWritable(false), m_allowFormatPromotion(false)
92 {}
93
94 AGX_FORCE_INLINE ParameterBinding::ParameterBinding(agxData::Data *value, const agxData::Format *format, agx::Parameter::MetaType metaType, bool isWritable, bool allowFormatPromotion) : m_value(value), m_format(format), m_metaType(metaType), m_isWritable(isWritable), m_allowFormatPromotion(allowFormatPromotion)
95 {}
96
104 AGX_FORCE_INLINE bool ParameterBinding::isWritable() const { return m_isWritable; }
105 AGX_FORCE_INLINE bool ParameterBinding::allowFormatPromotion() const { return m_allowFormatPromotion; }
106 AGX_FORCE_INLINE bool ParameterBinding::isValid() const { return m_value && m_format; }
107
108
109 template <typename T>
111 {
112 agxAssert(this->isValid());
113 agxAssert(m_metaType == agx::Parameter::SCALAR);
114 agxAssert(m_format->is(agxData::getFormat<T>()));
115 return static_cast< agxData::Scalar<T> *>(m_value)->get();
116 }
117
118 template <typename T>
120 {
121 return const_cast<ParameterBinding *>(this)->getScalar<T>();
122 }
123
124 template <typename T>
126 {
127 agxAssert(this->isValid());
128 agxAssert(m_metaType == agx::Parameter::ARRAY);
129 agxAssert(m_format->is(agxData::getFormat<T>()));
130 return *static_cast< agxData::Array<T> *>(m_value);
131 }
132
133 template <typename T>
135 {
136 return const_cast<ParameterBinding *>(this)->getArray<T>();
137 }
138
139 template <typename T>
141 {
142 agxAssert(this->isValid());
143 agxAssert(m_metaType == agx::Parameter::POINTER);
144 agxAssert(m_format->is(agxData::getFormat<T>()));
145 static T *blah;
146 return blah;
147 // return static_cast< agxData::Pointer<T> *>(m_value)->get(); // ?
148 }
149
150 template <typename T>
152 {
153 return const_cast<ParameterBinding *>(this)->getPointer<T>();
154 }
155
156
157}
158
159#endif /* AGXFN_PARAMETERBINDING_H */
#define AGXCORE_EXPORT
Generic data.
Definition Data.h:40
A format is an implementation of a agxData::Type.
Definition Format.h:64
Only use as member allocated variable.
Definition Value.h:285
bool is(const agx::Model *other) const
A binding between a formal function parameter and an actual value.
void setWritable(bool writable)
agxData::Array< T > & getArray()
const agxData::Format * getFormat() const
bool allowFormatPromotion() const
void setFormat(const agxData::Format *format)
agxData::Data * getValue()
void setMetaType(agx::UInt metaType)
void setValue(agxData::Data *value)
void setAllowFormatPromotion(bool flag)
agx::UInt getMetaType() const
MetaType
Specify which kind of parameter.
Definition Parameter.h:73
Vector containing 'raw' data.
Definition agx/Vector.h:246
#define agxAssert(expr)
Definition debug.h:143
#define AGX_FORCE_INLINE
Definition macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint64_t UInt
Definition Integer.h:27
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
agx::VectorPOD< ParameterBinding > ParameterBindingVector