From 3484afc9abe9fdf270f3bb10ab6db470b0646b5f Mon Sep 17 00:00:00 2001 From: Myun2 Date: Sat, 18 Sep 2010 04:59:54 +0900 Subject: [PATCH] =?utf8?q?document=5Fserial=5Fiterator.hpp:=20Update=20roa?= =?utf8?q?st=5Fxml=5Fdom=5Fparser.hpp:=20=E8=AA=AD=E3=81=BF=E8=BE=BC?= =?utf8?q?=E3=81=BF=E8=BF=BD=E5=8A=A0=E3=81=A8=E3=81=82=E3=81=A8=20dom=5Fg?= =?utf8?q?enerator=20=E3=81=AE=E7=9B=B4=E3=81=97=E3=81=A7=E3=81=99?= =?utf8?q?=E3=82=88=E3=83=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../xml/roast_xml/document_serial_iterator.hpp | 82 +++++++++++++++++----- .../roast/xml/roast_xml/roast_xml_dom_parser.hpp | 11 +-- 2 files changed, 72 insertions(+), 21 deletions(-) diff --git a/roast/include/roast/xml/roast_xml/document_serial_iterator.hpp b/roast/include/roast/xml/roast_xml/document_serial_iterator.hpp index a5062d20..19e3fb17 100644 --- a/roast/include/roast/xml/roast_xml/document_serial_iterator.hpp +++ b/roast/include/roast/xml/roast_xml/document_serial_iterator.hpp @@ -15,22 +15,38 @@ namespace roast class _document_serial_iterator_impl { public: - typedef T _ValueType, ValueType; + /*typedef T _ValueType, ValueType; typedef T* _IteratorType; typedef T& ValueTypeRef; typedef T* ValueTypePtr; typedef const T CValueType; typedef const T& CValueTypeRef; - typedef const T* CValueTypePtr; + typedef const T* CValueTypePtr;*/ - private: - typedef _linear_iterator_impl_base _Base; - protected: document *m_pdoc; - ::std::stack m_nl_now_stack; - size_t m_index; + //::std::stack m_nl_now_stack; + //::std::stack m_nl_in_stack; + typedef struct _nl_cur_ + { + node_list_t* nl; + size_t index; + + _nl_cur_(node_list_t* nl_in, size_t index_in=0) + { + nl = nl_in; + index = index_in; + } + + bool operator == (const _nl_cur_& from) + { + //return nl - from.nl || nl - from.nl + return ( nl == from.nl && index - from.index ); + } + } _nl_cur; + ::std::stack<_nl_cur> m_nl_cur_stack; + bool m_is_valid; public: _document_serial_iterator_impl(){ setup(NULL); } @@ -40,28 +56,60 @@ namespace roast void setup(document* pdoc) { m_pdoc = pdoc; - m_nl_now_stack.clear(); + //m_nl_cur_stack.clear(); + while (!m_nl_cur_stack.empty() ) + m_nl_cur_stack.pop(); + if ( m_pdoc != NULL ) - m_nl_now_stack.push(&m_pdoc->m_node_list); - m_index = 0; + m_nl_cur_stack.push(_nl_cur(&m_pdoc->m_node_list)); + //m_index = 0; + m_is_valid = true; } - + /////////////////////////////////////////////////////////////////////// int compare(const _document_serial_iterator_impl& target) const { - return ( m_nl_now_stack.top() == target.m_nl_now_stack.top() && - m_index == target.m_index ); + return ( m_nl_cur_stack == target.m_nl_cur_stack ); } - void next() { - m_it++; + void next() + { + _nl_cur &cur = m_nl_cur_stack.top(); + node_list_t &cur_nl = *(cur.nl); + //if ( m_nl_cur_stack.top().nl->operator [](index). + + // Element: Into child node_list. + if ( cur_nl[cur.index]->m_node_type == node::TYPE_ELEMENT ) + { + element* e = (element*)cur_nl[cur.index]; + m_nl_cur_stack.push(_nl_cur(&e->node_list)); + } + // Not Element: Increment index. + else + { + cur.index++; + if ( cur.index >= cur_nl.size() ) + { + if ( !m_nl_cur_stack.empty() ) + m_nl_cur_stack.pop(); + else + m_is_valid = false; + } + } } + // Iterator pointer Valid? + bool is_valid() const { + return m_is_valid; + } + // Value - node& get_value_ref() const + node& get_value_ref() { - return m_it; + _nl_cur &cur = m_nl_cur_stack.top(); + node_list_t &cur_nl = *(cur.nl); + return *(cur_nl[cur.index]); } }; } diff --git a/roast/include/roast/xml/roast_xml/roast_xml_dom_parser.hpp b/roast/include/roast/xml/roast_xml/roast_xml_dom_parser.hpp index 712a41ca..00408496 100644 --- a/roast/include/roast/xml/roast_xml/roast_xml_dom_parser.hpp +++ b/roast/include/roast/xml/roast_xml/roast_xml_dom_parser.hpp @@ -11,6 +11,8 @@ #include #include +#include "roast/container/condition_end_iterator.hpp" + namespace roast { namespace roast_xml @@ -199,15 +201,15 @@ namespace roast //////////////////////////////////////////////////////////////// - class dom_generator : public lexical::generator_base<_structure, document> + class dom_generator : public lexical::generator_base<_rule, document> { private: - typedef generator_base<_structure, document> _Base; + typedef generator_base<_rule, document> _Base; public: template - bool generate(const document& doc, _Strm &strm) + bool generate(_Strm &strm, const document& doc) { - return _Base::generate(doc, strm); + return _Base::generate(strm, doc); } }; @@ -290,5 +292,6 @@ namespace roast };*/ } } +#include "document_serial_iterator.hpp" #endif//__SFJP_ROAST__xml__roast_xml__roast_xml_dom_parser_HPP__ -- 2.11.0