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;
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;
119 template <
typename T>
131 template <
typename T> T *getDevice();
132 template <
typename T>
const T *getDevice()
const;
162 Object *findObject(
const Name& name,
Model *model,
size_t index)
const;
163 void triggerAddEvents(
Object *child);
164 void triggerRemoveEvents(
Object *child);
201 template <
typename T>
204 Object *
object = this->findObject(name, T::ClassModel(), index);
205 T *result =
dynamic_cast<T *
>(object);
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>
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGX_DECLARE_VECTOR_TYPES(type)
Templated callback with one argument.
Base class for ComponentVisitors.
A component is an object containing other objects, enabling hierarchical structuring.
Component(const agx::Name &name=agx::Name(), agx::Model *model=agx::Component::ClassModel(), agx::Device *device=nullptr)
static Component * load(TiXmlElement *eComponent, Device *device)
virtual void printSubtree() const override
virtual void buildNavigationTree(agxJson::Value &eNode) const override
agx::Device * getDevice()
static Component * load(const String &path, const Path &_namespace=Path())
void printSubtree(std::ostream &stream, int depth=0) const
void getObjects(agx::ObjectPtrVector &result, const agx::Model *model, bool recursive=false) const
ObjectEvent addObjectEvent
virtual String autoComplete(const String &partialName, StringVector &matchingNames) const
size_t getNumObjects(const agx::Name &name) const
virtual void configure(TiXmlElement *eComponent) override
void removeObject(const agx::Name &name, size_t index=0)
Remove an object with a specified name (and optional index) from the component.
static Component * load(const String &path, Device *device, const Path &_namespace=Path())
void configure(Model *model)
static Component * load(const Path &path, const Name &implementation, Device *device, const Path &_namespace=Path())
agx::Object * getObject(const agx::Name &name, size_t index=0)
void traverse(ComponentVisitor *)
String expandAutoCompletionMatch(const String &query, const StringVector &matchingNames) const
virtual void removeObject(agx::Object *object)
Remove an object from the component.
virtual void addObject(agx::Object *object, bool assignContext=true)
Add an object to the component.
Event2< Component *, Object * > ObjectEvent
Event when adding removing child objects.
virtual Object * getResourceImpl(const Path &path, agx::Model *model) override
const agx::ObjectRefVector & getObjects() const
static Component * _load(TiXmlElement *eComponent, Device *device)
virtual void rebind() override
virtual void snapshot(TiXmlNode *eParent, const String &directory) const override
ObjectEvent removeObjectEvent
void setDevice(Device *device)
Callback1< Object * > TraverseCallback
void traverse(const TraverseCallback &callback)
static agx::Model * ClassModel()
void removeAllObjects()
Remove all components.
An agx::Device is an abstract representation of a device on which data can be stored and processed.
An event with two arguments.
Inheritance with partial specialization due to bug with ref_ptr containers.
A model is an abstract representation of the class of an agx::Object.
Representation of a name string.
agx::Object is a refcounted object with a name.
agx::Path getPath() const
agx::Object * getContext()
Representation of a path, a list of name components.
Vector containing 'raw' data.
Smart pointer for handling referenced counted objects.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.