// -*- C++ -*- /*****************************************************************************\ * Copyright (c) 2004 Mark Aylett * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * * "Software"), to deal in the Software without restriction, including * * without limitation the rights to use, copy, modify, merge, publish, * * distribute, sublicense, and/or sell copies of the Software, and to permit * * persons to whom the Software is furnished to do so, subject to the * * following conditions: * * * * The above copyright notice and this permission notice shall be included * * in all copies or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN * * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * * USE OR OTHER DEALINGS IN THE SOFTWARE. * \*****************************************************************************/ /** * \file mar_iterator_cpp.h * \brief TODO */ #ifndef INCLUDED_MAR_ITERATOR_CPP #define INCLUDED_MAR_ITERATOR_CPP #ifndef INCLUDED_MAR_KEY_CPP #include "mar_key_cpp.h" #endif // INCLUDED_MAR_KEY_CPP #ifndef INCLUDED_MAR_UTIL_CPP #include "mar_util_cpp.h" #endif // INCLUDED_MAR_UTIL_CPP namespace mar { class const_iterator { friend size_t toord(const const_iterator&); public: typedef ssize_t difference_type; typedef key value_type; typedef const key* pointer; typedef key reference; typedef std::random_access_iterator_tag iterator_category; typedef size_t size_type; #if defined(_MSC_VER) && _MSC_VER < 1310 typedef difference_type distance_type; #endif // _MSC_VER < 1310 private: const archive* ar_; difference_type ord_; void fetch() const { } void move(difference_type diff) { ord_ += diff; } public: const_iterator(const archive& ar, size_type ord) : ar_(&ar), ord_(ord) { } reference operator *() const { key k; tokey(*ar_, k, ord_); return k; } const_iterator& operator ++() { move(1); return *this; } const const_iterator operator ++(int) { const_iterator tmp(*this); move(1); return tmp; } const_iterator& operator --() { move(-1); return *this; } const const_iterator operator --(int) { const_iterator tmp(*this); move(-1); return tmp; } const_iterator& operator +=(difference_type diff) { move(diff); return *this; } const_iterator& operator -=(difference_type diff) { move(-diff); return *this; } reference operator [](difference_type diff) { return *const_iterator(*ar_, ord_ + diff); } bool operator ==(const const_iterator& rhs) const { return *ar_ == *rhs.ar_ && ord_ == rhs.ord_; } bool operator <(const const_iterator& rhs) const { return *ar_ < *rhs.ar_ && ord_ < rhs.ord_; } }; #if !defined(_MSC_VER) || _MSC_VER >= 1310 #if !defined(_RWSTD_VER) typedef std::reverse_iterator< const_iterator> const_reverse_iterator; #else // _RWSTD_VER typedef std::reverse_iterator< const_iterator, std::random_access_iterator_tag, const_iterator::value_type, const_iterator::reference, const_iterator::pointer, const_iterator::difference_type> const_reverse_iterator; #endif // _RWSTD_VER #else // MSC_VER < 1310 typedef std::reverse_iterator< const_iterator, const_iterator::value_type, const_iterator::reference, const_iterator::pointer, const_iterator::difference_type> const_reverse_iterator; #endif // _MSC_VER < 1310 inline size_t toord(const const_iterator& it) { return it.ord_; } inline size_t toord(const const_reverse_iterator& it) { return toord(it.base()) - 1; } inline const_iterator operator +(const const_iterator& lhs, const_iterator::difference_type diff) { const_iterator tmp(lhs); return tmp += diff; } inline const_iterator operator -(const const_iterator& lhs, const_iterator::difference_type diff) { const_iterator tmp(lhs); return tmp -= diff; } inline const_iterator::difference_type operator -(const const_iterator& lhs, const const_iterator& rhs) { return toord(lhs) - toord(rhs); } inline bool operator !=(const const_iterator& lhs, const const_iterator& rhs) { return !(lhs == rhs); } inline bool operator >(const const_iterator& lhs, const const_iterator& rhs) { return rhs < lhs; } inline bool operator <=(const const_iterator& lhs, const const_iterator& rhs) { return !(lhs > rhs); } inline bool operator >=(const const_iterator& lhs, const const_iterator& rhs) { return !(lhs < rhs); } } #endif // INCLUDED_MAR_ITERATOR_CPP