OSDN Git Service

random_number_iterator.hpp: こいつ追加されてなかったんか・・・
authorMyun2 <myun2@nwhite.info>
Fri, 24 Sep 2010 10:59:19 +0000 (19:59 +0900)
committerMyun2 <myun2@nwhite.info>
Fri, 24 Sep 2010 10:59:19 +0000 (19:59 +0900)
roast/include/roast/container/random_number_iterator.hpp [new file with mode: 0644]

diff --git a/roast/include/roast/container/random_number_iterator.hpp b/roast/include/roast/container/random_number_iterator.hpp
new file mode 100644 (file)
index 0000000..53bf1c7
--- /dev/null
@@ -0,0 +1,154 @@
+//     Roast+ License
+
+/*
+       
+*/
+#ifndef __SFJP_ROAST__container__random_number_iterator_HPP__
+#define __SFJP_ROAST__container__random_number_iterator_HPP__
+
+#include "roast/container/iterator_base.hpp"
+
+namespace roast
+{
+       /////////////////////////////////////////////////////////
+       
+       //      !! Not Implemented is_valid() Method. !!
+
+       template <typename T, typename _RandomProc>
+       class _random_number_iterator_impl
+       {
+       public:
+               typedef T IteratorType;
+
+               typedef T ValueType;
+               typedef T ValueTypeRef;
+               typedef T* ValueTypePtr;
+               typedef const T CValueType;
+               typedef const T CValueTypeRef;
+               typedef const T* CValueTypePtr;
+       protected:
+               _RandomProc m_it;
+
+       public:
+               _linear_iterator_impl_base(){}
+               _linear_iterator_impl_base(const T& _beg)
+                       : m_it(_beg)
+                       {}
+               ///////////////////////////////////////////////////////////////////////
+               
+               void setup(const T& _beg)
+               {
+                       m_it = _beg;
+               }
+               
+               ///////////////////////////////////////////////////////////////////////
+               
+               int compare(const _random_number_iterator_impl& target) const 
+               {
+                       //return m_it - target.m_it;
+                       return 0;
+               }
+               
+               //      Next (Like iterator ++)
+               void next() {
+                       m_it++;
+               }
+
+               //      Value
+               //T& get_value_ref() const
+               T get_value_ref() const
+               {
+                       return m_it;
+               }
+       };
+       
+       ///////////////////////////////////////////////////////////
+
+       template <typename T>
+       class _linear_reverse_iterator_impl_base :
+               public _linear_iterator_impl_base<T>
+       {
+       private:
+               typedef _linear_iterator_impl_base<T> _Base;
+       public:
+               _linear_reverse_iterator_impl_base(){}
+               _linear_reverse_iterator_impl_base(const T& _beg)
+                       : _Base(_beg)
+                       {}
+               ///////////////////////////////////////////////////////////////////////
+               
+               //      Next (Like iterator ++)
+               void next() {
+                       m_it--;
+               }
+       };
+               
+       /////////////////////////////////////////////////////////
+       /////////////////////////////////////////////////////////
+
+       template <typename _ImplBase>
+       class _linear_iterator_arithmetic : public _ImplBase
+       {
+       private:
+               typedef _ImplBase _Base;
+               typedef _linear_iterator_arithmetic<_Base> _Self;
+               typedef typename _Base::IteratorType IteratorType;
+       public:
+               _linear_iterator_arithmetic(){}
+               _linear_iterator_arithmetic(const _ImplBase& _impl) : _Base(_impl){}
+               _linear_iterator_arithmetic(const IteratorType& _it) : _Base(_it){}
+
+               ///////////////////////////////////////////////////////////////////////
+               
+               //      Arithmetic operators
+               
+               int operator -(const _Self& target) const
+               {
+                       return m_it - target.m_it;
+               }
+               int operator -(const IteratorType& target) const
+               {
+                       return m_it - target;
+               }
+               _Self operator -(int n) const
+               {
+                       _Self work = *this;
+                       work.m_it -= n;
+                       return work;
+               }
+               _Self operator --() {
+                       _Self old = *this;
+                       m_it--;
+                       return old;
+               }
+               _Self operator --(int) {
+                       m_it--;
+                       return *this;
+               }
+               
+               _Self operator +(int n) const
+               {
+                       _Self work = *this;
+                       work.m_it += n;
+                       return work;
+               }
+       };
+               
+       /////////////////////////////////////////////////////////
+
+       template <typename T>
+       class linear_iterator_base :
+               public _iterator< _linear_iterator_impl_base<T> >
+       {
+       private:
+               typedef _linear_iterator_impl_base<T> _Impl;
+               typedef _iterator<_Impl> _Base;
+       public:
+               linear_iterator_base(){}
+               linear_iterator_base(const _Impl& impl) : _Base(impl){}
+               linear_iterator_base(const T& length)
+                       : _Base(_Impl(length)) {}
+       };
+}
+
+#endif//__SFJP_ROAST__container__random_number_iterator_HPP__