1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
24 #include <boost/noncopyable.hpp>
26 #include "model/SlideSorterModel.hxx"
27 #include "model/SlsPageDescriptor.hxx"
29 using namespace ::sd::slidesorter
;
30 using namespace ::sd::slidesorter::model
;
34 class PageEnumerationImpl
35 : public Enumeration
<SharedPageDescriptor
>, private boost::noncopyable
38 inline PageEnumerationImpl (
39 const SlideSorterModel
& rModel
,
40 const PageEnumeration::PagePredicate
& rPredicate
);
41 virtual ~PageEnumerationImpl();
42 /** Create a copy of the called enumeration object.
44 virtual ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> > Clone() SAL_OVERRIDE
;
46 virtual bool HasMoreElements() const SAL_OVERRIDE
;
47 virtual SharedPageDescriptor
GetNextElement() SAL_OVERRIDE
;
48 virtual void Rewind() SAL_OVERRIDE
;
51 const SlideSorterModel
& mrModel
;
52 const PageEnumeration::PagePredicate maPredicate
;
55 /** This constructor sets the internal page index to the given value.
56 It does not call AdvanceToNextValidElement() to skip elements that
57 do not fulfill Predicate.
59 inline PageEnumerationImpl (
60 const SlideSorterModel
& rModel
,
61 const PageEnumeration::PagePredicate
& rPredicate
,
64 /** Skip all elements that do not fulfill Predicate starting with the
65 one pointed to by mnIndex.
67 inline void AdvanceToNextValidElement();
70 } // end of anonymouse namespace
72 namespace sd
{ namespace slidesorter
{ namespace model
{
74 PageEnumeration
PageEnumeration::Create (
75 const SlideSorterModel
& rModel
,
76 const PagePredicate
& rPredicate
)
78 return PageEnumeration(::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> >(
79 new PageEnumerationImpl(rModel
, rPredicate
)));
82 PageEnumeration::PageEnumeration (
83 ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> > && pImpl
)
84 : mpImpl(std::move(pImpl
))
88 PageEnumeration::PageEnumeration (
89 PageEnumeration
& rEnumeration
,
95 mpImpl
= rEnumeration
.mpImpl
->Clone();
99 mpImpl
= std::move(rEnumeration
.mpImpl
);
103 PageEnumeration::PageEnumeration (const PageEnumeration
& rEnumeration
)
104 : sd::slidesorter::model::Enumeration
<sd::slidesorter::model::SharedPageDescriptor
>()
106 mpImpl
= rEnumeration
.mpImpl
->Clone();
109 PageEnumeration::~PageEnumeration()
113 PageEnumeration
& PageEnumeration::operator= (
114 const PageEnumeration
& rEnumeration
)
116 mpImpl
= rEnumeration
.mpImpl
->Clone();
120 ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> > PageEnumeration::Clone()
122 return ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> >(
123 new PageEnumeration (*this, true));
126 bool PageEnumeration::HasMoreElements() const
128 return mpImpl
->HasMoreElements();
131 SharedPageDescriptor
PageEnumeration::GetNextElement()
133 return mpImpl
->GetNextElement();
136 void PageEnumeration::Rewind()
138 return mpImpl
->Rewind();
141 } } } // end of namespace ::sd::slidesorter::model
145 PageEnumerationImpl::PageEnumerationImpl (
146 const SlideSorterModel
& rModel
,
147 const PageEnumeration::PagePredicate
& rPredicate
)
149 maPredicate(rPredicate
),
155 PageEnumerationImpl::PageEnumerationImpl (
156 const SlideSorterModel
& rModel
,
157 const PageEnumeration::PagePredicate
& rPredicate
,
160 maPredicate(rPredicate
),
165 PageEnumerationImpl::~PageEnumerationImpl()
169 ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> >
170 PageEnumerationImpl::Clone()
172 return ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> >(
173 new PageEnumerationImpl(mrModel
,maPredicate
,mnIndex
));
176 bool PageEnumerationImpl::HasMoreElements() const
178 return (mnIndex
< mrModel
.GetPageCount());
181 SharedPageDescriptor
PageEnumerationImpl::GetNextElement()
183 SharedPageDescriptor
pDescriptor (mrModel
.GetPageDescriptor(mnIndex
));
185 // Go to the following valid element.
187 AdvanceToNextValidElement();
192 void PageEnumerationImpl::Rewind()
194 // Go to first valid element.
196 AdvanceToNextValidElement();
199 void PageEnumerationImpl::AdvanceToNextValidElement()
201 while (mnIndex
< mrModel
.GetPageCount())
203 SharedPageDescriptor
pDescriptor (mrModel
.GetPageDescriptor(mnIndex
));
205 // Test for the predicate being fulfilled.
206 if (pDescriptor
.get()!=NULL
&& maPredicate(pDescriptor
))
208 // This predicate is valid.
213 // Advance to next predicate.
219 } // end of anonymous namespace
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */