Lumiera  0.pre.03
»edit your freedom«
mutation.cpp
Go to the documentation of this file.
1 /*
2  Mutation - 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 
39 #include "lib/error.hpp"
40 #include "lib/time/timevalue.hpp"
41 #include "lib/time/timequant.hpp"
42 #include "lib/time/timecode.hpp"
43 #include "lib/time/mutation.hpp"
44 #include "lib/util-quant.hpp"
45 
46 
47 namespace error = lumiera::error;
48 
49 namespace lib {
50 namespace time {
51 
52 
53  LUMIERA_ERROR_DEFINE (INVALID_MUTATION, "Changing a time value in this way was not designated");
54 
55 
56  Mutation::~Mutation() { } // emit VTable here....
57 
58 
59 
60 
61 
62  /* Warning: all the classes defined here must be of size below MUTATION_IMPL_SIZE */
63 
69  : public ClonableMutation
70  {
71  TimeValue newTime_;
72 
73  virtual void
74  change (Duration&) const
75  {
76  throw error::Logic ("mutating the start point of a pure Duration doesn't make sense"
77  , LUMIERA_ERROR_INVALID_MUTATION);
78  }
79 
80 
81  virtual void
82  change (TimeSpan& target) const
83  {
84  imposeChange (target, newTime_);
85  }
86 
87 
90  virtual void
91  change (QuTime& target) const
92  {
93  imposeChange (target, newTime_);
94  }
95 
96 
97  public:
98  explicit
100  : newTime_(t)
101  { }
102  };
103 
104 
110  : public ClonableMutation
111  {
112  Duration changedDuration_;
113 
114  virtual void
115  change (Duration& target) const
116  {
117  imposeChange (target, changedDuration_);
118  }
119 
120 
121  virtual void
122  change (TimeSpan& target) const
123  {
124  imposeChange (target.duration(), changedDuration_);
125  }
126 
127 
130  virtual void
131  change (QuTime&) const
132  {
133  throw error::Logic ("mutating the duration of a (quantised) time point doesn't make sense"
134  , LUMIERA_ERROR_INVALID_MUTATION);
135  }
136 
137 
138  public:
139  explicit
141  : changedDuration_(dur)
142  { }
143  };
144 
145 
151  : public ClonableMutation
152  {
153  Offset adjustment_;
154 
155  virtual void
156  change (Duration& target) const
157  {
158  imposeChange (target, adjustment_);
159  }
160 
161 
162  virtual void
163  change (TimeSpan& target) const
164  {
165  imposeChange (target, adjustment_);
166  }
167 
168 
171  virtual void
172  change (QuTime& target) const
173  {
174  imposeChange (target, adjustment_);
175  }
176 
177 
178  public:
179  explicit
181  : adjustment_(adj)
182  { }
183  };
184 
185 
193  : public SetNewStartTimeMutation
194  {
195  public:
196  explicit
197  MaterialiseIntoTarget (QuTime const& quant)
198  : SetNewStartTimeMutation (PQuant(quant)->materialise(quant))
199  { }
200  };
201 
202 
209  : public ImposeOffsetMutation
210  {
211 
212  static Offset
213  materialiseGridPoint (PQuant const& grid, int steps)
214  {
215  REQUIRE (grid);
216  return Offset(grid->timeOf(0), grid->timeOf(steps));
217  }
218 
219  public:
220  NudgeMutation (int relativeSteps, PQuant const& grid)
221  : ImposeOffsetMutation(materialiseGridPoint (grid,relativeSteps))
222  { }
223  };
224 
225 
238  : public ClonableMutation
239  {
240  int steps_;
241 
242  virtual void
243  change (Duration& target) const
244  {
245  imposeChange (target, steps_);
246  }
247 
248 
249  virtual void
250  change (TimeSpan& target) const
251  {
252  imposeChange (target, steps_);
253  }
254 
255 
257  virtual void
258  change (QuTime& target) const
259  {
260  imposeChange (target, steps_);
261  }
262 
263 
264  public:
265  explicit
266  NaturalNudgeMutation (int relativeSteps)
267  : steps_(relativeSteps)
268  { }
269  };
270 
271 
272 
273 
274 
275 
285  Mutation::changeTime (Time newStartTime)
286  {
287  return EncapsulatedMutation::build<SetNewStartTimeMutation> (newStartTime);
288  }
289 
290 
297  {
298  return EncapsulatedMutation::build<SetNewDuration> (changedDur);
299  }
300 
301 
308  {
309  return EncapsulatedMutation::build<ImposeOffsetMutation> (change);
310  }
311 
312 
319  Mutation::materialise (QuTime const& gridAlignedTime)
320  {
321  return EncapsulatedMutation::build<MaterialiseIntoTarget> (gridAlignedTime);
322  }
323 
324 
336  Mutation::nudge (int adjustment)
337  {
338  return EncapsulatedMutation::build<NaturalNudgeMutation> (adjustment);
339  }
340 
341 
362  Mutation::nudge (int adjustment, PQuant const& grid)
363  {
364  return EncapsulatedMutation::build<NudgeMutation> (adjustment, grid);
365  }
366 
367 
368 
369 
370 }} // lib::time
371 
Modifying time and timecode values.
static EncapsulatedMutation changeTime(Time)
Convenience factory to yield a simple Mutation changing the absolute start time.
Definition: mutation.cpp:285
concrete time value mutation: impose fixed new start time.
Definition: mutation.cpp:68
concrete time value mutation: make the grid aligned time value explicit, and impose the resulting val...
Definition: mutation.cpp:192
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
static TimeValue & imposeChange(TimeValue &, TimeValue const &)
Definition: mutation.hpp:138
virtual void change(QuTime &target) const
Definition: mutation.cpp:172
Implementation namespace for support and library code.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
Timecode handling library This header defines the foundation interface TCode to represent a grid alig...
static EncapsulatedMutation materialise(QuTime const &)
Convenience factory: materialise the given quantised time into an explicit fixed internal time value...
Definition: mutation.cpp:319
Template to build polymorphic value objects.
virtual void change(QuTime &) const
Definition: mutation.cpp:131
virtual void change(QuTime &target) const
Definition: mutation.cpp:91
Utilities for quantisation (grid alignment) and comparisons.
concrete time value mutation: adjust the given time entity by an offset amount.
Definition: mutation.cpp:150
concrete time value mutation: set a new overall duration for an extended timespan.
Definition: mutation.cpp:109
Lumiera error handling (C++ interface).
Support library to represent grid-aligned time specifications This is part of Lumiera&#39;s time and time...
virtual void change(QuTime &target) const
Definition: mutation.cpp:258
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
concrete time value mutation: nudge based on a implicit grid, which is either a quantised target valu...
Definition: mutation.cpp:237
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:573
a family of time value like entities and their relationships.
concrete time value mutation: nudge target value by the given number of &#39;steps&#39;, relative to the give...
Definition: mutation.cpp:208
basic constant internal time value.
Definition: timevalue.hpp:133
grid aligned time specification, referring to a specific scale.
Definition: timequant.hpp:90
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:71