1 /* This file is part of EdiTeX, an editor of mathematical
2 * expressions based on TeX syntax.
4 * Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
5 * 2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * For more information, please visit the project's home page
22 * http://helm.cs.unibo.it/editex/
23 * or send an email to <lpadovan@cs.unibo.it>
31 #include "TDictionary.hh"
36 TNode(void) : node(0) { };
37 TNode(const DOM::Node& n) : node(n) { };
38 TNode(const DOM::Element& elem) : node(elem) { };
39 TNode(const TNode& n) : node(n.node) { };
41 TNode next(void) const;
42 TNode nextL(void) const;
43 TNode prev(void) const;
44 TNode prevL(void) const;
45 TNode core(void) const;
46 TNode parent(void) const;
47 TNode first(void) const;
48 TNode firstL(void) const;
49 TNode last(void) const;
50 TNode lastL(void) const;
51 TNode child(unsigned) const;
52 unsigned size(void) const;
53 bool empty(void) const { return !first().node; };
54 std::string value(void) const { return (*this)["val"]; };
59 ProxyAttr(const DOM::Element& n, const std::string& s) : node(n), name(s) { };
60 operator std::string() const { return node.getAttribute(name); };
61 ProxyAttr& operator=(const std::string& v) { node.setAttribute(name, v); };
62 bool operator==(const std::string& v) const { return node.getAttribute(name) == v; };
63 bool operator!=(const std::string& v) const { return node.getAttribute(name) != v; };
69 operator bool() const { return node; };
70 DOM::Element element(void) const { return node; };
71 bool operator==(const TNode& n) const { return node == n.node; };
72 bool operator!=(const TNode& n) const { return node != n.node; };
73 TNode operator[](int i) const { return child(i); };
74 ProxyAttr operator[](const char* s) const { return ProxyAttr(node, s); };
76 //void advance(const TNode&) const;
77 void remove(void) const;
78 void replace(const TNode&) const;
79 void replace(const TNode&, const TNode&) const;
80 void insert(const TNode&) const;
81 void append(const TNode&) const;
82 void append(const TNode&, const TNode&) const;
83 void prepend(const TNode&) const;
85 std::string get(const std::string&) const;
86 void set(const std::string&, const std::string&) const;
88 std::string name(void) const { return node.get_localName(); };
89 std::string nameC(void) const { return node.getAttribute("name"); };
90 bool hasId(void) const { return node.hasAttribute("id"); };
91 bool hasId(const std::string& id) const { return node.getAttribute("id") == id; };
92 bool is(const std::string& s) const { return name() == s; };
93 bool isG(void) const { return is("g"); };
94 bool isSb(void) const { return is("sb"); };
95 bool isSp(void) const { return is("sp"); };
96 bool isC(void) const { return is("c"); }
97 bool isC(const std::string& name) const
98 { return isC() && node.getAttribute("name") == name; };
99 bool isT(void) const { return (is("o") || is("i") || is("n") || is("s")); };
101 friend class TDocument;
107 #endif // __TNode_hh__