/* libxml++
 * Copyright (C) 2000  Ari Johnson
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

/* Modified by Motama GmbH, Copyright (C) 2006-2007 Motama GmbH */


#ifndef NMM_XML_TREE_HPP
#define NMM_XML_TREE_HPP NMM_XML_TREE_HPP

#include "nmm/nmm_prefix.hpp"

#include <string>
#include <list>

#include "XMLProperty.hpp"
#include "XMLNodeForward.hpp"

#include "nmm/nmm_hash_map.hpp"

#include "visibility.hpp"

namespace NMM {
  
  class DLLEXPORT XMLTree {
  public:
    XMLTree() : _initialized(true), _filename(), _root(NULL), _compression(0) { };
    XMLTree(const std::string &fn)
      : _initialized(true), _filename(fn), _root(NULL), _compression(0) { read(); };
    
    /** Copy constructor
     */
    XMLTree(const XMLTree& );

    /** Destructor
     */         
    ~XMLTree();

    /**
     */
    inline bool     initialized(void)   const   { return _initialized; };

    /** returns the current root node
     */
    inline XMLNode* root(void)          const   { return _root; };

    /** sets a new root node. The old one is deleted
     */
    XMLNode *set_root(XMLNode *n);

    /** This resets the root node to 0 and returns a  pointer to the old. This pointer is not deleted.
     * The intend of this method is to integrate patial node without copy.
     */
    inline  XMLNode *release_root() { XMLNode* tmp = root(); _root = 0; return tmp;}

    /** returns the current filename
     */
    inline const std::string & filename(void)const   { return _filename; };

    /** sets a new filename
     */
    inline const std::string & set_filename(const std::string &fn) { return _filename = fn; };

    /** returns current compression
     */
    inline int compression(void)        const { return _compression; };

    /** sets the compression rate (value betwee 0-9)
     */
    int set_compression(int);

    /** reads an XML tree from current file. the old root node is deleted so you must request
     * the root node again if it is stored outside the class
     */
    bool read(void);

    /**
     */
    inline bool read(const std::string &fn) { set_filename(fn); return read(); };
    bool read_buffer(const std::string &);
    bool write(void) const;
    inline bool write(const std::string &fn) { set_filename(fn); return write(); };
    std::string write_buffer(void) const;


    const XMLTree& operator=(const XMLTree&);
    bool operator==(const XMLTree&);
    //  bool isSubset(const XMLTree&);

    XMLNodeList children(const std::string& name) const;
    
  private: //attributes
    bool _initialized;
    std::string _filename;
    XMLNode* _root;
    int _compression;
  };
  
}

#include "nmm/nmm_suffix.hpp"

#endif
