21 #ifndef DOXYGEN_NOTFOR_DEVEL
23 #ifndef Tulip_GLXMLTOOLS_H
24 #define Tulip_GLXMLTOOLS_H
30 #include <tulip/tulipconf.h>
31 #include <tulip/Color.h>
32 #include <tulip/Coord.h>
41 class TLP_GL_SCOPE GlXMLTools {
48 static void beginDataNode(std::string &outString);
53 static void endDataNode(std::string &outString);
58 static void enterDataNode(
const std::string &inString,
unsigned int ¤tPosition);
63 static void leaveDataNode(
const std::string &inString,
unsigned int ¤tPosition);
68 static void beginChildNode(std::string &outString,
const std::string &name=
"children");
73 static void endChildNode(std::string &outString,
const std::string &name=
"children");
79 static std::string enterChildNode(
const std::string &inString,
unsigned int ¤tPosition);
85 static void leaveChildNode(
const std::string &inString,
unsigned int ¤tPosition,
const std::string &childName);
90 static void createProperty(std::string &outString,
const std::string &name,
const std::string &value,
const std::string &parent=
"");
96 static std::map<std::string,std::string> getProperties(
const std::string &inString,
unsigned int ¤tPosition);
101 static GlSimpleEntity *createEntity(
const std::string &name);
106 template <
typename Obj>
107 static void getXML(std::string &outString,
const std::string &name,
const typename std::vector<Obj> &vect) {
109 std::stringstream str;
111 typename std::vector<Obj>::const_iterator it=vect.begin();
112 assert(it != vect.end());
116 for(; it!=vect.end(); ++it) {
121 outString.append(
"<"+name+
">"+str.str()+
"</"+name+
">\n");
127 template <
typename Obj>
128 static void setWithXML(
const std::string &inString,
unsigned int ¤tPosition,
const std::string &name,std::vector<Obj> &vect) {
130 goToNextCaracter(inString,currentPosition);
132 std::string nameTag=inString.substr(currentPosition,name.size()+2);
133 assert(nameTag==
"<"+name+
">");
134 currentPosition+=name.size()+2;
136 size_t endValuePosition=inString.find(
"</"+name+
">",currentPosition);
137 assert(endValuePosition!=std::string::npos);
139 std::istringstream is(inString.substr(currentPosition,endValuePosition-currentPosition));
145 vect.push_back(data);
149 currentPosition=endValuePosition+name.size()+3;
156 template <
typename Obj>
157 static void getXML(std::string &outString,
const std::string &name,
const Obj &value) {
158 std::stringstream str;
160 applyIndentation(outString);
161 outString.append(
"<"+name+
">"+str.str()+
"</"+name+
">\n");
165 static bool checkNextXMLtag(
const std::string &inString,
unsigned int ¤tPosition,
const std::string &name){
166 unsigned int tmp=currentPosition;
167 goToNextCaracter(inString,tmp);
168 std::string nameTag=inString.substr(tmp,name.size()+2);
169 return (nameTag==
"<"+name+
">");
175 template <
typename Obj>
176 static void setWithXML(
const std::string &inString,
unsigned int ¤tPosition,
const std::string &name, Obj &value) {
178 goToNextCaracter(inString,currentPosition);
180 std::string nameTag=inString.substr(currentPosition,name.size()+2);
181 assert(nameTag==
"<"+name+
">");
182 currentPosition+=name.size()+2;
184 size_t endValuePosition=inString.find(
"</"+name+
">",currentPosition);
185 assert(endValuePosition!=std::string::npos);
187 std::stringstream str(inString.substr(currentPosition,endValuePosition-currentPosition));
189 currentPosition=endValuePosition+name.size()+3;
195 template <
typename Obj>
196 static void setWithXML(
const std::string &inString,
unsigned int ¤tPosition,
const std::string &name, Obj &value,
const Obj &defValue) {
197 goToNextCaracter(inString,currentPosition);
199 std::string nameTag=inString.substr(currentPosition,name.size()+2);
201 if(nameTag==
"<"+name+
">") {
202 currentPosition+=name.size()+2;
204 size_t endValuePosition=inString.find(
"</"+name+
">",currentPosition);
205 assert(endValuePosition!=std::string::npos);
207 std::stringstream str(inString.substr(currentPosition,endValuePosition-currentPosition));
209 currentPosition=endValuePosition+name.size()+3;
218 static void applyIndentation(std::string &outString);
219 static void goToNextCaracter(
const std::string &inString,
unsigned int ¤tPosition);
221 static unsigned int indentationNumber;
228 #endif //DOXYGEN_NOTFOR_DEVEL