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)
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 
22 #include "steam/assetmanager.hpp"
23 #include "lib/time/quantiser.hpp"
24 #include "lib/time/timevalue.hpp"
25 #include "lib/format-string.hpp"
26 #include "common/advice.hpp"
27 #include "lib/util.hpp"
28 
29 #include <string>
30 
31 using util::_Fmt;
32 using util::isnil;
33 using std::string;
34 
35 
36 namespace steam {
37 namespace asset {
38 namespace meta {
39 
40  namespace error = lumiera::error;
41 
42 
43 
48  TimeGrid::TimeGrid (GridID const& nameID)
49  : Meta{nameID}
50  { }
51 
52 
53  using lib::time::Time;
55  using lib::time::TimeSpan;
56  using lib::time::Duration;
57  using lib::time::Offset;
58  using lib::time::FSecs;
59 
60  using lib::time::PQuant;
63  using std::dynamic_pointer_cast;
64 
65  namespace advice = lumiera::advice;
66 
67  namespace {
68 
76  inline PGrid
78  {
79  PGrid gridImplementation = AssetManager::instance().wrap (newGrid);
80  PQuant quantiser (dynamic_pointer_cast<const Quantiser>(gridImplementation));
81  Literal bindingID (cStr(newGrid.ident.name));
82 
83  advice::Provision<PGrid>(bindingID).setAdvice(gridImplementation);
84  advice::Provision<PQuant>(bindingID).setAdvice(quantiser);
85  return gridImplementation;
86  }
87 
88 
89  }
90 
102  : public TimeGrid
103  , public FixedFrameQuantiser
104  {
105 
106  public:
107  SimpleTimeGrid (Time start, Duration frameDuration, GridID const& name)
108  : TimeGrid (name)
109  , FixedFrameQuantiser(frameDuration,start)
110  { }
111 
112  SimpleTimeGrid (Time start, FrameRate frames_per_second, GridID const& name)
113  : TimeGrid (name)
114  , FixedFrameQuantiser(frames_per_second,start)
115  { }
116  };
117 
118 
119 
137  {
138  if (predecessor)
139  throw error::Invalid("compound and variable time grids are a planned feature"
140  , error::LUMIERA_ERROR_UNIMPLEMENTED);
141  ENSURE (fps, "infinite grid should have been detected by FrameRate ctor");
142 
143  if (isnil (id))
144  {
145  _Fmt gridIdFormat("grid(%f_%d)");
146  id = string(gridIdFormat % fps % _raw(origin));
147  }
148  GridID nameID (id);
149 
150  // build new Meta-Asset, registered with AssetManager, and publish into Advice-System
151  return publishWrapped (*new SimpleTimeGrid(origin, fps, nameID));
152  }
153 
154 
155  /* === TimeGrid shortcut builder functions === */
156 
157  PGrid
158  TimeGrid::build (FrameRate frames_per_second)
159  {
160  return build (Symbol::EMPTY,frames_per_second);
161  }
162 
163  PGrid
164  TimeGrid::build (Symbol gridID, FrameRate frames_per_second)
165  {
166  return build (gridID,frames_per_second, Time::ZERO);
167  }
168 
169 
170  PGrid
171  TimeGrid::build (Symbol gridID, FrameRate frames_per_second, Time origin)
172  {
173  string name(gridID);
174  Builder<TimeGrid> spec(name);
175  spec.fps = frames_per_second;
176  spec.origin = origin;
177 
178  return spec.commit();
179  }
180 
181 
182 }}} // namespace asset::meta
Interface: a grid and scale definition for time quantisation.
Definition: time-grid.hpp:77
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:155
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:59
Facility to create grid-aligned time values.
Definition: quantiser.hpp:93
Framerate specified as frames per second.
Definition: timevalue.hpp:655
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:76
Front-end for printf-style string template interpolation.
key abstraction: metadata, parametrisation, customisation and similar organisational traits...
Definition: asset/meta.hpp:109
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:126
static PGrid build(FrameRate frames_per_second)
Definition: time-grid.cpp:158
const Ident ident
Asset identification tuple.
Definition: asset.hpp:199
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:299
TimeGrid(GridID const &)
Definition: time-grid.cpp:48
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
lib::P< TimeGrid > commit()
create a time grid based on settings within this builder
Definition: time-grid.cpp:136
Token or Atom with distinct identity.
Definition: symbol.hpp:117
Expecting Advice and giving Advice: a cross-cutting collaboration of loosely coupled participants...
Access point for the advising entity (server).
Definition: advice.hpp:235
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:220
Library functions to support the formation of grid-aligned time values.
Offset measures a distance in time.
Definition: timevalue.hpp:358
To establish a reference scale for quantised time values.
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:468
Building and configuring a meta asset.
Definition: asset/meta.hpp:100
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:71
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:573
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:101
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:35
basic constant internal time value.
Definition: timevalue.hpp:133
Naming and labelling scheme for structural assets.
Simple stand-alone Quantiser implementation based on a constant sized gird.
Definition: quantiser.hpp:135
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption