Loading...
Searching...
No Matches
juce::DynamicObject Class Reference

## 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.

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

- juce_core/containers/juce_DynamicObject.h

Inheritance diagram for juce::DynamicObject:

## Public Types

using | Ptr = ReferenceCountedObjectPtr<DynamicObject>

## Public Member Functions

| DynamicObject ()
| DynamicObject (const DynamicObject &)
bool | hasProperty (const Identifier &propertyName) const
| Returns true if the object has a property with this name.
const var & | getProperty (const Identifier &propertyName) const
| Returns a named property.
void | setProperty (const Identifier &propertyName, const var &newValue)
| Sets a named property.
void | removeProperty (const Identifier &propertyName)
| Removes a named property.
bool | hasMethod (const Identifier &methodName) const
| Checks whether this object has a property with the given name that has a value of type NativeFunction.
var | invokeMethod (Identifier methodName, const var::NativeFunctionArgs &args)
| Invokes a named method on this object.
void | setMethod (Identifier methodName, var::NativeFunction function)
| Adds a method to the class.
void | clear ()
| Removes all properties and methods from the object.
NamedValueSet & | getProperties () noexcept
| Returns the NamedValueSet that holds the object's properties.
const NamedValueSet & | getProperties () const noexcept
| Returns the NamedValueSet that holds the object's properties.
void | cloneAllProperties ()
| Calls var::clone() on all the properties that this object contains.
virtual std::unique_ptr< DynamicObject > | clone () const
| Returns a clone of this object.
virtual void | writeAsJSON (OutputStream &, const JSON::FormatOptions &)
| Writes this object to a text stream in JSON format.
bool | equals (const DynamicObject &other) const
| Returns true if the properties of this object match the properties of the specified object, or false otherwise.
bool | operator== (const DynamicObject &other) const
| Returns true if the properties of this object match the properties of the specified object, or false otherwise.
bool | operator!= (const DynamicObject &other) const
| The inverse of operator==().
Public Member Functions inherited from juce::ReferenceCountedObject
void | incReferenceCount () noexcept
| Increments the object's reference count.
void | decReferenceCount () noexcept
| Decreases the object's reference count.
bool | decReferenceCountWithoutDeleting () 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 juce::ReferenceCountedObject
| ReferenceCountedObject ()=default
| Creates the reference-counted object (with an initial ref count of zero).
| ReferenceCountedObject (const ReferenceCountedObject &) noexcept
| Copying from another object does not affect this one's reference-count.
| ReferenceCountedObject (ReferenceCountedObject &&) noexcept
| Copying from another object does not affect this one's reference-count.
ReferenceCountedObject & | operator= (const ReferenceCountedObject &) noexcept
| Copying from another object does not affect this one's reference-count.
ReferenceCountedObject & | operator= (ReferenceCountedObject &&) noexcept
| Copying from another object does not affect this one's reference-count.
virtual | ~ReferenceCountedObject ()
| Destructor.
void | resetReferenceCount () noexcept
| Resets the reference count to zero without deleting the object.

## Member Typedef Documentation

## Ptr

using juce::DynamicObject::Ptr = ReferenceCountedObjectPtr<DynamicObject>

## Constructors and Destructors

## DynamicObject() [1/2]

juce::DynamicObject::DynamicObject | ( |  | ) |

Referenced by DynamicObject(), equals(), operator!=(), and operator==().

## DynamicObject() [2/2]

juce::DynamicObject::DynamicObject | ( | const DynamicObject & |  | ) |

References DynamicObject().

## Member Functions

## hasProperty()

bool juce::DynamicObject::hasProperty | ( | const Identifier & | propertyName | ) | const

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()

const var & juce::DynamicObject::getProperty | ( | const Identifier & | propertyName | ) | const

Returns a named property.

This returns var() if no such property exists.

## setProperty()

void juce::DynamicObject::setProperty | ( | const Identifier & | propertyName,
|  | const var & | newValue )

Sets a named property.

## removeProperty()

void juce::DynamicObject::removeProperty | ( | const Identifier & | propertyName | ) |

Removes a named property.

## hasMethod()

bool juce::DynamicObject::hasMethod | ( | const Identifier & | methodName | ) | const

Checks whether this object has a property with the given name that has a value of type NativeFunction.

## invokeMethod()

var juce::DynamicObject::invokeMethod | ( | Identifier | methodName,
|  | const var::NativeFunctionArgs & | args )

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.

## setMethod()

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.

## clear()

void juce::DynamicObject::clear | ( |  | ) |

Removes all properties and methods from the object.

## getProperties() [1/2]

NamedValueSet & juce::DynamicObject::getProperties | ( |  | ) |

inline noexcept

Returns the NamedValueSet that holds the object's properties.

## getProperties() [2/2]

const NamedValueSet & juce::DynamicObject::getProperties | ( |  | ) | const

inline noexcept

Returns the NamedValueSet that holds the object's properties.

## cloneAllProperties()

void juce::DynamicObject::cloneAllProperties | ( |  | ) |

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

## clone()

virtual std::unique_ptr< DynamicObject > juce::DynamicObject::clone | ( |  | ) | const

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 juce::DynamicObject::writeAsJSON | ( | OutputStream & | ,
|  | const JSON::FormatOptions & | )

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.

## equals()

bool juce::DynamicObject::equals | ( | const DynamicObject & | other | ) | const

Returns true if the properties of this object match the properties of the specified object, or false otherwise.

References DynamicObject().

Referenced by operator==().

## operator==()

bool juce::DynamicObject::operator== | ( | const DynamicObject & | other | ) | const

inline

Returns true if the properties of this object match the properties of the specified object, or false otherwise.

References DynamicObject(), and equals().

## operator!=()

bool juce::DynamicObject::operator!= | ( | const DynamicObject & | other | ) | const

inline

The inverse of operator==().

References DynamicObject().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited