Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
control-impl.hpp
Go to the documentation of this file.
1/*
2 CONTROL-IMPL.hpp - time::control implementation building blocks
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
44#ifndef LIB_TIME_CONTROL_IMPL_H
45#define LIB_TIME_CONTROL_IMPL_H
46
47#include "lib/error.hpp"
48#include "lib/time/mutation.hpp"
50
51#include <functional>
52#include <vector>
53
54
55namespace lib {
56namespace time {
57namespace mutation {
58
59 using std::function;
60
61
62
63
81 template<class TI>
82 class Mutator
83 : public Mutation
84 {
85 typedef function<TI(TI const&)> ValueSetter;
86 typedef function<TI(Offset const&)> Ofsetter;
87 typedef function<TI(int)> Nudger;
88
89 protected:
92 mutable Nudger nudge_;
93
94 void
96 {
97 if (!setVal_)
98 throw error::State("feeding time/value change "
99 "while not (yet) connected to any target to change"
100 ,error::LUMIERA_ERROR_UNCONNECTED);
101 }
102
103
104 template<class TAR>
105 void bind_to (TAR& target) const;
106
107 void unbind();
108
109 // using default construction and copy
110 };
111
112
113
125 template<class TI>
127 {
128 typedef function<void(TI const&)> ChangeSignal;
129 typedef std::vector<ChangeSignal> ListenerList;
130
132
133 public:
135 template<class SIG>
136 void
137 attach (SIG const& toNotify)
138 {
139 ChangeSignal newListener (std::ref(toNotify));
140 listeners_.push_back (newListener);
141 }
142
144 void
146 {
147 listeners_.clear();
148 }
149
151 TI
152 operator() (TI const& changedVal) const
153 {
154 using Iter = ListenerList::const_iterator;
155 Iter p = listeners_.begin();
156 Iter e = listeners_.end();
157
158 for ( ; p!=e; ++p )
159 (*p) (changedVal);
160 return changedVal;
161 }
162
163 // using default construction and copy
164 };
165}}} // lib::time::mutation
166
167
168/* ===== Definition of actual operations ===== */
170
171
172
173
174template<class TI>
175template<class TAR>
176void
185
186template<class TI>
187void
189{
190 setVal_ = ValueSetter();
191 offset_ = Ofsetter();
192 nudge_ = Nudger();
193}
194
195
196#endif
Interface: an opaque change imposed onto some time value.
Definition mutation.hpp:92
Offset measures a distance in time.
Implementation building block: impose changes to a Time element.
function< TI(Offset const &)> Ofsetter
function< TI(TI const &)> ValueSetter
void bind_to(TAR &target) const
Implementation building block: propagate changes to listeners.
std::vector< ChangeSignal > ListenerList
void attach(SIG const &toNotify)
install notification receiver
void disconnect()
disconnect any observers
function< void(TI const &)> ChangeSignal
TI operator()(TI const &changedVal) const
publish a change
Definition of special cases when imposing a change onto concrete time values.
Lumiera error handling (C++ interface).
Modifying time and timecode values.
Implementation namespace for support and library code.
LumieraError< LERR_(STATE)> State
Definition error.hpp:209
Policy how to impose changes onto a connected target time value entity This policy will be parametris...
a family of time value like entities and their relationships.