commit d615485758af096f89c03d0541fde432ea39e8e5
parent cd70dfbc423ef04d2e1963b2e3983ea3800fdf54
Author: fundamental <mark.d.mccurry@gmail.com>
Date: Fri, 11 Sep 2009 20:38:47 -0400
Removed unneeded stack within XMLwrapper
The stack that was implemented within the wrapper was not needed, as the mxml
nodes all have pointers to their parents.
Diffstat:
3 files changed, 12 insertions(+), 59 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -903,3 +903,4 @@
- Replaced int2str, real2str, str2int, and str2real from XMLwrapper
with stringTo<T> and stringFrom<T> function templates in Util.
- Moved newFFTFREQS and deleteFFTFREQS from Util to FFTwrapper
+ - Removed unneeded stack from XMLwrapper
diff --git a/src/Misc/XMLwrapper.cpp b/src/Misc/XMLwrapper.cpp
@@ -36,9 +36,7 @@
using namespace std;
-int xml_k=0;
-char tabs[STACKSIZE+2];
-
+int xml_k = 0;
bool verbose = false;
const char *XMLwrapper_whitespace_callback(mxml_node_t *node,int where)
@@ -93,11 +91,9 @@ const char *mxmlElementGetAttr(const mxml_node_t *node, const char *name)
XMLwrapper::XMLwrapper()
{
- ZERO(&parentstack,(int)sizeof(parentstack));
ZERO(&values,(int)sizeof(values));
minimal=true;
- stackpos=0;
tree=mxmlNewElement(MXML_NO_PARENT,"?xml version=\"1.0\" encoding=\"UTF-8\"?");
/* for mxml 2.1 (and older)
@@ -185,8 +181,7 @@ int XMLwrapper::saveXMLfile(const string &filename) const
char *XMLwrapper::getXMLdata() const
{
- //xml_k=0;
- ZERO(tabs,STACKSIZE+2);
+ xml_k=0;
char *xmldata=mxmlSaveAllocString(tree,XMLwrapper_whitespace_callback);
@@ -276,11 +271,8 @@ int XMLwrapper::loadXMLfile(const string &filename)
if (tree!=NULL) mxmlDelete(tree);
tree=NULL;
- ZERO(&parentstack,(int)sizeof(parentstack));
ZERO(&values,(int)sizeof(values));
- stackpos=0;
-
const char *xmldata=doloadfile(filename.c_str());
if (xmldata==NULL) return(-1);//the file could not be loaded or uncompressed
@@ -338,11 +330,8 @@ bool XMLwrapper::putXMLdata(const char *xmldata)
if (tree!=NULL) mxmlDelete(tree);
tree=NULL;
- ZERO(&parentstack,(int)sizeof(parentstack));
ZERO(&values,(int)sizeof(values));
- stackpos=0;
-
if (xmldata==NULL) return (false);
root=tree=mxmlLoadString(NULL,xmldata,MXML_OPAQUE_CALLBACK);
@@ -385,8 +374,7 @@ void XMLwrapper::exitbranch()
{
if(verbose)
cout << "exitbranch() " << endl;
- /**@bug Does not set the current node correctly*/
- pop();
+ node = pop();
};
@@ -498,52 +486,27 @@ void XMLwrapper::push(mxml_node_t *node)
{
if(verbose)
cout << "push() " << node << "-" << node->value.element.name << endl;
- if (stackpos>=STACKSIZE-1) {
- cerr << "BUG!: XMLwrapper::push() - full parentstack" << endl;
- return;
- };
- stackpos++;
- parentstack[stackpos]=node;
-
-// printf("push %d - %s\n",stackpos,node->value.element.name);
+ this->node = node;
+}
-};
mxml_node_t *XMLwrapper::pop()
{
if(verbose)
- cout << "pop() " << node->parent << " : " << parentstack[stackpos] << "-" << node->parent->value.element.name << " -" << parentstack[stackpos]->value.element.name <<endl;
- if (stackpos<=0) {
- cerr << "BUG!: XMLwrapper::pop() - empty parentstack" << endl;
- return (root);
- };
- mxml_node_t *node=parentstack[stackpos];
- parentstack[stackpos]=NULL;
-
-// printf("pop %d - %s\n",stackpos,node->value.element.name);
-
- stackpos--;
- return(node);
+ cout << "pop() " << node->parent << "-" << node->parent->value.element.name << endl;
+ return node->parent;
};
mxml_node_t *XMLwrapper::peek()
{
if(verbose)
- cout << "peek() " << node << " : " << parentstack[stackpos] << "-" << node->value.element.name << " -" << parentstack[stackpos]->value.element.name << endl;
- if (stackpos<=0) {
- cerr << "BUG!: XMLwrapper::peek() - empty parentstack" << endl;
- return (root);
- };
- return(parentstack[stackpos]);
+ cout << "peek() " << node << "-" << node->value.element.name << endl;
+ return node;
}
const mxml_node_t *XMLwrapper::peek() const
{
if(verbose)
- cout << "peek()const " << node << " : " << parentstack[stackpos] << "-" << node->value.element.name << " -" << parentstack[stackpos]->value.element.name << endl;
- if (stackpos<=0) {
- cerr << "BUG!: XMLwrapper::peek() - empty parentstack" << endl;
- return (root);
- };
- return(parentstack[stackpos]);
+ cout << "peek()const " << node << "-" << node->value.element.name << endl;
+ return node;
}
diff --git a/src/Misc/XMLwrapper.h b/src/Misc/XMLwrapper.h
@@ -31,11 +31,6 @@
#ifndef XML_WRAPPER_H
#define XML_WRAPPER_H
-#define TMPSTR_SIZE 50
-
-//the maxim tree depth
-#define STACKSIZE 100
-
/**Mxml wrapper*/
class XMLwrapper
{
@@ -250,12 +245,6 @@ private:
*/
mxml_node_t *addparams(const char *name, unsigned int params, ...) const;
- /**this is used to store the parents.
- * @todo Use the stack class provided by C++*/
- mxml_node_t *parentstack[STACKSIZE];
- int stackpos;/**<position in stack*/
-
-
void push(mxml_node_t *node);
/**Pops top node off of parent stack*/