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)
5  2010, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
25 #ifndef MOBJECT_SESSION_SPECIFIC_CONTENTS_QUERY_H
26 #define MOBJECT_SESSION_SPECIFIC_CONTENTS_QUERY_H
27 
28 
32 
33 #include <functional>
34 
35 
36 namespace steam {
37 namespace mobject {
38 namespace session {
39 
40  using std::function;
41 
43 
44 
53  template<class MO>
55  : public ContentsQuery<MO>
56  {
57  typedef typename ContentsQuery<MO>::ContentFilter ContentFilter;
58 
59  typedef Placement<MO> const& TypedPlacement;
60 
61  typedef function<bool(TypedPlacement)> SpecialPredicate;
62 
70  class Filter
71  {
72  SpecialPredicate predicate_;
73 
74  public:
75  Filter (SpecialPredicate const& pred)
76  : predicate_(pred)
77  { }
78 
79  bool
80  operator() (PlacementMO const& anyMO)
81  {
82  if (!anyMO.isCompatible<MO>())
83  return false;
84 
85  TypedPlacement interestingObject = static_cast<TypedPlacement> (anyMO);
86  return predicate_(interestingObject);
87  }
88  };
89 
90  Filter specialTest_;
91 
97  ContentFilter
99  {
100  return specialTest_;
101  }
102 
103 
104 
105  public:
106  SpecificContentsQuery (PlacementMO const& scope
107  ,SpecialPredicate const& specialPred)
108  : ContentsQuery<MO> (scope)
109  , specialTest_(specialPred)
110  { }
111  };
112 
113 
114 
115  namespace { // type matching helper
117  template<class PRED>
118  struct _PickResult;
119 
120  template<class MO>
121  struct _PickResult<function<bool(Placement<MO> const&)> >
122  {
123  typedef MO Type;
125  typedef typename ScopeQuery<MO>::iterator Iterator;
126  };
127 
128  template<class MO>
129  struct _PickResult<bool(&)(Placement<MO> const&)>
130  {
131  typedef MO Type;
133  typedef typename ScopeQuery<MO>::iterator Iterator;
134  };
135 
136  template<class MO>
137  struct _PickResult<bool(*)(Placement<MO> const&)>
138  {
139  typedef MO Type;
141  typedef typename ScopeQuery<MO>::iterator Iterator;
142  };
143  }
144 
145 
146 
147 
152  template<typename FUNC>
153  inline typename _PickResult<FUNC>::FilterQuery
154  pickAllSuitable(PlacementMO const& scope, FUNC predicate)
155  {
156  typedef typename _PickResult<FUNC>::FilterQuery Query;
157 
158  return Query(scope, predicate);
159  }
160 
166  template<typename FUNC>
167  inline typename _PickResult<FUNC>::Iterator
168  pickAllSuitable(PlacementMO const& scope, FUNC predicate, QueryResolver const& resolver)
169  {
170  typedef typename _PickResult<FUNC>::FilterQuery Query;
171 
172  return Query(scope, predicate ).resolveBy(resolver);
173  }
174 
175 
176 
177 }}} // namespace steam::mobject::session
178 #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:82
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:65
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:270