Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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"
42#include "lib/time/timecode.hpp"
43#include "lib/time/mutation.hpp"
44#include "lib/util-quant.hpp"
45
46
47namespace error = lumiera::error;
48
49namespace lib {
50namespace 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 {
72
73 virtual void
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
102 };
103
104
110 : public ClonableMutation
111 {
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 {
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
194 {
195 public:
196 explicit
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 {
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
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
Template to build polymorphic value objects.
A variation for limited copy support.
Duration is the internal Lumiera time metric.
concrete time value mutation: adjust the given time entity by an offset amount.
Definition mutation.cpp:152
virtual void change(Duration &target) const
Definition mutation.cpp:156
virtual void change(QuTime &target) const
Definition mutation.cpp:172
virtual void change(TimeSpan &target) const
Definition mutation.cpp:163
concrete time value mutation: make the grid aligned time value explicit, and impose the resulting val...
Definition mutation.cpp:194
MaterialiseIntoTarget(QuTime const &quant)
Definition mutation.cpp:197
virtual ~Mutation()
Definition mutation.cpp:56
static EncapsulatedMutation changeDuration(Duration)
Convenience factory: simple Mutation to adjust the duration or length of a timespan.
Definition mutation.cpp:296
virtual void change(Duration &) const =0
static EncapsulatedMutation materialise(QuTime const &)
Convenience factory: materialise the given quantised time into an explicit fixed internal time value,...
Definition mutation.cpp:319
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
static EncapsulatedMutation adjust(Offset)
Convenience factory: simple Mutation to adjust the duration or length of a timespan.
Definition mutation.cpp:307
static EncapsulatedMutation changeTime(Time)
Convenience factory to yield a simple Mutation changing the absolute start time.
Definition mutation.cpp:285
concrete time value mutation: nudge based on a implicit grid, which is either a quantised target valu...
Definition mutation.cpp:239
virtual void change(Duration &target) const
Definition mutation.cpp:243
virtual void change(QuTime &target) const
Definition mutation.cpp:258
NaturalNudgeMutation(int relativeSteps)
Definition mutation.cpp:266
virtual void change(TimeSpan &target) const
Definition mutation.cpp:250
concrete time value mutation: nudge target value by the given number of 'steps', relative to the give...
Definition mutation.cpp:210
NudgeMutation(int relativeSteps, PQuant const &grid)
Definition mutation.cpp:220
static Offset materialiseGridPoint(PQuant const &grid, int steps)
Definition mutation.cpp:213
Offset measures a distance in time.
grid aligned time specification, referring to a specific scale.
Definition timequant.hpp:91
concrete time value mutation: set a new overall duration for an extended timespan.
Definition mutation.cpp:111
virtual void change(Duration &target) const
Definition mutation.cpp:115
virtual void change(QuTime &) const
Definition mutation.cpp:131
virtual void change(TimeSpan &target) const
Definition mutation.cpp:122
SetNewDuration(Duration dur)
Definition mutation.cpp:140
concrete time value mutation: impose fixed new start time.
Definition mutation.cpp:70
virtual void change(QuTime &target) const
Definition mutation.cpp:91
virtual void change(Duration &) const
Definition mutation.cpp:74
virtual void change(TimeSpan &target) const
Definition mutation.cpp:82
A time interval anchored at a specific point in time.
Duration & duration()
basic constant internal time value.
Lumiera's internal time value datatype.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition error.h:71
Lumiera error handling (C++ interface).
Modifying time and timecode values.
lib::PolymorphicValue< Mutation, MUTATION_IMPL_SIZE, ClonableMutation > EncapsulatedMutation
Definition mutation.hpp:82
std::shared_ptr< const Quantiser > PQuant
Definition formats.hpp:58
Implementation namespace for support and library code.
LumieraError< LERR_(LOGIC)> Logic
Definition error.hpp:207
Timecode handling library This header defines the foundation interface TCode to represent a grid alig...
Support library to represent grid-aligned time specifications This is part of Lumiera's time and time...
a family of time value like entities and their relationships.
Utilities for quantisation (grid alignment) and comparisons.