LCOV - code coverage report
Current view: top level - libreoffice/autodoc/source/ary/inc/store - s_iterator.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 37 37 100.0 %
Date: 2012-12-27 Functions: 33 33 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef ARY_STORE_S_ITERATOR_HXX
      21             : #define ARY_STORE_S_ITERATOR_HXX
      22             : 
      23             : // USED SERVICES
      24             : #include <ary/getncast.hxx>
      25             : #include "s_base.hxx"
      26             : 
      27             : 
      28             : 
      29             : 
      30             : namespace ary
      31             : {
      32             : namespace stg
      33             : {
      34             : 
      35             : 
      36             : template <class>        class const_iterator;
      37             : template <class, class> class const_filter_iterator;
      38             : 
      39             : 
      40             : /** A non-const iterator that runs on a ->Storage<>.
      41             : 
      42             :     @collab Storage<>
      43             : */
      44             : template <class ENTITY>
      45             : class iterator : public std::iterator<std::forward_iterator_tag, ENTITY>
      46             : {
      47             :   public:
      48             :     typedef iterator<ENTITY>                            self;
      49             :     typedef typename Base<ENTITY>::impl_type            impl_container;
      50             :     typedef typename impl_container::const_iterator     impl_type;
      51             : 
      52             :     // OPERATORS
      53             :                         iterator()
      54             :                             :   itImpl()        {}
      55       39062 :     explicit            iterator(
      56             :                             impl_type           i_impl)
      57       39062 :                             :   itImpl(i_impl)  {}
      58       88278 :                         ~iterator()             {}
      59             : 
      60             :     bool                operator==(
      61             :                             self                i_other ) const
      62             :                                                 { return itImpl == i_other.itImpl; }
      63       63662 :     bool                operator!=(
      64             :                             self                i_other ) const
      65       63662 :                                                 { return itImpl != i_other.itImpl; }
      66       69001 :     ENTITY &            operator*() const       { csv_assert(*itImpl != 0);
      67       69001 :                                                   return *(*itImpl); }
      68       63658 :     self &              operator++()            { ++itImpl; return *this; }
      69             :     self                operator++(int)         { return self(itImpl++); }
      70             : 
      71             :   private:
      72             :     friend class const_iterator<ENTITY>;        // For const_iterator(iterator);
      73             :     impl_type           ImplIterator() const    { return itImpl; }
      74             : 
      75             :     // DATA
      76             :     impl_type           itImpl;
      77             : };
      78             : 
      79             : 
      80             : /** A const iterator that runs on a ->Storage<>.
      81             : 
      82             :     @collab Storage<>
      83             : */
      84             : template <class ENTITY>
      85             : class const_iterator :
      86             :     public std::iterator<std::forward_iterator_tag, const ENTITY>
      87             : {
      88             :   public:
      89             :     typedef const_iterator<ENTITY>                      self;
      90             :     typedef typename Base<ENTITY>::impl_type            impl_container;
      91             :     typedef typename impl_container::const_iterator     impl_type;
      92             : 
      93             :     // OPERATORS
      94             :                         const_iterator()
      95             :                             :   itImpl()        {}
      96          56 :     explicit            const_iterator(
      97             :                             impl_type           i_impl)
      98          56 :                             :   itImpl(i_impl)  {}
      99             :                         const_iterator(         // implicit conversions allowed
     100             :                             ::ary::stg::iterator<ENTITY>    i_it )
     101             :                             :   itImpl(i_it.ImplIterator()) {}
     102      566343 :                         ~const_iterator()       {}
     103             : 
     104             :     bool                operator==(
     105             :                             self                i_other ) const
     106             :                                                 { return itImpl == i_other.itImpl; }
     107      546757 :     bool                operator!=(
     108             :                             self                i_other ) const
     109      546757 :                                                 { return itImpl != i_other.itImpl; }
     110      566273 :     const ENTITY &      operator*() const       { csv_assert(*itImpl != 0);
     111      566273 :                                                   return *(*itImpl); }
     112      546729 :     self &              operator++()            { ++itImpl; return *this; }
     113             :     self                operator++(int)         { return self(itImpl++); }
     114             : 
     115             :   private:
     116             :     // DATA
     117             :     impl_type           itImpl;
     118             : };
     119             : 
     120             : 
     121             : 
     122             : 
     123             : 
     124             : /** A non const iterator that runs on a ->Storage<> and returns only
     125             :     the elements of a specific type.
     126             : 
     127             :     @tpl ENTITY
     128             :     The element type of the ->Storage<>
     129             : 
     130             :     @tpl FILTER
     131             :     The actual type of the returned items. FILTER needs to be derived from
     132             :     ENTITY.
     133             : 
     134             :     @collab Storage<>
     135             : */
     136             : template <class ENTITY, class FILTER>
     137             : class filter_iterator :
     138             :     public std::iterator<std::forward_iterator_tag, FILTER>
     139             : {
     140             :   public:
     141             :     typedef filter_iterator<ENTITY,FILTER>              self;
     142             :     typedef ::ary::stg::iterator<ENTITY>                impl_type;
     143             : 
     144             :     // OPERATORS
     145             :                         filter_iterator()
     146             :                             :   itCur()         {}
     147           4 :     explicit            filter_iterator(
     148             :                             impl_type           i_cur )
     149           4 :                             :   itCur(i_cur)    {}
     150       24610 :                         ~filter_iterator()      {}
     151             : 
     152             :     bool                operator==(
     153             :                             self                i_other ) const
     154             :                                                 { return itCur == i_other.itCur; }
     155       24606 :     bool                operator!=(
     156             :                             self                i_other ) const
     157       24606 :                                                 { return itCur != i_other.itCur; }
     158        5343 :     FILTER &            operator*() const       { csv_assert(IsValid());
     159        5343 :                                                   return static_cast< FILTER& >(*itCur); }
     160       24604 :     self &              operator++()            { ++itCur;
     161       24604 :                                                   return *this; }
     162             :     self                operator++(int)         { return self(itCur++); }
     163       24604 :     bool                IsValid() const         { return ary::is_type<FILTER>(*itCur); }
     164             : 
     165             :   private:
     166             :     friend class const_filter_iterator<ENTITY,FILTER>;  // For const_filter_iterator(filter_iterator);
     167             :     impl_type           ImplCur() const         { return itCur; }
     168             : 
     169             :     // DATA
     170             :     impl_type           itCur;
     171             : };
     172             : 
     173             : 
     174             : /** A const iterator that runs on a ->Storage<> and returns only
     175             :     the elements of a specific type.
     176             : 
     177             :     @tpl ENTITY
     178             :     The element type of the ->Storage<>
     179             : 
     180             :     @tpl FILTER
     181             :     The actual type of the returned items. FILTER needs to be derived from
     182             :     ENTITY.
     183             : 
     184             :     @collab Storage<>
     185             : */
     186             : template <class ENTITY, class FILTER>
     187             : class const_filter_iterator :
     188             :     public std::iterator<std::forward_iterator_tag, const FILTER>
     189             : {
     190             :   public:
     191             :     typedef const_filter_iterator<ENTITY,FILTER>        self;
     192             :     typedef ::ary::stg::const_iterator<ENTITY>          impl_type;
     193             : 
     194             :     // OPERATORS
     195             :                         const_filter_iterator()
     196             :                             :   itCur()         {}
     197           2 :     explicit            const_filter_iterator(
     198             :                             impl_type           i_cur )
     199           2 :                             :   itCur(i_cur)    {}
     200             :     explicit            const_filter_iterator(  // implicit conversions allowed
     201             :                             filter_iterator<ENTITY,FILTER>
     202             :                                                 i_it )
     203             :                             :   itCur(i_it.ImplCur())   {}
     204       19530 :                         ~const_filter_iterator()
     205       19530 :                                                 {}
     206             :     bool                operator==(
     207             :                             self                i_other ) const
     208             :                                                 { return itCur == i_other.itCur; }
     209       19528 :     bool                operator!=(
     210             :                             self                i_other ) const
     211       19528 :                                                 { return itCur != i_other.itCur; }
     212          18 :     const FILTER &      operator*() const       { csv_assert(IsValid());
     213          18 :                                                   return static_cast< const FILTER& >(*itCur); }
     214       19527 :     self &              operator++()            { ++itCur;
     215       19527 :                                                   return *this; }
     216             :     self                operator++(int)         { return self(itCur++); }
     217       19527 :     bool                IsValid() const         { return ary::is_type<FILTER>(*itCur); }
     218             : 
     219             :   private:
     220             :     // DATA
     221             :     impl_type           itCur;
     222             : };
     223             : 
     224             : 
     225             : 
     226             : 
     227             : }   // namespace stg
     228             : }   // namespace ary
     229             : #endif
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10