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 .
21 #include <sal/config.h>
25 #include <model/SlsPageEnumeration.hxx>
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
>
39 const SlideSorterModel
& rModel
,
40 const PageEnumeration::PagePredicate
& rPredicate
);
41 PageEnumerationImpl(const PageEnumerationImpl
&) = delete;
42 PageEnumerationImpl
& operator=(const PageEnumerationImpl
&) = delete;
43 /** Create a copy of the called enumeration object.
45 virtual ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> > Clone() override
;
47 virtual bool HasMoreElements() const override
;
48 virtual SharedPageDescriptor
GetNextElement() override
;
49 virtual void Rewind() override
;
52 const SlideSorterModel
& mrModel
;
53 const PageEnumeration::PagePredicate maPredicate
;
56 /** This constructor sets the internal page index to the given value.
57 It does not call AdvanceToNextValidElement() to skip elements that
58 do not fulfill Predicate.
61 const SlideSorterModel
& rModel
,
62 const PageEnumeration::PagePredicate
& rPredicate
,
65 /** Skip all elements that do not fulfill Predicate starting with the
66 one pointed to by mnIndex.
68 void AdvanceToNextValidElement();
71 } // end of anonymous namespace
73 namespace sd
{ namespace slidesorter
{ namespace model
{
75 PageEnumeration
PageEnumeration::Create (
76 const SlideSorterModel
& rModel
,
77 const PagePredicate
& rPredicate
)
79 return PageEnumeration(::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> >(
80 new PageEnumerationImpl(rModel
, rPredicate
)));
83 PageEnumeration::PageEnumeration (
84 ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> > && pImpl
)
85 : mpImpl(std::move(pImpl
))
89 PageEnumeration::PageEnumeration (const PageEnumeration
& rEnumeration
)
90 : sd::slidesorter::model::Enumeration
<sd::slidesorter::model::SharedPageDescriptor
>()
92 mpImpl
= rEnumeration
.mpImpl
->Clone();
95 PageEnumeration::~PageEnumeration()
99 PageEnumeration
& PageEnumeration::operator= (
100 const PageEnumeration
& rEnumeration
)
102 mpImpl
= rEnumeration
.mpImpl
->Clone();
106 ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> > PageEnumeration::Clone()
108 return ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> >(
109 new PageEnumeration (*this));
112 bool PageEnumeration::HasMoreElements() const
114 return mpImpl
->HasMoreElements();
117 SharedPageDescriptor
PageEnumeration::GetNextElement()
119 return mpImpl
->GetNextElement();
122 void PageEnumeration::Rewind()
124 return mpImpl
->Rewind();
127 } } } // end of namespace ::sd::slidesorter::model
131 PageEnumerationImpl::PageEnumerationImpl (
132 const SlideSorterModel
& rModel
,
133 const PageEnumeration::PagePredicate
& rPredicate
)
135 maPredicate(rPredicate
),
141 PageEnumerationImpl::PageEnumerationImpl (
142 const SlideSorterModel
& rModel
,
143 const PageEnumeration::PagePredicate
& rPredicate
,
146 maPredicate(rPredicate
),
151 ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> >
152 PageEnumerationImpl::Clone()
154 return ::std::unique_ptr
<Enumeration
<SharedPageDescriptor
> >(
155 new PageEnumerationImpl(mrModel
,maPredicate
,mnIndex
));
158 bool PageEnumerationImpl::HasMoreElements() const
160 return (mnIndex
< mrModel
.GetPageCount());
163 SharedPageDescriptor
PageEnumerationImpl::GetNextElement()
165 SharedPageDescriptor
pDescriptor (mrModel
.GetPageDescriptor(mnIndex
));
167 // Go to the following valid element.
169 AdvanceToNextValidElement();
174 void PageEnumerationImpl::Rewind()
176 // Go to first valid element.
178 AdvanceToNextValidElement();
181 void PageEnumerationImpl::AdvanceToNextValidElement()
183 while (mnIndex
< mrModel
.GetPageCount())
185 SharedPageDescriptor
pDescriptor (mrModel
.GetPageDescriptor(mnIndex
));
187 // Test for the predicate being fulfilled.
188 if (pDescriptor
.get()!=nullptr && maPredicate(pDescriptor
))
190 // This predicate is valid.
195 // Advance to next predicate.
201 } // end of anonymous namespace
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */