1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added an option JUCE_ALLOW_STATIC_NULL_VARIABLES that can be used to turn off dangerous statics like String::empty, var::null, etc.

This commit is contained in:
jules 2016-09-16 12:02:35 +01:00
parent d03755c9e0
commit 9fa0d49be7
145 changed files with 407 additions and 343 deletions

View file

@ -627,7 +627,9 @@ ValueTree::ValueTree() noexcept
{
}
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
const ValueTree ValueTree::invalid;
#endif
ValueTree::ValueTree (const Identifier& type) : object (new ValueTree::SharedObject (type))
{
@ -721,20 +723,30 @@ ValueTree ValueTree::getParent() const noexcept
ValueTree ValueTree::getSibling (const int delta) const noexcept
{
if (object == nullptr || object->parent == nullptr)
return invalid;
return ValueTree();
const int index = object->parent->indexOf (*this) + delta;
return ValueTree (object->parent->children.getObjectPointer (index));
}
static const var& getNullVarRef() noexcept
{
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
return var::null;
#else
static var nullVar;
return nullVar;
#endif
}
const var& ValueTree::operator[] (const Identifier& name) const noexcept
{
return object == nullptr ? var::null : object->properties[name];
return object == nullptr ? getNullVarRef() : object->properties[name];
}
const var& ValueTree::getProperty (const Identifier& name) const noexcept
{
return object == nullptr ? var::null : object->properties[name];
return object == nullptr ? getNullVarRef() : object->properties[name];
}
var ValueTree::getProperty (const Identifier& name, const var& defaultReturnValue) const

View file

@ -523,10 +523,13 @@ public:
}
}
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
/** An invalid ValueTree that can be used if you need to return one as an error condition, etc.
This invalid object is equivalent to ValueTree created with its default constructor.
This invalid object is equivalent to ValueTree created with its default constructor, but
you should always prefer to avoid it and use ValueTree() or {} instead.
*/
static const ValueTree invalid;
#endif
/** Returns the total number of references to the shared underlying data structure that this
ValueTree is using.