LibreOffice Module sd (master) 1
SlsPageEnumeration.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <memory>
21#include <sal/config.h>
22
23#include <utility>
24
27
28using namespace ::sd::slidesorter;
29using namespace ::sd::slidesorter::model;
30
31namespace {
32
33class PageEnumerationImpl
34 : public Enumeration<SharedPageDescriptor>
35{
36public:
37 PageEnumerationImpl (
38 const SlideSorterModel& rModel,
39 PageEnumeration::PagePredicate aPredicate);
40 PageEnumerationImpl(const PageEnumerationImpl&) = delete;
41 PageEnumerationImpl& operator=(const PageEnumerationImpl&) = delete;
44 virtual ::std::unique_ptr<Enumeration<SharedPageDescriptor> > Clone() override;
45
46 virtual bool HasMoreElements() const override;
47 virtual SharedPageDescriptor GetNextElement() override;
48 virtual void Rewind() override;
49
50private:
51 const SlideSorterModel& mrModel;
52 const PageEnumeration::PagePredicate maPredicate;
53 int mnIndex;
54
59 PageEnumerationImpl (
60 const SlideSorterModel& rModel,
61 PageEnumeration::PagePredicate aPredicate,
62 int nIndex);
63
67 void AdvanceToNextValidElement();
68};
69
70} // end of anonymous namespace
71
72namespace sd::slidesorter::model {
73
75 const SlideSorterModel& rModel,
76 const PagePredicate& rPredicate)
77{
78 return PageEnumeration(::std::unique_ptr<Enumeration<SharedPageDescriptor> >(
79 new PageEnumerationImpl(rModel, rPredicate)));
80}
81
83 ::std::unique_ptr<Enumeration<SharedPageDescriptor> > && pImpl)
84 : mpImpl(std::move(pImpl))
85{
86}
87
89: sd::slidesorter::model::Enumeration<sd::slidesorter::model::SharedPageDescriptor>()
90{
91 mpImpl = rEnumeration.mpImpl->Clone();
92}
93
95{
96}
97
99 const PageEnumeration& rEnumeration)
100{
101 mpImpl = rEnumeration.mpImpl->Clone();
102 return *this;
103}
104
105::std::unique_ptr<Enumeration<SharedPageDescriptor> > PageEnumeration::Clone()
106{
107 return ::std::unique_ptr<Enumeration<SharedPageDescriptor> >(
108 new PageEnumeration (*this));
109}
110
112{
113 return mpImpl->HasMoreElements();
114}
115
117{
118 return mpImpl->GetNextElement();
119}
120
122{
123 return mpImpl->Rewind();
124}
125
126} // end of namespace ::sd::slidesorter::model
127
128namespace {
129
130PageEnumerationImpl::PageEnumerationImpl (
131 const SlideSorterModel& rModel,
132 PageEnumeration::PagePredicate aPredicate)
133 : mrModel(rModel),
134 maPredicate(std::move(aPredicate)),
135 mnIndex(0)
136{
137 Rewind();
138}
139
140PageEnumerationImpl::PageEnumerationImpl (
141 const SlideSorterModel& rModel,
143 int nIndex)
144 : mrModel(rModel),
145 maPredicate(std::move(aPredicate)),
147{
148}
149
150::std::unique_ptr<Enumeration<SharedPageDescriptor> >
152{
153 return ::std::unique_ptr<Enumeration<SharedPageDescriptor> >(
154 new PageEnumerationImpl(mrModel,maPredicate,mnIndex));
155}
156
157bool PageEnumerationImpl::HasMoreElements() const
158{
159 return (mnIndex < mrModel.GetPageCount());
160}
161
162SharedPageDescriptor PageEnumerationImpl::GetNextElement()
163{
164 SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
165
166 // Go to the following valid element.
167 mnIndex += 1;
168 AdvanceToNextValidElement();
169
170 return pDescriptor;
171}
172
173void PageEnumerationImpl::Rewind()
174{
175 // Go to first valid element.
176 mnIndex = 0;
177 AdvanceToNextValidElement();
178}
179
180void PageEnumerationImpl::AdvanceToNextValidElement()
181{
182 while (mnIndex < mrModel.GetPageCount())
183 {
184 SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
185
186 // Test for the predicate being fulfilled.
187 if (pDescriptor && maPredicate(pDescriptor))
188 {
189 // This predicate is valid.
190 break;
191 }
192 else
193 {
194 // Advance to next predicate.
195 mnIndex += 1;
196 }
197 }
198}
199
200} // end of anonymous namespace
201
202/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ChartModel & mrModel
sal_Int32 mnIndex
Public class of page enumerations that delegates its calls to an implementation object that can filte...
virtual SharedPageDescriptor GetNextElement() override
Return the next element of the enumeration.
PageEnumeration & operator=(const PageEnumeration &rEnumeration)
PageEnumeration(const PageEnumeration &rEnumeration)
This copy constructor creates a copy of the given enumeration.
virtual bool HasMoreElements() const override
Return <TRUE> when the enumeration has more elements, i.e.
static PageEnumeration Create(const SlideSorterModel &rModel, const PagePredicate &rPredicate)
virtual void Rewind() override
Rewind the enumeration so that the next call to GetNextElement() will return its first element.
virtual ::std::unique_ptr< Enumeration< SharedPageDescriptor > > Clone() override
Create and return an exact copy of the called object.
::std::function< bool(const SharedPageDescriptor &)> PagePredicate
Create a new page enumeration that enumerates a subset of the pages of the given model.
::std::unique_ptr< Enumeration< SharedPageDescriptor > > mpImpl
Implementation object.
The model of the slide sorter gives access to the slides that are to be displayed in the slide sorter...
sal_Int32 nIndex
std::shared_ptr< PageDescriptor > SharedPageDescriptor
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
sal_uInt32 mnIndex