Represents a dynamically implemented object. More...
Inherits ReferenceCountedObject.
Public Types | |
| typedef ReferenceCountedObjectPtr < DynamicObject > | Ptr |
Public Member Functions | |
| DynamicObject () | |
| virtual | ~DynamicObject () |
| Destructor. | |
| virtual bool | hasProperty (const Identifier &propertyName) const |
| Returns true if the object has a property with this name. | |
| virtual var | getProperty (const Identifier &propertyName) const |
| Returns a named property. | |
| virtual void | setProperty (const Identifier &propertyName, const var &newValue) |
| Sets a named property. | |
| virtual void | removeProperty (const Identifier &propertyName) |
| Removes a named property. | |
| virtual bool | hasMethod (const Identifier &methodName) const |
| Checks whether this object has the specified method. | |
| virtual var | invokeMethod (const Identifier &methodName, const var *parameters, int numParameters) |
| Invokes a named method on this object. | |
| void | setMethod (const Identifier &methodName, var::MethodFunction methodFunction) |
| Sets up a method. | |
| void | clear () |
| Removes all properties and methods from the object. | |
| NamedValueSet & | getProperties () noexcept |
| Returns the NamedValueSet that holds the object's properties. | |
Public Member Functions inherited from ReferenceCountedObject | |
| void | incReferenceCount () noexcept |
| Increments the object's reference count. | |
| void | decReferenceCount () noexcept |
| Decreases the object's reference count. | |
| int | getReferenceCount () const noexcept |
| Returns the object's current reference count. | |
Additional Inherited Members | |
Protected Member Functions inherited from ReferenceCountedObject | |
| ReferenceCountedObject () | |
| Creates the reference-counted object (with an initial ref count of zero). | |
| virtual | ~ReferenceCountedObject () |
| Destructor. | |
| void | resetReferenceCount () noexcept |
| Resets the reference count to zero without deleting the object. | |
Represents a dynamically implemented object.
This class is primarily intended for wrapping scripting language objects, but could be used for other purposes.
An instance of a DynamicObject can be used to store named properties, and by subclassing hasMethod() and invokeMethod(), you can give your object methods.
| DynamicObject::DynamicObject | ( | ) |
|
virtual |
Destructor.
|
virtual |
Returns true if the object has a property with this name.
Note that if the property is actually a method, this will return false.
|
virtual |
Returns a named property.
This returns a void if no such property exists.
|
virtual |
Sets a named property.
|
virtual |
Removes a named property.
|
virtual |
Checks whether this object has the specified method.
The default implementation of this just checks whether there's a property with this name that's actually a method, but this can be overridden for building objects with dynamic invocation.
|
virtual |
Invokes a named method on this object.
The default implementation looks up the named property, and if it's a method call, then it invokes it.
This method is virtual to allow more dynamic invocation to used for objects where the methods may not already be set as properies.
| void DynamicObject::setMethod | ( | const Identifier & | methodName, |
| var::MethodFunction | methodFunction | ||
| ) |
Sets up a method.
This is basically the same as calling setProperty (methodName, (var::MethodFunction) myFunction), but helps to avoid accidentally invoking the wrong type of var constructor. It also makes the code easier to read,
The compiler will probably force you to use an explicit cast your method to a (var::MethodFunction), e.g.
| void DynamicObject::clear | ( | ) |
Removes all properties and methods from the object.
|
noexcept |
Returns the NamedValueSet that holds the object's properties.