Lumiera  0.pre.03
»edit your freedom«
specific-contents-query.hpp
Go to the documentation of this file.
1 /*
2  SPECIFIC-CONTENTS-QUERY.hpp - pick specific contents from the model, using a filter
3 
4  Copyright (C) Lumiera.org
5  2010, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
34 #ifndef MOBJECT_SESSION_SPECIFIC_CONTENTS_QUERY_H
35 #define MOBJECT_SESSION_SPECIFIC_CONTENTS_QUERY_H
36 
37 
41 
42 #include <functional>
43 
44 
45 namespace steam {
46 namespace mobject {
47 namespace session {
48 
49  using std::function;
50 
52 
53 
62  template<class MO>
64  : public ContentsQuery<MO>
65  {
66  typedef typename ContentsQuery<MO>::ContentFilter ContentFilter;
67 
68  typedef Placement<MO> const& TypedPlacement;
69 
70  typedef function<bool(TypedPlacement)> SpecialPredicate;
71 
79  class Filter
80  {
81  SpecialPredicate predicate_;
82 
83  public:
84  Filter (SpecialPredicate const& pred)
85  : predicate_(pred)
86  { }
87 
88  bool
89  operator() (PlacementMO const& anyMO)
90  {
91  if (!anyMO.isCompatible<MO>())
92  return false;
93 
94  TypedPlacement interestingObject = static_cast<TypedPlacement> (anyMO);
95  return predicate_(interestingObject);
96  }
97  };
98 
99  Filter specialTest_;
100 
106  ContentFilter
108  {
109  return specialTest_;
110  }
111 
112 
113 
114  public:
115  SpecificContentsQuery (PlacementMO const& scope
116  ,SpecialPredicate const& specialPred)
117  : ContentsQuery<MO> (scope)
118  , specialTest_(specialPred)
119  { }
120  };
121 
122 
123 
124  namespace { // type matching helper
126  template<class PRED>
127  struct _PickResult;
128 
129  template<class MO>
130  struct _PickResult<function<bool(Placement<MO> const&)> >
131  {
132  typedef MO Type;
134  typedef typename ScopeQuery<MO>::iterator Iterator;
135  };
136 
137  template<class MO>
138  struct _PickResult<bool(&)(Placement<MO> const&)>
139  {
140  typedef MO Type;
142  typedef typename ScopeQuery<MO>::iterator Iterator;
143  };
144 
145  template<class MO>
146  struct _PickResult<bool(*)(Placement<MO> const&)>
147  {
148  typedef MO Type;
150  typedef typename ScopeQuery<MO>::iterator Iterator;
151  };
152  }
153 
154 
155 
156 
161  template<typename FUNC>
162  inline typename _PickResult<FUNC>::FilterQuery
163  pickAllSuitable(PlacementMO const& scope, FUNC predicate)
164  {
165  typedef typename _PickResult<FUNC>::FilterQuery Query;
166 
167  return Query(scope, predicate);
168  }
169 
175  template<typename FUNC>
176  inline typename _PickResult<FUNC>::Iterator
177  pickAllSuitable(PlacementMO const& scope, FUNC predicate, QueryResolver const& resolver)
178  {
179  typedef typename _PickResult<FUNC>::FilterQuery Query;
180 
181  return Query(scope, predicate ).resolveBy(resolver);
182  }
183 
184 
185 
186 }}} // namespace steam::mobject::session
187 #endif
Filter functor, built on top of a predicate, which is provided by the client on creation of this Spec...
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Definition: trait.hpp:91
Interface: a facility for resolving (some kind of) queries A concrete subclass has the ability to cre...
framework and to resolve logical queries.
Core abstraction: placement of a media object into session context.
_PickResult< FUNC >::FilterQuery pickAllSuitable(PlacementMO const &scope, FUNC predicate)
convenience shortcut to issue a SpecificContentsQuery, figuring out the actual return/filter type aut...
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:74
ContentFilter buildContentFilter() const
using a specialised version of the filtering, which doesn&#39;t only check the concrete type...
from the session, based on a filter predicate.
Specific queries to explore contents of a scope within the high-level model.
Adapter for building an implementation of the »Lumiera Forward Iterator« concept. ...
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:279