xref: /AOO41X/main/autodoc/source/ary/inc/store/s_iterator.hxx (revision 1c78a5d6c0093dece4c096ba53051800fbad6e33)
1*1c78a5d6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*1c78a5d6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1c78a5d6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1c78a5d6SAndrew Rist  * distributed with this work for additional information
6*1c78a5d6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1c78a5d6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1c78a5d6SAndrew Rist  * "License"); you may not use this file except in compliance
9*1c78a5d6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*1c78a5d6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*1c78a5d6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1c78a5d6SAndrew Rist  * software distributed under the License is distributed on an
15*1c78a5d6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1c78a5d6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1c78a5d6SAndrew Rist  * specific language governing permissions and limitations
18*1c78a5d6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*1c78a5d6SAndrew Rist  *************************************************************/
21*1c78a5d6SAndrew Rist 
22*1c78a5d6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef ARY_STORE_S_ITERATOR_HXX
25cdf0e10cSrcweir #define ARY_STORE_S_ITERATOR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // USED SERVICES
28cdf0e10cSrcweir #include <ary/getncast.hxx>
29cdf0e10cSrcweir #include "s_base.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace ary
35cdf0e10cSrcweir {
36cdf0e10cSrcweir namespace stg
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir template <class>        class const_iterator;
41cdf0e10cSrcweir template <class, class> class const_filter_iterator;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /** A non-const iterator that runs on a ->Storage<>.
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     @collab Storage<>
47cdf0e10cSrcweir */
48cdf0e10cSrcweir template <class ENTITY>
49cdf0e10cSrcweir class iterator : public std::iterator<std::forward_iterator_tag, ENTITY>
50cdf0e10cSrcweir {
51cdf0e10cSrcweir   public:
52cdf0e10cSrcweir     typedef iterator<ENTITY>                            self;
53cdf0e10cSrcweir     typedef typename Base<ENTITY>::impl_type            impl_container;
54cdf0e10cSrcweir     typedef typename impl_container::const_iterator     impl_type;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     // OPERATORS
iterator()57cdf0e10cSrcweir                         iterator()
58cdf0e10cSrcweir                             :   itImpl()        {}
iterator(impl_type i_impl)59cdf0e10cSrcweir     explicit            iterator(
60cdf0e10cSrcweir                             impl_type           i_impl)
61cdf0e10cSrcweir                             :   itImpl(i_impl)  {}
~iterator()62cdf0e10cSrcweir                         ~iterator()             {}
63cdf0e10cSrcweir 
operator ==(self i_other) const64cdf0e10cSrcweir     bool                operator==(
65cdf0e10cSrcweir                             self                i_other ) const
66cdf0e10cSrcweir                                                 { return itImpl == i_other.itImpl; }
operator !=(self i_other) const67cdf0e10cSrcweir     bool                operator!=(
68cdf0e10cSrcweir                             self                i_other ) const
69cdf0e10cSrcweir                                                 { return itImpl != i_other.itImpl; }
operator *() const70cdf0e10cSrcweir     ENTITY &            operator*() const       { csv_assert(*itImpl != 0);
71cdf0e10cSrcweir                                                   return *(*itImpl); }
operator ++()72cdf0e10cSrcweir     self &              operator++()            { ++itImpl; return *this; }
operator ++(int)73cdf0e10cSrcweir     self                operator++(int)         { return self(itImpl++); }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir   private:
76cdf0e10cSrcweir     friend class const_iterator<ENTITY>;        // For const_iterator(iterator);
ImplIterator() const77cdf0e10cSrcweir     impl_type           ImplIterator() const    { return itImpl; }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     // DATA
80cdf0e10cSrcweir     impl_type           itImpl;
81cdf0e10cSrcweir };
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir /** A const iterator that runs on a ->Storage<>.
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     @collab Storage<>
87cdf0e10cSrcweir */
88cdf0e10cSrcweir template <class ENTITY>
89cdf0e10cSrcweir class const_iterator :
90cdf0e10cSrcweir     public std::iterator<std::forward_iterator_tag, const ENTITY>
91cdf0e10cSrcweir {
92cdf0e10cSrcweir   public:
93cdf0e10cSrcweir     typedef const_iterator<ENTITY>                      self;
94cdf0e10cSrcweir     typedef typename Base<ENTITY>::impl_type            impl_container;
95cdf0e10cSrcweir     typedef typename impl_container::const_iterator     impl_type;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     // OPERATORS
const_iterator()98cdf0e10cSrcweir                         const_iterator()
99cdf0e10cSrcweir                             :   itImpl()        {}
const_iterator(impl_type i_impl)100cdf0e10cSrcweir     explicit            const_iterator(
101cdf0e10cSrcweir                             impl_type           i_impl)
102cdf0e10cSrcweir                             :   itImpl(i_impl)  {}
const_iterator(::ary::stg::iterator<ENTITY> i_it)103cdf0e10cSrcweir                         const_iterator(         // implicit conversions allowed
104cdf0e10cSrcweir                             ::ary::stg::iterator<ENTITY>    i_it )
105cdf0e10cSrcweir                             :   itImpl(i_it.ImplIterator()) {}
~const_iterator()106cdf0e10cSrcweir                         ~const_iterator()       {}
107cdf0e10cSrcweir 
operator ==(self i_other) const108cdf0e10cSrcweir     bool                operator==(
109cdf0e10cSrcweir                             self                i_other ) const
110cdf0e10cSrcweir                                                 { return itImpl == i_other.itImpl; }
operator !=(self i_other) const111cdf0e10cSrcweir     bool                operator!=(
112cdf0e10cSrcweir                             self                i_other ) const
113cdf0e10cSrcweir                                                 { return itImpl != i_other.itImpl; }
operator *() const114cdf0e10cSrcweir     const ENTITY &      operator*() const       { csv_assert(*itImpl != 0);
115cdf0e10cSrcweir                                                   return *(*itImpl); }
operator ++()116cdf0e10cSrcweir     self &              operator++()            { ++itImpl; return *this; }
operator ++(int)117cdf0e10cSrcweir     self                operator++(int)         { return self(itImpl++); }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir   private:
120cdf0e10cSrcweir     // DATA
121cdf0e10cSrcweir     impl_type           itImpl;
122cdf0e10cSrcweir };
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir /** A non const iterator that runs on a ->Storage<> and returns only
129cdf0e10cSrcweir     the elements of a specific type.
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     @tpl ENTITY
132cdf0e10cSrcweir     The element type of the ->Storage<>
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     @tpl FILTER
135cdf0e10cSrcweir     The actual type of the returned items. FILTER needs to be derived from
136cdf0e10cSrcweir     ENTITY.
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     @collab Storage<>
139cdf0e10cSrcweir */
140cdf0e10cSrcweir template <class ENTITY, class FILTER>
141cdf0e10cSrcweir class filter_iterator :
142cdf0e10cSrcweir     public std::iterator<std::forward_iterator_tag, FILTER>
143cdf0e10cSrcweir {
144cdf0e10cSrcweir   public:
145cdf0e10cSrcweir     typedef filter_iterator<ENTITY,FILTER>              self;
146cdf0e10cSrcweir     typedef ::ary::stg::iterator<ENTITY>                impl_type;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     // OPERATORS
filter_iterator()149cdf0e10cSrcweir                         filter_iterator()
150cdf0e10cSrcweir                             :   itCur()         {}
filter_iterator(impl_type i_cur)151cdf0e10cSrcweir     explicit            filter_iterator(
152cdf0e10cSrcweir                             impl_type           i_cur )
153cdf0e10cSrcweir                             :   itCur(i_cur)    {}
~filter_iterator()154cdf0e10cSrcweir                         ~filter_iterator()      {}
155cdf0e10cSrcweir 
operator ==(self i_other) const156cdf0e10cSrcweir     bool                operator==(
157cdf0e10cSrcweir                             self                i_other ) const
158cdf0e10cSrcweir                                                 { return itCur == i_other.itCur; }
operator !=(self i_other) const159cdf0e10cSrcweir     bool                operator!=(
160cdf0e10cSrcweir                             self                i_other ) const
161cdf0e10cSrcweir                                                 { return itCur != i_other.itCur; }
operator *() const162cdf0e10cSrcweir     FILTER &            operator*() const       { csv_assert(IsValid());
163cdf0e10cSrcweir                                                   return static_cast< FILTER& >(*itCur); }
operator ++()164cdf0e10cSrcweir     self &              operator++()            { ++itCur;
165cdf0e10cSrcweir                                                   return *this; }
operator ++(int)166cdf0e10cSrcweir     self                operator++(int)         { return self(itCur++); }
IsValid() const167cdf0e10cSrcweir     bool                IsValid() const         { return ary::is_type<FILTER>(*itCur); }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir   private:
170cdf0e10cSrcweir     friend class const_filter_iterator<ENTITY,FILTER>;  // For const_filter_iterator(filter_iterator);
ImplCur() const171cdf0e10cSrcweir     impl_type           ImplCur() const         { return itCur; }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     // DATA
174cdf0e10cSrcweir     impl_type           itCur;
175cdf0e10cSrcweir };
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 
178cdf0e10cSrcweir /** A const iterator that runs on a ->Storage<> and returns only
179cdf0e10cSrcweir     the elements of a specific type.
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     @tpl ENTITY
182cdf0e10cSrcweir     The element type of the ->Storage<>
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     @tpl FILTER
185cdf0e10cSrcweir     The actual type of the returned items. FILTER needs to be derived from
186cdf0e10cSrcweir     ENTITY.
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     @collab Storage<>
189cdf0e10cSrcweir */
190cdf0e10cSrcweir template <class ENTITY, class FILTER>
191cdf0e10cSrcweir class const_filter_iterator :
192cdf0e10cSrcweir     public std::iterator<std::forward_iterator_tag, const FILTER>
193cdf0e10cSrcweir {
194cdf0e10cSrcweir   public:
195cdf0e10cSrcweir     typedef const_filter_iterator<ENTITY,FILTER>        self;
196cdf0e10cSrcweir     typedef ::ary::stg::const_iterator<ENTITY>          impl_type;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     // OPERATORS
const_filter_iterator()199cdf0e10cSrcweir                         const_filter_iterator()
200cdf0e10cSrcweir                             :   itCur()         {}
const_filter_iterator(impl_type i_cur)201cdf0e10cSrcweir     explicit            const_filter_iterator(
202cdf0e10cSrcweir                             impl_type           i_cur )
203cdf0e10cSrcweir                             :   itCur(i_cur)    {}
const_filter_iterator(filter_iterator<ENTITY,FILTER> i_it)204cdf0e10cSrcweir     explicit            const_filter_iterator(  // implicit conversions allowed
205cdf0e10cSrcweir                             filter_iterator<ENTITY,FILTER>
206cdf0e10cSrcweir                                                 i_it )
207cdf0e10cSrcweir                             :   itCur(i_it.ImplCur())   {}
~const_filter_iterator()208cdf0e10cSrcweir                         ~const_filter_iterator()
209cdf0e10cSrcweir                                                 {}
operator ==(self i_other) const210cdf0e10cSrcweir     bool                operator==(
211cdf0e10cSrcweir                             self                i_other ) const
212cdf0e10cSrcweir                                                 { return itCur == i_other.itCur; }
operator !=(self i_other) const213cdf0e10cSrcweir     bool                operator!=(
214cdf0e10cSrcweir                             self                i_other ) const
215cdf0e10cSrcweir                                                 { return itCur != i_other.itCur; }
operator *() const216cdf0e10cSrcweir     const FILTER &      operator*() const       { csv_assert(IsValid());
217cdf0e10cSrcweir                                                   return static_cast< const FILTER& >(*itCur); }
operator ++()218cdf0e10cSrcweir     self &              operator++()            { ++itCur;
219cdf0e10cSrcweir                                                   return *this; }
operator ++(int)220cdf0e10cSrcweir     self                operator++(int)         { return self(itCur++); }
IsValid() const221cdf0e10cSrcweir     bool                IsValid() const         { return ary::is_type<FILTER>(*itCur); }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir   private:
224cdf0e10cSrcweir     // DATA
225cdf0e10cSrcweir     impl_type           itCur;
226cdf0e10cSrcweir };
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 
231cdf0e10cSrcweir }   // namespace stg
232cdf0e10cSrcweir }   // namespace ary
233cdf0e10cSrcweir #endif
234