mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-20 01:14:20 +00:00
New class StringPool. Removed the class var::identifier from its parent class, and renamed it "Identifier" - I've left a typedef in var to allow old code to still work, but I'll remove this at some point, so please switch to using the new classname directly. Jucer development.
This commit is contained in:
parent
ed97872c1a
commit
b46e94cffd
90 changed files with 2839 additions and 1733 deletions
|
|
@ -39,40 +39,40 @@ DynamicObject::~DynamicObject()
|
|||
{
|
||||
}
|
||||
|
||||
bool DynamicObject::hasProperty (const var::identifier& propertyName) const
|
||||
bool DynamicObject::hasProperty (const Identifier& propertyName) const
|
||||
{
|
||||
var* const v = properties.getItem (propertyName);
|
||||
return v != 0 && ! v->isMethod();
|
||||
}
|
||||
|
||||
const var DynamicObject::getProperty (const var::identifier& propertyName) const
|
||||
const var DynamicObject::getProperty (const Identifier& propertyName) const
|
||||
{
|
||||
return properties [propertyName];
|
||||
}
|
||||
|
||||
void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
|
||||
void DynamicObject::setProperty (const Identifier& propertyName, const var& newValue)
|
||||
{
|
||||
properties.set (propertyName, newValue);
|
||||
}
|
||||
|
||||
void DynamicObject::removeProperty (const var::identifier& propertyName)
|
||||
void DynamicObject::removeProperty (const Identifier& propertyName)
|
||||
{
|
||||
properties.remove (propertyName);
|
||||
}
|
||||
|
||||
bool DynamicObject::hasMethod (const var::identifier& methodName) const
|
||||
bool DynamicObject::hasMethod (const Identifier& methodName) const
|
||||
{
|
||||
return getProperty (methodName).isMethod();
|
||||
}
|
||||
|
||||
const var DynamicObject::invokeMethod (const var::identifier& methodName,
|
||||
const var DynamicObject::invokeMethod (const Identifier& methodName,
|
||||
const var* parameters,
|
||||
int numParameters)
|
||||
{
|
||||
return properties [methodName].invoke (var (this), parameters, numParameters);
|
||||
}
|
||||
|
||||
void DynamicObject::setMethod (const var::identifier& name,
|
||||
void DynamicObject::setMethod (const Identifier& name,
|
||||
var::MethodFunction methodFunction)
|
||||
{
|
||||
properties.set (name, var (methodFunction));
|
||||
|
|
|
|||
|
|
@ -54,19 +54,19 @@ public:
|
|||
/** 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 bool hasProperty (const var::identifier& propertyName) const;
|
||||
virtual bool hasProperty (const Identifier& propertyName) const;
|
||||
|
||||
/** Returns a named property.
|
||||
|
||||
This returns a void if no such property exists.
|
||||
*/
|
||||
virtual const var getProperty (const var::identifier& propertyName) const;
|
||||
virtual const var getProperty (const Identifier& propertyName) const;
|
||||
|
||||
/** Sets a named property. */
|
||||
virtual void setProperty (const var::identifier& propertyName, const var& newValue);
|
||||
virtual void setProperty (const Identifier& propertyName, const var& newValue);
|
||||
|
||||
/** Removes a named property. */
|
||||
virtual void removeProperty (const var::identifier& propertyName);
|
||||
virtual void removeProperty (const Identifier& propertyName);
|
||||
|
||||
//==============================================================================
|
||||
/** Checks whether this object has the specified method.
|
||||
|
|
@ -75,7 +75,7 @@ public:
|
|||
with this name that's actually a method, but this can be overridden for
|
||||
building objects with dynamic invocation.
|
||||
*/
|
||||
virtual bool hasMethod (const var::identifier& methodName) const;
|
||||
virtual bool hasMethod (const Identifier& methodName) const;
|
||||
|
||||
/** Invokes a named method on this object.
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ public:
|
|||
This method is virtual to allow more dynamic invocation to used for objects
|
||||
where the methods may not already be set as properies.
|
||||
*/
|
||||
virtual const var invokeMethod (const var::identifier& methodName,
|
||||
virtual const var invokeMethod (const Identifier& methodName,
|
||||
const var* parameters,
|
||||
int numParameters);
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ public:
|
|||
setMethod ("doSomething", (var::MethodFunction) &MyClass::doSomething);
|
||||
@endcode
|
||||
*/
|
||||
void setMethod (const var::identifier& methodName,
|
||||
void setMethod (const Identifier& methodName,
|
||||
var::MethodFunction methodFunction);
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
88
src/containers/juce_Identifier.cpp
Normal file
88
src/containers/juce_Identifier.cpp
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-10 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#include "../core/juce_StandardHeader.h"
|
||||
|
||||
BEGIN_JUCE_NAMESPACE
|
||||
|
||||
#include "juce_Identifier.h"
|
||||
#include "../utilities/juce_DeletedAtShutdown.h"
|
||||
#include "../core/juce_Singleton.h"
|
||||
#include "../text/juce_StringPool.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
class Identifier::Pool : public DeletedAtShutdown
|
||||
{
|
||||
public:
|
||||
Pool() {}
|
||||
~Pool() {}
|
||||
|
||||
StringPool pool;
|
||||
|
||||
juce_DeclareSingleton_SingleThreaded_Minimal (Pool);
|
||||
};
|
||||
|
||||
juce_ImplementSingleton_SingleThreaded (Identifier::Pool);
|
||||
|
||||
|
||||
//==============================================================================
|
||||
Identifier::Identifier() throw()
|
||||
: name (0)
|
||||
{
|
||||
}
|
||||
|
||||
Identifier::Identifier (const Identifier& other) throw()
|
||||
: name (other.name)
|
||||
{
|
||||
}
|
||||
|
||||
Identifier& Identifier::operator= (const Identifier& other) throw()
|
||||
{
|
||||
name = other.name;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Identifier::Identifier (const String& name_)
|
||||
: name (Identifier::Pool::getInstance()->pool.getPooledString (name_))
|
||||
{
|
||||
/* An Identifier string must be suitable for use as a script variable or XML
|
||||
attribute, so it can only contain this limited set of characters.. */
|
||||
jassert (name_.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name_.isNotEmpty());
|
||||
}
|
||||
|
||||
Identifier::Identifier (const char* const name_)
|
||||
: name (Identifier::Pool::getInstance()->pool.getPooledString (name_))
|
||||
{
|
||||
/* An Identifier string must be suitable for use as a script variable or XML
|
||||
attribute, so it can only contain this limited set of characters.. */
|
||||
jassert (toString().containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && toString().isNotEmpty());
|
||||
}
|
||||
|
||||
Identifier::~Identifier()
|
||||
{
|
||||
}
|
||||
|
||||
END_JUCE_NAMESPACE
|
||||
85
src/containers/juce_Identifier.h
Normal file
85
src/containers/juce_Identifier.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-10 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef __JUCE_IDENTIFIER_JUCEHEADER__
|
||||
#define __JUCE_IDENTIFIER_JUCEHEADER__
|
||||
|
||||
#include "../text/juce_String.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Represents a string identifier, designed for accessing properties by name.
|
||||
|
||||
Identifier objects are very light and fast to copy, but slower to initialise
|
||||
from a string, so it's much faster to keep a static identifier object to refer
|
||||
to frequently-used names, rather than constructing them each time you need it.
|
||||
|
||||
@see NamedPropertySet, ValueTree
|
||||
*/
|
||||
class JUCE_API Identifier
|
||||
{
|
||||
public:
|
||||
/** Creates a null identifier. */
|
||||
Identifier() throw();
|
||||
|
||||
/** Creates an identifier with a specified name.
|
||||
Because this name may need to be used in contexts such as script variables or XML
|
||||
tags, it must only contain ascii letters and digits, or the underscore character.
|
||||
*/
|
||||
Identifier (const char* name);
|
||||
|
||||
/** Creates an identifier with a specified name.
|
||||
Because this name may need to be used in contexts such as script variables or XML
|
||||
tags, it must only contain ascii letters and digits, or the underscore character.
|
||||
*/
|
||||
Identifier (const String& name);
|
||||
|
||||
/** Creates a copy of another identifier. */
|
||||
Identifier (const Identifier& other) throw();
|
||||
|
||||
/** Creates a copy of another identifier. */
|
||||
Identifier& operator= (const Identifier& other) throw();
|
||||
|
||||
/** Destructor */
|
||||
~Identifier();
|
||||
|
||||
/** Compares two identifiers. This is a very fast operation. */
|
||||
inline bool operator== (const Identifier& other) const throw() { return name == other.name; }
|
||||
|
||||
/** Compares two identifiers. This is a very fast operation. */
|
||||
inline bool operator!= (const Identifier& other) const throw() { return name != other.name; }
|
||||
|
||||
const String toString() const { return name; }
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
const juce_wchar* name;
|
||||
|
||||
class Pool;
|
||||
};
|
||||
|
||||
|
||||
#endif // __JUCE_IDENTIFIER_JUCEHEADER__
|
||||
|
|
@ -35,7 +35,7 @@ NamedValueSet::NamedValue::NamedValue() throw()
|
|||
{
|
||||
}
|
||||
|
||||
inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
|
||||
inline NamedValueSet::NamedValue::NamedValue (const Identifier& name_, const var& value_)
|
||||
: name (name_), value (value_)
|
||||
{
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ int NamedValueSet::size() const throw()
|
|||
return values.size();
|
||||
}
|
||||
|
||||
const var& NamedValueSet::operator[] (const var::identifier& name) const
|
||||
const var& NamedValueSet::operator[] (const Identifier& name) const
|
||||
{
|
||||
for (int i = values.size(); --i >= 0;)
|
||||
{
|
||||
|
|
@ -78,13 +78,13 @@ const var& NamedValueSet::operator[] (const var::identifier& name) const
|
|||
return var::null;
|
||||
}
|
||||
|
||||
const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
|
||||
const var NamedValueSet::getWithDefault (const Identifier& name, const var& defaultReturnValue) const
|
||||
{
|
||||
const var* v = getItem (name);
|
||||
return v != 0 ? *v : defaultReturnValue;
|
||||
}
|
||||
|
||||
var* NamedValueSet::getItem (const var::identifier& name) const
|
||||
var* NamedValueSet::getItem (const Identifier& name) const
|
||||
{
|
||||
for (int i = values.size(); --i >= 0;)
|
||||
{
|
||||
|
|
@ -97,7 +97,7 @@ var* NamedValueSet::getItem (const var::identifier& name) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool NamedValueSet::set (const var::identifier& name, const var& newValue)
|
||||
bool NamedValueSet::set (const Identifier& name, const var& newValue)
|
||||
{
|
||||
for (int i = values.size(); --i >= 0;)
|
||||
{
|
||||
|
|
@ -117,12 +117,12 @@ bool NamedValueSet::set (const var::identifier& name, const var& newValue)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool NamedValueSet::contains (const var::identifier& name) const
|
||||
bool NamedValueSet::contains (const Identifier& name) const
|
||||
{
|
||||
return getItem (name) != 0;
|
||||
}
|
||||
|
||||
bool NamedValueSet::remove (const var::identifier& name)
|
||||
bool NamedValueSet::remove (const Identifier& name)
|
||||
{
|
||||
for (int i = values.size(); --i >= 0;)
|
||||
{
|
||||
|
|
@ -136,7 +136,7 @@ bool NamedValueSet::remove (const var::identifier& name)
|
|||
return false;
|
||||
}
|
||||
|
||||
const var::identifier NamedValueSet::getName (const int index) const
|
||||
const Identifier NamedValueSet::getName (const int index) const
|
||||
{
|
||||
jassert (((unsigned int) index) < (unsigned int) values.size());
|
||||
return values [index].name;
|
||||
|
|
|
|||
|
|
@ -59,37 +59,37 @@ public:
|
|||
If the name isn't found, this will return a void variant.
|
||||
@see getProperty
|
||||
*/
|
||||
const var& operator[] (const var::identifier& name) const;
|
||||
const var& operator[] (const Identifier& name) const;
|
||||
|
||||
/** Tries to return the named value, but if no such value is found, this will
|
||||
instead return the supplied default value.
|
||||
*/
|
||||
const var getWithDefault (const var::identifier& name, const var& defaultReturnValue) const;
|
||||
const var getWithDefault (const Identifier& name, const var& defaultReturnValue) const;
|
||||
|
||||
/** Returns a pointer to the object holding a named value, or
|
||||
null if there is no value with this name. */
|
||||
var* getItem (const var::identifier& name) const;
|
||||
var* getItem (const Identifier& name) const;
|
||||
|
||||
/** Changes or adds a named value.
|
||||
@returns true if a value was changed or added; false if the
|
||||
value was already set the the value passed-in.
|
||||
*/
|
||||
bool set (const var::identifier& name, const var& newValue);
|
||||
bool set (const Identifier& name, const var& newValue);
|
||||
|
||||
/** Returns true if the set contains an item with the specified name. */
|
||||
bool contains (const var::identifier& name) const;
|
||||
bool contains (const Identifier& name) const;
|
||||
|
||||
/** Removes a value from the set.
|
||||
@returns true if a value was removed; false if there was no value
|
||||
with the name that was given.
|
||||
*/
|
||||
bool remove (const var::identifier& name);
|
||||
bool remove (const Identifier& name);
|
||||
|
||||
/** Returns the name of the value at a given index.
|
||||
The index must be between 0 and size() - 1. Out-of-range indexes will
|
||||
return an empty identifier.
|
||||
*/
|
||||
const var::identifier getName (int index) const;
|
||||
const Identifier getName (int index) const;
|
||||
|
||||
/** Returns the value of the item at a given index.
|
||||
The index must be between 0 and size() - 1. Out-of-range indexes will
|
||||
|
|
@ -107,9 +107,9 @@ private:
|
|||
struct NamedValue
|
||||
{
|
||||
NamedValue() throw();
|
||||
NamedValue (const var::identifier& name, const var& value);
|
||||
NamedValue (const Identifier& name, const var& value);
|
||||
|
||||
var::identifier name;
|
||||
Identifier name;
|
||||
var value;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ BEGIN_JUCE_NAMESPACE
|
|||
class ValueTree::SetPropertyAction : public UndoableAction
|
||||
{
|
||||
public:
|
||||
SetPropertyAction (const SharedObjectPtr& target_, const var::identifier& name_,
|
||||
SetPropertyAction (const SharedObjectPtr& target_, const Identifier& name_,
|
||||
const var& newValue_, const var& oldValue_,
|
||||
const bool isAddingNewProperty_, const bool isDeletingProperty_)
|
||||
: target (target_), name (name_), newValue (newValue_), oldValue (oldValue_),
|
||||
|
|
@ -90,7 +90,7 @@ public:
|
|||
|
||||
private:
|
||||
const SharedObjectPtr target;
|
||||
const var::identifier name;
|
||||
const Identifier name;
|
||||
const var newValue;
|
||||
var oldValue;
|
||||
const bool isAddingNewProperty : 1, isDeletingProperty : 1;
|
||||
|
|
@ -207,7 +207,7 @@ private:
|
|||
|
||||
|
||||
//==============================================================================
|
||||
ValueTree::SharedObject::SharedObject (const String& type_)
|
||||
ValueTree::SharedObject::SharedObject (const Identifier& type_)
|
||||
: type (type_), parent (0)
|
||||
{
|
||||
}
|
||||
|
|
@ -237,7 +237,7 @@ ValueTree::SharedObject::~SharedObject()
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
|
||||
void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const Identifier& property)
|
||||
{
|
||||
for (int i = valueTreesWithListeners.size(); --i >= 0;)
|
||||
{
|
||||
|
|
@ -247,7 +247,7 @@ void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const
|
|||
}
|
||||
}
|
||||
|
||||
void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
|
||||
void ValueTree::SharedObject::sendPropertyChangeMessage (const Identifier& property)
|
||||
{
|
||||
ValueTree tree (this);
|
||||
ValueTree::SharedObject* t = this;
|
||||
|
|
@ -302,17 +302,17 @@ void ValueTree::SharedObject::sendParentChangeMessage()
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
|
||||
const var& ValueTree::SharedObject::getProperty (const Identifier& name) const
|
||||
{
|
||||
return properties [name];
|
||||
}
|
||||
|
||||
const var ValueTree::SharedObject::getProperty (const var::identifier& name, const var& defaultReturnValue) const
|
||||
const var ValueTree::SharedObject::getProperty (const Identifier& name, const var& defaultReturnValue) const
|
||||
{
|
||||
return properties.getWithDefault (name, defaultReturnValue);
|
||||
}
|
||||
|
||||
void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
|
||||
void ValueTree::SharedObject::setProperty (const Identifier& name, const var& newValue, UndoManager* const undoManager)
|
||||
{
|
||||
if (undoManager == 0)
|
||||
{
|
||||
|
|
@ -335,12 +335,12 @@ void ValueTree::SharedObject::setProperty (const var::identifier& name, const va
|
|||
}
|
||||
}
|
||||
|
||||
bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
|
||||
bool ValueTree::SharedObject::hasProperty (const Identifier& name) const
|
||||
{
|
||||
return properties.contains (name);
|
||||
}
|
||||
|
||||
void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
|
||||
void ValueTree::SharedObject::removeProperty (const Identifier& name, UndoManager* const undoManager)
|
||||
{
|
||||
if (undoManager == 0)
|
||||
{
|
||||
|
|
@ -360,7 +360,7 @@ void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManage
|
|||
{
|
||||
while (properties.size() > 0)
|
||||
{
|
||||
const var::identifier name (properties.getName (properties.size() - 1));
|
||||
const Identifier name (properties.getName (properties.size() - 1));
|
||||
properties.remove (name);
|
||||
sendPropertyChangeMessage (name);
|
||||
}
|
||||
|
|
@ -372,7 +372,7 @@ void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManage
|
|||
}
|
||||
}
|
||||
|
||||
ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
|
||||
ValueTree ValueTree::SharedObject::getChildWithName (const Identifier& typeToMatch) const
|
||||
{
|
||||
for (int i = 0; i < children.size(); ++i)
|
||||
if (children.getUnchecked(i)->type == typeToMatch)
|
||||
|
|
@ -381,7 +381,7 @@ ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch)
|
|||
return ValueTree::invalid;
|
||||
}
|
||||
|
||||
ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
|
||||
ValueTree ValueTree::SharedObject::getChildWithProperty (const Identifier& propertyName, const var& propertyValue) const
|
||||
{
|
||||
for (int i = 0; i < children.size(); ++i)
|
||||
if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
|
||||
|
|
@ -508,10 +508,10 @@ ValueTree::ValueTree() throw()
|
|||
|
||||
const ValueTree ValueTree::invalid;
|
||||
|
||||
ValueTree::ValueTree (const String& type_)
|
||||
ValueTree::ValueTree (const Identifier& type_)
|
||||
: object (new ValueTree::SharedObject (type_))
|
||||
{
|
||||
jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
|
||||
jassert (type_.toString().isNotEmpty()); // All objects should be given a sensible type name!
|
||||
}
|
||||
|
||||
ValueTree::ValueTree (SharedObject* const object_)
|
||||
|
|
@ -561,14 +561,14 @@ ValueTree ValueTree::createCopy() const
|
|||
return ValueTree (object != 0 ? new SharedObject (*object) : 0);
|
||||
}
|
||||
|
||||
bool ValueTree::hasType (const String& typeName) const
|
||||
bool ValueTree::hasType (const Identifier& typeName) const
|
||||
{
|
||||
return object != 0 && object->type == typeName;
|
||||
}
|
||||
|
||||
const String ValueTree::getType() const
|
||||
{
|
||||
return object != 0 ? object->type : String::empty;
|
||||
return object != 0 ? object->type.toString() : String::empty;
|
||||
}
|
||||
|
||||
ValueTree ValueTree::getParent() const
|
||||
|
|
@ -576,35 +576,35 @@ ValueTree ValueTree::getParent() const
|
|||
return ValueTree (object != 0 ? object->parent : (SharedObject*) 0);
|
||||
}
|
||||
|
||||
const var& ValueTree::operator[] (const var::identifier& name) const
|
||||
const var& ValueTree::operator[] (const Identifier& name) const
|
||||
{
|
||||
return object == 0 ? var::null : object->getProperty (name);
|
||||
}
|
||||
|
||||
const var& ValueTree::getProperty (const var::identifier& name) const
|
||||
const var& ValueTree::getProperty (const Identifier& name) const
|
||||
{
|
||||
return object == 0 ? var::null : object->getProperty (name);
|
||||
}
|
||||
|
||||
const var ValueTree::getProperty (const var::identifier& name, const var& defaultReturnValue) const
|
||||
const var ValueTree::getProperty (const Identifier& name, const var& defaultReturnValue) const
|
||||
{
|
||||
return object == 0 ? defaultReturnValue : object->getProperty (name, defaultReturnValue);
|
||||
}
|
||||
|
||||
void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
|
||||
void ValueTree::setProperty (const Identifier& name, const var& newValue, UndoManager* const undoManager)
|
||||
{
|
||||
jassert (name.name.isNotEmpty());
|
||||
jassert (name.toString().isNotEmpty());
|
||||
|
||||
if (object != 0 && name.name.isNotEmpty())
|
||||
if (object != 0 && name.toString().isNotEmpty())
|
||||
object->setProperty (name, newValue, undoManager);
|
||||
}
|
||||
|
||||
bool ValueTree::hasProperty (const var::identifier& name) const
|
||||
bool ValueTree::hasProperty (const Identifier& name) const
|
||||
{
|
||||
return object != 0 && object->hasProperty (name);
|
||||
}
|
||||
|
||||
void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
|
||||
void ValueTree::removeProperty (const Identifier& name, UndoManager* const undoManager)
|
||||
{
|
||||
if (object != 0)
|
||||
object->removeProperty (name, undoManager);
|
||||
|
|
@ -621,9 +621,9 @@ int ValueTree::getNumProperties() const
|
|||
return object == 0 ? 0 : object->properties.size();
|
||||
}
|
||||
|
||||
const var::identifier ValueTree::getPropertyName (const int index) const
|
||||
const Identifier ValueTree::getPropertyName (const int index) const
|
||||
{
|
||||
return object == 0 ? var::identifier()
|
||||
return object == 0 ? Identifier()
|
||||
: object->properties.getName (index);
|
||||
}
|
||||
|
||||
|
|
@ -633,7 +633,7 @@ class ValueTreePropertyValueSource : public Value::ValueSource,
|
|||
{
|
||||
public:
|
||||
ValueTreePropertyValueSource (const ValueTree& tree_,
|
||||
const var::identifier& property_,
|
||||
const Identifier& property_,
|
||||
UndoManager* const undoManager_)
|
||||
: tree (tree_),
|
||||
property (property_),
|
||||
|
|
@ -657,7 +657,7 @@ public:
|
|||
tree.setProperty (property, newValue, undoManager);
|
||||
}
|
||||
|
||||
void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
|
||||
void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const Identifier& changedProperty)
|
||||
{
|
||||
if (tree == treeWhosePropertyHasChanged && property == changedProperty)
|
||||
sendChangeMessage (false);
|
||||
|
|
@ -668,13 +668,13 @@ public:
|
|||
|
||||
private:
|
||||
ValueTree tree;
|
||||
const var::identifier property;
|
||||
const Identifier property;
|
||||
UndoManager* const undoManager;
|
||||
|
||||
ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
|
||||
};
|
||||
|
||||
Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
|
||||
Value ValueTree::getPropertyAsValue (const Identifier& name, UndoManager* const undoManager) const
|
||||
{
|
||||
return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
|
||||
}
|
||||
|
|
@ -690,12 +690,12 @@ ValueTree ValueTree::getChild (int index) const
|
|||
return ValueTree (object != 0 ? (SharedObject*) object->children [index] : (SharedObject*) 0);
|
||||
}
|
||||
|
||||
ValueTree ValueTree::getChildWithName (const String& type) const
|
||||
ValueTree ValueTree::getChildWithName (const Identifier& type) const
|
||||
{
|
||||
return object != 0 ? object->getChildWithName (type) : ValueTree::invalid;
|
||||
}
|
||||
|
||||
ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
|
||||
ValueTree ValueTree::getChildWithProperty (const Identifier& propertyName, const var& propertyValue) const
|
||||
{
|
||||
return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree::invalid;
|
||||
}
|
||||
|
|
@ -763,17 +763,17 @@ void ValueTree::removeListener (Listener* listener)
|
|||
//==============================================================================
|
||||
XmlElement* ValueTree::SharedObject::createXml() const
|
||||
{
|
||||
XmlElement* xml = new XmlElement (type);
|
||||
XmlElement* xml = new XmlElement (type.toString());
|
||||
|
||||
int i;
|
||||
for (i = 0; i < properties.size(); ++i)
|
||||
{
|
||||
var::identifier name (properties.getName(i));
|
||||
Identifier name (properties.getName(i));
|
||||
const var& v = properties [name];
|
||||
|
||||
jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
|
||||
|
||||
xml->setAttribute (name.name, v.toString());
|
||||
xml->setAttribute (name.toString(), v.toString());
|
||||
}
|
||||
|
||||
for (i = 0; i < children.size(); ++i)
|
||||
|
|
@ -815,8 +815,8 @@ void ValueTree::writeToStream (OutputStream& output)
|
|||
int i;
|
||||
for (i = 0; i < numProps; ++i)
|
||||
{
|
||||
const var::identifier name (getPropertyName(i));
|
||||
output.writeString (name.name);
|
||||
const Identifier name (getPropertyName(i));
|
||||
output.writeString (name.toString());
|
||||
getProperty(name).writeToStream (output);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public:
|
|||
Like an XmlElement, each ValueTree node has a type, which you can access with
|
||||
getType() and hasType().
|
||||
*/
|
||||
explicit ValueTree (const String& type);
|
||||
explicit ValueTree (const Identifier& type);
|
||||
|
||||
/** Creates a reference to another ValueTree. */
|
||||
ValueTree (const ValueTree& other);
|
||||
|
|
@ -130,7 +130,7 @@ public:
|
|||
/** Returns true if the node has this type.
|
||||
The comparison is case-sensitive.
|
||||
*/
|
||||
bool hasType (const String& typeName) const;
|
||||
bool hasType (const Identifier& typeName) const;
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the value of a named property.
|
||||
|
|
@ -138,37 +138,37 @@ public:
|
|||
You can also use operator[] to get a property.
|
||||
@see var, setProperty, hasProperty
|
||||
*/
|
||||
const var& getProperty (const var::identifier& name) const;
|
||||
const var& getProperty (const Identifier& name) const;
|
||||
|
||||
/** Returns the value of a named property, or a user-specified default if the property doesn't exist.
|
||||
If no such property has been set, this will return the value of defaultReturnValue.
|
||||
You can also use operator[] and getProperty to get a property.
|
||||
@see var, getProperty, setProperty, hasProperty
|
||||
*/
|
||||
const var getProperty (const var::identifier& name, const var& defaultReturnValue) const;
|
||||
const var getProperty (const Identifier& name, const var& defaultReturnValue) const;
|
||||
|
||||
/** Returns the value of a named property.
|
||||
If no such property has been set, this will return a void variant. This is the same as
|
||||
calling getProperty().
|
||||
@see getProperty
|
||||
*/
|
||||
const var& operator[] (const var::identifier& name) const;
|
||||
const var& operator[] (const Identifier& name) const;
|
||||
|
||||
/** Changes a named property of the node.
|
||||
If the undoManager parameter is non-null, its UndoManager::perform() method will be used,
|
||||
so that this change can be undone.
|
||||
@see var, getProperty, removeProperty
|
||||
*/
|
||||
void setProperty (const var::identifier& name, const var& newValue, UndoManager* undoManager);
|
||||
void setProperty (const Identifier& name, const var& newValue, UndoManager* undoManager);
|
||||
|
||||
/** Returns true if the node contains a named property. */
|
||||
bool hasProperty (const var::identifier& name) const;
|
||||
bool hasProperty (const Identifier& name) const;
|
||||
|
||||
/** Removes a property from the node.
|
||||
If the undoManager parameter is non-null, its UndoManager::perform() method will be used,
|
||||
so that this change can be undone.
|
||||
*/
|
||||
void removeProperty (const var::identifier& name, UndoManager* undoManager);
|
||||
void removeProperty (const Identifier& name, UndoManager* undoManager);
|
||||
|
||||
/** Removes all properties from the node.
|
||||
If the undoManager parameter is non-null, its UndoManager::perform() method will be used,
|
||||
|
|
@ -184,7 +184,7 @@ public:
|
|||
/** Returns the identifier of the property with a given index.
|
||||
@see getNumProperties
|
||||
*/
|
||||
const var::identifier getPropertyName (int index) const;
|
||||
const Identifier getPropertyName (int index) const;
|
||||
|
||||
/** Returns a Value object that can be used to control and respond to one of the tree's properties.
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ public:
|
|||
it needs to change the value. Attaching a Value::Listener to the value object will provide
|
||||
callbacks whenever the property changes.
|
||||
*/
|
||||
Value getPropertyAsValue (const var::identifier& name, UndoManager* undoManager) const;
|
||||
Value getPropertyAsValue (const Identifier& name, UndoManager* undoManager) const;
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the number of child nodes belonging to this one.
|
||||
|
|
@ -210,7 +210,7 @@ public:
|
|||
If no such node is found, it'll return an invalid node. (See isValid() to find out
|
||||
whether a node is valid).
|
||||
*/
|
||||
ValueTree getChildWithName (const String& type) const;
|
||||
ValueTree getChildWithName (const Identifier& type) const;
|
||||
|
||||
/** Looks for the first child node that has the speficied property value.
|
||||
|
||||
|
|
@ -220,7 +220,7 @@ public:
|
|||
If no such node is found, it'll return an invalid node. (See isValid() to find out
|
||||
whether a node is valid).
|
||||
*/
|
||||
ValueTree getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const;
|
||||
ValueTree getChildWithProperty (const Identifier& propertyName, const var& propertyValue) const;
|
||||
|
||||
/** Adds a child to this node.
|
||||
|
||||
|
|
@ -340,7 +340,7 @@ public:
|
|||
simply check the tree parameter in this callback to make sure it's the tree you're interested in.
|
||||
*/
|
||||
virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
|
||||
const var::identifier& property) = 0;
|
||||
const Identifier& property) = 0;
|
||||
|
||||
/** This method is called when a child sub-tree is added or removed.
|
||||
|
||||
|
|
@ -435,31 +435,31 @@ private:
|
|||
class JUCE_API SharedObject : public ReferenceCountedObject
|
||||
{
|
||||
public:
|
||||
explicit SharedObject (const String& type);
|
||||
explicit SharedObject (const Identifier& type);
|
||||
SharedObject (const SharedObject& other);
|
||||
~SharedObject();
|
||||
|
||||
const String type;
|
||||
const Identifier type;
|
||||
NamedValueSet properties;
|
||||
ReferenceCountedArray <SharedObject> children;
|
||||
SortedSet <ValueTree*> valueTreesWithListeners;
|
||||
SharedObject* parent;
|
||||
|
||||
void sendPropertyChangeMessage (const var::identifier& property);
|
||||
void sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property);
|
||||
void sendPropertyChangeMessage (const Identifier& property);
|
||||
void sendPropertyChangeMessage (ValueTree& tree, const Identifier& property);
|
||||
void sendChildChangeMessage();
|
||||
void sendChildChangeMessage (ValueTree& tree);
|
||||
void sendParentChangeMessage();
|
||||
const var& getProperty (const var::identifier& name) const;
|
||||
const var getProperty (const var::identifier& name, const var& defaultReturnValue) const;
|
||||
void setProperty (const var::identifier& name, const var& newValue, UndoManager*);
|
||||
bool hasProperty (const var::identifier& name) const;
|
||||
void removeProperty (const var::identifier& name, UndoManager*);
|
||||
const var& getProperty (const Identifier& name) const;
|
||||
const var getProperty (const Identifier& name, const var& defaultReturnValue) const;
|
||||
void setProperty (const Identifier& name, const var& newValue, UndoManager*);
|
||||
bool hasProperty (const Identifier& name) const;
|
||||
void removeProperty (const Identifier& name, UndoManager*);
|
||||
void removeAllProperties (UndoManager*);
|
||||
bool isAChildOf (const SharedObject* possibleParent) const;
|
||||
int indexOf (const ValueTree& child) const;
|
||||
ValueTree getChildWithName (const String& type) const;
|
||||
ValueTree getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const;
|
||||
ValueTree getChildWithName (const Identifier& type) const;
|
||||
ValueTree getChildWithProperty (const Identifier& propertyName, const var& propertyValue) const;
|
||||
void addChild (SharedObject* child, int index, UndoManager*);
|
||||
void removeChild (int childIndex, UndoManager*);
|
||||
void removeAllChildren (UndoManager*);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ BEGIN_JUCE_NAMESPACE
|
|||
#include "juce_Variant.h"
|
||||
#include "juce_DynamicObject.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
var::var() throw()
|
||||
: type (voidType)
|
||||
|
|
@ -283,7 +284,7 @@ const var var::readFromStream (InputStream& input)
|
|||
return var::null;
|
||||
}
|
||||
|
||||
const var var::operator[] (const var::identifier& propertyName) const
|
||||
const var var::operator[] (const Identifier& propertyName) const
|
||||
{
|
||||
if (type == objectType && value.objectValue != 0)
|
||||
return value.objectValue->getProperty (propertyName);
|
||||
|
|
@ -291,7 +292,7 @@ const var var::operator[] (const var::identifier& propertyName) const
|
|||
return var::null;
|
||||
}
|
||||
|
||||
const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
|
||||
const var var::invoke (const Identifier& method, const var* arguments, int numArguments) const
|
||||
{
|
||||
if (type == objectType && value.objectValue != 0)
|
||||
return value.objectValue->invokeMethod (method, arguments, numArguments);
|
||||
|
|
@ -312,68 +313,39 @@ const var var::invoke (const var& targetObject, const var* arguments, int numArg
|
|||
return var::null;
|
||||
}
|
||||
|
||||
const var var::call (const var::identifier& method) const
|
||||
const var var::call (const Identifier& method) const
|
||||
{
|
||||
return invoke (method, 0, 0);
|
||||
}
|
||||
|
||||
const var var::call (const var::identifier& method, const var& arg1) const
|
||||
const var var::call (const Identifier& method, const var& arg1) const
|
||||
{
|
||||
return invoke (method, &arg1, 1);
|
||||
}
|
||||
|
||||
const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
|
||||
const var var::call (const Identifier& method, const var& arg1, const var& arg2) const
|
||||
{
|
||||
var args[] = { arg1, arg2 };
|
||||
return invoke (method, args, 2);
|
||||
}
|
||||
|
||||
const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
|
||||
const var var::call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3)
|
||||
{
|
||||
var args[] = { arg1, arg2, arg3 };
|
||||
return invoke (method, args, 3);
|
||||
}
|
||||
|
||||
const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
|
||||
const var var::call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
|
||||
{
|
||||
var args[] = { arg1, arg2, arg3, arg4 };
|
||||
return invoke (method, args, 4);
|
||||
}
|
||||
|
||||
const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
|
||||
const var var::call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
|
||||
{
|
||||
var args[] = { arg1, arg2, arg3, arg4, arg5 };
|
||||
return invoke (method, args, 5);
|
||||
}
|
||||
|
||||
|
||||
//==============================================================================
|
||||
var::identifier::identifier() throw()
|
||||
: hashCode (0)
|
||||
{
|
||||
}
|
||||
|
||||
var::identifier::identifier (const String& name_)
|
||||
: name (name_),
|
||||
hashCode (name_.hashCode())
|
||||
{
|
||||
/* An identifier string must be suitable for use as a script variable or XML
|
||||
attribute, so it can only contain this limited set of characters.. */
|
||||
jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
|
||||
}
|
||||
|
||||
var::identifier::identifier (const char* const name_)
|
||||
: name (name_),
|
||||
hashCode (name.hashCode())
|
||||
{
|
||||
/* An identifier string must be suitable for use as a script variable or XML
|
||||
attribute, so it can only contain this limited set of characters.. */
|
||||
jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
|
||||
}
|
||||
|
||||
var::identifier::~identifier()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
END_JUCE_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#ifndef __JUCE_VARIANT_JUCEHEADER__
|
||||
#define __JUCE_VARIANT_JUCEHEADER__
|
||||
|
||||
#include "juce_Identifier.h"
|
||||
#include "../io/streams/juce_OutputStream.h"
|
||||
#include "../io/streams/juce_InputStream.h"
|
||||
|
||||
|
|
@ -47,6 +48,7 @@ class JUCE_API var
|
|||
public:
|
||||
//==============================================================================
|
||||
typedef const var (DynamicObject::*MethodFunction) (const var* arguments, int numArguments);
|
||||
typedef Identifier identifier;
|
||||
|
||||
//==============================================================================
|
||||
/** Creates a void variant. */
|
||||
|
|
@ -109,56 +111,25 @@ public:
|
|||
static const var readFromStream (InputStream& input);
|
||||
|
||||
//==============================================================================
|
||||
class JUCE_API identifier
|
||||
{
|
||||
public:
|
||||
/** Creates a null identifier. */
|
||||
identifier() throw();
|
||||
|
||||
/** Creates an identifier with a specified name.
|
||||
Because this name may need to be used in contexts such as script variables or XML
|
||||
tags, it must only contain ascii letters and digits, or the underscore character.
|
||||
*/
|
||||
identifier (const char* name);
|
||||
|
||||
/** Creates an identifier with a specified name.
|
||||
Because this name may need to be used in contexts such as script variables or XML
|
||||
tags, it must only contain ascii letters and digits, or the underscore character.
|
||||
*/
|
||||
identifier (const String& name);
|
||||
|
||||
/** Destructor */
|
||||
~identifier();
|
||||
|
||||
bool operator== (const identifier& other) const throw()
|
||||
{
|
||||
jassert (hashCode != other.hashCode || name == other.name); // check for name hash collisions
|
||||
return hashCode == other.hashCode;
|
||||
}
|
||||
|
||||
String name;
|
||||
int hashCode;
|
||||
};
|
||||
|
||||
/** If this variant is an object, this returns one of its properties. */
|
||||
const var operator[] (const identifier& propertyName) const;
|
||||
const var operator[] (const Identifier& propertyName) const;
|
||||
|
||||
//==============================================================================
|
||||
/** If this variant is an object, this invokes one of its methods with no arguments. */
|
||||
const var call (const identifier& method) const;
|
||||
const var call (const Identifier& method) const;
|
||||
/** If this variant is an object, this invokes one of its methods with one argument. */
|
||||
const var call (const identifier& method, const var& arg1) const;
|
||||
const var call (const Identifier& method, const var& arg1) const;
|
||||
/** If this variant is an object, this invokes one of its methods with 2 arguments. */
|
||||
const var call (const identifier& method, const var& arg1, const var& arg2) const;
|
||||
const var call (const Identifier& method, const var& arg1, const var& arg2) const;
|
||||
/** If this variant is an object, this invokes one of its methods with 3 arguments. */
|
||||
const var call (const identifier& method, const var& arg1, const var& arg2, const var& arg3);
|
||||
const var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3);
|
||||
/** If this variant is an object, this invokes one of its methods with 4 arguments. */
|
||||
const var call (const identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const;
|
||||
const var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const;
|
||||
/** If this variant is an object, this invokes one of its methods with 5 arguments. */
|
||||
const var call (const identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const;
|
||||
const var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const;
|
||||
|
||||
/** If this variant is an object, this invokes one of its methods with a list of arguments. */
|
||||
const var invoke (const identifier& method, const var* arguments, int numArguments) const;
|
||||
const var invoke (const Identifier& method, const var* arguments, int numArguments) const;
|
||||
|
||||
//==============================================================================
|
||||
/** If this variant is a method pointer, this invokes it on a target object. */
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public:
|
|||
{
|
||||
jassert (row >= 0);
|
||||
|
||||
const var::identifier tagPropertyName ("_tableLastUseNum");
|
||||
const Identifier tagPropertyName ("_tableLastUseNum");
|
||||
const int newTag = Random::getSystemRandom().nextInt();
|
||||
|
||||
const TableHeaderComponent* const header = owner.getHeader();
|
||||
|
|
|
|||
|
|
@ -1783,7 +1783,7 @@ void Component::sendLookAndFeelChange()
|
|||
}
|
||||
}
|
||||
|
||||
static const var::identifier getColourPropertyId (const int colourId)
|
||||
static const Identifier getColourPropertyId (const int colourId)
|
||||
{
|
||||
String s;
|
||||
s.preallocateStorage (18);
|
||||
|
|
@ -1827,9 +1827,9 @@ void Component::copyAllExplicitColoursTo (Component& target) const
|
|||
|
||||
for (int i = properties.size(); --i >= 0;)
|
||||
{
|
||||
const var::identifier name (properties.getName(i));
|
||||
const Identifier name (properties.getName(i));
|
||||
|
||||
if (name.name.startsWith ("jcclr_"))
|
||||
if (name.toString().startsWith ("jcclr_"))
|
||||
if (target.properties.set (name, properties [name]))
|
||||
changed = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -826,6 +826,39 @@ bool File::replaceWithText (const String& textToWrite,
|
|||
return tempFile.overwriteTargetFileWithTemporary();
|
||||
}
|
||||
|
||||
bool File::hasIdenticalContentTo (const File& other) const
|
||||
{
|
||||
if (other == *this)
|
||||
return true;
|
||||
|
||||
if (getSize() == other.getSize() && existsAsFile() && other.existsAsFile())
|
||||
{
|
||||
FileInputStream in1 (*this), in2 (other);
|
||||
|
||||
const int bufferSize = 4096;
|
||||
HeapBlock <char> buffer1, buffer2;
|
||||
buffer1.malloc (bufferSize);
|
||||
buffer2.malloc (bufferSize);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const int num1 = in1.read (buffer1, bufferSize);
|
||||
const int num2 = in2.read (buffer2, bufferSize);
|
||||
|
||||
if (num1 != num2)
|
||||
break;
|
||||
|
||||
if (num1 <= 0)
|
||||
return true;
|
||||
|
||||
if (memcmp (buffer1, buffer2, num1) != 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
const String File::createLegalPathName (const String& original)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -669,6 +669,11 @@ public:
|
|||
bool asUnicode = false,
|
||||
bool writeUnicodeHeaderBytes = false) const;
|
||||
|
||||
/** Attempts to scan the contents of this file and compare it to another file, returning
|
||||
true if this is possible and they match byte-for-byte.
|
||||
*/
|
||||
bool hasIdenticalContentTo (const File& other) const;
|
||||
|
||||
//==============================================================================
|
||||
/** Creates a set of files to represent each file root.
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@
|
|||
#ifndef __JUCE_HEAPBLOCK_JUCEHEADER__
|
||||
#include "containers/juce_HeapBlock.h"
|
||||
#endif
|
||||
#ifndef __JUCE_IDENTIFIER_JUCEHEADER__
|
||||
#include "containers/juce_Identifier.h"
|
||||
#endif
|
||||
#ifndef __JUCE_MEMORYBLOCK_JUCEHEADER__
|
||||
#include "containers/juce_MemoryBlock.h"
|
||||
#endif
|
||||
|
|
@ -224,6 +227,9 @@
|
|||
#ifndef __JUCE_STRINGPAIRARRAY_JUCEHEADER__
|
||||
#include "text/juce_StringPairArray.h"
|
||||
#endif
|
||||
#ifndef __JUCE_STRINGPOOL_JUCEHEADER__
|
||||
#include "text/juce_StringPool.h"
|
||||
#endif
|
||||
#ifndef __JUCE_XMLDOCUMENT_JUCEHEADER__
|
||||
#include "text/juce_XmlDocument.h"
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -781,12 +781,17 @@ bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
|
|||
|
||||
int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
|
||||
{
|
||||
if (digit >= '0' && digit <= '9')
|
||||
return digit - '0';
|
||||
else if (digit >= 'a' && digit <= 'f')
|
||||
return digit - ('a' - 10);
|
||||
else if (digit >= 'A' && digit <= 'F')
|
||||
return digit - ('A' - 10);
|
||||
unsigned int d = digit - '0';
|
||||
if (d < (unsigned int) 10)
|
||||
return (int) d;
|
||||
|
||||
d += '0' - 'a';
|
||||
if (d < (unsigned int) 6)
|
||||
return (int) d + 10;
|
||||
|
||||
d += 'a' - 'A';
|
||||
if (d < (unsigned int) 6)
|
||||
return (int) d + 10;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public:
|
|||
/** Destructor. */
|
||||
~String() throw();
|
||||
|
||||
//========================juce_wchar======================================================
|
||||
//==============================================================================
|
||||
/** This is an empty string that can be used whenever one is needed.
|
||||
|
||||
It's better to use this than String() because it explains what's going on
|
||||
|
|
|
|||
105
src/text/juce_StringPool.cpp
Normal file
105
src/text/juce_StringPool.cpp
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-10 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#include "../core/juce_StandardHeader.h"
|
||||
|
||||
BEGIN_JUCE_NAMESPACE
|
||||
|
||||
#include "juce_StringPool.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
StringPool::StringPool() throw() {}
|
||||
StringPool::~StringPool() {}
|
||||
|
||||
template <class StringType>
|
||||
static const juce_wchar* getPooledStringFromArray (Array<String>& strings, StringType newString)
|
||||
{
|
||||
int start = 0;
|
||||
int end = strings.size();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (start >= end)
|
||||
{
|
||||
jassert (start <= end);
|
||||
strings.insert (start, newString);
|
||||
return strings.getReference (start);
|
||||
}
|
||||
else
|
||||
{
|
||||
const String& startString = strings.getReference (start);
|
||||
|
||||
if (startString == newString)
|
||||
return startString;
|
||||
|
||||
const int halfway = (start + end) >> 1;
|
||||
|
||||
if (halfway == start)
|
||||
{
|
||||
if (startString.compare (newString) < 0)
|
||||
++start;
|
||||
|
||||
strings.insert (start, newString);
|
||||
return strings.getReference (start);
|
||||
}
|
||||
|
||||
const int comp = strings.getReference (halfway).compare (newString);
|
||||
|
||||
if (comp == 0)
|
||||
return strings.getReference (halfway);
|
||||
else if (comp < 0)
|
||||
start = halfway;
|
||||
else
|
||||
end = halfway;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const juce_wchar* StringPool::getPooledString (const String& s)
|
||||
{
|
||||
if (s.isEmpty())
|
||||
return String::empty;
|
||||
|
||||
return getPooledStringFromArray (strings, s);
|
||||
}
|
||||
|
||||
const juce_wchar* StringPool::getPooledString (const char* const s)
|
||||
{
|
||||
if (s == 0 || *s == 0)
|
||||
return String::empty;
|
||||
|
||||
return getPooledStringFromArray (strings, s);
|
||||
}
|
||||
|
||||
const juce_wchar* StringPool::getPooledString (const juce_wchar* const s)
|
||||
{
|
||||
if (s == 0 || *s == 0)
|
||||
return String::empty;
|
||||
|
||||
return getPooledStringFromArray (strings, s);
|
||||
}
|
||||
|
||||
END_JUCE_NAMESPACE
|
||||
82
src/text/juce_StringPool.h
Normal file
82
src/text/juce_StringPool.h
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-10 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef __JUCE_STRINGPOOL_JUCEHEADER__
|
||||
#define __JUCE_STRINGPOOL_JUCEHEADER__
|
||||
|
||||
#include "juce_String.h"
|
||||
#include "../containers/juce_Array.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
A StringPool holds a set of shared strings, which reduces storage overheads and improves
|
||||
comparison speed when dealing with many duplicate strings.
|
||||
|
||||
When you add a string to a pool using getPooledString, it'll return a character
|
||||
array containing the same string. This array is owned by the pool, and the same array
|
||||
is returned every time a matching string is asked for. This means that it's trivial to
|
||||
compare two pooled strings for equality, as you can simply compare their pointers. It
|
||||
also cuts down on storage if you're using many copies of the same string.
|
||||
*/
|
||||
class JUCE_API StringPool
|
||||
{
|
||||
public:
|
||||
/** Creates an empty pool. */
|
||||
StringPool() throw();
|
||||
|
||||
/** Destructor */
|
||||
~StringPool();
|
||||
|
||||
/** Returns a pointer to a copy of the string that is passed in.
|
||||
|
||||
The pool will always return the same pointer when asked for a string that matches it.
|
||||
The pool will own all the pointers that it returns, deleting them when the pool itself
|
||||
is deleted.
|
||||
*/
|
||||
const juce_wchar* getPooledString (const String& original);
|
||||
|
||||
/** Returns a pointer to a copy of the string that is passed in.
|
||||
|
||||
The pool will always return the same pointer when asked for a string that matches it.
|
||||
The pool will own all the pointers that it returns, deleting them when the pool itself
|
||||
is deleted.
|
||||
*/
|
||||
const juce_wchar* getPooledString (const char* original);
|
||||
|
||||
/** Returns a pointer to a copy of the string that is passed in.
|
||||
|
||||
The pool will always return the same pointer when asked for a string that matches it.
|
||||
The pool will own all the pointers that it returns, deleting them when the pool itself
|
||||
is deleted.
|
||||
*/
|
||||
const juce_wchar* getPooledString (const juce_wchar* original);
|
||||
|
||||
private:
|
||||
Array <String> strings;
|
||||
};
|
||||
|
||||
|
||||
#endif // __JUCE_STRINGPOOL_JUCEHEADER__
|
||||
Loading…
Add table
Add a link
Reference in a new issue