17 #ifndef AGX_COMPONENT_H 18 #define AGX_COMPONENT_H 27 class ComponentVisitor;
49 virtual void configure(TiXmlElement* eComponent)
override;
50 virtual void snapshot(TiXmlNode* eParent,
const String& directory)
const override;
74 virtual void addObject(
agx::Object *
object,
bool assignContext =
true);
84 void removeObject(
const agx::Name& name,
size_t index = 0);
89 void removeAllObjects();
100 template <
typename T>
101 T *getObject(
const agx::Name& name,
size_t index = 0);
103 template <
typename T>
104 const T *getObject(
const agx::Name& name,
size_t index = 0)
const;
109 size_t getNumObjects(
const agx::Name& name)
const;
119 template <
typename T>
131 template <
typename T> T *getDevice();
132 template <
typename T>
const T *getDevice()
const;
135 virtual void rebind()
override;
142 void traverse(
const TraverseCallback& callback );
146 virtual void printSubtree()
const override;
147 void printSubtree(std::ostream& stream,
int depth=0)
const;
149 void configure(
Model *model);
153 virtual void buildNavigationTree(agxJson::Value& eNode)
const override;
158 void setDevice(
Device* device);
162 Object *findObject(
const Name& name,
Model *model,
size_t index)
const;
163 void triggerAddEvents(
Object *child);
164 void triggerRemoveEvents(
Object *child);
185 agxAssert(!parent || dynamic_cast<Component *>(parent));
201 template <
typename T>
204 Object *
object = this->findObject(name, T::ClassModel(), index);
205 T *result =
dynamic_cast<T *
>(object);
208 if (
object && !result && this->getNumObjects(name) > 1)
209 std::cout << this->getPath() <<
": Unable to cast child object \'" << name <<
"\' (" <<
object <<
") to type \'" <<
typeid(T).name() <<
"\', there are however other children with the same name so an unintended name clash could be the problem." << std::endl;
215 template <
typename T>
218 return const_cast<Component *
>(
this)->getObject<T>(name, index);
225 template <
typename T>
228 agxAssert(dynamic_cast<T *>(m_device.get()));
229 return static_cast<T *
>(m_device.get());
232 template <
typename T>
235 agxAssert(dynamic_cast<const T *>(m_device.get()));
236 return static_cast<const T *
>(m_device.get());
240 template <
typename T>
Representation of a path, a list of name components.
const agx::ObjectRefVector & getObjects() const
A component is an object containing other objects, enabling hierarchical structuring.
A model is an abstract representation of the class of an agx::Object.
#define AGX_DECLARE_POINTER_TYPES(type)
Representation of a name string.
ObjectEvent addObjectEvent
Vector containing 'raw' data.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::Object * getObject(const agx::Name &name, size_t index=0)
Smart pointer for handling referenced counted objects.
agx::Object * getContext()
static agx::Model * ClassModel()
agx::Device * getDevice()
Event2< Component *, Object * > ObjectEvent
Event when adding removing child objects.
Callback1< Object * > TraverseCallback
ObjectEvent removeObjectEvent
#define AGX_DECLARE_VECTOR_TYPES(type)
Inheritance with partial specialization due to bug with ref_ptr containers.
An agx::Device is an abstract representation of a device on which data can be stored and processed...
Base class for ComponentVisitors.
agx::Object is a refcounted object with a name.