Scopira 20080306

iterator_imp.h

00001 
00002 /*
00003  *  Copyright (c) 2002    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED__SCOPIRA_TOOL_ITERATOR_IMP_H__
00015 #define __INCLUDED__SCOPIRA_TOOL_ITERATOR_IMP_H__
00016 
00017 // the following is for developers who want to quickly build
00018 // iterator_imps from stl based ones 
00019 
00020 #include <scopira/tool/iterator.h>
00021 
00022 namespace scopira
00023 {
00024   namespace tool
00025   {
00026     template <class T> struct deref {
00027       typedef T in_type;
00028       T operator()(T r) const { return r; }
00029     };
00030     template <class TOUT, class DEF, class TIN = typename DEF::in_type > struct deref_first {
00031       typedef TIN in_type;
00032       TOUT operator()(TIN r) { return DEF()(r).first; }
00033     };
00034     template <class TOUT, class DEF, class TIN = typename DEF::in_type > struct deref_second {
00035       typedef TIN in_type;
00036       TOUT operator()(TIN r) { return DEF()(r).second; }
00037     };
00038     template <class TOUT, class DEF, class TIN = typename DEF::in_type > struct deref_ptr {
00039       typedef TIN in_type;
00040       TOUT operator()(TIN a) { return *DEF()(a); }
00041     };
00042     template <class TOUT, class DEF, class TIN = typename DEF::in_type > struct deref_objauto {
00043       typedef TIN in_type;
00044       TOUT operator()(TIN a) { return DEF()(a).get(); }
00045     };
00046     template <class ITER, class T, class DEF > class stl_iterator_imp_g;
00047 
00048     // utlity for for_each
00049   }
00050 }
00051 
00057 template <class ITER, class T, class DEF> class scopira::tool::stl_iterator_imp_g
00058   : public scopira::tool::iterator_imp_g<T>
00059 {
00060   protected:
00061     ITER m_current, m_end;
00062 
00063   public:
00064     stl_iterator_imp_g(const ITER & _start, const ITER & _end)
00065       : m_current(_start), m_end(_end) { }
00067     virtual T current(void) {
00068       return DEF()(*m_current);
00069     }
00071     virtual bool valid(void) const {
00072       return m_current != m_end;
00073     }
00075     virtual void next(void) {
00076       m_current++;
00077     }
00078 };
00079 
00080 #endif
00081