JUCE
Public Types | Public Member Functions | List of all members
DynamicObject Class Reference

Represents a dynamically implemented object. More...

Inheritance diagram for DynamicObject:

Public Types

using Ptr = ReferenceCountedObjectPtr< DynamicObject >
 

Public Member Functions

 DynamicObject ()
 
 DynamicObject (const DynamicObject &)
 
 ~DynamicObject () override
 
virtual bool hasProperty (const Identifier &propertyName) const
 Returns true if the object has a property with this name. More...
 
virtual const vargetProperty (const Identifier &propertyName) const
 Returns a named property. More...
 
virtual void setProperty (const Identifier &propertyName, const var &newValue)
 Sets a named property. More...
 
virtual void removeProperty (const Identifier &propertyName)
 Removes a named property. More...
 
virtual bool hasMethod (const Identifier &methodName) const
 Checks whether this object has the specified method. More...
 
virtual var invokeMethod (Identifier methodName, const var::NativeFunctionArgs &args)
 Invokes a named method on this object. More...
 
void setMethod (Identifier methodName, var::NativeFunction function)
 Adds a method to the class. More...
 
void clear ()
 Removes all properties and methods from the object. More...
 
NamedValueSetgetProperties () noexcept
 Returns the NamedValueSet that holds the object's properties. More...
 
void cloneAllProperties ()
 Calls var::clone() on all the properties that this object contains. More...
 
virtual Ptr clone ()
 Returns a clone of this object. More...
 
virtual void writeAsJSON (OutputStream &, int indentLevel, bool allOnOneLine, int maximumDecimalPlaces)
 Writes this object to a text stream in JSON format. More...
 
- Public Member Functions inherited from ReferenceCountedObject
void incReferenceCount () noexcept
 Increments the object's reference count. More...
 
void decReferenceCount () noexcept
 Decreases the object's reference count. More...
 
bool decReferenceCountWithoutDeleting () noexcept
 Decreases the object's reference count. More...
 
int getReferenceCount () const noexcept
 Returns the object's current reference count. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ReferenceCountedObject
 ReferenceCountedObject ()=default
 Creates the reference-counted object (with an initial ref count of zero). More...
 
 ReferenceCountedObject (const ReferenceCountedObject &) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
 ReferenceCountedObject (ReferenceCountedObject &&) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
ReferenceCountedObjectoperator= (const ReferenceCountedObject &) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
ReferenceCountedObjectoperator= (ReferenceCountedObject &&) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
virtual ~ReferenceCountedObject ()
 Destructor. More...
 
void resetReferenceCount () noexcept
 Resets the reference count to zero without deleting the object. More...
 

Detailed Description

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.

Member Typedef Documentation

◆ Ptr

Constructor & Destructor Documentation

◆ DynamicObject() [1/2]

DynamicObject::DynamicObject ( )

◆ DynamicObject() [2/2]

DynamicObject::DynamicObject ( const DynamicObject )

◆ ~DynamicObject()

DynamicObject::~DynamicObject ( )
override

Member Function Documentation

◆ hasProperty()

virtual bool DynamicObject::hasProperty ( const Identifier propertyName) const
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.

◆ getProperty()

virtual const var& DynamicObject::getProperty ( const Identifier propertyName) const
virtual

Returns a named property.

This returns var() if no such property exists.

◆ setProperty()

virtual void DynamicObject::setProperty ( const Identifier propertyName,
const var newValue 
)
virtual

Sets a named property.

◆ removeProperty()

virtual void DynamicObject::removeProperty ( const Identifier propertyName)
virtual

Removes a named property.

◆ hasMethod()

virtual bool DynamicObject::hasMethod ( const Identifier methodName) const
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.

◆ invokeMethod()

virtual var DynamicObject::invokeMethod ( Identifier  methodName,
const var::NativeFunctionArgs args 
)
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.

◆ setMethod()

void 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,

◆ clear()

void DynamicObject::clear ( )

Removes all properties and methods from the object.

◆ getProperties()

NamedValueSet& DynamicObject::getProperties ( )
noexcept

Returns the NamedValueSet that holds the object's properties.

References JUCE_LEAK_DETECTOR.

◆ cloneAllProperties()

void DynamicObject::cloneAllProperties ( )

Calls var::clone() on all the properties that this object contains.

◆ clone()

virtual Ptr DynamicObject::clone ( )
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.

◆ writeAsJSON()

virtual void DynamicObject::writeAsJSON ( OutputStream ,
int  indentLevel,
bool  allOnOneLine,
int  maximumDecimalPlaces 
)
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.


The documentation for this class was generated from the following file: