Lumiera  0.pre.03
»edit your freedom«
timequant.hpp
Go to the documentation of this file.
1 /*
2  TIMEQUANT.hpp - quantised (grid aligned) time values
3 
4  Copyright (C) Lumiera.org
5  2010, 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 
66 #ifndef LIB_TIME_TIMEQUANT_H
67 #define LIB_TIME_TIMEQUANT_H
68 
69 #include "lib/time/timevalue.hpp"
70 #include "lib/time/quantiser.hpp"
71 #include "lib/time/timecode.hpp"
72 #include "lib/symbol.hpp"
73 
74 //#include <boost/operators.hpp>
75 #include <string>
76 
77 
78 namespace lib {
79 namespace time {
80 
81  using lib::Symbol;
82 
83 
99  class QuTime
100  : public Time
101  {
102  PQuant quantiser_;
103 
104  public:
105  QuTime (TimeValue raw, Symbol gridID);
106  QuTime (TimeValue raw, PQuant quantisation_to_use);
107 
108  operator PQuant() const;
109 
110  template<class FMT>
111  bool supports() const;
112 
113  template<class FMT>
115  formatAs() const;
116 
117  template<class TC>
118  void
119  castInto (TC& timecode) const;
120 
123  void accept (Mutation const&);
124  };
125 
126 
127 
128  /* == implementation == */
129 
130  inline
131  QuTime::operator PQuant() const
132  {
133  ASSERT (quantiser_);
134  return quantiser_;
135  }
136 
137  template<class FMT>
138  inline bool
140  {
141  return quantiser_->supports<FMT>();
142  }
143 
144 
145  template<class FMT>
146  inline typename format::Traits<FMT>::TimeCode
148  {
149  using TC = typename format::Traits<FMT>::TimeCode;
150  return TC(*this);
151  }
152 
153 
163  template<class TC>
164  inline void
165  QuTime::castInto (TC& timecode) const
166  {
167  using Format = typename TC::Format;
168  REQUIRE (supports<Format>());
169 
170  Format::rebuild (timecode, *quantiser_, TimeValue(*this));
171  }
172 
173 
174 }} // lib::time
175 #endif
Interface: an opaque change imposed onto some time value.
Definition: mutation.hpp:100
void accept(Mutation const &)
receive change message, which might cause re-quantisation
Implementation namespace for support and library code.
QuTime(TimeValue raw, Symbol gridID)
build a quantised time value, referring the time grid by-name.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
format::Traits< FMT >::TimeCode formatAs() const
create new time code instance, then castInto
Definition: timequant.hpp:147
Token or Atom with distinct identity.
Definition: symbol.hpp:126
void castInto(TC &timecode) const
quantise into implicit grid, then rebuild the timecode
Definition: timequant.hpp:165
Timecode handling library This header defines the foundation interface TCode to represent a grid alig...
Marker types to indicate a literal string and a Symbol.
TimeValue(TimeValue const &origin, TimeValue const &target)
Definition: timevalue.hpp:170
Library functions to support the formation of grid-aligned time values.
bool supports() const
does our implicit time grid support building that timecode format?
Definition: timequant.hpp:139
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:142
grid aligned time specification, referring to a specific scale.
Definition: timequant.hpp:99