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 {
46 static void beginDataNode(std::string &outString);
51 static void endDataNode(std::string &outString);
56 static void enterDataNode(
const std::string &inString,
unsigned int ¤tPosition);
61 static void leaveDataNode(
const std::string &inString,
unsigned int ¤tPosition);
66 static void beginChildNode(std::string &outString,
const std::string &name =
"children");
71 static void endChildNode(std::string &outString,
const std::string &name =
"children");
77 static std::string enterChildNode(
const std::string &inString,
unsigned int ¤tPosition);
84 static void leaveChildNode(
const std::string &inString,
unsigned int ¤tPosition,
85 const std::string &childName);
90 static void createProperty(std::string &outString,
const std::string &name,
91 const std::string &value,
const std::string &parent =
"");
97 static std::map<std::string, std::string> getProperties(
const std::string &inString,
98 unsigned int ¤tPosition);
103 static GlSimpleEntity *createEntity(
const std::string &name);
108 template <
typename Obj>
109 static void getXML(std::string &outString,
const std::string &name,
110 const typename std::vector<Obj> &vect) {
112 std::stringstream str;
114 typename std::vector<Obj>::const_iterator it = vect.begin();
115 assert(it != vect.end());
119 for (; it != vect.end(); ++it) {
124 outString.append(
"<" + name +
">" + str.str() +
"</" + name +
">\n");
130 template <
typename Obj>
131 static void setWithXML(
const std::string &inString,
unsigned int ¤tPosition,
132 const std::string &name, std::vector<Obj> &vect) {
134 goToNextCaracter(inString, currentPosition);
136 std::string nameTag = inString.substr(currentPosition, name.size() + 2);
137 assert(nameTag ==
"<" + name +
">");
138 currentPosition += name.size() + 2;
140 size_t endValuePosition = inString.find(
"</" + name +
">", currentPosition);
141 assert(endValuePosition != std::string::npos);
143 std::istringstream is(inString.substr(currentPosition, endValuePosition - currentPosition));
149 vect.push_back(data);
153 currentPosition = endValuePosition + name.size() + 3;
159 template <
typename Obj>
160 static void getXML(std::string &outString,
const std::string &name,
const Obj &value) {
161 std::stringstream str;
163 applyIndentation(outString);
164 outString.append(
"<" + name +
">" + str.str() +
"</" + name +
">\n");
167 static bool checkNextXMLtag(
const std::string &inString,
unsigned int ¤tPosition,
168 const std::string &name) {
169 unsigned int tmp = currentPosition;
170 goToNextCaracter(inString, tmp);
171 std::string nameTag = inString.substr(tmp, name.size() + 2);
172 return (nameTag ==
"<" + name +
">");
178 template <
typename Obj>
179 static void setWithXML(
const std::string &inString,
unsigned int ¤tPosition,
180 const std::string &name, Obj &value) {
182 goToNextCaracter(inString, currentPosition);
184 std::string nameTag = inString.substr(currentPosition, name.size() + 2);
185 assert(nameTag ==
"<" + name +
">");
186 currentPosition += name.size() + 2;
188 size_t endValuePosition = inString.find(
"</" + name +
">", currentPosition);
189 assert(endValuePosition != std::string::npos);
191 std::stringstream str(inString.substr(currentPosition, endValuePosition - currentPosition));
193 currentPosition = endValuePosition + name.size() + 3;
199 template <
typename Obj>
200 static void setWithXML(
const std::string &inString,
unsigned int ¤tPosition,
201 const std::string &name, Obj &value,
const Obj &defValue) {
202 goToNextCaracter(inString, currentPosition);
204 std::string nameTag = inString.substr(currentPosition, name.size() + 2);
206 if (nameTag ==
"<" + name +
">") {
207 currentPosition += name.size() + 2;
209 size_t endValuePosition = inString.find(
"</" + name +
">", currentPosition);
210 assert(endValuePosition != std::string::npos);
212 std::stringstream str(inString.substr(currentPosition, endValuePosition - currentPosition));
214 currentPosition = endValuePosition + name.size() + 3;
221 static void applyIndentation(std::string &outString);
222 static void goToNextCaracter(
const std::string &inString,
unsigned int ¤tPosition);
224 static unsigned int indentationNumber;
229 #endif // DOXYGEN_NOTFOR_DEVEL