AGX Dynamics  2.37.3.2
ParameterBinding.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx 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 
25 namespace 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 
98  AGX_FORCE_INLINE const agxData::Data *ParameterBinding::getValue() const { return m_value; }
99  AGX_FORCE_INLINE const agxData::Format *ParameterBinding::getFormat() const { return m_format; }
102  AGX_FORCE_INLINE bool ParameterBinding::isArray() const { return m_metaType == agx::Parameter::ARRAY; }
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 */
bool is(const agx::Model *other) const
MetaType
Specify which kind of parameter.
Definition: Parameter.h:72
AGXCORE_EXPORT Format * getFormat(const agx::String &typeFormatName)
agx::VectorPOD< ParameterBinding > ParameterBindingVector
bool allowFormatPromotion() const
Generic data.
Definition: Data.h:39
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
A format is an implementation of a agxData::Type.
Definition: Format.h:63
#define AGX_FORCE_INLINE
Definition: Object.h:59
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
uint32_t UInt
Definition: Integer.h:34
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
const agxData::Format * getFormat() const
#define agxAssert(expr)
Definition: debug.h:143
Templated scalar.
Definition: Data.h:30
agxData::Array< T > & getArray()
agx::UInt getMetaType() const
#define AGXCORE_EXPORT
A binding between a formal function parameter and an actual value.
agxData::Data * getValue()