X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fpbd%2Fxml%2B%2B.h;h=e6795e5d455a0b2b9697322d8de57608ff562d64;hb=e3329000557015ce54691235769db8821e75666b;hp=1aae15bbc3de7e40d8f3e0b9d9dec742430860bd;hpb=376263d92514f0e55daee8ea0c33cd226da1e97c;p=ardour.git diff --git a/libs/pbd/pbd/xml++.h b/libs/pbd/pbd/xml++.h index 1aae15bbc3..e6795e5d45 100644 --- a/libs/pbd/pbd/xml++.h +++ b/libs/pbd/pbd/xml++.h @@ -1,7 +1,30 @@ +/* + Copyright (C) 2012 Paul Davis + + This program 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. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __XML_H +#define __XML_H + /* xml++.h * libxml++ and this file are copyright (C) 2000 by Ari Johnson, and * are covered by the GNU Lesser General Public License, which should be * included with libxml++ as the file COPYING. + * Modified for Ardour and released under the same terms. */ #include @@ -12,139 +35,144 @@ #include #include +#include -#ifndef __XML_H -#define __XML_H - -using std::string; -using std::map; -using std::list; +#include "pbd/libpbd_visibility.h" class XMLTree; class XMLNode; class XMLProperty; -typedef list XMLNodeList; -typedef XMLNodeList::iterator XMLNodeIterator; -typedef XMLNodeList::const_iterator XMLNodeConstIterator; -typedef list XMLPropertyList; -typedef XMLPropertyList::iterator XMLPropertyIterator; -typedef XMLPropertyList::const_iterator XMLPropertyConstIterator; -typedef map XMLPropertyMap; - -class XMLTree { -private: - string _filename; - XMLNode *_root; - int _compression; +typedef std::list XMLNodeList; +typedef std::list > XMLSharedNodeList; +typedef XMLNodeList::iterator XMLNodeIterator; +typedef XMLNodeList::const_iterator XMLNodeConstIterator; +typedef std::list XMLPropertyList; +typedef XMLPropertyList::iterator XMLPropertyIterator; +typedef XMLPropertyList::const_iterator XMLPropertyConstIterator; +typedef std::map XMLPropertyMap; +class LIBPBD_API XMLTree { public: - XMLTree(); - XMLTree(const string &fn); - XMLTree(const XMLTree *); - ~XMLTree(); + XMLTree(); + XMLTree(const std::string& fn, bool validate = false); + XMLTree(const XMLTree*); + ~XMLTree(); - XMLNode *root() const { return _root; }; - XMLNode *set_root(XMLNode *n) { return _root = n; }; + XMLNode* root() const { return _root; } + XMLNode* set_root(XMLNode* n) { return _root = n; } - const string & filename() const { return _filename; }; - const string & set_filename(const string &fn) { return _filename = fn; }; + const std::string& filename() const { return _filename; } + const std::string& set_filename(const std::string& fn) { return _filename = fn; } - int compression() const { return _compression; }; - int set_compression(int); + int compression() const { return _compression; } + int set_compression(int); - bool read(); - bool read(const string &fn) { set_filename(fn); return read(); }; - bool read_buffer(const string &); + bool read() { return read_internal(false); } + bool read(const std::string& fn) { set_filename(fn); return read_internal(false); } + bool read_and_validate() { return read_internal(true); } + bool read_and_validate(const std::string& fn) { set_filename(fn); return read_internal(true); } + bool read_buffer(const std::string&); - bool write() const; - bool write(const string &fn) { set_filename(fn); return write(); }; + bool write() const; + bool write(const std::string& fn) { set_filename(fn); return write(); } - void debug (FILE*) const; + void debug (FILE*) const; - const string & write_buffer() const; -}; + const std::string& write_buffer() const; + + boost::shared_ptr find(const std::string xpath, XMLNode* = 0) const; -class XMLNode { private: - string _name; - bool _is_content; - string _content; - XMLNodeList _children; - XMLPropertyList _proplist; - XMLPropertyMap _propmap; + bool read_internal(bool validate); + + std::string _filename; + XMLNode* _root; + xmlDocPtr _doc; + int _compression; +}; +class LIBPBD_API XMLNode { public: - XMLNode(const string &); - XMLNode(const string &, const string &); - XMLNode(const XMLNode&); - ~XMLNode(); - - const string name() const { return _name; }; - - bool is_content() const { return _is_content; }; - const string & content() const { return _content; }; - const string & set_content (const string &); - XMLNode *add_content(const string & = string()); - - const XMLNodeList & children (const string& str = string()) const; - XMLNode *add_child (const char *); - XMLNode *add_child_copy (const XMLNode&); - XMLNode *child (const char*) const; - void add_child_nocopy (XMLNode&); - - XMLNodeList *find(const std::string xpath) const; - - const XMLPropertyList & properties() const { return _proplist; }; - XMLProperty *property(const char * ); - XMLProperty *property(const std::string&); - const XMLProperty *property(const char * n) const - { return ((XMLNode *) this)->property(n); }; - const XMLProperty *property(const std::string& ns) const - { return ((XMLNode *) this)->property(ns); }; - XMLProperty *add_property(const char *, const string &); - XMLProperty *add_property(const char *, const char * = ""); - - void remove_property(const string &); - - /** Remove all nodes with the name passed to remove_nodes */ - void remove_nodes(const string &); - /** Remove and delete all nodes with the name passed to remove_nodes */ - void remove_nodes_and_delete(const string &); - /** Remove and delete all nodes with property prop matching val */ - void remove_nodes_and_delete(const string& propname, const string& val); -}; + XMLNode(const std::string& name); + XMLNode(const std::string& name, const std::string& content); + XMLNode(const XMLNode& other); + ~XMLNode(); + + XMLNode& operator= (const XMLNode& other); + + const std::string& name() const { return _name; } + + bool is_content() const { return _is_content; } + const std::string& content() const { return _content; } + const std::string& set_content(const std::string&); + XMLNode* add_content(const std::string& s = std::string()); + + const XMLNodeList& children(const std::string& str = std::string()) const; + XMLNode* child(const char*) const; + XMLNode* add_child(const char *); + XMLNode* add_child_copy(const XMLNode&); + void add_child_nocopy(XMLNode&); + + std::string attribute_value(); + + const XMLPropertyList& properties() const { return _proplist; } + XMLProperty* property(const char*); + XMLProperty* property(const std::string&); + const XMLProperty* property(const char* n) const { return const_cast(this)->property(n); } + const XMLProperty* property(const std::string& n) const { return const_cast(this)->property(n); } + + XMLProperty* add_property(const char* name, const std::string& value); + XMLProperty* add_property(const char* name, const char* value = ""); + XMLProperty* add_property(const char* name, const long value); + + void remove_property(const std::string&); + void remove_property_recursively(const std::string&); + + /** Remove all nodes with the name passed to remove_nodes */ + void remove_nodes(const std::string&); + /** Remove and delete all nodes with the name passed to remove_nodes */ + void remove_nodes_and_delete(const std::string&); + /** Remove and delete all nodes with property prop matching val */ + void remove_nodes_and_delete(const std::string& propname, const std::string& val); + + void dump (std::ostream &, std::string p = "") const; -class XMLProperty { private: - string _name; - string _value; + std::string _name; + bool _is_content; + std::string _content; + XMLNodeList _children; + XMLPropertyList _proplist; + XMLPropertyMap _propmap; + mutable XMLNodeList _selected_children; + + void clear_lists (); +}; +class LIBPBD_API XMLProperty { public: - XMLProperty(const string &n, const string &v = string()); - ~XMLProperty(); + XMLProperty(const std::string& n, const std::string& v = std::string()); + ~XMLProperty(); - const string & name() const { return _name; }; - const string & value() const { return _value; }; - const string & set_value(const string &v) { return _value = v; }; + const std::string& name() const { return _name; } + const std::string& value() const { return _value; } + const std::string& set_value(const std::string& v) { return _value = v; } + +private: + std::string _name; + std::string _value; }; -class XMLException: public std::exception -{ +class LIBPBD_API XMLException: public std::exception { public: - explicit XMLException(const string message) - : message_(message) - { - } - - virtual ~XMLException() throw() {}; + explicit XMLException(const std::string msg) : _message(msg) {} + virtual ~XMLException() throw() {} - virtual const char* what() const throw() { return message_.c_str(); } - virtual void Raise() const { throw *this; } - virtual exception * Clone() const { return new exception(*this); } + virtual const char* what() const throw() { return _message.c_str(); } private: - string message_; + std::string _message; }; #endif /* __XML_H */