Represents a dynamically implemented object. More...
#include <juce_DynamicObject.h>
Public Types | |
using | Ptr = ReferenceCountedObjectPtr< DynamicObject > |
Public Member Functions | |
DynamicObject () | |
DynamicObject (const DynamicObject &) | |
~DynamicObject () override | |
void | clear () |
Removes all properties and methods from the object. More... | |
virtual Ptr | clone () |
Returns a clone of this object. More... | |
void | cloneAllProperties () |
Calls var::clone() on all the properties that this object contains. More... | |
void | decReferenceCount () noexcept |
Decreases the object's reference count. More... | |
bool | decReferenceCountWithoutDeleting () noexcept |
Decreases the object's reference count. More... | |
NamedValueSet & | getProperties () noexcept |
Returns the NamedValueSet that holds the object's properties. More... | |
virtual const var & | getProperty (const Identifier &propertyName) const |
Returns a named property. More... | |
int | getReferenceCount () const noexcept |
Returns the object's current reference count. More... | |
virtual bool | hasMethod (const Identifier &methodName) const |
Checks whether this object has the specified method. More... | |
virtual bool | hasProperty (const Identifier &propertyName) const |
Returns true if the object has a property with this name. More... | |
void | incReferenceCount () noexcept |
Increments the object's reference count. More... | |
virtual var | invokeMethod (Identifier methodName, const var::NativeFunctionArgs &args) |
Invokes a named method on this object. More... | |
virtual void | removeProperty (const Identifier &propertyName) |
Removes a named property. More... | |
void | setMethod (Identifier methodName, var::NativeFunction function) |
Adds a method to the class. More... | |
virtual void | setProperty (const Identifier &propertyName, const var &newValue) |
Sets a named property. More... | |
virtual void | writeAsJSON (OutputStream &, int indentLevel, bool allOnOneLine, int maximumDecimalPlaces) |
Writes this object to a text stream in JSON format. More... | |
Protected Member Functions | |
void | resetReferenceCount () noexcept |
Resets the reference count to zero without deleting the object. More... | |
Private Attributes | |
NamedValueSet | properties |
Atomic< int > | refCount { 0 } |
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.
@tags{Core}
juce::DynamicObject::DynamicObject | ( | ) |
juce::DynamicObject::DynamicObject | ( | const DynamicObject & | ) |
|
override |
void juce::DynamicObject::clear | ( | ) |
Removes all properties and methods from the object.
|
virtual |
Returns a clone of this object.
The default implementation of this method just returns a new DynamicObject with a (deep) copy of all of its properties. Subclasses can override this to implement their own custom copy routines.
void juce::DynamicObject::cloneAllProperties | ( | ) |
Calls var::clone() on all the properties that this object contains.
|
inlinenoexceptinherited |
Decreases the object's reference count.
If the count gets to zero, the object will be deleted.
References jassert.
|
inlinenoexceptinherited |
Decreases the object's reference count.
If the count gets to zero, the object will not be deleted, but this method will return true, allowing the caller to take care of deletion.
References jassert.
|
inlinenoexcept |
Returns the NamedValueSet that holds the object's properties.
Referenced by juce::varObjectToNSDictionary().
|
virtual |
Returns a named property.
This returns var() if no such property exists.
|
inlinenoexceptinherited |
Returns the object's current reference count.
|
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 |
Returns true if the object has a property with this name.
Note that if the property is actually a method, this will return false.
|
inlinenoexceptinherited |
Increments the object's reference count.
This is done automatically by the smart pointer, but is public just in case it's needed for nefarious purposes.
Referenced by juce::ReferenceCountedObjectPtr< juce::ReferenceCountedObject >::operator=().
|
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 properties.
|
virtual |
Removes a named property.
|
inlineprotectednoexceptinherited |
Resets the reference count to zero without deleting the object.
You should probably never need to use this!
void juce::DynamicObject::setMethod | ( | Identifier | methodName, |
var::NativeFunction | function | ||
) |
Adds a method to the class.
This is basically the same as calling setProperty (methodName, (var::NativeFunction) myFunction), but helps to avoid accidentally invoking the wrong type of var constructor. It also makes the code easier to read.
|
virtual |
Sets a named property.
|
virtual |
Writes this object to a text stream in JSON format.
This method is used by JSON::toString and JSON::writeToStream, and you should never need to call it directly, but it's virtual so that custom object types can stringify themselves appropriately.
|
private |