1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-03 03:30:06 +00:00

Jack audio fix. New class LinkedListPointer. Couple of new menu methods in DocumentWindow. win32 window size constrainer tweak.

This commit is contained in:
Julian Storer 2010-12-26 22:56:10 +00:00
parent 4009680f79
commit cac0a7e3f8
27 changed files with 1298 additions and 1000 deletions

View file

@ -37,15 +37,13 @@ BEGIN_JUCE_NAMESPACE
//==============================================================================
XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
: name (other.name),
value (other.value),
next (0)
value (other.value)
{
}
XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_, const String& value_) throw()
: name (name_),
value (value_),
next (0)
value (value_)
{
#if JUCE_DEBUG
// this checks whether the attribute name string contains any illegals characters..
@ -61,10 +59,7 @@ inline bool XmlElement::XmlAttributeNode::hasName (const String& nameToMatch) co
//==============================================================================
XmlElement::XmlElement (const String& tagName_) throw()
: tagName (tagName_),
firstChildElement (0),
nextElement (0),
attributes (0)
: tagName (tagName_)
{
// the tag name mustn't be empty, or it'll look like a text element!
jassert (tagName_.containsNonWhitespaceChars())
@ -74,17 +69,11 @@ XmlElement::XmlElement (const String& tagName_) throw()
}
XmlElement::XmlElement (int /*dummy*/) throw()
: firstChildElement (0),
nextElement (0),
attributes (0)
{
}
XmlElement::XmlElement (const XmlElement& other)
: tagName (other.tagName),
firstChildElement (0),
nextElement (0),
attributes (0)
: tagName (other.tagName)
{
copyChildrenAndAttributesFrom (other);
}
@ -106,58 +95,17 @@ XmlElement& XmlElement::operator= (const XmlElement& other)
void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other)
{
XmlElement* child = other.firstChildElement;
XmlElement* lastChild = 0;
jassert (firstChildElement.get() == 0);
firstChildElement.addCopyOfList (other.firstChildElement);
while (child != 0)
{
XmlElement* const copiedChild = new XmlElement (*child);
if (lastChild != 0)
lastChild->nextElement = copiedChild;
else
firstChildElement = copiedChild;
lastChild = copiedChild;
child = child->nextElement;
}
const XmlAttributeNode* att = other.attributes;
XmlAttributeNode* lastAtt = 0;
while (att != 0)
{
XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
if (lastAtt != 0)
lastAtt->next = newAtt;
else
attributes = newAtt;
lastAtt = newAtt;
att = att->next;
}
jassert (attributes.get() == 0);
attributes.addCopyOfList (other.attributes);
}
XmlElement::~XmlElement() throw()
{
XmlElement* child = firstChildElement;
while (child != 0)
{
XmlElement* const nextChild = child->nextElement;
delete child;
child = nextChild;
}
XmlAttributeNode* att = attributes;
while (att != 0)
{
XmlAttributeNode* const nextAtt = att->next;
delete att;
att = nextAtt;
}
firstChildElement.deleteAll();
attributes.deleteAll();
}
//==============================================================================
@ -279,7 +227,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream,
const int attIndent = indentationLevel + tagName.length() + 1;
int lineLen = 0;
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
for (const XmlAttributeNode* att = attributes; att != 0; att = att->nextListItem)
{
if (lineLen > lineWrapLength && indentationLevel >= 0)
{
@ -322,7 +270,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream,
lastWasTextNode = false;
}
child = child->nextElement;
child = child->getNextElement();
}
if (indentationLevel >= 0 && ! lastWasTextNode)
@ -438,10 +386,10 @@ bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
{
XmlElement* e = nextElement;
XmlElement* e = nextListItem;
while (e != 0 && ! e->hasTagName (requiredTagName))
e = e->nextElement;
e = e->nextListItem;
return e;
}
@ -449,47 +397,24 @@ XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName
//==============================================================================
int XmlElement::getNumAttributes() const throw()
{
int count = 0;
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
++count;
return count;
return attributes.size();
}
const String& XmlElement::getAttributeName (const int index) const throw()
{
int count = 0;
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
{
if (count == index)
return att->name;
++count;
}
return String::empty;
const XmlAttributeNode* const att = attributes [index];
return att != 0 ? att->name : String::empty;
}
const String& XmlElement::getAttributeValue (const int index) const throw()
{
int count = 0;
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
{
if (count == index)
return att->value;
++count;
}
return String::empty;
const XmlAttributeNode* const att = attributes [index];
return att != 0 ? att->value : String::empty;
}
bool XmlElement::hasAttribute (const String& attributeName) const throw()
{
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
for (const XmlAttributeNode* att = attributes; att != 0; att = att->nextListItem)
if (att->hasName (attributeName))
return true;
@ -499,7 +424,7 @@ bool XmlElement::hasAttribute (const String& attributeName) const throw()
//==============================================================================
const String& XmlElement::getStringAttribute (const String& attributeName) const throw()
{
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
for (const XmlAttributeNode* att = attributes; att != 0; att = att->nextListItem)
if (att->hasName (attributeName))
return att->value;
@ -508,7 +433,7 @@ const String& XmlElement::getStringAttribute (const String& attributeName) const
const String XmlElement::getStringAttribute (const String& attributeName, const String& defaultReturnValue) const
{
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
for (const XmlAttributeNode* att = attributes; att != 0; att = att->nextListItem)
if (att->hasName (attributeName))
return att->value;
@ -517,7 +442,7 @@ const String XmlElement::getStringAttribute (const String& attributeName, const
int XmlElement::getIntAttribute (const String& attributeName, const int defaultReturnValue) const
{
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
for (const XmlAttributeNode* att = attributes; att != 0; att = att->nextListItem)
if (att->hasName (attributeName))
return att->value.getIntValue();
@ -526,7 +451,7 @@ int XmlElement::getIntAttribute (const String& attributeName, const int defaultR
double XmlElement::getDoubleAttribute (const String& attributeName, const double defaultReturnValue) const
{
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
for (const XmlAttributeNode* att = attributes; att != 0; att = att->nextListItem)
if (att->hasName (attributeName))
return att->value.getDoubleValue();
@ -535,7 +460,7 @@ double XmlElement::getDoubleAttribute (const String& attributeName, const double
bool XmlElement::getBoolAttribute (const String& attributeName, const bool defaultReturnValue) const
{
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
for (const XmlAttributeNode* att = attributes; att != 0; att = att->nextListItem)
{
if (att->hasName (attributeName))
{
@ -559,7 +484,7 @@ bool XmlElement::compareAttribute (const String& attributeName,
const String& stringToCompareAgainst,
const bool ignoreCase) const throw()
{
for (const XmlAttributeNode* att = attributes; att != 0; att = att->next)
for (const XmlAttributeNode* att = attributes; att != 0; att = att->nextListItem)
if (att->hasName (attributeName))
return ignoreCase ? att->value.equalsIgnoreCase (stringToCompareAgainst)
: att->value == stringToCompareAgainst;
@ -585,13 +510,13 @@ void XmlElement::setAttribute (const String& attributeName, const String& value)
att->value = value;
break;
}
else if (att->next == 0)
else if (att->nextListItem == 0)
{
att->next = new XmlAttributeNode (attributeName, value);
att->nextListItem = new XmlAttributeNode (attributeName, value);
break;
}
att = att->next;
att = att->nextListItem;
}
}
}
@ -608,62 +533,34 @@ void XmlElement::setAttribute (const String& attributeName, const double number)
void XmlElement::removeAttribute (const String& attributeName) throw()
{
XmlAttributeNode* lastAtt = 0;
LinkedListPointer<XmlAttributeNode>* att = &attributes;
for (XmlAttributeNode* att = attributes; att != 0; att = att->next)
while (att->get() != 0)
{
if (att->hasName (attributeName))
if (att->get()->hasName (attributeName))
{
if (lastAtt == 0)
attributes = att->next;
else
lastAtt->next = att->next;
delete att;
delete att->removeNext();
break;
}
lastAtt = att;
att = &(att->get()->nextListItem);
}
}
void XmlElement::removeAllAttributes() throw()
{
while (attributes != 0)
{
XmlAttributeNode* const nextAtt = attributes->next;
delete attributes;
attributes = nextAtt;
}
attributes.deleteAll();
}
//==============================================================================
int XmlElement::getNumChildElements() const throw()
{
int count = 0;
const XmlElement* child = firstChildElement;
while (child != 0)
{
++count;
child = child->nextElement;
}
return count;
return firstChildElement.size();
}
XmlElement* XmlElement::getChildElement (const int index) const throw()
{
int count = 0;
XmlElement* child = firstChildElement;
while (child != 0 && count < index)
{
child = child->nextElement;
++count;
}
return child;
return firstChildElement [index].get();
}
XmlElement* XmlElement::getChildByName (const String& childName) const throw()
@ -675,7 +572,7 @@ XmlElement* XmlElement::getChildByName (const String& childName) const throw()
if (child->hasTagName (childName))
break;
child = child->nextElement;
child = child->nextListItem;
}
return child;
@ -684,25 +581,7 @@ XmlElement* XmlElement::getChildByName (const String& childName) const throw()
void XmlElement::addChildElement (XmlElement* const newNode) throw()
{
if (newNode != 0)
{
if (firstChildElement == 0)
{
firstChildElement = newNode;
}
else
{
XmlElement* child = firstChildElement;
while (child->nextElement != 0)
child = child->nextElement;
child->nextElement = newNode;
// if this is non-zero, then something's probably
// gone wrong..
jassert (newNode->nextElement == 0);
}
}
firstChildElement.append (newNode);
}
void XmlElement::insertChildElement (XmlElement* const newNode,
@ -711,32 +590,7 @@ void XmlElement::insertChildElement (XmlElement* const newNode,
if (newNode != 0)
{
removeChildElement (newNode, false);
if (indexToInsertAt == 0)
{
newNode->nextElement = firstChildElement;
firstChildElement = newNode;
}
else
{
if (firstChildElement == 0)
{
firstChildElement = newNode;
}
else
{
if (indexToInsertAt < 0)
indexToInsertAt = std::numeric_limits<int>::max();
XmlElement* child = firstChildElement;
while (child->nextElement != 0 && --indexToInsertAt > 0)
child = child->nextElement;
newNode->nextElement = child->nextElement;
child->nextElement = newNode;
}
}
firstChildElement.insertAtIndex (indexToInsertAt, newNode);
}
}
@ -752,30 +606,14 @@ bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
{
if (newNode != 0)
{
XmlElement* child = firstChildElement;
XmlElement* previousNode = 0;
LinkedListPointer<XmlElement>* const p = firstChildElement.findPointerTo (currentChildElement);
while (child != 0)
if (p != 0)
{
if (child == currentChildElement)
{
if (child != newNode)
{
if (previousNode == 0)
firstChildElement = newNode;
else
previousNode->nextElement = newNode;
if (currentChildElement != newNode)
delete p->replaceNext (newNode);
newNode->nextElement = child->nextElement;
delete child;
}
return true;
}
previousNode = child;
child = child->nextElement;
return true;
}
}
@ -787,33 +625,7 @@ void XmlElement::removeChildElement (XmlElement* const childToRemove,
{
if (childToRemove != 0)
{
if (firstChildElement == childToRemove)
{
firstChildElement = childToRemove->nextElement;
childToRemove->nextElement = 0;
}
else
{
XmlElement* child = firstChildElement;
XmlElement* last = 0;
while (child != 0)
{
if (child == childToRemove)
{
if (last == 0)
firstChildElement = child->nextElement;
else
last->nextElement = child->nextElement;
childToRemove->nextElement = 0;
break;
}
last = child;
child = child->nextElement;
}
}
firstChildElement.remove (childToRemove);
if (shouldDeleteTheChild)
delete childToRemove;
@ -838,7 +650,7 @@ bool XmlElement::isEquivalentTo (const XmlElement* const other,
if (! other->compareAttribute (att->name, att->value))
return false;
att = att->next;
att = att->nextListItem;
++totalAtts;
}
@ -866,8 +678,8 @@ bool XmlElement::isEquivalentTo (const XmlElement* const other,
return false;
}
thisAtt = thisAtt->next;
otherAtt = otherAtt->next;
thisAtt = thisAtt->nextListItem;
otherAtt = otherAtt->nextListItem;
}
}
@ -887,8 +699,8 @@ bool XmlElement::isEquivalentTo (const XmlElement* const other,
if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
return false;
thisChild = thisChild->nextElement;
otherChild = otherChild->nextElement;
thisChild = thisChild->nextListItem;
otherChild = otherChild->nextListItem;
}
}
@ -897,12 +709,7 @@ bool XmlElement::isEquivalentTo (const XmlElement* const other,
void XmlElement::deleteAllChildElements() throw()
{
while (firstChildElement != 0)
{
XmlElement* const nextChild = firstChildElement->nextElement;
delete firstChildElement;
firstChildElement = nextChild;
}
firstChildElement.deleteAll();
}
void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
@ -911,32 +718,18 @@ void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
while (child != 0)
{
XmlElement* const nextChild = child->nextListItem;
if (child->hasTagName (name))
{
XmlElement* const nextChild = child->nextElement;
removeChildElement (child, true);
child = nextChild;
}
else
{
child = child->nextElement;
}
child = nextChild;
}
}
bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
{
const XmlElement* child = firstChildElement;
while (child != 0)
{
if (child == possibleChild)
return true;
child = child->nextElement;
}
return false;
return firstChildElement.contains (possibleChild);
}
XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
@ -956,7 +749,7 @@ XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLo
if (found != 0)
return found;
child = child->nextElement;
child = child->nextListItem;
}
return 0;
@ -964,13 +757,7 @@ XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLo
void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
{
XmlElement* e = firstChildElement;
while (e != 0)
{
*elems++ = e;
e = e->nextElement;
}
firstChildElement.copyToArray (elems);
}
void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
@ -979,11 +766,11 @@ void XmlElement::reorderChildElements (XmlElement** const elems, const int num)
for (int i = 1; i < num; ++i)
{
e->nextElement = elems[i];
e = e->nextElement;
e->nextListItem = elems[i];
e = e->nextListItem;
}
e->nextElement = 0;
e->nextListItem = 0;
}
//==============================================================================
@ -1023,7 +810,7 @@ const String XmlElement::getAllSubText() const
while (child != 0)
{
concatenator.append (child->getAllSubText());
child = child->nextElement;
child = child->nextListItem;
}
return result;
@ -1058,7 +845,7 @@ void XmlElement::deleteAllTextElements() throw()
while (child != 0)
{
XmlElement* const next = child->nextElement;
XmlElement* const next = child->nextListItem;
if (child->isTextElement())
removeChildElement (child, true);