21 #ifndef DOXYGEN_NOTFOR_DEVEL
23 #ifndef Tulip_GLXMLTOOLS_H
24 #define Tulip_GLXMLTOOLS_H
31 #include <tulip/tulipconf.h>
40 class TLP_GL_SCOPE GlXMLTools {
47 static void beginDataNode(std::string &outString);
52 static void endDataNode(std::string &outString);
57 static void enterDataNode(
const std::string &inString,
unsigned int ¤tPosition);
62 static void leaveDataNode(
const std::string &inString,
unsigned int ¤tPosition);
67 static void beginChildNode(std::string &outString,
const std::string &name=
"children");
72 static void endChildNode(std::string &outString,
const std::string &name=
"children");
78 static std::string enterChildNode(
const std::string &inString,
unsigned int ¤tPosition);
84 static void leaveChildNode(
const std::string &inString,
unsigned int ¤tPosition,
const std::string &childName);
89 static void createProperty(std::string &outString,
const std::string &name,
const std::string &value,
const std::string &parent=
"");
95 static std::map<std::string,std::string> getProperties(
const std::string &inString,
unsigned int ¤tPosition);
100 static GlSimpleEntity *createEntity(
const std::string &name);
105 template <
typename Obj>
106 static void getXML(std::string &outString,
const std::string &name,
const typename std::vector<Obj> &vect) {
108 std::stringstream str;
110 typename std::vector<Obj>::const_iterator it=vect.begin();
111 assert(it != vect.end());
115 for(; it!=vect.end(); ++it) {
120 outString.append(
"<"+name+
">"+str.str()+
"</"+name+
">\n");
126 template <
typename Obj>
127 static void setWithXML(
const std::string &inString,
unsigned int ¤tPosition,
const std::string &name,std::vector<Obj> &vect) {
129 goToNextCaracter(inString,currentPosition);
131 std::string nameTag=inString.substr(currentPosition,name.size()+2);
132 assert(nameTag==
"<"+name+
">");
133 currentPosition+=name.size()+2;
135 size_t endValuePosition=inString.find(
"</"+name+
">",currentPosition);
136 assert(endValuePosition!=std::string::npos);
138 std::istringstream is(inString.substr(currentPosition,endValuePosition-currentPosition));
144 vect.push_back(data);
148 currentPosition=endValuePosition+name.size()+3;
155 template <
typename Obj>
156 static void getXML(std::string &outString,
const std::string &name,
const Obj &value) {
157 std::stringstream str;
159 applyIndentation(outString);
160 outString.append(
"<"+name+
">"+str.str()+
"</"+name+
">\n");
164 static bool checkNextXMLtag(
const std::string &inString,
unsigned int ¤tPosition,
const std::string &name) {
165 unsigned int tmp=currentPosition;
166 goToNextCaracter(inString,tmp);
167 std::string nameTag=inString.substr(tmp,name.size()+2);
168 return (nameTag==
"<"+name+
">");
174 template <
typename Obj>
175 static void setWithXML(
const std::string &inString,
unsigned int ¤tPosition,
const std::string &name, Obj &value) {
177 goToNextCaracter(inString,currentPosition);
179 std::string nameTag=inString.substr(currentPosition,name.size()+2);
180 assert(nameTag==
"<"+name+
">");
181 currentPosition+=name.size()+2;
183 size_t endValuePosition=inString.find(
"</"+name+
">",currentPosition);
184 assert(endValuePosition!=std::string::npos);
186 std::stringstream str(inString.substr(currentPosition,endValuePosition-currentPosition));
188 currentPosition=endValuePosition+name.size()+3;
194 template <
typename Obj>
195 static void setWithXML(
const std::string &inString,
unsigned int ¤tPosition,
const std::string &name, Obj &value,
const Obj &defValue) {
196 goToNextCaracter(inString,currentPosition);
198 std::string nameTag=inString.substr(currentPosition,name.size()+2);
200 if(nameTag==
"<"+name+
">") {
201 currentPosition+=name.size()+2;
203 size_t endValuePosition=inString.find(
"</"+name+
">",currentPosition);
204 assert(endValuePosition!=std::string::npos);
206 std::stringstream str(inString.substr(currentPosition,endValuePosition-currentPosition));
208 currentPosition=endValuePosition+name.size()+3;
217 static void applyIndentation(std::string &outString);
218 static void goToNextCaracter(
const std::string &inString,
unsigned int ¤tPosition);
220 static unsigned int indentationNumber;
227 #endif //DOXYGEN_NOTFOR_DEVEL