AGX Dynamics  2.37.3.2
ObjectWrapper.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 #ifndef AGX_OBJECTWRAPPER_H
18 #define AGX_OBJECTWRAPPER_H
19 
20 #include <agx/Object.h>
21 
22 namespace agx
23 {
24  template <typename T>
25  class ObjectWrapper : public agx::Object
26  {
27  public:
28  ObjectWrapper(const agx::Name& name, const T& value = T());
29 
30  T& get();
31  const T& get() const;
32 
33  void set(const T& value);
34 
35  protected:
36  virtual ~ObjectWrapper() {}
37 
38  private:
39  T m_object;
40  };
41 
42  #if 0
43  template <typename T>
44  class ObjectRefWrapper : public agx::Object
45  {
46  public:
47  ObjectRefWrapper(const agx::Name& name);
48 
49  T *get();
50  const T *get() const;
51 
52  void set(const T *value);
53 
54  protected:
55  virtual ~ObjectRefWrapper() {}
56 
57  private:
58  agx::ref_ptr<T> m_object;
59  };
60  #endif
61 
62 
63  /* Implementation */
64  template <typename T>
65  ObjectWrapper<T>::ObjectWrapper(const agx::Name& name, const T& value) : Object(name), m_object(value)
66  {
67  }
68 
69  template <typename T>
70  AGX_FORCE_INLINE T& ObjectWrapper<T>::get() { return m_object; }
71 
72  template <typename T>
73  AGX_FORCE_INLINE const T& ObjectWrapper<T>::get() const { return m_object; }
74 
75  template <typename T>
76  AGX_FORCE_INLINE void ObjectWrapper<T>::set(const T& value) { m_object = value; }
77 
78 
80  #if 0
81  template <typename T>
82  ObjectWrapperRef<T>::ObjectWrapperRef(const agx::Name& name, T *object) : Object(name), m_object(object)
83  {
84  }
85 
86  template <typename T>
87  AGX_FORCE_INLINE T *ObjectWrapperRef<T>::get() { return m_object; }
88 
89  template <typename T>
90  AGX_FORCE_INLINE const T *ObjectWrapperRef<T>::get() const { return m_object; }
91 
92  template <typename T>
93  AGX_FORCE_INLINE void ObjectWrapperRef<T>::set(T *object) { m_object = object; }
94  #endif
95 }
96 
97 
98 #endif /* AGX_OBJECTWRAPPER_H */
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:59
virtual ~ObjectWrapper()
Definition: ObjectWrapper.h:36
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
ObjectWrapper(const agx::Name &name, const T &value=T())
Definition: ObjectWrapper.h:65
void set(const T &value)
Definition: ObjectWrapper.h:76
Object(const Name &name=Name(), Model *model=Object::ClassModel())
agx::Object is a refcounted object with a name.
Definition: Object.h:58