commit e471ce83b7e980da47cc0b3d999dc54720998833
parent ffad30d12f6bbf82b52a8a884c4158dc3eee38b9
Author: fundamental <mark.d.mccurry@gmail.com>
Date: Fri, 25 Sep 2009 09:34:50 -0400
XMLwrapper: added string loading from mxml TEXT
With the addition of loading from mxml TEXT fields, this fixes one of the reuse
issues that XMLwrapper had.
This means that in locations where multiple XMLwrappers may have been needed,
one may now suffice.
Diffstat:
3 files changed, 35 insertions(+), 53 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -909,3 +909,7 @@
- Started to use versioning information in XMLwrapper
- Remove last of stack helper functions in XMLwrapper
- Added std::string retreval to XMLwrapper
+
+25 Sep 2009 (Mark McCurry)
+ - Allowed for XMLwrapper to retrieve strings stored in mxml TEXT
+ fields
diff --git a/src/Misc/XMLwrapper.cpp b/src/Misc/XMLwrapper.cpp
@@ -437,9 +437,14 @@ void XMLwrapper::getparstr(const string &name,char *par,int maxstrlen) const
if (tmp==NULL) return;
if (tmp->child==NULL) return;
- if (tmp->child->type!=MXML_OPAQUE) return;
-
- snprintf(par,maxstrlen,"%s",tmp->child->value.element.name);
+ if (tmp->child->type==MXML_OPAQUE){
+ snprintf(par,maxstrlen,"%s",tmp->child->value.element.name);
+ return;
+ }
+ if (tmp->child->type==MXML_TEXT && tmp->child->value.text.string!=NULL){
+ snprintf(par,maxstrlen,"%s",tmp->child->value.text.string);
+ return;
+ }
};
@@ -447,10 +452,16 @@ string XMLwrapper::getparstr(const string &name,const std::string &defaultpar) c
{
const mxml_node_t * tmp = mxmlFindElement(node, node, "string", "name", name.c_str(), MXML_DESCEND_FIRST);
- if (tmp==NULL||tmp->child==NULL||tmp->child->type!=MXML_OPAQUE)
+ if (tmp==NULL||tmp->child==NULL)
return defaultpar;
- return tmp->child->value.element.name;
+ if (tmp->child->type==MXML_OPAQUE && tmp->child->value.element.name!=NULL)
+ return tmp->child->value.element.name;
+
+ if (tmp->child->type==MXML_TEXT && tmp->child->value.text.string!=NULL)
+ return tmp->child->value.text.string;
+
+ return defaultpar;
}
REALTYPE XMLwrapper::getparreal(const char *name,REALTYPE defaultpar) const
diff --git a/src/Tests/MicrotonalTest.h b/src/Tests/MicrotonalTest.h
@@ -63,7 +63,7 @@ public:
TS_ASSERT_DELTA(testMicro->getnotefreq(19,0),24.4997,0.0001);
}
-
+
//performs basic sanity check with the == and != operators
void testeqeq(){
Microtonal other;
@@ -77,68 +77,35 @@ public:
//Gah, the XMLwrapper is a twisted maze
testMicro->Penabled=1;
XMLwrapper xml;
- XMLwrapper xml2;
xml.beginbranch("Dummy"); //this should not be needed, but odd behavior
//seems to exist from MICROTONAL being on the
- //top of the stack
+ //top of the stack
xml.beginbranch("MICROTONAL");
testMicro->add2XML(&xml);
xml.endbranch();
- xml.endbranch();//this will cause the system to complain about
- //stack errors
-
- char *tmp=xml.getXMLdata();
- xml2.putXMLdata(tmp);
- //printf("%s",tmp);
- Microtonal other;
+ xml.endbranch();
- //cout << (char*)testMicro->Pname << " vs1 "
- // << (char*)other.Pname << endl;
+ char *tmp = xml.getXMLdata();
+ Microtonal other;
other.Penabled=1;
strcpy((char *)other.Pname,"Myname");//will be nicer with strings
- //cout << (char*)testMicro->Pname << " vs1.5 "
- // << (char*)other.Pname << endl;
-
TS_ASSERT(*testMicro!=other);//sanity check
-
- TS_ASSERT(xml2.enterbranch("Dummy"));
- TS_ASSERT(xml2.enterbranch("MICROTONAL"));
- //printf("%s",tmp);
-
- other.getfromXML(&xml2); //failure here
- xml2.exitbranch();
- xml2.exitbranch();
- char *tmpo=xml2.getXMLdata();
-
- //cout << (char*)testMicro->Pname << " vs2 "
- // << (char*)other.Pname << endl; //shows error here
-
- //printf("%s",tmpo);
-
- FILE *f=fopen("aaaa.xml","w");
- fprintf(f,tmp);
- fclose(f);
- FILE *f2=fopen("aaaaoo.xml","w");
- fprintf(f2,tmpo);
- fclose(f2);
- TS_ASSERT(!strcmp(tmp,tmpo)); //these should be equal, but there seems
- //to be one line that is duplicated
- //(I think in one of the reads)
+
+ TS_ASSERT(xml.enterbranch("Dummy"));
+ TS_ASSERT(xml.enterbranch("MICROTONAL"));
+
+ other.getfromXML(&xml);
+ xml.exitbranch();
+ xml.exitbranch();
+ char *tmpo=xml.getXMLdata();
+
+ TS_ASSERT(!strcmp(tmp,tmpo));
free(tmp);
free(tmpo);
- //testMicro->saveXML("0testMicro.xml");
- //other.saveXML("0other.xml");
-
TS_ASSERT(*testMicro==other); //cxxTest sees error here
- //cout << (char*)testMicro->Pname << " vs3 "
- // << (char*)other.Pname << endl;
- //remove unneeded files
- remove("aaaa.xml");
- remove("aaaaoo.xml");
-
}
/**\todo Test Saving/loading from file*/