JUCE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions | List of all members
DynamicObject Class Reference

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

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

Constructor & Destructor Documentation

DynamicObject::DynamicObject ( )
virtual DynamicObject::~DynamicObject ( )
virtual

Destructor.

Member Function Documentation

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.

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

Returns a named property.

This returns a void if no such property exists.

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

Sets a named property.

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

Removes a named property.

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.

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

setMethod ("doSomething", (var::MethodFunction) &MyClass::doSomething);
void DynamicObject::clear ( )

Removes all properties and methods from the object.

NamedValueSet& DynamicObject::getProperties ( )
noexcept

Returns the NamedValueSet that holds the object's properties.


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