summaryrefslogtreecommitdiff
path: root/indra/llxml/llxmlnode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llxml/llxmlnode.cpp')
-rwxr-xr-x[-rw-r--r--]indra/llxml/llxmlnode.cpp254
1 files changed, 110 insertions, 144 deletions
diff --git a/indra/llxml/llxmlnode.cpp b/indra/llxml/llxmlnode.cpp
index 8168f968cd..455df13e48 100644..100755
--- a/indra/llxml/llxmlnode.cpp
+++ b/indra/llxml/llxmlnode.cpp
@@ -43,8 +43,6 @@
#include "lluuid.h"
#include "lldir.h"
-const S32 MAX_COLUMN_WIDTH = 80;
-
// static
BOOL LLXMLNode::sStripEscapedStrings = TRUE;
BOOL LLXMLNode::sStripWhitespaceValues = FALSE;
@@ -147,13 +145,15 @@ LLXMLNodePtr LLXMLNode::deepCopy()
for (LLXMLChildList::iterator iter = mChildren->map.begin();
iter != mChildren->map.end(); ++iter)
{
- newnode->addChild(iter->second->deepCopy());
+ LLXMLNodePtr temp_ptr_for_gcc(iter->second->deepCopy());
+ newnode->addChild(temp_ptr_for_gcc);
}
}
for (LLXMLAttribList::iterator iter = mAttributes.begin();
iter != mAttributes.end(); ++iter)
{
- newnode->addChild(iter->second->deepCopy());
+ LLXMLNodePtr temp_ptr_for_gcc(iter->second->deepCopy());
+ newnode->addChild(temp_ptr_for_gcc);
}
return newnode;
@@ -259,7 +259,7 @@ BOOL LLXMLNode::removeChild(LLXMLNode *target_child)
return FALSE;
}
-void LLXMLNode::addChild(LLXMLNodePtr new_child, LLXMLNodePtr after_child)
+void LLXMLNode::addChild(LLXMLNodePtr& new_child)
{
if (new_child->mParent != NULL)
{
@@ -273,6 +273,11 @@ void LLXMLNode::addChild(LLXMLNodePtr new_child, LLXMLNodePtr after_child)
new_child->mParent = this;
if (new_child->mIsAttribute)
{
+ LLXMLAttribList::iterator found_it = mAttributes.find(new_child->mName);
+ if (found_it != mAttributes.end())
+ {
+ removeChild(found_it->second);
+ }
mAttributes.insert(std::make_pair(new_child->mName, new_child));
}
else
@@ -285,49 +290,11 @@ void LLXMLNode::addChild(LLXMLNodePtr new_child, LLXMLNodePtr after_child)
}
mChildren->map.insert(std::make_pair(new_child->mName, new_child));
- // if after_child is specified, it damn well better be in the list of children
- // for this node. I'm not going to assert that, because it would be expensive,
- // but don't specify that parameter if you didn't get the value for it from the
- // list of children of this node!
- if (after_child.isNull())
- {
- if (mChildren->tail != new_child)
- {
- mChildren->tail->mNext = new_child;
- new_child->mPrev = mChildren->tail;
- mChildren->tail = new_child;
- }
- }
- // if after_child == parent, then put new_child at beginning
- else if (after_child == this)
- {
- // add to front of list
- new_child->mNext = mChildren->head;
- if (mChildren->head)
- {
- mChildren->head->mPrev = new_child;
- mChildren->head = new_child;
- }
- else // no children
- {
- mChildren->head = new_child;
- mChildren->tail = new_child;
- }
- }
- else
+ if (mChildren->tail != new_child)
{
- if (after_child->mNext.notNull())
- {
- // if after_child was not the last item, fix up some pointers
- after_child->mNext->mPrev = new_child;
- new_child->mNext = after_child->mNext;
- }
- new_child->mPrev = after_child;
- after_child->mNext = new_child;
- if (mChildren->tail == after_child)
- {
- mChildren->tail = new_child;
- }
+ mChildren->tail->mNext = new_child;
+ new_child->mPrev = mChildren->tail;
+ mChildren->tail = new_child;
}
}
@@ -343,8 +310,9 @@ LLXMLNodePtr LLXMLNode::createChild(const char* name, BOOL is_attribute)
// virtual
LLXMLNodePtr LLXMLNode::createChild(LLStringTableEntry* name, BOOL is_attribute)
{
- LLXMLNode* ret = new LLXMLNode(name, is_attribute);
+ LLXMLNodePtr ret(new LLXMLNode(name, is_attribute));
ret->mID.clear();
+
addChild(ret);
return ret;
}
@@ -358,11 +326,12 @@ BOOL LLXMLNode::deleteChild(LLXMLNode *child)
return FALSE;
}
-void LLXMLNode::setParent(LLXMLNodePtr new_parent)
+void LLXMLNode::setParent(LLXMLNodePtr& new_parent)
{
if (new_parent.notNull())
{
- new_parent->addChild(this);
+ LLXMLNodePtr this_ptr(this);
+ new_parent->addChild(this_ptr);
}
else
{
@@ -417,7 +386,7 @@ void XMLCALL StartXMLNode(void *userData,
if (NULL == parent)
{
- llwarns << "parent (userData) is NULL; aborting function" << llendl;
+ LL_WARNS() << "parent (userData) is NULL; aborting function" << LL_ENDL;
return;
}
@@ -605,7 +574,7 @@ bool LLXMLNode::updateNode(
if (!node || !update_node)
{
- llwarns << "Node invalid" << llendl;
+ LL_WARNS() << "Node invalid" << LL_ENDL;
return FALSE;
}
@@ -631,13 +600,14 @@ bool LLXMLNode::updateNode(
}
//update all of node's children with updateNodes children that match name
- LLXMLNodePtr child;
+ LLXMLNodePtr child = node->getFirstChild();
+ LLXMLNodePtr last_child = child;
LLXMLNodePtr updateChild;
for (updateChild = update_node->getFirstChild(); updateChild.notNull();
updateChild = updateChild->getNextSibling())
{
- for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling())
+ while(child.notNull())
{
std::string nodeName;
std::string updateName;
@@ -656,6 +626,22 @@ bool LLXMLNode::updateNode(
if ((nodeName != "") && (updateName == nodeName))
{
updateNode(child, updateChild);
+ last_child = child;
+ child = child->getNextSibling();
+ if (child.isNull())
+ {
+ child = node->getFirstChild();
+ }
+ break;
+ }
+
+ child = child->getNextSibling();
+ if (child.isNull())
+ {
+ child = node->getFirstChild();
+ }
+ if (child == last_child)
+ {
break;
}
}
@@ -664,27 +650,6 @@ bool LLXMLNode::updateNode(
return TRUE;
}
-
-// static
-LLXMLNodePtr LLXMLNode::replaceNode(LLXMLNodePtr node, LLXMLNodePtr update_node)
-{
- if (!node || !update_node)
- {
- llwarns << "Node invalid" << llendl;
- return node;
- }
-
- LLXMLNodePtr cloned_node = update_node->deepCopy();
- node->mParent->addChild(cloned_node, node); // add after node
- LLXMLNodePtr parent = node->mParent;
- parent->removeChild(node);
- parent->updateDefault();
-
- return cloned_node;
-}
-
-
-
// static
bool LLXMLNode::parseFile(const std::string& filename, LLXMLNodePtr& node, LLXMLNode* defaults_tree)
{
@@ -693,7 +658,7 @@ bool LLXMLNode::parseFile(const std::string& filename, LLXMLNodePtr& node, LLXML
LLFILE* fp = LLFile::fopen(filename, "rb"); /* Flawfinder: ignore */
if (fp == NULL)
{
- node = new LLXMLNode();
+ node = NULL ;
return false;
}
fseek(fp, 0, SEEK_END);
@@ -733,10 +698,10 @@ bool LLXMLNode::parseBuffer(
// Do the parsing
if (XML_Parse(my_parser, (const char *)buffer, length, TRUE) != XML_STATUS_OK)
{
- llwarns << "Error parsing xml error code: "
+ LL_WARNS() << "Error parsing xml error code: "
<< XML_ErrorString(XML_GetErrorCode(my_parser))
<< " on line " << XML_GetCurrentLineNumber(my_parser)
- << llendl;
+ << LL_ENDL;
}
// Deinit
@@ -744,9 +709,9 @@ bool LLXMLNode::parseBuffer(
if (!file_node->mChildren || file_node->mChildren->map.size() != 1)
{
- llwarns << "Parse failure - wrong number of top-level nodes xml."
- << llendl;
- node = new LLXMLNode();
+ LL_WARNS() << "Parse failure - wrong number of top-level nodes xml."
+ << LL_ENDL;
+ node = NULL ;
return false;
}
@@ -784,14 +749,14 @@ bool LLXMLNode::parseStream(
while(str.good())
{
str.read((char*)buffer, BUFSIZE);
- int count = str.gcount();
+ int count = (int)str.gcount();
if (XML_Parse(my_parser, (const char *)buffer, count, !str.good()) != XML_STATUS_OK)
{
- llwarns << "Error parsing xml error code: "
+ LL_WARNS() << "Error parsing xml error code: "
<< XML_ErrorString(XML_GetErrorCode(my_parser))
<< " on lne " << XML_GetCurrentLineNumber(my_parser)
- << llendl;
+ << LL_ENDL;
break;
}
}
@@ -803,9 +768,9 @@ bool LLXMLNode::parseStream(
if (!file_node->mChildren || file_node->mChildren->map.size() != 1)
{
- llwarns << "Parse failure - wrong number of top-level nodes xml."
- << llendl;
- node = new LLXMLNode();
+ LL_WARNS() << "Parse failure - wrong number of top-level nodes xml."
+ << LL_ENDL;
+ node = NULL;
return false;
}
@@ -859,36 +824,32 @@ BOOL LLXMLNode::isFullyDefault()
}
// static
-bool LLXMLNode::getLayeredXMLNode(const std::string &xui_filename, LLXMLNodePtr& root,
+bool LLXMLNode::getLayeredXMLNode(LLXMLNodePtr& root,
const std::vector<std::string>& paths)
{
- std::string full_filename = gDirUtilp->findSkinnedFilename(paths.front(), xui_filename);
- if (full_filename.empty())
+ if (paths.empty()) return false;
+
+ std::string filename = paths.front();
+ if (filename.empty())
{
return false;
}
-
- if (!LLXMLNode::parseFile(full_filename, root, NULL))
+
+ if (!LLXMLNode::parseFile(filename, root, NULL))
{
- // try filename as passed in since sometimes we load an xml file from a user-supplied path
- if (!LLXMLNode::parseFile(xui_filename, root, NULL))
- {
- llwarns << "Problem reading UI description file: " << xui_filename << llendl;
- return false;
- }
+ LL_WARNS() << "Problem reading UI description file: " << filename << LL_ENDL;
+ return false;
}
LLXMLNodePtr updateRoot;
std::vector<std::string>::const_iterator itor;
- for (itor = paths.begin(), ++itor; itor != paths.end(); ++itor)
+ // We've already dealt with the first item, skip that one
+ for (itor = paths.begin() + 1; itor != paths.end(); ++itor)
{
- std::string nodeName;
- std::string updateName;
-
- std::string layer_filename = gDirUtilp->findSkinnedFilename((*itor), xui_filename);
- if(layer_filename.empty())
+ std::string layer_filename = *itor;
+ if(layer_filename.empty() || layer_filename == filename)
{
// no localized version of this file, that's ok, keep looking
continue;
@@ -896,10 +857,13 @@ bool LLXMLNode::getLayeredXMLNode(const std::string &xui_filename, LLXMLNodePtr&
if (!LLXMLNode::parseFile(layer_filename, updateRoot, NULL))
{
- llwarns << "Problem reading localized UI description file: " << (*itor) + gDirUtilp->getDirDelimiter() + xui_filename << llendl;
+ LL_WARNS() << "Problem reading localized UI description file: " << layer_filename << LL_ENDL;
return false;
}
+ std::string nodeName;
+ std::string updateName;
+
updateRoot->getAttributeString("name", updateName);
root->getAttributeString("name", nodeName);
@@ -932,7 +896,7 @@ void LLXMLNode::writeToFile(LLFILE *out_file, const std::string& indent, bool us
size_t written = fwrite(outstring.c_str(), 1, outstring.length(), out_file);
if (written != outstring.length())
{
- llwarns << "Short write" << llendl;
+ LL_WARNS() << "Short write" << LL_ENDL;
}
}
@@ -1183,7 +1147,8 @@ void LLXMLNode::scrubToTree(LLXMLNode *tree)
std::vector<LLXMLNodePtr>::iterator itor3;
for (itor3=to_delete_list.begin(); itor3!=to_delete_list.end(); ++itor3)
{
- (*itor3)->setParent(NULL);
+ LLXMLNodePtr ptr;
+ (*itor3)->setParent(ptr);
}
}
}
@@ -1208,7 +1173,7 @@ bool LLXMLNode::getChild(const LLStringTableEntry* name, LLXMLNodePtr& node, BOO
{
return mDefault->getChild(name, node, FALSE);
}
- node = new LLXMLNode();
+ node = NULL;
return false;
}
@@ -1279,7 +1244,7 @@ bool LLXMLNode::getAttribute(const LLStringTableEntry* name, LLXMLNodePtr& node,
{
return mDefault->getAttribute(name, node, FALSE);
}
- node = new LLXMLNode();
+
return false;
}
@@ -1768,9 +1733,9 @@ U32 LLXMLNode::getBoolValue(U32 expected_length, BOOL *array)
#if LL_DEBUG
if (ret_length != expected_length)
{
- lldebugs << "LLXMLNode::getBoolValue() failed for node named '"
+ LL_DEBUGS() << "LLXMLNode::getBoolValue() failed for node named '"
<< mName->mString << "' -- expected " << expected_length << " but "
- << "only found " << ret_length << llendl;
+ << "only found " << ret_length << LL_ENDL;
}
#endif
return ret_length;
@@ -1789,8 +1754,8 @@ U32 LLXMLNode::getByteValue(U32 expected_length, U8 *array, Encoding encoding)
if (mLength > 0 && mLength != expected_length)
{
- llwarns << "XMLNode::getByteValue asked for " << expected_length
- << " elements, while node has " << mLength << llendl;
+ LL_WARNS() << "XMLNode::getByteValue asked for " << expected_length
+ << " elements, while node has " << mLength << LL_ENDL;
return 0;
}
@@ -1813,7 +1778,7 @@ U32 LLXMLNode::getByteValue(U32 expected_length, U8 *array, Encoding encoding)
}
if (value > 255 || is_negative)
{
- llwarns << "getByteValue: Value outside of valid range." << llendl;
+ LL_WARNS() << "getByteValue: Value outside of valid range." << LL_ENDL;
break;
}
array[i] = U8(value);
@@ -1821,9 +1786,9 @@ U32 LLXMLNode::getByteValue(U32 expected_length, U8 *array, Encoding encoding)
#if LL_DEBUG
if (i != expected_length)
{
- lldebugs << "LLXMLNode::getByteValue() failed for node named '"
+ LL_DEBUGS() << "LLXMLNode::getByteValue() failed for node named '"
<< mName->mString << "' -- expected " << expected_length << " but "
- << "only found " << i << llendl;
+ << "only found " << i << LL_ENDL;
}
#endif
return i;
@@ -1841,8 +1806,8 @@ U32 LLXMLNode::getIntValue(U32 expected_length, S32 *array, Encoding encoding)
if (mLength > 0 && mLength != expected_length)
{
- llwarns << "XMLNode::getIntValue asked for " << expected_length
- << " elements, while node has " << mLength << llendl;
+ LL_WARNS() << "XMLNode::getIntValue asked for " << expected_length
+ << " elements, while node has " << mLength << LL_ENDL;
return 0;
}
@@ -1865,7 +1830,7 @@ U32 LLXMLNode::getIntValue(U32 expected_length, S32 *array, Encoding encoding)
}
if (value > 0x7fffffff)
{
- llwarns << "getIntValue: Value outside of valid range." << llendl;
+ LL_WARNS() << "getIntValue: Value outside of valid range." << LL_ENDL;
break;
}
array[i] = S32(value) * (is_negative?-1:1);
@@ -1874,9 +1839,9 @@ U32 LLXMLNode::getIntValue(U32 expected_length, S32 *array, Encoding encoding)
#if LL_DEBUG
if (i != expected_length)
{
- lldebugs << "LLXMLNode::getIntValue() failed for node named '"
+ LL_DEBUGS() << "LLXMLNode::getIntValue() failed for node named '"
<< mName->mString << "' -- expected " << expected_length << " but "
- << "only found " << i << llendl;
+ << "only found " << i << LL_ENDL;
}
#endif
return i;
@@ -1894,8 +1859,8 @@ U32 LLXMLNode::getUnsignedValue(U32 expected_length, U32 *array, Encoding encodi
if (mLength > 0 && mLength != expected_length)
{
- llwarns << "XMLNode::getUnsignedValue asked for " << expected_length
- << " elements, while node has " << mLength << llendl;
+ LL_WARNS() << "XMLNode::getUnsignedValue asked for " << expected_length
+ << " elements, while node has " << mLength << LL_ENDL;
return 0;
}
@@ -1919,7 +1884,7 @@ U32 LLXMLNode::getUnsignedValue(U32 expected_length, U32 *array, Encoding encodi
}
if (is_negative || value > 0xffffffff)
{
- llwarns << "getUnsignedValue: Value outside of valid range." << llendl;
+ LL_WARNS() << "getUnsignedValue: Value outside of valid range." << LL_ENDL;
break;
}
array[i] = U32(value);
@@ -1928,9 +1893,9 @@ U32 LLXMLNode::getUnsignedValue(U32 expected_length, U32 *array, Encoding encodi
#if LL_DEBUG
if (i != expected_length)
{
- lldebugs << "LLXMLNode::getUnsignedValue() failed for node named '"
+ LL_DEBUGS() << "LLXMLNode::getUnsignedValue() failed for node named '"
<< mName->mString << "' -- expected " << expected_length << " but "
- << "only found " << i << llendl;
+ << "only found " << i << LL_ENDL;
}
#endif
@@ -1949,7 +1914,7 @@ U32 LLXMLNode::getLongValue(U32 expected_length, U64 *array, Encoding encoding)
if (mLength > 0 && mLength != expected_length)
{
- llwarns << "XMLNode::getLongValue asked for " << expected_length << " elements, while node has " << mLength << llendl;
+ LL_WARNS() << "XMLNode::getLongValue asked for " << expected_length << " elements, while node has " << mLength << LL_ENDL;
return 0;
}
@@ -1973,7 +1938,7 @@ U32 LLXMLNode::getLongValue(U32 expected_length, U64 *array, Encoding encoding)
}
if (is_negative)
{
- llwarns << "getLongValue: Value outside of valid range." << llendl;
+ LL_WARNS() << "getLongValue: Value outside of valid range." << LL_ENDL;
break;
}
array[i] = value;
@@ -1982,9 +1947,9 @@ U32 LLXMLNode::getLongValue(U32 expected_length, U64 *array, Encoding encoding)
#if LL_DEBUG
if (i != expected_length)
{
- lldebugs << "LLXMLNode::getLongValue() failed for node named '"
+ LL_DEBUGS() << "LLXMLNode::getLongValue() failed for node named '"
<< mName->mString << "' -- expected " << expected_length << " but "
- << "only found " << i << llendl;
+ << "only found " << i << LL_ENDL;
}
#endif
@@ -2003,7 +1968,7 @@ U32 LLXMLNode::getFloatValue(U32 expected_length, F32 *array, Encoding encoding)
if (mLength > 0 && mLength != expected_length)
{
- llwarns << "XMLNode::getFloatValue asked for " << expected_length << " elements, while node has " << mLength << llendl;
+ LL_WARNS() << "XMLNode::getFloatValue asked for " << expected_length << " elements, while node has " << mLength << LL_ENDL;
return 0;
}
@@ -2028,9 +1993,9 @@ U32 LLXMLNode::getFloatValue(U32 expected_length, F32 *array, Encoding encoding)
#if LL_DEBUG
if (i != expected_length)
{
- lldebugs << "LLXMLNode::getFloatValue() failed for node named '"
+ LL_DEBUGS() << "LLXMLNode::getFloatValue() failed for node named '"
<< mName->mString << "' -- expected " << expected_length << " but "
- << "only found " << i << llendl;
+ << "only found " << i << LL_ENDL;
}
#endif
return i;
@@ -2048,7 +2013,7 @@ U32 LLXMLNode::getDoubleValue(U32 expected_length, F64 *array, Encoding encoding
if (mLength > 0 && mLength != expected_length)
{
- llwarns << "XMLNode::getDoubleValue asked for " << expected_length << " elements, while node has " << mLength << llendl;
+ LL_WARNS() << "XMLNode::getDoubleValue asked for " << expected_length << " elements, while node has " << mLength << LL_ENDL;
return 0;
}
@@ -2073,9 +2038,9 @@ U32 LLXMLNode::getDoubleValue(U32 expected_length, F64 *array, Encoding encoding
#if LL_DEBUG
if (i != expected_length)
{
- lldebugs << "LLXMLNode::getDoubleValue() failed for node named '"
+ LL_DEBUGS() << "LLXMLNode::getDoubleValue() failed for node named '"
<< mName->mString << "' -- expected " << expected_length << " but "
- << "only found " << i << llendl;
+ << "only found " << i << LL_ENDL;
}
#endif
return i;
@@ -2089,7 +2054,7 @@ U32 LLXMLNode::getStringValue(U32 expected_length, std::string *array)
if (mLength > 0 && mLength != expected_length)
{
- llwarns << "XMLNode::getStringValue asked for " << expected_length << " elements, while node has " << mLength << llendl;
+ LL_WARNS() << "XMLNode::getStringValue asked for " << expected_length << " elements, while node has " << mLength << LL_ENDL;
return 0;
}
@@ -2121,9 +2086,9 @@ U32 LLXMLNode::getStringValue(U32 expected_length, std::string *array)
#if LL_DEBUG
if (num_returned_strings != expected_length)
{
- lldebugs << "LLXMLNode::getStringValue() failed for node named '"
+ LL_DEBUGS() << "LLXMLNode::getStringValue() failed for node named '"
<< mName->mString << "' -- expected " << expected_length << " but "
- << "only found " << num_returned_strings << llendl;
+ << "only found " << num_returned_strings << LL_ENDL;
}
#endif
@@ -2166,9 +2131,9 @@ U32 LLXMLNode::getUUIDValue(U32 expected_length, LLUUID *array)
#if LL_DEBUG
if (i != expected_length)
{
- lldebugs << "LLXMLNode::getUUIDValue() failed for node named '"
+ LL_DEBUGS() << "LLXMLNode::getUUIDValue() failed for node named '"
<< mName->mString << "' -- expected " << expected_length << " but "
- << "only found " << i << llendl;
+ << "only found " << i << LL_ENDL;
}
#endif
return i;
@@ -2197,11 +2162,11 @@ U32 LLXMLNode::getNodeRefValue(U32 expected_length, LLXMLNode **array)
root->findID(string_array[strnum], node_list);
if (node_list.empty())
{
- llwarns << "XML: Could not find node ID: " << string_array[strnum] << llendl;
+ LL_WARNS() << "XML: Could not find node ID: " << string_array[strnum] << LL_ENDL;
}
else if (node_list.size() > 1)
{
- llwarns << "XML: Node ID not unique: " << string_array[strnum] << llendl;
+ LL_WARNS() << "XML: Node ID not unique: " << string_array[strnum] << LL_ENDL;
}
else
{
@@ -2718,7 +2683,8 @@ void LLXMLNode::setName(LLStringTableEntry* name)
mName = name;
if (old_parent)
{
- old_parent->addChild(this);
+ LLXMLNodePtr this_ptr(this);
+ old_parent->addChild(this_ptr);
}
}