1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_SLIDESORTER_PAGE_ENUMERATION_HXX
25 #define SD_SLIDESORTER_PAGE_ENUMERATION_HXX
26 
27 #include "pres.hxx"
28 
29 
30 #include "model/SlsEnumeration.hxx"
31 #include "model/SlsSharedPageDescriptor.hxx"
32 
33 #include <boost/function.hpp>
34 #include <memory>
35 
36 namespace sd { namespace slidesorter { namespace model {
37 
38 class SlideSorterModel;
39 
40 
41 /** Public class of page enumerations that delegates its calls to an
42     implementation object that can filter pages by using a given predicate.
43 
44     @see PageEnumerationProvider
45         The PageEnumerationProvider has methods for creating different types
46         of page enumerations.
47 */
48 class PageEnumeration
49     : public Enumeration<SharedPageDescriptor>
50 {
51 public:
52     /** Create a new page enumeration that enumerates a subset of the pages
53         of the given model.
54         @param rModel
55             The new page enumeration enumerates the pages of this model.
56         @param rPredicate
57             This predicate determines which pages to include in the
58             enumeration.  Pages for which rPredicate returns <FALSE/> are
59             exclude.
60     */
61     typedef ::boost::function<bool(const SharedPageDescriptor&)> PagePredicate;
62     static PageEnumeration Create (
63         const SlideSorterModel& rModel,
64         const PagePredicate& rPredicate);
65 
66     /** This copy constructor creates a copy of the given enumeration.
67     */
68     PageEnumeration (const PageEnumeration& rEnumeration);
69 
70 	virtual ~PageEnumeration();
71 
72     /** Create a new enumeration object.  The ownership of the
73         implementation object goes to the new object.  Use this copy
74         constructor only when you know what you are doing.  When in doubt,
75         use the one argument version.
76         @param bCloneImpl
77             When <TRUE/> is given this constructor behaves exactly like its
78             one argument version.  When <FALSE/> is given then the
79             implementation object is not copied but moved from the given
80             enumeration to the newly created one.  The given enumeration
81             thus becomes empty.
82     */
83     PageEnumeration (PageEnumeration& rEnumeration, bool bCloneImpl);
84 
85     /** Create and return an exact copy of the called object.
86     */
87     virtual ::std::auto_ptr<Enumeration<SharedPageDescriptor> > Clone (void);
88 
89     PageEnumeration& operator= (const PageEnumeration& rEnumeration);
90 
91     /** Return <TRUE/> when the enumeration has more elements, i.e. it is
92         save to call GetNextElement() at least one more time.
93     */
94     virtual bool HasMoreElements (void) const;
95 
96     /** Return the next element of the enumeration.  Call the
97         HasMoreElements() before to make sure that there exists at least one
98         more element.  Calling this method with HasMoreElements() returning
99         <FALSE/> is an error.
100     */
101     virtual SharedPageDescriptor GetNextElement (void);
102 
103     /** Rewind the enumeration so that the next call to GetNextElement()
104         will return its first element.
105     */
106     virtual void Rewind (void);
107 
108 private:
109     /// Implementation object.
110     ::std::auto_ptr<Enumeration<SharedPageDescriptor> > mpImpl;
111 
112     /** This constructor expects an implementation object that holds
113         the predicate that filters the pages.
114     */
115     PageEnumeration (::std::auto_ptr<Enumeration<SharedPageDescriptor> > pImpl);
116 
117     // Default constructor not implemented.
118     PageEnumeration (void);
119 };
120 
121 } } } // end of namespace ::sd::slidesorter::model
122 
123 #endif
124