X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=lsystem3d%2Fsrc%2Fxmlstructure.h;fp=lsystem3d%2Fsrc%2Fxmlstructure.h;h=6f3f6586100644bbf69ae54b79ec67fadd35425c;hb=e5247a3b88c449937af08f46afc271afda2954a2;hp=0000000000000000000000000000000000000000;hpb=c48a55e9e62ed7a9d46e3c6a53faae4bc05856e5;p=lsystem3d.git diff --git a/lsystem3d/src/xmlstructure.h b/lsystem3d/src/xmlstructure.h new file mode 100644 index 0000000..6f3f658 --- /dev/null +++ b/lsystem3d/src/xmlstructure.h @@ -0,0 +1,151 @@ +// Copyright (C) 2006 Erik Dahlberg +// +// This file is part of LSystem3d. +// +// LSystem3D is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// LSystem3D is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with LSystem3D; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + + + +#ifndef XMLSTRUCTURE_H +#define XMLSTRUCTURE_H + +#include + +#include +#include +#include +#include + +using namespace std; + + + +/** + * Basic logic for building and parsing xml-structures + */ +class XMLStructure +{ +public: + /** + * Constructor + */ + XMLStructure(); + + /** + * Destructor + */ + ~XMLStructure(); + +protected: + + // Saver + // ----- + + /** + * Create new document with root node + * @param rootName name of root + */ + void createDocumentWithRoot(string rootName); + + /** + * Add new child to root + * @param name name of child + */ + void addChildToRoot(string name); + + /** + * Add a string as content of current child + * @param text the text + */ + void addString(string text); + + /** + * Add a number as content of current child + * @param value the number + */ + void addNumber(double value); + + /** + * Add attribute to current child + * @param name name of attribute + * @param value value of attribute + */ + void addAttribute(string name, string value); + + /** + * Save document to file + * @param path path to file + */ + void saveToDisk(string path); + + + // Loader + // ------ + + /** + * Load document from file + * @param path path to file + */ + void loadFromDisk(string path); + + /** + * Find all children with the specified name + * @param name name of children + * @return true if found, else false + */ + bool findChild(string name); + + /** + * Find next child in current search result list + * @return true if found, else false + */ + bool findNextChild(); + + /** + * Get content of current child as a string + * @return the string + */ + string getString(); + + /** + * Get content of current child as a number + * @return the number + */ + double getNumber(); + + /** + * Get attribute value of current child + * @param name name of attribute + * @return the value + */ + string getAttribute(string name); + +private: + + // Saver + xmlpp::Element *_rootElement; + xmlpp::Element *_activeElement; + xmlpp::Document *_activeDocument; + + // Loader + xmlpp::DomParser _parser; + xmlpp::Node::NodeList _activeList; + xmlpp::Node::NodeList::iterator _activeChildInList; +}; + + + +#endif