Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OXMLTreeManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 /*
17  *
18  *
19  *
20  *
21  */
22 
23 #ifndef __O_XML_TREE_MANAGER__
24 #define __O_XML_TREE_MANAGER__
25 
26 #include <QtXml/qdom.h>
27 
39 {
40 public:
48  virtual ~OXMLTreeManager();
49 
54  bool create(const QString& docname);
55 
60  virtual bool load(const QString& filename);
65  bool load(const QByteArray& bytearray);
66 
71  virtual bool save(const QString& filename);
72 
76  enum FIELDTYPE
77  {
80  STRING
81  };
82 
87  bool isFieldPresent(const QString& field);
88 
94  bool getFieldType(const QString& field, FIELDTYPE& type);
95 
100  bool addField(const QString& field, long value);
105  bool addField(const QString& field, float value);
110  bool addField(const QString& field, const QString& value);
111 
118  bool getFieldLongValue(const QString& field, long& value);
125  bool getFieldFloatValue(const QString& field, float& value);
132  bool getFieldStringValue(const QString& field, QString& value);
133 
140  bool setFieldLongValue(const QString& field, long value);
147  bool setFieldFloatValue(const QString& field, float value);
154  bool setFieldStringValue(const QString& field, const QString& value);
155 
162  bool isDirectoryPresent(const QString& directory, bool absolute = false, int index = 0);
163 
172  bool setCurrentDirectory(const QString& directory, bool absolute = false, int index = 0);
176  bool setCurrentSubDirectory(int index);
180  bool setCurrentDirectoryUp();
181 
185  QString getCurrentDirectory();
189  QString getCurrentSubDirectory();
194  unsigned long getSubDirectoryCount(const QString& directory = QString());
195 
199  unsigned long getFieldCount();
200 
205  bool addDirectory(const QString& directory);
210  bool remDirectory(const QString& directory);
211 
212 private:
213  inline void setCurrentDomNode(const QDomNode& node);
214  inline QDomNode getCurrentDomNode();
215  inline QDomNode getRootDomNode();
216  bool findDirectory(const QString& directory, QDomNode& foundnode, bool absolute, int index = 0);
217  bool findField(const QString& field, const QDomNode& currentnode, QDomAttr& attribute);
218  static bool isRoot(const QDomNode& node)
219  {
220  return (node.parentNode().toElement().isNull());
221  }
222 
223 private:
224  QDomDocument* m_pDomDocument;
226 };
227 
228 inline void OXMLTreeManager::setCurrentDomNode(const QDomNode& node)
229 {
230  m_CurrentDomNode = node;
231 }
232 
234 {
235  return m_CurrentDomNode;
236 }
237 
239 {
240  QDomNode node;
241 
242  if (m_pDomDocument != NULL)
243  {
244  QDomElement docElem = m_pDomDocument->documentElement();
245  node = docElem;
246  }
247  else
248  {
249  node.clear();
250  }
251  return node;
252 }
253 
254 #endif // __O_XML_TREE_MANAGER__
bool findField(const QString &field, const QDomNode &currentnode, QDomAttr &attribute)
unsigned long getFieldCount()
bool getFieldFloatValue(const QString &field, float &value)
QString getCurrentSubDirectory()
QDomDocument * m_pDomDocument
static bool isRoot(const QDomNode &node)
bool setFieldStringValue(const QString &field, const QString &value)
void setCurrentDomNode(const QDomNode &node)
unsigned long getSubDirectoryCount(const QString &directory=QString())
bool setCurrentDirectory(const QString &directory, bool absolute=false, int index=0)
bool setFieldFloatValue(const QString &field, float value)
QString getCurrentDirectory()
bool findDirectory(const QString &directory, QDomNode &foundnode, bool absolute, int index=0)
bool isFieldPresent(const QString &field)
bool setCurrentSubDirectory(int index)
bool getFieldType(const QString &field, FIELDTYPE &type)
virtual bool load(const QString &filename)
bool getFieldStringValue(const QString &field, QString &value)
bool isDirectoryPresent(const QString &directory, bool absolute=false, int index=0)
QDomNode getCurrentDomNode()
virtual bool save(const QString &filename)
bool addField(const QString &field, long value)
bool create(const QString &docname)
bool getFieldLongValue(const QString &field, long &value)
bool addDirectory(const QString &directory)
QDomNode m_CurrentDomNode
bool remDirectory(const QString &directory)
virtual ~OXMLTreeManager()
bool setFieldLongValue(const QString &field, long value)
QDomNode getRootDomNode()