Lumiera  0.pre.03
»edit your freedom«
time-grid.cpp
Go to the documentation of this file.
1 /*
2  TimeGrid - reference scale for quantised time
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 
31 #include "steam/assetmanager.hpp"
32 #include "lib/time/quantiser.hpp"
33 #include "lib/time/timevalue.hpp"
34 #include "lib/format-string.hpp"
35 #include "common/advice.hpp"
36 #include "lib/util.hpp"
37 
38 #include <string>
39 
40 using util::_Fmt;
41 using util::isnil;
42 using std::string;
43 
44 
45 namespace steam {
46 namespace asset {
47 namespace meta {
48 
49  namespace error = lumiera::error;
50 
51 
52 
57  TimeGrid::TimeGrid (GridID const& nameID)
58  : Meta{nameID}
59  { }
60 
61 
62  using lib::time::Time;
64  using lib::time::TimeSpan;
65  using lib::time::Duration;
66  using lib::time::Offset;
67  using lib::time::FSecs;
68 
69  using lib::time::PQuant;
72  using std::dynamic_pointer_cast;
73 
74  namespace advice = lumiera::advice;
75 
76  namespace {
77 
85  inline PGrid
87  {
88  PGrid gridImplementation = AssetManager::instance().wrap (newGrid);
89  PQuant quantiser (dynamic_pointer_cast<const Quantiser>(gridImplementation));
90  Literal bindingID (cStr(newGrid.ident.name));
91 
92  advice::Provision<PGrid>(bindingID).setAdvice(gridImplementation);
93  advice::Provision<PQuant>(bindingID).setAdvice(quantiser);
94  return gridImplementation;
95  }
96 
97 
98  }
99 
111  : public TimeGrid
112  , public FixedFrameQuantiser
113  {
114 
115  public:
116  SimpleTimeGrid (Time start, Duration frameDuration, GridID const& name)
117  : TimeGrid (name)
118  , FixedFrameQuantiser(frameDuration,start)
119  { }
120 
121  SimpleTimeGrid (Time start, FrameRate frames_per_second, GridID const& name)
122  : TimeGrid (name)
123  , FixedFrameQuantiser(frames_per_second,start)
124  { }
125  };
126 
127 
128 
146  {
147  if (predecessor)
148  throw error::Invalid("compound and variable time grids are a planned feature"
149  , error::LUMIERA_ERROR_UNIMPLEMENTED);
150  ENSURE (fps, "infinite grid should have been detected by FrameRate ctor");
151 
152  if (isnil (id))
153  {
154  _Fmt gridIdFormat("grid(%f_%d)");
155  id = string(gridIdFormat % fps % _raw(origin));
156  }
157  GridID nameID (id);
158 
159  // build new Meta-Asset, registered with AssetManager, and publish into Advice-System
160  return publishWrapped (*new SimpleTimeGrid(origin, fps, nameID));
161  }
162 
163 
164  /* === TimeGrid shortcut builder functions === */
165 
166  PGrid
167  TimeGrid::build (FrameRate frames_per_second)
168  {
169  return build (Symbol::EMPTY,frames_per_second);
170  }
171 
172  PGrid
173  TimeGrid::build (Symbol gridID, FrameRate frames_per_second)
174  {
175  return build (gridID,frames_per_second, Time::ZERO);
176  }
177 
178 
179  PGrid
180  TimeGrid::build (Symbol gridID, FrameRate frames_per_second, Time origin)
181  {
182  string name(gridID);
183  Builder<TimeGrid> spec(name);
184  spec.fps = frames_per_second;
185  spec.origin = origin;
186 
187  return spec.commit();
188  }
189 
190 
191 }}} // namespace asset::meta
Interface: a grid and scale definition for time quantisation.
Definition: time-grid.hpp:86
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:164
Steam-Layer Interface: Asset Lookup and Organisation.
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
Definition: symbol.hpp:68
Facility to create grid-aligned time values.
Definition: quantiser.hpp:102
Framerate specified as frames per second.
Definition: timevalue.hpp:664
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
Front-end for printf-style string template interpolation.
key abstraction: metadata, parametrisation, customisation and similar organisational traits...
Definition: asset/meta.hpp:118
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:135
static PGrid build(FrameRate frames_per_second)
Definition: time-grid.cpp:167
const Ident ident
Asset identification tuple.
Definition: asset.hpp:208
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
TimeGrid(GridID const &)
Definition: time-grid.cpp:57
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
lib::P< TimeGrid > commit()
create a time grid based on settings within this builder
Definition: time-grid.cpp:145
Token or Atom with distinct identity.
Definition: symbol.hpp:126
Expecting Advice and giving Advice: a cross-cutting collaboration of loosely coupled participants...
Access point for the advising entity (server).
Definition: advice.hpp:244
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:229
Library functions to support the formation of grid-aligned time values.
Offset measures a distance in time.
Definition: timevalue.hpp:367
To establish a reference scale for quantised time values.
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
Building and configuring a meta asset.
Definition: asset/meta.hpp:109
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:80
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:582
a family of time value like entities and their relationships.
TimeGrid implementation: a trivial time grid, starting at a given point in time and using a constant ...
Definition: time-grid.cpp:110
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:44
basic constant internal time value.
Definition: timevalue.hpp:142
Naming and labelling scheme for structural assets.
Simple stand-alone Quantiser implementation based on a constant sized gird.
Definition: quantiser.hpp:144
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption