summaryrefslogtreecommitdiff
path: root/src/domhelpers.h
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-07-24 19:06:51 +0000
committerStef Walter <stef@memberwebs.com>2004-07-24 19:06:51 +0000
commit8335fdb6b7e7afb57d096e0f3a453b662f7a23c0 (patch)
treeef3c3079f58b44cb9f1b2953f05e1628d6846e9b /src/domhelpers.h
parentff4568d01651afd615751f9fc683dbe30f2ced9b (diff)
- Post processing code cleanup.
Diffstat (limited to 'src/domhelpers.h')
-rw-r--r--src/domhelpers.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/domhelpers.h b/src/domhelpers.h
index 043ffd4..d125f80 100644
--- a/src/domhelpers.h
+++ b/src/domhelpers.h
@@ -40,6 +40,9 @@
#define __DOMHELPERS_H__
#include "sablo.h"
+#include <map>
+#include <stack>
+#include <set>
/*
* DOMHelpers
@@ -68,6 +71,88 @@ public:
// Get previous element (in XML flow) of a given name
static DOM::Element getPriorElement(const DOM::Node& node, const string& name);
+
+ // Get first child element of a given name
+ static DOM::Element getChildElement(const DOM::Node& parent, const string& name);
+
+ // Check if a given element is anothers ancestor
+ static bool hasAncestor(const DOM::Node& ancestor, const DOM::Node& node);
+};
+
+/*
+ * ElementTable
+ *
+ * A table of elements matched to their ids for quick access while applying
+ * things like fonts, styles, lists from their definitions.
+ */
+class ElementTable :
+ public std::map<wstring, DOM::Element>
+{
+public:
+ void load(const DOM::Node& parent, const string& name);
+
+ DOM::Element get(const wstring& id) const;
+
+ bool has(const wstring& id) const
+ { return find(id) != end(); }
+
+ void removeIds();
+};
+
+// Some other handy types
+typedef std::set<string> StringSet;
+typedef std::stack<DOM::Node> NodeStack;
+
+/*
+ * ElementIterator
+ *
+ * For iterating through the elements in a document.
+ */
+class ElementIterator
+ : public std::iterator<std::input_iterator_tag, DOM::Element, ptrdiff_t>
+{
+public:
+ ElementIterator()
+ { m_current = NULL; }
+ ElementIterator(const DOM::Element& top)
+ { m_top = top; m_current = top; next(); }
+ ElementIterator(const ElementIterator& x)
+ { m_top = x.m_top; m_current = x.m_current; }
+
+ const DOM::Element& operator*() const
+ { return m_current; }
+ const DOM::Element* operator->() const
+ { return (&**this); }
+ const ElementIterator& operator++()
+ { next(); return (*this); }
+ const ElementIterator& operator--()
+ { prev(); return (*this); }
+
+ // Friend comparision functions
+ friend bool operator==(const ElementIterator& x, const ElementIterator& y);
+ friend bool operator!=(const ElementIterator& x, const ElementIterator& y);
+
+// Implementation
+protected:
+
+ void next();
+ DOM::Element nextel(DOM::Node node);
+
+ void prev();
+ DOM::Element prevel(DOM::Node node);
+
+// Data
+protected:
+
+ DOM::Element m_top;
+ DOM::Element m_current;
+ bool m_done;
};
+// friend functions
+inline bool operator==(const ElementIterator& x, const ElementIterator& y)
+ { return y.m_current == x.m_current && y.m_top == x.m_top; }
+inline bool operator!=(const ElementIterator& x, const ElementIterator& y)
+ { return (!(x == y)); }
+
#endif // __DOMHELPERS_H__