mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-20 01:14:20 +00:00
Modified the return types of some var and DynamicObject operator[] methods to avoid a common pitfall.
This commit is contained in:
parent
24bce65869
commit
7cfcf7940d
4 changed files with 7 additions and 7 deletions
|
|
@ -45,7 +45,7 @@ bool DynamicObject::hasProperty (const Identifier& propertyName) const
|
|||
return v != nullptr && ! v->isMethod();
|
||||
}
|
||||
|
||||
var DynamicObject::getProperty (const Identifier& propertyName) const
|
||||
const var& DynamicObject::getProperty (const Identifier& propertyName) const
|
||||
{
|
||||
return properties [propertyName];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public:
|
|||
/** Returns a named property.
|
||||
This returns var::null if no such property exists.
|
||||
*/
|
||||
virtual var getProperty (const Identifier& propertyName) const;
|
||||
virtual const var& getProperty (const Identifier& propertyName) const;
|
||||
|
||||
/** Sets a named property. */
|
||||
virtual void setProperty (const Identifier& propertyName, const var& newValue);
|
||||
|
|
|
|||
|
|
@ -576,15 +576,15 @@ var var::clone() const noexcept
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
var var::operator[] (const Identifier propertyName) const
|
||||
const var& var::operator[] (Identifier propertyName) const
|
||||
{
|
||||
if (DynamicObject* const o = getDynamicObject())
|
||||
return o->getProperty (propertyName);
|
||||
|
||||
return var();
|
||||
return var::null;
|
||||
}
|
||||
|
||||
var var::operator[] (const char* const propertyName) const
|
||||
const var& var::operator[] (const char* const propertyName) const
|
||||
{
|
||||
return operator[] (Identifier (propertyName));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,9 +242,9 @@ public:
|
|||
|
||||
//==============================================================================
|
||||
/** If this variant is an object, this returns one of its properties. */
|
||||
var operator[] (Identifier propertyName) const;
|
||||
const var& operator[] (Identifier propertyName) const;
|
||||
/** If this variant is an object, this returns one of its properties. */
|
||||
var operator[] (const char* propertyName) const;
|
||||
const var& operator[] (const char* propertyName) const;
|
||||
/** If this variant is an object, this returns one of its properties, or a default
|
||||
fallback value if the property is not set. */
|
||||
var getProperty (Identifier propertyName, const var& defaultReturnValue) const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue