Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "model/SlideSorterModel.hxx"
31 : : #include "model/SlsPageDescriptor.hxx"
32 : :
33 : : using namespace ::sd::slidesorter;
34 : : using namespace ::sd::slidesorter::model;
35 : :
36 : : namespace {
37 : :
38 : : class PageEnumerationImpl
39 : : : public Enumeration<SharedPageDescriptor>
40 : : {
41 : : public:
42 : : inline PageEnumerationImpl (
43 : : const SlideSorterModel& rModel,
44 : : const PageEnumeration::PagePredicate& rPredicate);
45 : : virtual ~PageEnumerationImpl (void);
46 : : /** Create a copy of the called enumeration object.
47 : : */
48 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
49 : : virtual inline ::std::auto_ptr<Enumeration<SharedPageDescriptor> > Clone (void);
50 : : SAL_WNODEPRECATED_DECLARATIONS_POP
51 : :
52 : : virtual inline bool HasMoreElements (void) const;
53 : : virtual inline SharedPageDescriptor GetNextElement (void);
54 : : virtual inline void Rewind (void);
55 : :
56 : : private:
57 : : const SlideSorterModel& mrModel;
58 : : const PageEnumeration::PagePredicate maPredicate;
59 : : int mnIndex;
60 : :
61 : : /** This constructor sets the internal page index to the given value.
62 : : It does not call AdvanceToNextValidElement() to skip elements that
63 : : do not fullfill Predicate.
64 : : */
65 : : inline PageEnumerationImpl (
66 : : const SlideSorterModel& rModel,
67 : : const PageEnumeration::PagePredicate& rPredicate,
68 : : int nIndex);
69 : :
70 : : /** Skip all elements that do not fullfill Predicate starting with the
71 : : one pointed to by mnIndex.
72 : : */
73 : : inline void AdvanceToNextValidElement (void);
74 : :
75 : : // Default constructor not implemented.
76 : : PageEnumerationImpl (void);
77 : : // Assignment operator not implemented.
78 : : PageEnumerationImpl& operator= (const PageEnumerationImpl&);
79 : : };
80 : :
81 : : } // end of anonymouse namespace
82 : :
83 : :
84 : :
85 : :
86 : : namespace sd { namespace slidesorter { namespace model {
87 : :
88 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
89 : 5349 : PageEnumeration PageEnumeration::Create (
90 : : const SlideSorterModel& rModel,
91 : : const PagePredicate& rPredicate)
92 : : {
93 : : return PageEnumeration(::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
94 [ + - ][ + - ]: 5349 : new PageEnumerationImpl(rModel, rPredicate)));
[ + - ]
95 : : }
96 : : SAL_WNODEPRECATED_DECLARATIONS_POP
97 : :
98 : :
99 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
100 : 5349 : PageEnumeration::PageEnumeration (
101 : : ::std::auto_ptr<Enumeration<SharedPageDescriptor> > pImpl)
102 : 5349 : : mpImpl(pImpl)
103 : : {
104 : 5349 : }
105 : : SAL_WNODEPRECATED_DECLARATIONS_POP
106 : :
107 : :
108 : :
109 : 0 : PageEnumeration::PageEnumeration (
110 : : PageEnumeration& rEnumeration,
111 : 0 : bool bCloneImpl)
112 : : {
113 : :
114 [ # # ]: 0 : if( bCloneImpl )
115 : : {
116 [ # # ][ # # ]: 0 : mpImpl = rEnumeration.mpImpl->Clone();
117 : : }
118 : : else
119 : : {
120 : 0 : mpImpl = rEnumeration.mpImpl;
121 : : }
122 : 0 : }
123 : :
124 : :
125 : :
126 : :
127 : 0 : PageEnumeration::PageEnumeration (const PageEnumeration& rEnumeration )
128 : 0 : : sd::slidesorter::model::Enumeration<sd::slidesorter::model::SharedPageDescriptor>()
129 : : {
130 [ # # ][ # # ]: 0 : mpImpl = rEnumeration.mpImpl->Clone();
131 : 0 : }
132 : :
133 : :
134 : :
135 : :
136 [ + - ]: 5349 : PageEnumeration::~PageEnumeration (void)
137 : : {
138 [ - + ]: 5349 : }
139 : :
140 : :
141 : :
142 : :
143 : 0 : PageEnumeration& PageEnumeration::operator= (
144 : : const PageEnumeration& rEnumeration)
145 : : {
146 : 0 : mpImpl = rEnumeration.mpImpl->Clone();
147 : 0 : return *this;
148 : : }
149 : :
150 : :
151 : :
152 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
153 : 0 : ::std::auto_ptr<Enumeration<SharedPageDescriptor> > PageEnumeration::Clone (void)
154 : : {
155 : : return ::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
156 [ # # ]: 0 : new PageEnumeration (*this, true));
157 : : }
158 : : SAL_WNODEPRECATED_DECLARATIONS_POP
159 : :
160 : :
161 : :
162 : 10125 : bool PageEnumeration::HasMoreElements (void) const
163 : : {
164 : 10125 : return mpImpl->HasMoreElements();
165 : : }
166 : :
167 : :
168 : :
169 : 5068 : SharedPageDescriptor PageEnumeration::GetNextElement (void)
170 : : {
171 : 5068 : return mpImpl->GetNextElement();
172 : : }
173 : :
174 : :
175 : :
176 : :
177 : 0 : void PageEnumeration::Rewind (void)
178 : : {
179 : 0 : return mpImpl->Rewind();
180 : : }
181 : :
182 : : } } } // end of namespace ::sd::slidesorter::model
183 : :
184 : :
185 : :
186 : :
187 : : namespace {
188 : :
189 : 5349 : PageEnumerationImpl::PageEnumerationImpl (
190 : : const SlideSorterModel& rModel,
191 : : const PageEnumeration::PagePredicate& rPredicate)
192 : : : mrModel(rModel),
193 : : maPredicate(rPredicate),
194 [ + - ]: 5349 : mnIndex(0)
195 : : {
196 [ + - ]: 5349 : Rewind();
197 : 5349 : }
198 : :
199 : :
200 : :
201 : :
202 : 0 : PageEnumerationImpl::PageEnumerationImpl (
203 : : const SlideSorterModel& rModel,
204 : : const PageEnumeration::PagePredicate& rPredicate,
205 : : int nIndex)
206 : : : mrModel(rModel),
207 : : maPredicate(rPredicate),
208 [ # # ]: 0 : mnIndex(nIndex)
209 : : {
210 : 0 : }
211 : :
212 : :
213 : :
214 : :
215 [ + - ]: 5349 : PageEnumerationImpl::~PageEnumerationImpl (void)
216 : : {
217 [ - + ]: 10698 : }
218 : :
219 : :
220 : :
221 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
222 : : ::std::auto_ptr<Enumeration<SharedPageDescriptor> >
223 : 0 : PageEnumerationImpl::Clone (void)
224 : : {
225 : : return ::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
226 [ # # ]: 0 : new PageEnumerationImpl(mrModel,maPredicate,mnIndex));
227 : : }
228 : : SAL_WNODEPRECATED_DECLARATIONS_POP
229 : :
230 : :
231 : :
232 : 10125 : bool PageEnumerationImpl::HasMoreElements (void) const
233 : : {
234 : 10125 : return (mnIndex < mrModel.GetPageCount());
235 : : }
236 : :
237 : :
238 : :
239 : :
240 : 5068 : SharedPageDescriptor PageEnumerationImpl::GetNextElement (void)
241 : : {
242 : 5068 : SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
243 : :
244 : : // Go to the following valid element.
245 : 5068 : mnIndex += 1;
246 [ + - ]: 5068 : AdvanceToNextValidElement();
247 : :
248 : 5068 : return pDescriptor;
249 : : }
250 : :
251 : :
252 : :
253 : :
254 : 5349 : void PageEnumerationImpl::Rewind (void)
255 : : {
256 : : // Go to first valid element.
257 : 5349 : mnIndex = 0;
258 : 5349 : AdvanceToNextValidElement();
259 : 5349 : }
260 : :
261 : :
262 : :
263 : :
264 : :
265 : 10417 : void PageEnumerationImpl::AdvanceToNextValidElement (void)
266 : : {
267 [ + + ]: 10417 : while (mnIndex < mrModel.GetPageCount())
268 : : {
269 [ + - ]: 5230 : SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
270 : :
271 : : // Test for the predicate being fullfilled.
272 [ + - ][ + - ]: 5230 : if (pDescriptor.get()!=NULL && maPredicate(pDescriptor))
[ + - ][ + - ]
273 : : {
274 : : // This predicate is valid.
275 : : break;
276 : : }
277 : : else
278 : : {
279 : : // Advance to next predicate.
280 [ - + ]: 5230 : mnIndex += 1;
281 : : }
282 [ + - ]: 5230 : }
283 : 10417 : }
284 : :
285 : : } // end of anonymous namespace
286 : :
287 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|