1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
// Copyright (C) 2000-2004, Luca Padovani <luca.padovani@cs.unibo.it>.
//
// This file is part of GtkMathView, a Gtk widget for MathML.
//
// GtkMathView 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.
//
// GtkMathView 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 GtkMathView; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// For details, see the GtkMathView World-Wide-Web page,
// http://helm.cs.unibo.it/mml-widget/, or send a mail to
// <lpadovan@cs.unibo.it>
#ifndef __libxml2_Model_hh__
#define __libxml2_Model_hh__
#include <libxml/tree.h>
#include <cassert>
#include "String.hh"
#include "TemplateNodeIterator.hh"
#include "TemplateElementIterator.hh"
struct GMV_FrontEnd_EXPORT libxml2_Model
{
enum {
TEXT_NODE = XML_TEXT_NODE,
ELEMENT_NODE = XML_ELEMENT_NODE
};
typedef xmlNode* Node;
typedef xmlElement* Element;
typedef xmlDoc* Document;
typedef TemplateNodeIterator<libxml2_Model> NodeIterator;
typedef TemplateElementIterator<libxml2_Model> ElementIterator;
// method for parsing a model
// MUST be available
static xmlDoc* document(const class AbstractLogger&, const String&, bool = false);
static xmlDoc* documentFromBuffer(const class AbstractLogger&, const String&, bool = false);
static Element getDocumentElement(const Document&);
// methods for casting an element to a node and viceversa
static Node asNode(const Element& el) { return (Node) el; }
static Element asElement(const Node& n) { return (n && n->type == XML_ELEMENT_NODE) ? (xmlElement*) n : 0; }
// methods for querying nodes
// MUST be available for TemplateBuilder and TemplateSetup to work
static unsigned getNodeType(const Node& n) { return n->type; }
static String getNodeName(const Node&);
static String getNodeValue(const Node&);
static String getNodeNamespaceURI(const Node&);
// methods for querying elements
// MUST be available for TemplateBuilder and TemplateSetup to work
static String getElementValue(const Element&);
static String getAttribute(const Element&, const String&);
// MUST be implemented if the default RefinementContext is used
static bool hasAttribute(const Element&, const String&);
// methods for navigating the model
// must be available if the default iterators are used
static Node getNextSibling(const Node& n)
{ return n->next; }
static Node getFirstChild(const Node& n)
{ return n->children; }
// auxiliary conversion functions from/to libxml2 strings
static String fromModelString(const xmlChar* str) { return reinterpret_cast<const String::value_type*>(str); }
static const xmlChar* toModelString(const String& str) { return BAD_CAST(str.c_str()); }
// MUST be available if the default linker is used
struct Hash
{
size_t operator()(xmlElement* el) const
{
assert(el);
assert(sizeof(size_t) == sizeof(xmlElement*));
return reinterpret_cast<size_t>(el);
}
};
};
#endif // __libxml2_Model_hh__
|