OSDN Git Service

primitive_array_iterator も最新イテレータに対応
authorMyun2 <myun2@nwhite.info>
Fri, 4 Jun 2010 04:10:22 +0000 (13:10 +0900)
committerMyun2 <myun2@nwhite.info>
Fri, 4 Jun 2010 04:10:22 +0000 (13:10 +0900)
roast/include/roast/container/pa_iterator.hpp
roast/include/roast/container/primitive_array_iterator.hpp
roast/test/roast_test_VC90/iterator_test.cpp

index 4f28586..cd27e8f 100644 (file)
@@ -8,19 +8,22 @@
 namespace roast{
        ////////////////////////////////////////////////
        
-       template <typename T, unsigned int _END=0, unsigned int _START=0>
-       class pa_iterator : public primitive_array_iterator<T,_END,_START>
+       template <typename T, typename _IndexType = size_t>
+       class pa_iterator : public primitive_array_iterator<T,_IndexType>
        {
+       private:
+               typedef primitive_array_iterator<T,_IndexType> _Base;
        public:
                //////////////////////////////////////////
        
                //      Constructors
-               pa_iterator(T* p_array=NULL, unsigned int length=_END) :
-                 primitive_array_iterator<T,_END,_START>(p_array,length){}
-               
-               pa_iterator(T* p_array, unsigned int start, unsigned int end) :
-                 primitive_array_iterator<T,_END,_START>(p_array,start,end){}
-
+               pa_iterator(){}
+               pa_iterator(T* p_array, const _IndexType& length)
+                       : _Base(p_array, length)
+               {}
+               pa_iterator(T* p_array, const _IndexType& start, const _IndexType& end)
+                       : _Base(p_array, start, end)
+               {}
        };
                                
 }//end of roast namespace
index 07c3b9c..23b1914 100644 (file)
@@ -4,11 +4,13 @@
 #define __SFJP_ROAST___container__primitive_array_iterator_HPP__
 
 #include <string.h>
-#include "roast/container/begin_end_iterator.hpp"
+#include "roast/container/indexer_iterator.hpp"
 
 namespace roast{
        ////////////////////////////////////////////////
        
+       /*      ?????
+       
        template <typename T, unsigned int _END=0>
        class _primitive_array_iterator_impl
                : public _begin_end_iterator_impl<T, T*>
@@ -22,46 +24,29 @@ namespace roast{
                _primitive_array_iterator_impl(T* p_array=NULL, IndexType length=_END)
                        : _Base(p_array, p_array + length){}
        };
+       */
        
        ////////////////////////////////////////////////
        
-       template <typename T, unsigned int _END=0, unsigned int _START=0, typename _IndexType = size_t >
-       class _primitive_array_iterator_ex_impl
-               : public begin_end_iterator<T, T*>
+       template <typename T, typename _IndexType = size_t >
+       class _primitive_array_iterator_impl
+               : public _indexer_iterator_impl<T*,T>
        {
        private:
-               typedef begin_end_iterator<T, T*> _Base;
-               
-       protected:
-               typedef _IndexType IndexType;
-               T* m_p_array;
-               
+               typedef _indexer_iterator_impl<T*,T> _Base;
        public:
                //////////////////////////////////////////
        
                //      Constructors
-               /*_primitive_array_iterator_ex_impl()
-                       : _Base(0, 0),
-                         m_p_array(NULL)
-                       {}*/
-                       
-               _primitive_array_iterator_ex_impl(T* p_array=NULL, const IndexType& length=_END)
-                       : _Base(_START, length),
-                         m_p_array(p_array)
-                       {}
-                       
-               _primitive_array_iterator_ex_impl(T* p_array, const IndexType& start, const IndexType& end)
-                       : _Base(start, end),
-                         m_p_array(p_array)
-                       {}
-               
-               //////////////////////////////////////////
-
-               //      Index operations
-               void set_index(const IndexType& index) { m_it = m_p_array[index]; }
-               IndexType get_index() const { return m_it - m_p_array; }
-               void change_end(const IndexType& index) { m_end = m_p_array[index]; }
+               _primitive_array_iterator_impl(){}
+               _primitive_array_iterator_impl(T* p_array, const IndexType& length)
+                       : _Base(p_array, length)
+               {}
+               _primitive_array_iterator_impl(T* p_array, const IndexType& start, const IndexType& end)
+                       : _Base(p_array, start, end)
+               {}
        };
+       
        /*
        ////////////////////////////////////////////////
        
@@ -91,24 +76,38 @@ namespace roast{
                bool is_valid(){ return m_index >= m_end; }
        };*/
        
-       ////////////////////////////////////////////////
-       
-       /////////////////////////////////////////////////////////
+       //////////////////////////////////////////////////////////////////////////////////////////
 
-       template <typename T, unsigned int _END=0>
+       template <typename T, typename _IndexType = size_t>
        class primitive_array_iterator :
-               public _iterator< _primitive_array_iterator_impl<T,_END> >
+               public _iterator< _primitive_array_iterator_impl<T,_IndexType> >
        {
        private:
-               typedef _primitive_array_iterator_impl<T,_END> _Impl;
-               typedef _iterator<_Impl> _Base;
+               typedef _primitive_array_iterator_impl<T,_IndexType> Impl;
+               typedef _iterator<Impl> _Base;
        public:
-               begin_end_iterator(){}
-               begin_end_iterator(const _Impl& impl) : _Base(impl){}
-               begin_end_iterator(T* p_array=NULL, IndexType length=_END)
-                       : _Base(_Impl(p_array,length)) {}
+               primitive_array_iterator(){}
+               primitive_array_iterator(T* p_array, const _IndexType& length)
+                       : _Base(Impl(p_array, length))
+               {}
+               primitive_array_iterator(T* p_array, const _IndexType& start, const _IndexType& end)
+                       : _Base(Impl(p_array, start, end))
+               {}
        };
-
+       
+       //////////////////////////////////////////////////////////////////////////////////////////
+       
+       /*
+       template <typename T, typename _IndexType>
+       typename primitive_array_iterator<T,_IndexType>
+               make_primitive_array_iterator(T con, _IndexType length)
+       {
+               return 
+                       primitive_array_iterator<T,_IndexType>
+                       (con,length);
+       }
+       */
+       
 }//end of roast namespace
 
 #endif//__SFJP_ROAST___container__primitive_array_iterator_HPP__
index c8be4a0..19d8ece 100644 (file)
@@ -1,5 +1,5 @@
 #include "stdafx.h"
-#include "roast/container/indexer_iterator.hpp"
+#include "roast/container/pa_iterator.hpp"
 #include <stdio.h>
 
 #define lengthof(x) (sizeof(x) / sizeof(*(x)))
@@ -13,7 +13,8 @@ void main()
        work[0] = 1;
 
        //indexer_iterator<char*, char>::type a = _indexer_iterator_impl<char*, char>(work,32);
-       indexer_iterator<int*, int>::type a = make_indexer_iterator<int*, int>(work,0,lengthof(work));
+       //indexer_iterator<int*, int>::type a = make_indexer_iterator<int*, int>(work,0,lengthof(work));
+       pa_iterator<int> a = pa_iterator<int>(work,lengthof(work));
        //counter_iterator ca(lengthof(work),0);
        countdown_iterator ca(lengthof(work));
 
@@ -27,7 +28,7 @@ void main()
        }
        while(a.in_dowhile());
 
-       a = make_indexer_iterator<int*, int>(work,lengthof(work));
+       a = pa_iterator<int>(work,lengthof(work));
        do
        {
                printf("%d,", *a);