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) Lumiera.org
5  2011, 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 
48 #include "lib/error.hpp"
49 #include "lib/time/timevalue.hpp"
50 #include "lib/time/timequant.hpp"
51 #include "lib/time/timecode.hpp"
52 #include "lib/time/mutation.hpp"
53 #include "lib/util-quant.hpp"
54 
55 
56 namespace error = lumiera::error;
57 
58 namespace lib {
59 namespace time {
60 
61 
62  LUMIERA_ERROR_DEFINE (INVALID_MUTATION, "Changing a time value in this way was not designated");
63 
64 
65  Mutation::~Mutation() { } // emit VTable here....
66 
67 
68 
69 
70 
71  /* Warning: all the classes defined here must be of size below MUTATION_IMPL_SIZE */
72 
78  : public ClonableMutation
79  {
80  TimeValue newTime_;
81 
82  virtual void
83  change (Duration&) const
84  {
85  throw error::Logic ("mutating the start point of a pure Duration doesn't make sense"
86  , LUMIERA_ERROR_INVALID_MUTATION);
87  }
88 
89 
90  virtual void
91  change (TimeSpan& target) const
92  {
93  imposeChange (target, newTime_);
94  }
95 
96 
99  virtual void
100  change (QuTime& target) const
101  {
102  imposeChange (target, newTime_);
103  }
104 
105 
106  public:
107  explicit
109  : newTime_(t)
110  { }
111  };
112 
113 
119  : public ClonableMutation
120  {
121  Duration changedDuration_;
122 
123  virtual void
124  change (Duration& target) const
125  {
126  imposeChange (target, changedDuration_);
127  }
128 
129 
130  virtual void
131  change (TimeSpan& target) const
132  {
133  imposeChange (target.duration(), changedDuration_);
134  }
135 
136 
139  virtual void
140  change (QuTime&) const
141  {
142  throw error::Logic ("mutating the duration of a (quantised) time point doesn't make sense"
143  , LUMIERA_ERROR_INVALID_MUTATION);
144  }
145 
146 
147  public:
148  explicit
150  : changedDuration_(dur)
151  { }
152  };
153 
154 
160  : public ClonableMutation
161  {
162  Offset adjustment_;
163 
164  virtual void
165  change (Duration& target) const
166  {
167  imposeChange (target, adjustment_);
168  }
169 
170 
171  virtual void
172  change (TimeSpan& target) const
173  {
174  imposeChange (target, adjustment_);
175  }
176 
177 
180  virtual void
181  change (QuTime& target) const
182  {
183  imposeChange (target, adjustment_);
184  }
185 
186 
187  public:
188  explicit
190  : adjustment_(adj)
191  { }
192  };
193 
194 
202  : public SetNewStartTimeMutation
203  {
204  public:
205  explicit
206  MaterialiseIntoTarget (QuTime const& quant)
207  : SetNewStartTimeMutation (PQuant(quant)->materialise(quant))
208  { }
209  };
210 
211 
218  : public ImposeOffsetMutation
219  {
220 
221  static Offset
222  materialiseGridPoint (PQuant const& grid, int steps)
223  {
224  REQUIRE (grid);
225  return Offset(grid->timeOf(0), grid->timeOf(steps));
226  }
227 
228  public:
229  NudgeMutation (int relativeSteps, PQuant const& grid)
230  : ImposeOffsetMutation(materialiseGridPoint (grid,relativeSteps))
231  { }
232  };
233 
234 
247  : public ClonableMutation
248  {
249  int steps_;
250 
251  virtual void
252  change (Duration& target) const
253  {
254  imposeChange (target, steps_);
255  }
256 
257 
258  virtual void
259  change (TimeSpan& target) const
260  {
261  imposeChange (target, steps_);
262  }
263 
264 
266  virtual void
267  change (QuTime& target) const
268  {
269  imposeChange (target, steps_);
270  }
271 
272 
273  public:
274  explicit
275  NaturalNudgeMutation (int relativeSteps)
276  : steps_(relativeSteps)
277  { }
278  };
279 
280 
281 
282 
283 
284 
294  Mutation::changeTime (Time newStartTime)
295  {
296  return EncapsulatedMutation::build<SetNewStartTimeMutation> (newStartTime);
297  }
298 
299 
306  {
307  return EncapsulatedMutation::build<SetNewDuration> (changedDur);
308  }
309 
310 
317  {
318  return EncapsulatedMutation::build<ImposeOffsetMutation> (change);
319  }
320 
321 
328  Mutation::materialise (QuTime const& gridAlignedTime)
329  {
330  return EncapsulatedMutation::build<MaterialiseIntoTarget> (gridAlignedTime);
331  }
332 
333 
345  Mutation::nudge (int adjustment)
346  {
347  return EncapsulatedMutation::build<NaturalNudgeMutation> (adjustment);
348  }
349 
350 
371  Mutation::nudge (int adjustment, PQuant const& grid)
372  {
373  return EncapsulatedMutation::build<NudgeMutation> (adjustment, grid);
374  }
375 
376 
377 
378 
379 }} // lib::time
380 
Modifying time and timecode values.
static EncapsulatedMutation changeTime(Time)
Convenience factory to yield a simple Mutation changing the absolute start time.
Definition: mutation.cpp:294
concrete time value mutation: impose fixed new start time.
Definition: mutation.cpp:77
concrete time value mutation: make the grid aligned time value explicit, and impose the resulting val...
Definition: mutation.cpp:201
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:316
static TimeValue & imposeChange(TimeValue &, TimeValue const &)
Definition: mutation.hpp:147
virtual void change(QuTime &target) const
Definition: mutation.cpp:181
Implementation namespace for support and library code.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
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:328
Template to build polymorphic value objects.
virtual void change(QuTime &) const
Definition: mutation.cpp:140
virtual void change(QuTime &target) const
Definition: mutation.cpp:100
Utilities for quantisation (grid alignment) and comparisons.
concrete time value mutation: adjust the given time entity by an offset amount.
Definition: mutation.cpp:159
concrete time value mutation: set a new overall duration for an extended timespan.
Definition: mutation.cpp:118
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:267
Offset measures a distance in time.
Definition: timevalue.hpp:367
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:345
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
static EncapsulatedMutation changeDuration(Duration)
Convenience factory: simple Mutation to adjust the duration or length of a timespan.
Definition: mutation.cpp:305
concrete time value mutation: nudge based on a implicit grid, which is either a quantised target valu...
Definition: mutation.cpp:246
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:582
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:217
basic constant internal time value.
Definition: timevalue.hpp:142
grid aligned time specification, referring to a specific scale.
Definition: timequant.hpp:99
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:80