OSDN Git Service

document_serial_iterator.hpp: Update
authorMyun2 <myun2@nwhite.info>
Fri, 17 Sep 2010 19:59:54 +0000 (04:59 +0900)
committerMyun2 <myun2@nwhite.info>
Fri, 17 Sep 2010 20:04:02 +0000 (05:04 +0900)
roast_xml_dom_parser.hpp: 読み込み追加とあと dom_generator の直しですよー

roast/include/roast/xml/roast_xml/document_serial_iterator.hpp
roast/include/roast/xml/roast_xml/roast_xml_dom_parser.hpp

index a5062d2..19e3fb1 100644 (file)
@@ -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<T*> _Base;
-               
                protected:
                        document *m_pdoc;
-                       ::std::stack<node_list_t*> m_nl_now_stack;
-                       size_t m_index;
+                       //::std::stack<node_list_t*> m_nl_now_stack;
+                       //::std::stack<size_t> 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]);
                        }
                };
        }
index 712a41c..0040849 100644 (file)
@@ -11,6 +11,8 @@
 #include <vector>
 #include <stack>
 
+#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 <typename _Strm>
-                       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__