Clean up xml++.h and xml++.cc in Ardour style.

No functional changes.
(We've diverged far enough for it to not matter, and are about to diverge even more, so might as well).


git-svn-id: svn://localhost/ardour2/branches/3.0@4649 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2009-02-22 20:52:34 +00:00
parent 5b04ddf424
commit c9e5903e73
2 changed files with 245 additions and 252 deletions

View file

@ -2,6 +2,7 @@
* 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 <string>
@ -35,80 +36,71 @@ typedef XMLPropertyList::const_iterator XMLPropertyConstIterator;
typedef map<string, XMLProperty*> XMLPropertyMap;
class XMLTree {
private:
string _filename;
XMLNode *_root;
int _compression;
bool read_internal(bool validate);
public:
XMLTree();
XMLTree(const 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 string& filename() const { return _filename; }
const string& set_filename(const string& fn) { return _filename = fn; }
int compression() const { return _compression; };
int compression() const { return _compression; }
int set_compression(int);
bool read() { return read_internal(false); };
bool read(const string &fn) { set_filename(fn); return read_internal(false); };
bool read_and_validate() { return read_internal(true); };
bool read_and_validate(const string &fn) { set_filename(fn); return read_internal(true); };
bool read() { return read_internal(false); }
bool read(const string& fn) { set_filename(fn); return read_internal(false); }
bool read_and_validate() { return read_internal(true); }
bool read_and_validate(const string& fn) { set_filename(fn); return read_internal(true); }
bool read_buffer(const string&);
bool write() const;
bool write(const string &fn) { set_filename(fn); return write(); };
bool write(const string& fn) { set_filename(fn); return write(); }
void debug (FILE*) const;
const string& write_buffer() const;
private:
bool read_internal(bool validate);
string _filename;
XMLNode* _root;
int _compression;
};
class XMLNode {
private:
string _name;
bool _is_content;
string _content;
XMLNodeList _children;
XMLPropertyList _proplist;
XMLPropertyMap _propmap;
mutable XMLNodeList _selected_children;
public:
XMLNode(const string& name);
XMLNode(const string& name, const string& content);
XMLNode(const XMLNode& other);
~XMLNode();
const string name() const { return _name; };
const string& name() const { return _name; }
bool is_content() const { return _is_content; };
const string & content() const { return _content; };
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());
XMLNode* add_content(const string& s = string());
const XMLNodeList& children(const string& str = string()) const;
XMLNode* child(const char*) const;
XMLNode* add_child(const char *);
XMLNode* add_child_copy(const XMLNode&);
XMLNode *child (const char*) const;
void add_child_nocopy(XMLNode&);
boost::shared_ptr<XMLSharedNodeList> find(const std::string xpath) const;
std::string attribute_value();
const XMLPropertyList & properties() const { return _proplist; };
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* property(const string&);
const XMLProperty* property(const char* n) const { return ((XMLNode*)this)->property(n); }
const XMLProperty* property(const string& n) const { return ((XMLNode*)this)->property(n); }
XMLProperty* add_property(const char* name, const string& value);
XMLProperty* add_property(const char* name, const char* value = "");
XMLProperty* add_property(const char* name, const long value);
@ -121,38 +113,40 @@ public:
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);
private:
string _name;
bool _is_content;
string _content;
XMLNodeList _children;
XMLPropertyList _proplist;
XMLPropertyMap _propmap;
mutable XMLNodeList _selected_children;
};
class XMLProperty {
private:
string _name;
string _value;
public:
XMLProperty(const string& n, const string& v = string());
~XMLProperty();
const string & name() const { return _name; };
const string & value() const { return _value; };
const string & set_value(const string &v) { return _value = v; };
};
class XMLException: public std::exception
{
public:
explicit XMLException(const string message)
: message_(message)
{
}
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); }
const string& name() const { return _name; }
const string& value() const { return _value; }
const string& set_value(const string& v) { return _value = v; }
private:
string message_;
string _name;
string _value;
};
class XMLException: public std::exception {
public:
explicit XMLException(const string msg) : _message(msg) {}
virtual ~XMLException() throw() {}
virtual const char* what() const throw() { return _message.c_str(); }
private:
string _message;
};
#endif /* __XML_H */

View file

@ -2,6 +2,7 @@
* 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 <pbd/xml++.h>
@ -13,28 +14,28 @@
static XMLNode* readnode(xmlNodePtr);
static void writenode(xmlDocPtr, XMLNode*, xmlNodePtr, int);
static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string xpath);
static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string& xpath);
XMLTree::XMLTree()
: _filename(),
_root(0),
_compression(0)
: _filename()
, _root(0)
, _compression(0)
{
}
XMLTree::XMLTree(const string& fn, bool validate)
: _filename(fn),
_root(0),
_compression(0)
: _filename(fn)
, _root(0)
, _compression(0)
{
read_internal(validate);
}
XMLTree::XMLTree(const XMLTree* from)
: _filename(from->filename())
, _root(new XMLNode(*from->root()))
, _compression(from->compression())
{
_filename = from->filename();
_root = new XMLNode(*from->root());
_compression = from->compression();
}
XMLTree::~XMLTree()
@ -132,7 +133,7 @@ XMLTree::read_buffer(const string & buffer)
bool
XMLTree::write(void) const
XMLTree::write() const
{
xmlDocPtr doc;
XMLNodeList children;
@ -167,7 +168,7 @@ XMLTree::debug(FILE* out) const
}
const string&
XMLTree::write_buffer(void) const
XMLTree::write_buffer() const
{
static string retval;
char* ptr;
@ -190,12 +191,15 @@ XMLTree::write_buffer(void) const
}
XMLNode::XMLNode(const string& n)
: _name(n), _is_content(false), _content(string())
: _name(n)
, _is_content(false)
{
}
XMLNode::XMLNode(const string& n, const string& c)
:_name(n), _is_content(true), _content(c)
: _name(n)
, _is_content(true)
, _content(c)
{
}
@ -467,8 +471,8 @@ XMLNode::remove_nodes_and_delete(const string& propname, const string& val)
}
XMLProperty::XMLProperty(const string& n, const string& v)
: _name(n),
_value(v)
: _name(n)
, _value(v)
{
// Normalize property name (replace '_' with '-' as old session are inconsistent)
for (size_t i = 0; i < _name.length(); ++i) {
@ -548,20 +552,18 @@ writenode(xmlDocPtr doc, XMLNode * n, xmlNodePtr p, int root = 0)
}
}
static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string xpath)
static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string& xpath)
{
xmlXPathObject* result = xmlXPathEval((const xmlChar*)xpath.c_str(), ctxt);
if(!result)
{
if (!result) {
xmlXPathFreeContext(ctxt);
xmlFreeDoc(ctxt->doc);
throw XMLException("Invalid XPath: " + xpath);
}
if(result->type != XPATH_NODESET)
{
if (result->type != XPATH_NODESET) {
xmlXPathFreeObject(result);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(ctxt->doc);
@ -571,15 +573,12 @@ static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string xpath)
xmlNodeSet* nodeset = result->nodesetval;
XMLSharedNodeList* nodes = new XMLSharedNodeList();
if( nodeset )
{
if (nodeset) {
for (int i = 0; i < nodeset->nodeNr; ++i) {
XMLNode* node = readnode(nodeset->nodeTab[i]);
nodes->push_back(boost::shared_ptr<XMLNode>(node));
}
}
else
{
} else {
// return empty set
}