26 DynamicObject::DynamicObject()
30 DynamicObject::DynamicObject (
const DynamicObject& other)
35 DynamicObject::~DynamicObject()
41 const var*
const v = properties.getVarPointer (propertyName);
42 return v !=
nullptr && ! v->isMethod();
47 return properties [propertyName];
52 properties.set (propertyName, newValue);
57 properties.remove (propertyName);
62 return getProperty (methodName).isMethod();
67 if (
auto function = properties [method].getNativeFunction())
68 return function (args);
75 properties.set (name,
var (
function));
85 for (
int i = properties.size(); --i >= 0;)
86 if (
auto* v = properties.getVarPointerAt (i))
93 d->cloneAllProperties();
103 const int numValues = properties.size();
105 for (
int i = 0; i < numValues; ++i)
108 JSONFormatter::writeSpaces (out, indentLevel + JSONFormatter::indentSize);
111 JSONFormatter::writeString (out, properties.getName (i));
113 JSONFormatter::write (out, properties.getValueAt (i), indentLevel + JSONFormatter::indentSize, allOnOneLine, maximumDecimalPlaces);
115 if (i < numValues - 1)
120 out <<
',' << newLine;
122 else if (! allOnOneLine)
127 JSONFormatter::writeSpaces (out, indentLevel);
void clear()
Removes all properties and methods from the object.
virtual void removeProperty(const Identifier &propertyName)
Removes a named property.
virtual Ptr clone()
Returns a clone of this object.
Represents a string identifier, designed for accessing properties by name.
void setMethod(Identifier methodName, var::NativeFunction function)
Adds a method to the class.
ReferenceCountedObject()=default
Creates the reference-counted object (with an initial ref count of zero).
A variant class, that can be used to hold a range of primitive values.
virtual const var & getProperty(const Identifier &propertyName) const
Returns a named property.
virtual void setProperty(const Identifier &propertyName, const var &newValue)
Sets a named property.
virtual bool hasProperty(const Identifier &propertyName) const
Returns true if the object has a property with this name.
Represents a dynamically implemented object.
The base class for streams that write data to some kind of destination.
This structure is passed to a NativeFunction callback, and contains invocation details about the func...
void cloneAllProperties()
Calls var::clone() on all the properties that this object contains.
virtual void writeAsJSON(OutputStream &, int indentLevel, bool allOnOneLine, int maximumDecimalPlaces)
Writes this object to a text stream in JSON format.
virtual var invokeMethod(Identifier methodName, const var::NativeFunctionArgs &args)
Invokes a named method on this object.
virtual bool hasMethod(const Identifier &methodName) const
Checks whether this object has the specified method.