Last active
December 27, 2015 17:59
-
-
Save jvcleave/7366381 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "ofMain.h" | |
| #define STRINGIFY(x) #x | |
| class ofApp : public ofBaseApp | |
| { | |
| public: | |
| ofParameter<bool> createBoolean(ofXml& xmlParser) | |
| { | |
| string childName = xmlParser.getName(); | |
| ofParameter<bool> item; | |
| item.set(childName, xmlParser.getBoolValue()); | |
| return item; | |
| } | |
| ofParameterGroup createParameterGroup(ofXml& xmlParser) | |
| { | |
| ofParameterGroup parameterGroup; | |
| string elementName = xmlParser.getName(); | |
| parameterGroup.setName(elementName); | |
| int numElementChildren = xmlParser.getNumChildren(); | |
| for(int j=0; j<numElementChildren; j++) | |
| { | |
| xmlParser.setToChild(j); | |
| ofParameter<bool> item = createBoolean(xmlParser); | |
| parameterGroup.add(item); | |
| xmlParser.setToParent(); | |
| } | |
| return parameterGroup; | |
| } | |
| void setup() | |
| { | |
| ofSetLogLevel(OF_LOG_VERBOSE); | |
| inputXML = STRINGIFY( | |
| <root> | |
| <single>0</single> | |
| <double>0</double> | |
| <triple>0</triple> | |
| <quad>0</quad> | |
| <clauses> | |
| <who>0</who> | |
| <what>0</what> | |
| <where>0</where> | |
| <how>0</how> | |
| </clauses> | |
| <locations> | |
| <here>0</here> | |
| <there>0</there> | |
| </locations> | |
| </root> | |
| ); | |
| ofLogVerbose() << "inputXML: " << inputXML; | |
| xmlParser.loadFromBuffer(inputXML); | |
| xmlParser.setTo("root"); | |
| mainGroup.setName("main"); | |
| int numRootChildren = xmlParser.getNumChildren(); | |
| ofLogVerbose() << "numRootChildren: " << numRootChildren; | |
| for(int i=0; i<numRootChildren; i++) | |
| { | |
| xmlParser.setToChild(i); | |
| int numElementChildren = xmlParser.getNumChildren(); | |
| ofLogVerbose() << "xmlParser.getName(): " << xmlParser.getName(); | |
| if (numElementChildren>0) | |
| { | |
| ofParameterGroup parameterGroup = createParameterGroup(xmlParser); | |
| mainGroup.add(parameterGroup); | |
| ofLogVerbose() << mainGroup.getName() << "\n" << mainGroup.toString(); | |
| }else | |
| { | |
| ofParameter<bool> singleItem = createBoolean(xmlParser); | |
| mainGroup.add(singleItem); | |
| ofLogVerbose() << mainGroup.getName() << ":" << mainGroup.toString(); | |
| } | |
| xmlParser.setToParent(); | |
| } | |
| //next line will crash | |
| ofLogVerbose() << mainGroup.getName() << ":" << mainGroup.toString(); | |
| //; | |
| } | |
| string inputXML; | |
| ofXml xmlParser; | |
| ofParameterGroup mainGroup; | |
| }; | |
| //======================================================================== | |
| int main( ){ | |
| ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context | |
| // this kicks off the running of my app | |
| // can be OF_WINDOW or OF_FULLSCREEN | |
| // pass in width and height too: | |
| ofRunApp( new ofApp()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "ofMain.h" | |
| #define STRINGIFY(x) #x | |
| class ofApp : public ofBaseApp | |
| { | |
| public: | |
| ofParameter<bool> createBoolean(ofXml& xmlParser) | |
| { | |
| string childName = xmlParser.getName(); | |
| ofParameter<bool> item; | |
| item.set(childName, xmlParser.getBoolValue()); | |
| return item; | |
| } | |
| ofParameterGroup* createParameterGroup(ofXml& xmlParser) | |
| { | |
| ofParameterGroup* parameterGroup = new ofParameterGroup(); | |
| string elementName = xmlParser.getName(); | |
| parameterGroup->setName(elementName); | |
| int numElementChildren = xmlParser.getNumChildren(); | |
| for(int j=0; j<numElementChildren; j++) | |
| { | |
| xmlParser.setToChild(j); | |
| ofParameter<bool> item = createBoolean(xmlParser); | |
| parameterGroup->add(item); | |
| xmlParser.setToParent(); | |
| } | |
| return parameterGroup; | |
| } | |
| void setup() | |
| { | |
| ofSetLogLevel(OF_LOG_VERBOSE); | |
| inputXML = STRINGIFY( | |
| <root> | |
| <single>0</single> | |
| <double>0</double> | |
| <triple>0</triple> | |
| <quad>0</quad> | |
| <clauses> | |
| <who>0</who> | |
| <what>0</what> | |
| <where>0</where> | |
| <how>0</how> | |
| </clauses> | |
| <locations> | |
| <here>0</here> | |
| <there>0</there> | |
| </locations> | |
| </root> | |
| ); | |
| ofLogVerbose() << "inputXML: " << inputXML; | |
| xmlParser.loadFromBuffer(inputXML); | |
| xmlParser.setTo("root"); | |
| mainGroup.setName("main"); | |
| int numRootChildren = xmlParser.getNumChildren(); | |
| ofLogVerbose() << "numRootChildren: " << numRootChildren; | |
| for(int i=0; i<numRootChildren; i++) | |
| { | |
| xmlParser.setToChild(i); | |
| int numElementChildren = xmlParser.getNumChildren(); | |
| ofLogVerbose() << "xmlParser.getName(): " << xmlParser.getName(); | |
| if (numElementChildren>0) | |
| { | |
| ofParameterGroup* parameterGroup = createParameterGroup(xmlParser); | |
| mainGroup.add(*parameterGroup); | |
| ofLogVerbose() << mainGroup.getName() << "\n" << mainGroup.toString(); | |
| }else | |
| { | |
| ofParameter<bool> singleItem = createBoolean(xmlParser); | |
| mainGroup.add(singleItem); | |
| ofLogVerbose() << mainGroup.getName() << ":" << mainGroup.toString(); | |
| } | |
| xmlParser.setToParent(); | |
| } | |
| ofLogVerbose() << mainGroup.getName() << ":" << mainGroup.toString(); | |
| // | |
| } | |
| string inputXML; | |
| ofXml xmlParser; | |
| ofParameterGroup mainGroup; | |
| }; | |
| //======================================================================== | |
| int main( ){ | |
| ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context | |
| // this kicks off the running of my app | |
| // can be OF_WINDOW or OF_FULLSCREEN | |
| // pass in width and height too: | |
| ofRunApp( new ofApp()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment