xref: /AOO41X/main/sd/source/ui/slidesorter/model/SlsPageEnumeration.cxx (revision 79aad27f7f29270c03e208e3d687e8e3850af11d)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "model/SlideSorterModel.hxx"
27cdf0e10cSrcweir #include "model/SlsPageDescriptor.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir using namespace ::sd::slidesorter;
30cdf0e10cSrcweir using namespace ::sd::slidesorter::model;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace {
33cdf0e10cSrcweir 
34cdf0e10cSrcweir class PageEnumerationImpl
35cdf0e10cSrcweir     : public Enumeration<SharedPageDescriptor>
36cdf0e10cSrcweir {
37cdf0e10cSrcweir public:
38cdf0e10cSrcweir     inline PageEnumerationImpl (
39cdf0e10cSrcweir         const SlideSorterModel& rModel,
40cdf0e10cSrcweir         const PageEnumeration::PagePredicate& rPredicate);
41cdf0e10cSrcweir     virtual ~PageEnumerationImpl (void);
42cdf0e10cSrcweir     /** Create a copy of the called enumeration object.
43cdf0e10cSrcweir     */
44cdf0e10cSrcweir     virtual inline ::std::auto_ptr<Enumeration<SharedPageDescriptor> > Clone (void);
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     virtual inline bool HasMoreElements (void) const;
47cdf0e10cSrcweir     virtual inline SharedPageDescriptor GetNextElement (void);
48cdf0e10cSrcweir     virtual inline void Rewind (void);
49cdf0e10cSrcweir 
50cdf0e10cSrcweir private:
51cdf0e10cSrcweir     const SlideSorterModel& mrModel;
52cdf0e10cSrcweir     const PageEnumeration::PagePredicate maPredicate;
53cdf0e10cSrcweir     int mnIndex;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     /** This constructor sets the internal page index to the given value.
56cdf0e10cSrcweir         It does not call AdvanceToNextValidElement() to skip elements that
57cdf0e10cSrcweir         do not fullfill Predicate.
58cdf0e10cSrcweir     */
59cdf0e10cSrcweir     inline PageEnumerationImpl (
60cdf0e10cSrcweir         const SlideSorterModel& rModel,
61cdf0e10cSrcweir         const PageEnumeration::PagePredicate& rPredicate,
62cdf0e10cSrcweir         int nIndex);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     /** Skip all elements that do not fullfill Predicate starting with the
65cdf0e10cSrcweir         one pointed to by mnIndex.
66cdf0e10cSrcweir     */
67cdf0e10cSrcweir     inline void AdvanceToNextValidElement (void);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     // Default constructor not implemented.
70cdf0e10cSrcweir     PageEnumerationImpl (void);
71cdf0e10cSrcweir     // Assignment operator not implemented.
72cdf0e10cSrcweir     PageEnumerationImpl& operator= (const PageEnumerationImpl&);
73cdf0e10cSrcweir };
74cdf0e10cSrcweir 
75cdf0e10cSrcweir } // end of anonymouse namespace
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 
80cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace model {
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
Create(const SlideSorterModel & rModel,const PagePredicate & rPredicate)83cdf0e10cSrcweir PageEnumeration PageEnumeration::Create (
84cdf0e10cSrcweir     const SlideSorterModel& rModel,
85cdf0e10cSrcweir     const PagePredicate& rPredicate)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     return PageEnumeration(::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
88cdf0e10cSrcweir         new PageEnumerationImpl(rModel, rPredicate)));
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
PageEnumeration(::std::auto_ptr<Enumeration<SharedPageDescriptor>> pImpl)94cdf0e10cSrcweir PageEnumeration::PageEnumeration (
95cdf0e10cSrcweir     ::std::auto_ptr<Enumeration<SharedPageDescriptor> > pImpl)
96cdf0e10cSrcweir     : mpImpl(pImpl)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
PageEnumeration(PageEnumeration & rEnumeration,bool bCloneImpl)103cdf0e10cSrcweir PageEnumeration::PageEnumeration (
104cdf0e10cSrcweir     PageEnumeration& rEnumeration,
105cdf0e10cSrcweir     bool bCloneImpl)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	if( bCloneImpl )
109cdf0e10cSrcweir 	{
110cdf0e10cSrcweir 		mpImpl = rEnumeration.mpImpl->Clone();
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir 	else
113cdf0e10cSrcweir 	{
114cdf0e10cSrcweir 		mpImpl = rEnumeration.mpImpl;
115cdf0e10cSrcweir 	}
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
PageEnumeration(const PageEnumeration & rEnumeration)121cdf0e10cSrcweir PageEnumeration::PageEnumeration (const PageEnumeration& rEnumeration )
122cdf0e10cSrcweir : sd::slidesorter::model::Enumeration<sd::slidesorter::model::SharedPageDescriptor>()
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	mpImpl = rEnumeration.mpImpl->Clone();
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
~PageEnumeration(void)130cdf0e10cSrcweir PageEnumeration::~PageEnumeration (void)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 
operator =(const PageEnumeration & rEnumeration)137cdf0e10cSrcweir PageEnumeration& PageEnumeration::operator= (
138cdf0e10cSrcweir     const PageEnumeration& rEnumeration)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     mpImpl = rEnumeration.mpImpl->Clone();
141cdf0e10cSrcweir     return *this;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
Clone(void)147cdf0e10cSrcweir ::std::auto_ptr<Enumeration<SharedPageDescriptor> > PageEnumeration::Clone (void)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     return ::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
150cdf0e10cSrcweir         new PageEnumeration (*this, true));
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 
HasMoreElements(void) const156cdf0e10cSrcweir bool PageEnumeration::HasMoreElements (void) const
157cdf0e10cSrcweir {
158cdf0e10cSrcweir     return mpImpl->HasMoreElements();
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 
GetNextElement(void)163cdf0e10cSrcweir SharedPageDescriptor PageEnumeration::GetNextElement (void)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir     return mpImpl->GetNextElement();
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 
Rewind(void)171cdf0e10cSrcweir void PageEnumeration::Rewind (void)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     return mpImpl->Rewind();
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir } } } // end of namespace ::sd::slidesorter::model
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
181cdf0e10cSrcweir namespace {
182cdf0e10cSrcweir 
PageEnumerationImpl(const SlideSorterModel & rModel,const PageEnumeration::PagePredicate & rPredicate)183cdf0e10cSrcweir PageEnumerationImpl::PageEnumerationImpl (
184cdf0e10cSrcweir     const SlideSorterModel& rModel,
185cdf0e10cSrcweir     const PageEnumeration::PagePredicate& rPredicate)
186cdf0e10cSrcweir     : mrModel(rModel),
187cdf0e10cSrcweir       maPredicate(rPredicate),
188cdf0e10cSrcweir       mnIndex(0)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     Rewind();
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 
PageEnumerationImpl(const SlideSorterModel & rModel,const PageEnumeration::PagePredicate & rPredicate,int nIndex)196cdf0e10cSrcweir PageEnumerationImpl::PageEnumerationImpl (
197cdf0e10cSrcweir     const SlideSorterModel& rModel,
198cdf0e10cSrcweir     const PageEnumeration::PagePredicate& rPredicate,
199cdf0e10cSrcweir     int nIndex)
200cdf0e10cSrcweir     : mrModel(rModel),
201cdf0e10cSrcweir       maPredicate(rPredicate),
202cdf0e10cSrcweir       mnIndex(nIndex)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 
~PageEnumerationImpl(void)209cdf0e10cSrcweir PageEnumerationImpl::~PageEnumerationImpl (void)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 
216cdf0e10cSrcweir ::std::auto_ptr<Enumeration<SharedPageDescriptor> >
Clone(void)217cdf0e10cSrcweir     PageEnumerationImpl::Clone (void)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     return ::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
220cdf0e10cSrcweir         new PageEnumerationImpl(mrModel,maPredicate,mnIndex));
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 
HasMoreElements(void) const226cdf0e10cSrcweir bool PageEnumerationImpl::HasMoreElements (void) const
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     return (mnIndex < mrModel.GetPageCount());
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 
GetNextElement(void)234cdf0e10cSrcweir SharedPageDescriptor PageEnumerationImpl::GetNextElement (void)
235cdf0e10cSrcweir {
236cdf0e10cSrcweir     SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     // Go to the following valid element.
239cdf0e10cSrcweir     mnIndex += 1;
240cdf0e10cSrcweir     AdvanceToNextValidElement();
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     return pDescriptor;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 
Rewind(void)248cdf0e10cSrcweir void PageEnumerationImpl::Rewind (void)
249cdf0e10cSrcweir {
250cdf0e10cSrcweir     // Go to first valid element.
251cdf0e10cSrcweir     mnIndex = 0;
252cdf0e10cSrcweir     AdvanceToNextValidElement();
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 
AdvanceToNextValidElement(void)259cdf0e10cSrcweir void PageEnumerationImpl::AdvanceToNextValidElement (void)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir     while (mnIndex < mrModel.GetPageCount())
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
264cdf0e10cSrcweir 
265cdf0e10cSrcweir         // Test for the predicate being fullfilled.
266cdf0e10cSrcweir         if (pDescriptor.get()!=NULL && maPredicate(pDescriptor))
267cdf0e10cSrcweir         {
268cdf0e10cSrcweir             // This predicate is valid.
269cdf0e10cSrcweir             break;
270cdf0e10cSrcweir         }
271cdf0e10cSrcweir         else
272cdf0e10cSrcweir         {
273cdf0e10cSrcweir             // Advance to next predicate.
274cdf0e10cSrcweir             mnIndex += 1;
275cdf0e10cSrcweir         }
276cdf0e10cSrcweir     }
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir } // end of anonymous namespace
280cdf0e10cSrcweir 
281