Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:22

0001 /*-----------------------------------------------------------------------------+
0002 Copyright (c) 2009-2009: Joachim Faulhaber
0003 +------------------------------------------------------------------------------+
0004    Distributed under the Boost Software License, Version 1.0.
0005       (See accompanying file LICENCE.txt or copy at
0006            http://www.boost.org/LICENSE_1_0.txt)
0007 +-----------------------------------------------------------------------------*/
0008 #ifndef BOOST_ICL_ITERATOR_HPP_JOFA_091003
0009 #define BOOST_ICL_ITERATOR_HPP_JOFA_091003
0010 
0011 #include <iterator>
0012 
0013 namespace boost{namespace icl
0014 {
0015 
0016 /** \brief Performes an addition using a container's memberfunction add, when operator= is called. */
0017 template<class ContainerT> class add_iterator
0018 {
0019 public:
0020     /// The container's type.
0021     typedef ContainerT container_type;
0022     typedef std::output_iterator_tag iterator_category; 
0023     typedef void value_type;
0024     typedef void difference_type;
0025     typedef void pointer;
0026     typedef void reference;
0027 
0028     /** An add_iterator is constructed with a container and a position 
0029         that has to be maintained. */
0030     add_iterator(ContainerT& cont, typename ContainerT::iterator iter)
0031     : _cont(&cont), _iter(iter) {}
0032 
0033     /** This assignment operator adds the \c value before the current position.
0034         It maintains it's position by incrementing after addition.    */
0035     add_iterator& operator=(typename ContainerT::const_reference value)
0036     {
0037         _iter = icl::add(*_cont, _iter, value);
0038         if(_iter != _cont->end())
0039             ++_iter;
0040         return *this;
0041     }
0042 
0043     add_iterator& operator*()    { return *this; }
0044     add_iterator& operator++()   { return *this; }
0045     add_iterator& operator++(int){ return *this; }
0046 
0047 private:
0048     ContainerT*                   _cont;
0049     typename ContainerT::iterator _iter;
0050 };
0051 
0052 
0053 /** Function adder creates and initializes an add_iterator */
0054 template<class ContainerT, typename IteratorT>
0055 inline add_iterator<ContainerT> adder(ContainerT& cont, IteratorT iter_)
0056 {
0057     return add_iterator<ContainerT>(cont, typename ContainerT::iterator(iter_));
0058 }
0059 
0060 /** \brief Performes an insertion using a container's memberfunction add, when operator= is called. */
0061 template<class ContainerT> class insert_iterator
0062 {
0063 public:
0064     /// The container's type.
0065     typedef ContainerT container_type;
0066     typedef std::output_iterator_tag iterator_category; 
0067     typedef void value_type;
0068     typedef void difference_type;
0069     typedef void pointer;
0070     typedef void reference;
0071 
0072     /** An insert_iterator is constructed with a container and a position 
0073         that has to be maintained. */
0074     insert_iterator(ContainerT& cont, typename ContainerT::iterator iter)
0075     : _cont(&cont), _iter(iter) {}
0076 
0077     /** This assignment operator adds the \c value before the current position.
0078         It maintains it's position by incrementing after addition.    */
0079     insert_iterator& operator=(typename ContainerT::const_reference value)
0080     {
0081         _iter = _cont->insert(_iter, value);
0082         if(_iter != _cont->end())
0083             ++_iter;
0084         return *this;
0085     }
0086 
0087     insert_iterator& operator*()    { return *this; }
0088     insert_iterator& operator++()   { return *this; }
0089     insert_iterator& operator++(int){ return *this; }
0090 
0091 private:
0092     ContainerT*                   _cont;
0093     typename ContainerT::iterator _iter;
0094 };
0095 
0096 
0097 /** Function inserter creates and initializes an insert_iterator */
0098 template<class ContainerT, typename IteratorT>
0099 inline insert_iterator<ContainerT> inserter(ContainerT& cont, IteratorT iter_)
0100 {
0101     return insert_iterator<ContainerT>(cont, typename ContainerT::iterator(iter_));
0102 }
0103 
0104 }} // namespace icl boost
0105 
0106 #endif // BOOST_ICL_ITERATOR_HPP_JOFA_091003
0107 
0108