#pragma once
#include "ofMain.h"
#include <string.h>
#if (_MSC_VER)
#include "../libs/tinyxml.h"
#else
#include "tinyxml.h"
#endif
using namespace std;
#define MAX_TAG_VALUE_LENGTH_IN_CHARS 1024
class ofxXmlSettings{
public:
ofxXmlSettings();
ofxXmlSettings(const string& xmlFile);
~ofxXmlSettings();
void setVerbose(bool _verbose);
bool loadFile(const string& xmlFile);
bool saveFile(const string& xmlFile);
bool saveFile();
bool load(const string & path);
bool save(const string & path);
void clearTagContents(const string& tag, int which = 0);
void removeTag(const string& tag, int which = 0);
bool tagExists(const string& tag, int which = 0) const;
void clear();
int getValue(const string& tag, int defaultValue, int which = 0) const;
double getValue(const string& tag, double defaultValue, int which = 0) const;
string getValue(const string& tag, const string& defaultValue, int which = 0) const;
int setValue(const string& tag, int value, int which = 0);
int setValue(const string& tag, double value, int which = 0);
int setValue(const string& tag, const string& value, int which = 0);
bool pushTag(const string& tag, int which = 0);
int popTag();
int getPushLevel();
int getNumTags(const string& tag) const;
int addValue(const string& tag, int value);
int addValue(const string& tag, double value);
int addValue(const string& tag, const string& value);
int addTag(const string& tag);
int addAttribute(const string& tag, const string& attribute, int value, int which = 0);
int addAttribute(const string& tag, const string& attribute, double value, int which = 0);
int addAttribute(const string& tag, const string& attribute, const string& value, int which = 0);
int addAttribute(const string& tag, const string& attribute, int value);
int addAttribute(const string& tag, const string& attribute, double value);
int addAttribute(const string& tag, const string& attribute, const string& value);
void removeAttribute(const string& tag, const string& attribute, int which = 0);
void clearTagAttributes(const string& tag, int which = 0);
int getNumAttributes(const string& tag, int which = 0) const;
bool attributeExists(const string& tag, const string& attribute, int which = 0) const;
bool getAttributeNames(const string& tag, vector<string>& outNames, int which = 0) const;
int getAttribute(const string& tag, const string& attribute, int defaultValue, int which = 0) const;
double getAttribute(const string& tag, const string& attribute, double defaultValue, int which = 0) const;
string getAttribute(const string& tag, const string& attribute, const string& defaultValue, int which = 0) const;
int setAttribute(const string& tag, const string& attribute, int value, int which = 0);
int setAttribute(const string& tag, const string& attribute, double value, int which = 0);
int setAttribute(const string& tag, const string& attribute, const string& value, int which = 0);
int setAttribute(const string& tag, const string& attribute, int value);
int setAttribute(const string& tag, const string& attribute, double value);
int setAttribute(const string& tag, const string& attribute, const string& value);
bool loadFromBuffer( string buffer );
void copyXmlToString(string & str) const;
TiXmlDocument doc;
bool bDocLoaded;
protected:
TiXmlHandle storedHandle;
int level;
int writeTag(const string& tag, const string& valueString, int which = 0);
bool readTag(const string& tag, TiXmlHandle& valHandle, int which = 0) const;
int writeAttribute(const string& tag, const string& attribute, const string& valueString, int which = 0);
TiXmlElement* getElementForAttribute(const string& tag, int which) const;
bool readIntAttribute(const string& tag, const string& attribute, int& valueString, int which) const;
bool readDoubleAttribute(const string& tag, const string& attribute, double& outValue, int which) const;
bool readStringAttribute(const string& tag, const string& attribute, string& outValue, int which) const;
};
void ofSerialize(ofxXmlSettings & settings, const ofAbstractParameter & parameter);
void ofDeserialize(const ofxXmlSettings & settings, ofAbstractParameter & parameter);
Comments