AGXDynamics  2.35.0.3
ParameterBinding.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 */
AGXCORE_EXPORT
#define AGXCORE_EXPORT
agx::ParameterBinding::getArray
agxData::Array< T > & getArray()
Definition: ParameterBinding.h:125
Scalar.h
agx::ParameterBinding::isScalar
bool isScalar() const
Definition: ParameterBinding.h:101
agx::ParameterBinding::getMetaType
agx::UInt getMetaType() const
Definition: ParameterBinding.h:100
agx::ParameterBinding::getScalar
T & getScalar()
Definition: ParameterBinding.h:110
agx::ParameterBinding
A binding between a formal function parameter and an actual value.
Definition: ParameterBinding.h:30
agxData::getFormat
AGXCORE_EXPORT Format * getFormat(const agx::String &typeFormatName)
agxData::Scalar
Templated scalar.
Definition: Data.h:30
agx::Parameter::SCALAR
@ SCALAR
Definition: Parameter.h:74
agx::ParameterBinding::isArray
bool isArray() const
Definition: ParameterBinding.h:102
agx::Model::is
bool is(const agx::Model *other) const
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
agx::ParameterBinding::getFormat
const agxData::Format * getFormat() const
Definition: ParameterBinding.h:99
agxData::Format
A format is an implementation of a agxData::Type.
Definition: Format.h:63
agx::ParameterBinding::ParameterBinding
ParameterBinding()
Definition: ParameterBinding.h:91
agxData::Data
Generic data.
Definition: Data.h:39
Array.h
agx::ParameterBinding::getValue
agxData::Data * getValue()
Definition: ParameterBinding.h:97
agx::VectorPOD
Vector containing 'raw' data.
Definition: Vector.h:245
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agxData::Array
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
agx::Parameter::MetaType
MetaType
Specify which kind of parameter.
Definition: Parameter.h:72
agx::ParameterBinding::isValid
bool isValid() const
Definition: ParameterBinding.h:106
agx::Parameter::POINTER
@ POINTER
Definition: Parameter.h:76
agx::ParameterBindingVector
agx::VectorPOD< ParameterBinding > ParameterBindingVector
Definition: ParameterBinding.h:87
Parameter.h
agx::ParameterBinding::isWritable
bool isWritable() const
Definition: ParameterBinding.h:104
agx::UInt
uint32_t UInt
Definition: Integer.h:34
agx::ParameterBinding::getPointer
T *& getPointer()
Definition: ParameterBinding.h:140
agx::Parameter::ARRAY
@ ARRAY
Definition: Parameter.h:75
agx::InvalidIndex
const AGXCORE_EXPORT InvalidIndexStruct InvalidIndex
agx::ParameterBinding::isPointer
bool isPointer() const
Definition: ParameterBinding.h:103
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::ParameterBinding::allowFormatPromotion
bool allowFormatPromotion() const
Definition: ParameterBinding.h:105