Lumiera  0.pre.03
»edit your freedom«
scope-query.hpp
Go to the documentation of this file.
1 /*
2  SCOPE-QUERY.hpp - query to discover the contents of a container-like part of the model
3 
4  Copyright (C) Lumiera.org
5  2009, 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 
41 #ifndef STEAM_MOBJECT_SESSION_SCOPE_QUERY_H
42 #define STEAM_MOBJECT_SESSION_SCOPE_QUERY_H
43 
44 
47 #include "lib/format-string.hpp"
48 
49 #include <functional>
50 
51 
52 namespace steam {
53 namespace mobject {
54 namespace session {
55 
56  using std::bind;
57  using std::function;
58  using std::placeholders::_1;
59 
60  using lumiera::Goal;
61  using lumiera::Query;
62 
63 
64 
73  template<class MO>
75  : public Query<Placement<MO>>
76  {
77  typedef Query<Placement<MO>> _Query;
78 
79 
80  public:
81  typedef typename _Query::iterator iterator;
82 
83  typedef function<bool(PlacementMO const&)> ContentFilter;
84 
85 
86  ContentFilter
87  contentFilter () const
88  {
89  return buildContentFilter();
90  }
91 
92  protected:
94  virtual ContentFilter buildContentFilter() const =0;
95 
96 
97 
98 
100  : _Query (_Query::defineQueryTypeID (Goal::DISCOVERY)
101  , lib::QueryText("")) // syntactic representation supplied on demand
102  { }
103 
104  private:
106  DiscoveryQuery const& operator=(DiscoveryQuery const&);
107  };
108 
109 
111  { CONTENTS = 0
114  , PATH
115  };
116 
117 
143  template<class MO>
145  : public DiscoveryQuery<MO>
146  {
147  typedef DiscoveryQuery<MO> _Parent;
148  typedef Query<Placement<MO>> _Query;
149 
150 
151  PlacementMO::ID startPoint_;
152  ScopeQueryKind to_discover_;
153 
154  public:
155  typedef typename _Parent::iterator iterator;
156  typedef typename _Parent::ContentFilter ContentFilter;
157 
158 
159  ScopeQuery (PlacementMO const& scope,
160  ScopeQueryKind direction)
161  : startPoint_(scope)
162  , to_discover_(direction)
163  { }
164 
165 
166 
167  PlacementMO::ID const&
168  searchScope () const
169  {
170  return startPoint_;
171  }
172 
174  searchDirection () const
175  {
176  return to_discover_;
177  }
178 
179 
180 
181  private:
188  ContentFilter
190  {
191  return bind (&PlacementMO::isCompatible<MO>, _1 );
192  }
193 
202  {
203  using util::_Fmt;
204  TODO ("valid syntactic representation of scope queries");
205  return lib::QueryText (_Fmt ("scope(X, %08X), scopeRelation(X, %d)")
206  % hash_value(searchScope())
207  % uint(searchDirection()));
208  }
209  };
210 
211 
212  template<class MO>
214  : ScopeQuery<MO>
215  {
216  ContentsQuery (PlacementMO const& scope)
217  : ScopeQuery<MO> (scope, CONTENTS)
218  { }
219 
220  };
221 
222 
223  template<class MO>
224  struct PathQuery
225  : ScopeQuery<MO>
226  {
227  PathQuery (PlacementMO const& scope)
228  : ScopeQuery<MO> (scope, PARENTS)
229  { }
230 
231  };
232 
233 
234 
235 
236 }}} // namespace steam::mobject::session
237 #endif
Query ABC: unspecific goal for resolution or retrieval.
Definition: query.hpp:125
Query a scope to discover it&#39;s contents or location.
framework and to resolve logical queries.
Core abstraction: placement of a media object into session context.
Front-end for printf-style string template interpolation.
ContentFilter buildContentFilter() const
the default implementation of the content filtering builds on the downcast-function available on each...
discover any contained objects depth-first
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:74
discover the path to root
discover the enclosing scopes
virtual ContentFilter buildContentFilter() const =0
yield additional filter to be applied to the result set.
lib::QueryText buildSyntacticRepresentation() const
supplement a syntactic representation (as generic query in predicate form).
discover the immediate children
DiscoveryQuery const & operator=(DiscoveryQuery const &)
Assignment explicitly disallowed (but copy ctor is ok)
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
ABC to build Queries for placement-attached objects.
Definition: scope-query.hpp:74
Syntactical query representation.
Definition: query-text.hpp:70