Lumiera  0.pre.03
»edit your freedom«
mutation.hpp
Go to the documentation of this file.
1 /*
2  MUTATION.hpp - changing and adjusting time values
3 
4  Copyright (C)
5  2011, 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 
52 #ifndef LIB_TIME_MUTATION_H
53 #define LIB_TIME_MUTATION_H
54 
55 #include "lib/error.hpp"
56 #include "lib/nocopy.hpp"
57 #include "lib/time/timevalue.hpp"
59 #include "lib/symbol.hpp"
60 
61 
62 
63 namespace lib {
64 namespace time {
65 
66  using lib::Symbol;
67 
68  LUMIERA_ERROR_DECLARE (INVALID_MUTATION);
69 
70  class QuTime;
71  class Mutation;
72 
73 
74  /* The following typedefs allow to hand out
75  * "unspecific" mutation value objects from
76  * factory functions, without disclosing any
77  * implementation details here in this header.
78  */
79  enum{ MUTATION_IMPL_SIZE = sizeof(TimeValue) };
80 
81  typedef lib::polyvalue::CloneValueSupport<Mutation> ClonableMutation;
83 
91  class Mutation
92  {
93  public:
94  virtual ~Mutation();
95 
96  virtual void change (Duration&) const =0;
97  virtual void change (TimeSpan&) const =0;
98  virtual void change (QuTime&) const =0;
99 
100  /* === convenience shortcuts for simple cases === */
101 
102  static EncapsulatedMutation changeTime (Time);
103  static EncapsulatedMutation changeDuration (Duration);
104  static EncapsulatedMutation adjust (Offset);
105  static EncapsulatedMutation materialise (QuTime const&);
106  static EncapsulatedMutation nudge (int adjustment);
107  static EncapsulatedMutation nudge (int adjustment, Symbol gridID);
108 #ifdef LIB_TIME_TIMEQUANT_H
109  static EncapsulatedMutation nudge (int adjustment, PQuant const& grid);
110 #endif
111 
112  protected:
113  static TimeValue& imposeChange (TimeValue&, TimeValue const&);
114  static TimeValue& imposeChange (TimeValue&, Offset const&);
115  static TimeValue& imposeChange (TimeValue&, int);
116  static TimeValue& imposeChange (QuTime&, int);
117  };
118 
119 
120  /* === defining the visitation responses === */
121 
122  inline void Duration::accept (Mutation const& muta) { muta.change (*this); }
123  inline void TimeSpan::accept (Mutation const& muta) { muta.change (*this); }
124 
125 #ifdef LIB_TIME_TIMEQUANT_H
126  inline void QuTime::accept (Mutation const& muta) { muta.change (*this); }
127 #endif
128 
129 
130 
131  /* === implementing the actual changes === */
132 
137  inline TimeValue&
138  Mutation::imposeChange (TimeValue& target, TimeValue const& valueToSet)
139  {
140  return target = valueToSet;
141  }
142 
144  inline TimeValue&
145  Mutation::imposeChange (TimeValue& target, Offset const& offset)
146  {
147  return imposeChange (target, TimeVar(target) += offset);
148  }
149 
153  inline TimeValue&
154  Mutation::imposeChange (TimeValue& target, int steps)
155  {
156  return imposeChange (target, TimeVar(target) += Time(FSecs(steps)));
157  }
158 
159 #ifdef LIB_TIME_TIMEQUANT_H
160 
167  inline TimeValue&
168  Mutation::imposeChange (QuTime& target, int steps)
169  {
170  PQuant const& grid (target);
171  FrameCnt originalGridPoint = grid->gridPoint(target);
172  FrameCnt adjustedGridPoint = originalGridPoint + steps;
173  return imposeChange (target, grid->timeOf (adjustedGridPoint));
174  }
175 #endif
176 
177 
178 
179 }} // lib::time
180 #endif
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:232
static EncapsulatedMutation changeTime(Time)
Convenience factory to yield a simple Mutation changing the absolute start time.
Definition: mutation.cpp:285
void accept(Mutation const &)
may change start / duration
Definition: mutation.hpp:123
A variation for limited copy support.
static EncapsulatedMutation adjust(Offset)
Convenience factory: simple Mutation to adjust the duration or length of a timespan.
Definition: mutation.cpp:307
Interface: an opaque change imposed onto some time value.
Definition: mutation.hpp:91
A mechanism to allow for opaque polymorphic value objects.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:62
static TimeValue & imposeChange(TimeValue &, TimeValue const &)
Definition: mutation.hpp:138
void accept(Mutation const &)
receive change message, which might cause re-quantisation
Implementation namespace for support and library code.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
Token or Atom with distinct identity.
Definition: symbol.hpp:117
Mix-Ins to allow or prohibit various degrees of copying and cloning.
static EncapsulatedMutation materialise(QuTime const &)
Convenience factory: materialise the given quantised time into an explicit fixed internal time value...
Definition: mutation.cpp:319
Marker types to indicate a literal string and a Symbol.
Template to build polymorphic value objects.
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:220
Lumiera error handling (C++ interface).
Offset measures a distance in time.
Definition: timevalue.hpp:358
static EncapsulatedMutation nudge(int adjustment)
build a time mutation to nudge the target time value by an offset, defined as number of steps on an i...
Definition: mutation.cpp:336
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:468
static EncapsulatedMutation changeDuration(Duration)
Convenience factory: simple Mutation to adjust the duration or length of a timespan.
Definition: mutation.cpp:296
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:573
int64_t FrameCnt
relative framecount or frame number.
Definition: digxel.hpp:312
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:133
grid aligned time specification, referring to a specific scale.
Definition: timequant.hpp:90