Main Page   Class Hierarchy   File List  

IterAdapter.h

00001 /*
00002         Copyright (c) 2003 Michael Carrato. All rights reserved.        
00003 
00004         Permission to use, modify, copy, and distribute this software 
00005         and its documentation is hereby granted without fee, 
00006         provided that the above copyright notice appears in all copies.
00007         This software is provided "as is" without express or implied 
00008     warranty.
00009 */
00010 
00011 #if !defined(AFX_ITERADAPTER_H__2F47FAA0_633A_47D4_8313_5D58C18BCAEB__INCLUDED_)
00012 #define AFX_ITERADAPTER_H__2F47FAA0_633A_47D4_8313_5D58C18BCAEB__INCLUDED_
00013 
00014 #if _MSC_VER > 1000
00015 #pragma once
00016 #pragma warning (disable:4786)
00017 #pragma warning (disable:4284)
00018 #endif // _MSC_VER > 1000
00019 
00020 
00021 template <class ITERIMPL>
00022 class CIterAdapter
00023 {
00024 public:
00025     typedef typename ITERIMPL::iterator_category iterator_category;
00026     typedef typename ITERIMPL::value_type value_type;
00027     typedef value_type* pointer;
00028     typedef value_type& reference;
00029     typedef const value_type* const_pointer;
00030     typedef const value_type& const_reference;
00031     typedef typename ITERIMPL::size_type size_type;
00032     typedef typename ITERIMPL::difference_type difference_type;
00033     CIterAdapter(const ITERIMPL& i)
00034         : impl_(i)
00035     { }
00036     CIterAdapter()
00037     { }
00038     const_reference operator*() const
00039     {
00040         return impl_.dereference();
00041     }
00042     const_pointer operator->() const
00043     {
00044         return (&**this); 
00045     }
00046     CIterAdapter& operator++()
00047     {
00048         impl_.increment();
00049         return *this;
00050     }
00051     CIterAdapter operator++(int)
00052     {
00053         CIterAdapter ret = *this;
00054         ++*this;
00055         return ret;
00056     }
00057     CIterAdapter& operator--()
00058     {
00059         impl_.decrement();
00060         return *this; 
00061     }
00062     CIterAdapter operator--(int)
00063     {
00064         CIterAdapter ret = *this;
00065         --*this;
00066         return ret; 
00067     }
00068     bool operator==(const CIterAdapter& rhs) const
00069     {
00070         return impl_.equals(rhs.impl_);
00071     }
00072     bool operator!=(const CIterAdapter& rhs) const
00073     {
00074         return (!(*this == rhs)); 
00075     }
00076         //need to have this public accessor for some containers. A friendship would be better.
00077         ITERIMPL& getImpl_()
00078         {
00079                 return impl_;
00080         }
00081 protected:
00082     ITERIMPL impl_;
00083 };
00084 
00085 template <class ITERIMPL>
00086 class IterAdapter : public CIterAdapter<ITERIMPL>
00087 {
00088 public:
00089     typedef typename ITERIMPL::value_type value_type;
00090     typedef value_type* pointer;
00091     typedef value_type& reference;
00092 
00093     IterAdapter(const ITERIMPL& i)
00094     { 
00095         impl_ = i;
00096     }
00097     IterAdapter()
00098     { }
00099     reference operator*() const
00100     {
00101         return impl_.dereference();
00102     }
00103     pointer operator->() const
00104     {
00105         return (&**this); 
00106     }
00107     IterAdapter& operator++()
00108     {
00109         impl_.increment();
00110         return *this;
00111     }
00112     IterAdapter operator++(int)
00113     {
00114         IterAdapter ret = *this;
00115         ++*this;
00116         return ret;
00117     }
00118     IterAdapter& operator--()
00119     {
00120         impl_.decrement();
00121         return *this; 
00122     }
00123     IterAdapter operator--(int)
00124     {
00125         IterAdapter ret = *this;
00126         --*this;
00127         return ret; 
00128     }
00129 };
00130 
00131 #endif // !defined(AFX_ITERADAPTER_H__2F47FAA0_633A_47D4_8313_5D58C18BCAEB__INCLUDED_)
00132 *this;
00133         return ret; 
00134     }
00135 };
00136 
00137 #endif // !defined(AFX_ITERADAPTER_H__2F47FAA0_633A_47D4_8313_5D58C18BCAEB__INCLUDED_)

Generated on Wed May 28 12:44:07 2003 for Compact Associative Collections by doxygen1.2.18