mirror of
https://github.com/jezhiggins/arabica
synced 2024-12-28 22:23:21 +01:00
reworked for gcc 4.0.1, I hope
This commit is contained in:
parent
1b4e8ebca4
commit
476e8c32ed
1 changed files with 461 additions and 439 deletions
|
@ -28,18 +28,20 @@ enum Axis
|
|||
SELF
|
||||
}; // Axis
|
||||
|
||||
namespace impl
|
||||
{
|
||||
template<class string_type> class AxisWalker;
|
||||
|
||||
template<class axis_walker, class string_type>
|
||||
AxisWalker<string_type>* CreateAxis(const DOM::Node<string_type>& context) { return new axis_walker(context); }
|
||||
} // namespace impl
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
class AxisEnumerator
|
||||
{
|
||||
class AxisWalker;
|
||||
|
||||
template<class axis_walker>
|
||||
static AxisWalker* CreateAxis(const DOM::Node<string_type>& context) { return new axis_walker(context); }
|
||||
|
||||
typedef AxisWalker* (*CreateAxisPtr)(const DOM::Node<string_type>& context);
|
||||
typedef impl::AxisWalker<string_type>* (*CreateAxisPtr)(const DOM::Node<string_type>& context);
|
||||
|
||||
struct NamedAxis { Axis name; CreateAxisPtr creator; };
|
||||
|
||||
static const NamedAxis AxisLookupTable[];
|
||||
|
||||
public:
|
||||
|
@ -61,7 +63,7 @@ public:
|
|||
|
||||
AxisEnumerator& operator=(const AxisEnumerator& rhs)
|
||||
{
|
||||
AxisWalker* newwalker = rhs.walker_->clone();
|
||||
impl::AxisWalker<string_type>* newwalker = rhs.walker_->clone();
|
||||
delete walker_;
|
||||
walker_ = newwalker;
|
||||
return *this;
|
||||
|
@ -80,88 +82,123 @@ public:
|
|||
AxisEnumerator operator++(int) { AxisEnumerator copy(*this); walker_->advance(); return copy; }
|
||||
|
||||
private:
|
||||
AxisWalker* walker_;
|
||||
impl::AxisWalker<string_type>* walker_;
|
||||
|
||||
AxisEnumerator();
|
||||
}; // class AxisEnumerator
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
class AxisWalker
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
namespace impl
|
||||
{
|
||||
|
||||
template<class string_type>
|
||||
class AxisWalker
|
||||
{
|
||||
public:
|
||||
virtual ~AxisWalker() { }
|
||||
const DOM::Node<string_type>& get() const { return current_; }
|
||||
virtual void advance() = 0;
|
||||
bool forward() { return forward_; }
|
||||
virtual AxisWalker* clone() const = 0;
|
||||
virtual AxisWalker<string_type>* clone() const = 0;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
AxisWalker(bool forward) : forward_(forward) { }
|
||||
AxisWalker(const AxisWalker& rhs) : current_(rhs.current_), forward_(rhs.forward_) { }
|
||||
void set(const DOM::Node<string_type>& current) { current_ = current; }
|
||||
void end() { current_ = 0; }
|
||||
|
||||
private:
|
||||
static DOM::Node<string_type> walkDown(const DOM::Node<string_type>& context, const DOM::Node<string_type>& origin)
|
||||
{
|
||||
if(context.getNodeType() == DOM::Node<string_type>::ATTRIBUTE_NODE)
|
||||
return 0;
|
||||
|
||||
DOM::Node<string_type> next = context.getFirstChild();
|
||||
if((next == 0) && (context == origin)) // node with no children
|
||||
return 0;
|
||||
|
||||
if(next != 0)
|
||||
return next;
|
||||
|
||||
next = context.getNextSibling();
|
||||
if(next != 0)
|
||||
return next;
|
||||
|
||||
DOM::Node<string_type> parent = context.getParentNode();
|
||||
while(parent != origin && next == 0)
|
||||
{
|
||||
next = parent.getNextSibling();
|
||||
parent = parent.getParentNode();
|
||||
} // while ...
|
||||
|
||||
return next;
|
||||
} // walkDown
|
||||
|
||||
private:
|
||||
DOM::Node<string_type> current_;
|
||||
bool forward_;
|
||||
|
||||
AxisWalker& operator=(const AxisWalker&);
|
||||
bool operator==(const AxisWalker&);
|
||||
}; // AxisWalker
|
||||
}; // AxisWalker
|
||||
|
||||
class AncestorAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
AncestorAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(false)
|
||||
template<class string_type>
|
||||
class AncestorAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
AncestorAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(false)
|
||||
{
|
||||
if(context == 0)
|
||||
return;
|
||||
|
||||
if(context.getNodeType() != DOM::Node<string_type>::ATTRIBUTE_NODE)
|
||||
AxisWalker::set(context.getParentNode());
|
||||
AxisWalker<string_type>::set(context.getParentNode());
|
||||
else
|
||||
AxisWalker::set((static_cast<DOM::Attr<string_type> >(context)).getOwnerElement());
|
||||
AxisWalker<string_type>::set((static_cast<DOM::Attr<string_type> >(context)).getOwnerElement());
|
||||
} // AncestorAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
if(AxisWalker::get() != 0)
|
||||
AxisWalker::set(AxisWalker::get().getParentNode());
|
||||
if(AxisWalker<string_type>::get() != 0)
|
||||
AxisWalker<string_type>::set(AxisWalker<string_type>::get().getParentNode());
|
||||
} // advance
|
||||
virtual AxisWalker* clone() const { return new AncestorAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new AncestorAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
AncestorAxisWalker(const AncestorAxisWalker& rhs) : AxisWalker(rhs) { }
|
||||
}; // class AncestorAxisWalker
|
||||
private:
|
||||
AncestorAxisWalker(const AncestorAxisWalker& rhs) : AxisWalker<string_type>(rhs) { }
|
||||
}; // class AncestorAxisWalker
|
||||
|
||||
class AncestorOrSelfAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
AncestorOrSelfAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(false)
|
||||
template<class string_type>
|
||||
class AncestorOrSelfAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
AncestorOrSelfAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(false)
|
||||
{
|
||||
if(context != 0)
|
||||
AxisWalker::set(context);
|
||||
AxisWalker<string_type>::set(context);
|
||||
} // AncestorAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
if(AxisWalker::get() == 0)
|
||||
if(AxisWalker<string_type>::get() == 0)
|
||||
return;
|
||||
|
||||
if(AxisWalker::get().getNodeType() != DOM::Node<string_type>::ATTRIBUTE_NODE)
|
||||
AxisWalker::set(AxisWalker::get().getParentNode());
|
||||
if(AxisWalker<string_type>::get().getNodeType() != DOM::Node<string_type>::ATTRIBUTE_NODE)
|
||||
AxisWalker<string_type>::set(AxisWalker<string_type>::get().getParentNode());
|
||||
else
|
||||
AxisWalker::set((static_cast<DOM::Attr<string_type> >(AxisWalker::get())).getOwnerElement());
|
||||
AxisWalker<string_type>::set((static_cast<DOM::Attr<string_type> >(AxisWalker<string_type>::get())).getOwnerElement());
|
||||
} // advance
|
||||
virtual AxisWalker* clone() const { return new AncestorOrSelfAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new AncestorOrSelfAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
AncestorOrSelfAxisWalker(const AncestorOrSelfAxisWalker& rhs) : AxisWalker(rhs) { }
|
||||
}; // class AncestorOrSelfAxisWalker
|
||||
private:
|
||||
AncestorOrSelfAxisWalker(const AncestorOrSelfAxisWalker& rhs) : AxisWalker<string_type>(rhs) { }
|
||||
}; // class AncestorOrSelfAxisWalker
|
||||
|
||||
class AttributeAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
AttributeAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(true),
|
||||
template<class string_type>
|
||||
class AttributeAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
AttributeAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(true),
|
||||
index_(0), count_(0)
|
||||
{
|
||||
if((context != 0) && (context.hasAttributes()))
|
||||
|
@ -174,16 +211,16 @@ private:
|
|||
|
||||
virtual void advance()
|
||||
{
|
||||
if(AxisWalker::get() == 0)
|
||||
if(AxisWalker<string_type>::get() == 0)
|
||||
return;
|
||||
set_next();
|
||||
} // advance
|
||||
|
||||
virtual AxisWalker* clone() const { return new AttributeAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new AttributeAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
private:
|
||||
AttributeAxisWalker(const AttributeAxisWalker& rhs) :
|
||||
AxisWalker(rhs),
|
||||
AxisWalker<string_type>(rhs),
|
||||
attrs_(rhs.attrs_),
|
||||
index_(rhs.index_),
|
||||
count_(rhs.count_) { }
|
||||
|
@ -196,7 +233,7 @@ private:
|
|||
{
|
||||
if(index_ == count_)
|
||||
{
|
||||
AxisWalker::end();
|
||||
AxisWalker<string_type>::end();
|
||||
return;
|
||||
} // if ...
|
||||
|
||||
|
@ -206,57 +243,59 @@ private:
|
|||
a = attrs_.item(index_++);
|
||||
} while ((a != 0) && (a.getNamespaceURI() == "http://www.w3.org/2000/xmlns/"));
|
||||
|
||||
AxisWalker::set(a);
|
||||
AxisWalker<string_type>::set(a);
|
||||
} // set_next
|
||||
}; // class AttributeAxisEnumerator
|
||||
}; // class AttributeAxisEnumerator
|
||||
|
||||
class ChildAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
ChildAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(true)
|
||||
template<class string_type>
|
||||
class ChildAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
ChildAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(true)
|
||||
{
|
||||
if(context != 0)
|
||||
AxisWalker::set(context.getFirstChild());
|
||||
AxisWalker<string_type>::set(context.getFirstChild());
|
||||
} // ChildAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
if(AxisWalker::get() != 0)
|
||||
AxisWalker::set(AxisWalker::get().getNextSibling());
|
||||
if(AxisWalker<string_type>::get() != 0)
|
||||
AxisWalker<string_type>::set(AxisWalker<string_type>::get().getNextSibling());
|
||||
} // advance
|
||||
virtual AxisWalker* clone() const { return new ChildAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new ChildAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
ChildAxisWalker(const ChildAxisWalker& rhs) : AxisWalker(rhs) { }
|
||||
}; // class ChildAxisWalker
|
||||
private:
|
||||
ChildAxisWalker(const ChildAxisWalker& rhs) : AxisWalker<string_type>(rhs) { }
|
||||
}; // class ChildAxisWalker
|
||||
|
||||
class DescendantAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
DescendantAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(true),
|
||||
template<class string_type>
|
||||
class DescendantAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
DescendantAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(true),
|
||||
origin_(context)
|
||||
{
|
||||
if((context != 0) && (context.getNodeType() != DOM::Node<string_type>::ATTRIBUTE_NODE))
|
||||
AxisWalker::set(context.getFirstChild());
|
||||
AxisWalker<string_type>::set(context.getFirstChild());
|
||||
} // DescendantAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
AxisWalker::set(nextDescendant());
|
||||
AxisWalker<string_type>::set(nextDescendant());
|
||||
} // advance
|
||||
|
||||
virtual AxisWalker* clone() const { return new DescendantAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new DescendantAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
private:
|
||||
DOM::Node<string_type> nextDescendant()
|
||||
{
|
||||
DOM::Node<string_type> next = AxisWalker::get().getFirstChild();
|
||||
DOM::Node<string_type> next = AxisWalker<string_type>::get().getFirstChild();
|
||||
if(next == 0)
|
||||
next = AxisWalker::get().getNextSibling();
|
||||
next = AxisWalker<string_type>::get().getNextSibling();
|
||||
if(next != 0)
|
||||
return next;
|
||||
|
||||
DOM::Node<string_type> parent = AxisWalker::get().getParentNode();
|
||||
DOM::Node<string_type> parent = AxisWalker<string_type>::get().getParentNode();
|
||||
while(parent != origin_ && next == 0)
|
||||
{
|
||||
next = parent.getNextSibling();
|
||||
|
@ -266,47 +305,49 @@ private:
|
|||
return next;
|
||||
} // nextDescendant
|
||||
|
||||
DescendantAxisWalker(const DescendantAxisWalker& rhs) : AxisWalker(rhs), origin_(rhs.origin_) { }
|
||||
DescendantAxisWalker(const DescendantAxisWalker& rhs) : AxisWalker<string_type>(rhs), origin_(rhs.origin_) { }
|
||||
const DOM::Node<string_type> origin_;
|
||||
}; // class DescendantAxisWalker
|
||||
}; // class DescendantAxisWalker
|
||||
|
||||
class DescendantOrSelfAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
DescendantOrSelfAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(true),
|
||||
template<class string_type>
|
||||
class DescendantOrSelfAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
DescendantOrSelfAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(true),
|
||||
origin_(context)
|
||||
{
|
||||
if(context != 0)
|
||||
AxisWalker::set(context);
|
||||
AxisWalker<string_type>::set(context);
|
||||
} // DescendantAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
AxisWalker::set(walkDown(AxisWalker::get(), origin_));
|
||||
AxisWalker<string_type>::set(AxisWalker<string_type>::walkDown(AxisWalker<string_type>::get(), origin_));
|
||||
} // advance
|
||||
|
||||
virtual AxisWalker* clone() const { return new DescendantOrSelfAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new DescendantOrSelfAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
DescendantOrSelfAxisWalker(const DescendantOrSelfAxisWalker& rhs) : AxisWalker(rhs), origin_(rhs.origin_) { }
|
||||
private:
|
||||
DescendantOrSelfAxisWalker(const DescendantOrSelfAxisWalker& rhs) : AxisWalker<string_type>(rhs), origin_(rhs.origin_) { }
|
||||
const DOM::Node<string_type> origin_;
|
||||
}; // class DescendantOrSelfAxisWalker
|
||||
}; // class DescendantOrSelfAxisWalker
|
||||
|
||||
class FollowingAxisWalker : public AxisWalker
|
||||
template<class string_type>
|
||||
class FollowingAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
FollowingAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(true)
|
||||
{
|
||||
public:
|
||||
FollowingAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(true)
|
||||
{
|
||||
AxisWalker::set(firstFollowing(context));
|
||||
AxisWalker<string_type>::set(firstFollowing(context));
|
||||
} // FollowingAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
AxisWalker::set(walkDown(AxisWalker::get(), AxisWalker::get().getOwnerDocument()));
|
||||
AxisWalker<string_type>::set(AxisWalker<string_type>::walkDown(AxisWalker<string_type>::get(), AxisWalker<string_type>::get().getOwnerDocument()));
|
||||
} // advance
|
||||
virtual AxisWalker* clone() const { return new FollowingAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new FollowingAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
private:
|
||||
DOM::Node<string_type> firstFollowing(const DOM::Node<string_type>& context) const
|
||||
{
|
||||
if(context.getNodeType() == DOM::Node<string_type>::ATTRIBUTE_NODE)
|
||||
|
@ -326,33 +367,35 @@ private:
|
|||
return next;
|
||||
} // firstFollowing
|
||||
|
||||
FollowingAxisWalker(const FollowingAxisWalker& rhs) : AxisWalker(rhs) { }
|
||||
}; // class FollowingAxisWalker
|
||||
FollowingAxisWalker(const FollowingAxisWalker& rhs) : AxisWalker<string_type>(rhs) { }
|
||||
}; // class FollowingAxisWalker
|
||||
|
||||
class FollowingSiblingAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
FollowingSiblingAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(true)
|
||||
template<class string_type>
|
||||
class FollowingSiblingAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
FollowingSiblingAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(true)
|
||||
{
|
||||
if(context != 0)
|
||||
AxisWalker::set(context.getNextSibling());
|
||||
AxisWalker<string_type>::set(context.getNextSibling());
|
||||
} // FollowingSiblingAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
if(AxisWalker::get() != 0)
|
||||
AxisWalker::set(AxisWalker::get().getNextSibling());
|
||||
if(AxisWalker<string_type>::get() != 0)
|
||||
AxisWalker<string_type>::set(AxisWalker<string_type>::get().getNextSibling());
|
||||
} // advance
|
||||
virtual AxisWalker* clone() const { return new FollowingSiblingAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new FollowingSiblingAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
FollowingSiblingAxisWalker(const FollowingSiblingAxisWalker& rhs) : AxisWalker(rhs) { }
|
||||
}; // class FollowingSiblingAxisWalker
|
||||
private:
|
||||
FollowingSiblingAxisWalker(const FollowingSiblingAxisWalker& rhs) : AxisWalker<string_type>(rhs) { }
|
||||
}; // class FollowingSiblingAxisWalker
|
||||
|
||||
class NamespaceAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
NamespaceAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(true),
|
||||
template<class string_type, class string_adaptor>
|
||||
class NamespaceAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
NamespaceAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(true),
|
||||
xmlns_prefix_(string_adaptor().makeStringT("xmlns")),
|
||||
index_(0)
|
||||
{
|
||||
|
@ -372,65 +415,67 @@ private:
|
|||
current = current.getParentNode();
|
||||
} // while
|
||||
list_.push_back(DOM::Node<string_type>(0));
|
||||
AxisWalker::set(list_[index_]);
|
||||
AxisWalker<string_type>::set(list_[index_]);
|
||||
} // NamespaceAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
if(index_ != list_.size())
|
||||
AxisWalker::set(list_[++index_]);
|
||||
AxisWalker<string_type>::set(list_[++index_]);
|
||||
} // advance
|
||||
|
||||
virtual AxisWalker* clone() const { return new NamespaceAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new NamespaceAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
NamespaceAxisWalker(const NamespaceAxisWalker& rhs) : AxisWalker(rhs) { }
|
||||
private:
|
||||
NamespaceAxisWalker(const NamespaceAxisWalker& rhs) : AxisWalker<string_type>(rhs) { }
|
||||
std::vector<DOM::Node<string_type> > list_;
|
||||
const string_type xmlns_prefix_;
|
||||
unsigned int index_;
|
||||
}; // class NamespaceAxisWalker
|
||||
}; // class NamespaceAxisWalker
|
||||
|
||||
class ParentAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
ParentAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(false)
|
||||
template<class string_type>
|
||||
class ParentAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
ParentAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(false)
|
||||
{
|
||||
if(context == 0)
|
||||
return;
|
||||
|
||||
if(context.getNodeType() != DOM::Node<string_type>::ATTRIBUTE_NODE)
|
||||
AxisWalker::set(context.getParentNode());
|
||||
AxisWalker<string_type>::set(context.getParentNode());
|
||||
else
|
||||
AxisWalker::set((static_cast<DOM::Attr<string_type> >(context)).getOwnerElement());
|
||||
AxisWalker<string_type>::set((static_cast<DOM::Attr<string_type> >(context)).getOwnerElement());
|
||||
} // ParentAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
if(AxisWalker::get() != 0)
|
||||
AxisWalker::set(0);
|
||||
if(AxisWalker<string_type>::get() != 0)
|
||||
AxisWalker<string_type>::set(0);
|
||||
} // advance
|
||||
virtual AxisWalker* clone() const { return new ParentAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new ParentAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
ParentAxisWalker(const ParentAxisWalker& rhs) : AxisWalker(rhs) { }
|
||||
}; // class ParentAxisWalker
|
||||
private:
|
||||
ParentAxisWalker(const ParentAxisWalker& rhs) : AxisWalker<string_type>(rhs) { }
|
||||
}; // class ParentAxisWalker
|
||||
|
||||
class PrecedingAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
PrecedingAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(false)
|
||||
template<class string_type>
|
||||
class PrecedingAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
PrecedingAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(false)
|
||||
{
|
||||
nextAncestor_ = context.getParentNode();
|
||||
AxisWalker::set(previousInDocument(context));
|
||||
AxisWalker<string_type>::set(previousInDocument(context));
|
||||
} // PrecedingAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
AxisWalker::set(previousInDocument(AxisWalker::get()));
|
||||
AxisWalker<string_type>::set(previousInDocument(AxisWalker<string_type>::get()));
|
||||
} // advance
|
||||
virtual AxisWalker* clone() const { return new PrecedingAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new PrecedingAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
private:
|
||||
DOM::Node<string_type> previousInDocument(const DOM::Node<string_type>& context)
|
||||
{
|
||||
DOM::Node<string_type> next = context.getPreviousSibling();
|
||||
|
@ -461,89 +506,66 @@ private:
|
|||
return getLastDescendant(c);
|
||||
} // getLastDescendant
|
||||
|
||||
PrecedingAxisWalker(const PrecedingAxisWalker& rhs) : AxisWalker(rhs), nextAncestor_(rhs.nextAncestor_) { }
|
||||
PrecedingAxisWalker(const PrecedingAxisWalker& rhs) : AxisWalker<string_type>(rhs), nextAncestor_(rhs.nextAncestor_) { }
|
||||
DOM::Node<string_type> nextAncestor_;
|
||||
}; // PrecedingAxisWalker
|
||||
}; // PrecedingAxisWalker
|
||||
|
||||
class PrecedingSiblingAxisWalker : public AxisWalker
|
||||
{
|
||||
public:
|
||||
PrecedingSiblingAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(false)
|
||||
template<class string_type>
|
||||
class PrecedingSiblingAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
PrecedingSiblingAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(false)
|
||||
{
|
||||
if(context != 0)
|
||||
AxisWalker::set(context.getPreviousSibling());
|
||||
AxisWalker<string_type>::set(context.getPreviousSibling());
|
||||
} // PrecedingSiblingAxisWalker
|
||||
|
||||
virtual void advance()
|
||||
{
|
||||
if(AxisWalker::get() != 0)
|
||||
AxisWalker::set(AxisWalker::get().getPreviousSibling());
|
||||
if(AxisWalker<string_type>::get() != 0)
|
||||
AxisWalker<string_type>::set(AxisWalker<string_type>::get().getPreviousSibling());
|
||||
} // advance
|
||||
virtual AxisWalker* clone() const { return new PrecedingSiblingAxisWalker(*this); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new PrecedingSiblingAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
PrecedingSiblingAxisWalker(const PrecedingSiblingAxisWalker& rhs) : AxisWalker(rhs) { }
|
||||
}; // class PrecedingSiblingAxisWalker
|
||||
private:
|
||||
PrecedingSiblingAxisWalker(const PrecedingSiblingAxisWalker& rhs) : AxisWalker<string_type>(rhs) { }
|
||||
}; // class PrecedingSiblingAxisWalker
|
||||
|
||||
class SelfAxisWalker : public AxisWalker
|
||||
template<class string_type>
|
||||
class SelfAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
SelfAxisWalker(const DOM::Node<string_type>& context) : AxisWalker<string_type>(true)
|
||||
{
|
||||
public:
|
||||
SelfAxisWalker(const DOM::Node<string_type>& context) : AxisWalker(true)
|
||||
{
|
||||
AxisWalker::set(context);
|
||||
AxisWalker<string_type>::set(context);
|
||||
} // SelfAxisWalker
|
||||
|
||||
virtual void advance() { AxisWalker::end(); }
|
||||
virtual AxisWalker* clone() const { return new SelfAxisWalker(*this); }
|
||||
virtual void advance() { AxisWalker<string_type>::end(); }
|
||||
virtual AxisWalker<string_type>* clone() const { return new SelfAxisWalker(*this); }
|
||||
|
||||
private:
|
||||
SelfAxisWalker(const SelfAxisWalker& rhs) : AxisWalker(rhs) { }
|
||||
}; // class SelfAxisWalker
|
||||
private:
|
||||
SelfAxisWalker(const SelfAxisWalker& rhs) : AxisWalker<string_type>(rhs) { }
|
||||
}; // class SelfAxisWalker
|
||||
|
||||
static DOM::Node<string_type> walkDown(const DOM::Node<string_type>& context, const DOM::Node<string_type>& origin)
|
||||
{
|
||||
if(context.getNodeType() == DOM::Node<string_type>::ATTRIBUTE_NODE)
|
||||
return 0;
|
||||
|
||||
DOM::Node<string_type> next = context.getFirstChild();
|
||||
if((next == 0) && (context == origin)) // node with no children
|
||||
return 0;
|
||||
|
||||
if(next != 0)
|
||||
return next;
|
||||
|
||||
next = context.getNextSibling();
|
||||
if(next != 0)
|
||||
return next;
|
||||
|
||||
DOM::Node<string_type> parent = context.getParentNode();
|
||||
while(parent != origin && next == 0)
|
||||
{
|
||||
next = parent.getNextSibling();
|
||||
parent = parent.getParentNode();
|
||||
} // while ...
|
||||
|
||||
return next;
|
||||
} // walkDown
|
||||
}; // class AxisEnumerator
|
||||
} // namespace impl
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
const typename AxisEnumerator<string_type, string_adaptor>::NamedAxis
|
||||
AxisEnumerator<string_type, string_adaptor>::AxisLookupTable[] =
|
||||
{
|
||||
{ ANCESTOR, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator<string_type, string_adaptor>::AncestorAxisWalker> },
|
||||
{ ANCESTOR_OR_SELF, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::AncestorOrSelfAxisWalker> },
|
||||
{ ATTRIBUTE, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::AttributeAxisWalker> },
|
||||
{ CHILD, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::ChildAxisWalker> },
|
||||
{ DESCENDANT, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::DescendantAxisWalker> },
|
||||
{ DESCENDANT_OR_SELF, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::DescendantOrSelfAxisWalker> },
|
||||
{ FOLLOWING, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::FollowingAxisWalker> },
|
||||
{ FOLLOWING_SIBLING, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::FollowingSiblingAxisWalker> },
|
||||
{ NAMESPACE, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::NamespaceAxisWalker> },
|
||||
{ PARENT, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::ParentAxisWalker> },
|
||||
{ PRECEDING, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::PrecedingAxisWalker> },
|
||||
{ PRECEDING_SIBLING, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::PrecedingSiblingAxisWalker> },
|
||||
{ SELF, AxisEnumerator<string_type, string_adaptor>::CreateAxis<AxisEnumerator::SelfAxisWalker> },
|
||||
{ ANCESTOR, impl::CreateAxis<impl::AncestorAxisWalker<string_type>, string_type> },
|
||||
{ ANCESTOR_OR_SELF, impl::CreateAxis<impl::AncestorOrSelfAxisWalker<string_type>, string_type> },
|
||||
{ ATTRIBUTE, impl::CreateAxis<impl::AttributeAxisWalker<string_type>, string_type> },
|
||||
{ CHILD, impl::CreateAxis<impl::ChildAxisWalker<string_type>, string_type> },
|
||||
{ DESCENDANT, impl::CreateAxis<impl::DescendantAxisWalker<string_type>, string_type> },
|
||||
{ DESCENDANT_OR_SELF, impl::CreateAxis<impl::DescendantOrSelfAxisWalker<string_type>, string_type> },
|
||||
{ FOLLOWING, impl::CreateAxis<impl::FollowingAxisWalker<string_type>, string_type> },
|
||||
{ FOLLOWING_SIBLING, impl::CreateAxis<impl::FollowingSiblingAxisWalker<string_type>, string_type> },
|
||||
{ NAMESPACE, impl::CreateAxis<impl::NamespaceAxisWalker<string_type, string_adaptor>, string_type> },
|
||||
{ PARENT, impl::CreateAxis<impl::ParentAxisWalker<string_type>, string_type> },
|
||||
{ PRECEDING, impl::CreateAxis<impl::PrecedingAxisWalker<string_type>, string_type> },
|
||||
{ PRECEDING_SIBLING, impl::CreateAxis<impl::PrecedingSiblingAxisWalker<string_type>, string_type> },
|
||||
{ SELF, impl::CreateAxis<impl::SelfAxisWalker<string_type>, string_type> },
|
||||
{ static_cast<Axis>(0), 0 }
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue