1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsPageEnumeration.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "model/SlideSorterModel.hxx"
34 #include "model/SlsPageDescriptor.hxx"
36 using namespace ::sd::slidesorter
;
37 using namespace ::sd::slidesorter::model
;
41 class PageEnumerationImpl
42 : public Enumeration
<SharedPageDescriptor
>
45 inline PageEnumerationImpl (
46 const SlideSorterModel
& rModel
,
47 const PageEnumeration::PagePredicate
& rPredicate
);
48 virtual ~PageEnumerationImpl (void);
49 /** Create a copy of the called enumeration object.
51 virtual inline ::std::auto_ptr
<Enumeration
<SharedPageDescriptor
> > Clone (void);
53 virtual inline bool HasMoreElements (void) const;
54 virtual inline SharedPageDescriptor
GetNextElement (void);
55 virtual inline void Rewind (void);
58 const SlideSorterModel
& mrModel
;
59 const PageEnumeration::PagePredicate maPredicate
;
62 /** This constructor sets the internal page index to the given value.
63 It does not call AdvanceToNextValidElement() to skip elements that
64 do not fullfill Predicate.
66 inline PageEnumerationImpl (
67 const SlideSorterModel
& rModel
,
68 const PageEnumeration::PagePredicate
& rPredicate
,
71 /** Skip all elements that do not fullfill Predicate starting with the
72 one pointed to by mnIndex.
74 inline void AdvanceToNextValidElement (void);
76 // Default constructor not implemented.
77 PageEnumerationImpl (void);
78 // Assignment operator not implemented.
79 PageEnumerationImpl
& operator= (const PageEnumerationImpl
&);
82 } // end of anonymouse namespace
87 namespace sd
{ namespace slidesorter
{ namespace model
{
90 PageEnumeration
PageEnumeration::Create (
91 const SlideSorterModel
& rModel
,
92 const PagePredicate
& rPredicate
)
94 return PageEnumeration(::std::auto_ptr
<Enumeration
<SharedPageDescriptor
> >(
95 new PageEnumerationImpl(rModel
, rPredicate
)));
101 PageEnumeration::PageEnumeration (
102 ::std::auto_ptr
<Enumeration
<SharedPageDescriptor
> > pImpl
)
110 PageEnumeration::PageEnumeration (
111 PageEnumeration
& rEnumeration
,
117 mpImpl
= rEnumeration
.mpImpl
->Clone();
121 mpImpl
= rEnumeration
.mpImpl
;
128 PageEnumeration::PageEnumeration (const PageEnumeration
& rEnumeration
)
129 : sd::slidesorter::model::Enumeration
<sd::slidesorter::model::SharedPageDescriptor
>()
131 mpImpl
= rEnumeration
.mpImpl
->Clone();
137 PageEnumeration::~PageEnumeration (void)
144 PageEnumeration
& PageEnumeration::operator= (
145 const PageEnumeration
& rEnumeration
)
147 mpImpl
= rEnumeration
.mpImpl
->Clone();
154 ::std::auto_ptr
<Enumeration
<SharedPageDescriptor
> > PageEnumeration::Clone (void)
156 return ::std::auto_ptr
<Enumeration
<SharedPageDescriptor
> >(
157 new PageEnumeration (*this, true));
163 bool PageEnumeration::HasMoreElements (void) const
165 return mpImpl
->HasMoreElements();
170 SharedPageDescriptor
PageEnumeration::GetNextElement (void)
172 return mpImpl
->GetNextElement();
178 void PageEnumeration::Rewind (void)
180 return mpImpl
->Rewind();
183 } } } // end of namespace ::sd::slidesorter::model
190 PageEnumerationImpl::PageEnumerationImpl (
191 const SlideSorterModel
& rModel
,
192 const PageEnumeration::PagePredicate
& rPredicate
)
194 maPredicate(rPredicate
),
203 PageEnumerationImpl::PageEnumerationImpl (
204 const SlideSorterModel
& rModel
,
205 const PageEnumeration::PagePredicate
& rPredicate
,
208 maPredicate(rPredicate
),
216 PageEnumerationImpl::~PageEnumerationImpl (void)
223 ::std::auto_ptr
<Enumeration
<SharedPageDescriptor
> >
224 PageEnumerationImpl::Clone (void)
226 return ::std::auto_ptr
<Enumeration
<SharedPageDescriptor
> >(
227 new PageEnumerationImpl(mrModel
,maPredicate
,mnIndex
));
233 bool PageEnumerationImpl::HasMoreElements (void) const
235 return (mnIndex
< mrModel
.GetPageCount());
241 SharedPageDescriptor
PageEnumerationImpl::GetNextElement (void)
243 SharedPageDescriptor
pDescriptor (mrModel
.GetPageDescriptor(mnIndex
));
245 // Go to the following valid element.
247 AdvanceToNextValidElement();
255 void PageEnumerationImpl::Rewind (void)
257 // Go to first valid element.
259 AdvanceToNextValidElement();
266 void PageEnumerationImpl::AdvanceToNextValidElement (void)
268 while (mnIndex
< mrModel
.GetPageCount())
270 SharedPageDescriptor
pDescriptor (mrModel
.GetPageDescriptor(mnIndex
));
272 // Test for the predicate being fullfilled.
273 if (pDescriptor
.get()!=NULL
&& maPredicate(pDescriptor
))
275 // This predicate is valid.
280 // Advance to next predicate.
286 } // end of anonymous namespace