Lumiera  0.pre.03
»edit your freedom«
formats.hpp
Go to the documentation of this file.
1 /*
2  FORMATS.hpp - formats for displaying and specifying time
3 
4  Copyright (C)
5  2010, 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 
25 #ifndef LIB_TIME_FORMATS_H
26 #define LIB_TIME_FORMATS_H
27 
28 #include "lib/time/timevalue.hpp"
29 #include "lib/meta/no-instance.hpp"
30 #include "lib/meta/typelist.hpp"
31 #include "lib/meta/generator.hpp"
32 #include "lib/typed-counter.hpp"
33 
34 #include <memory>
35 #include <string>
36 #include <bitset>
37 
38 namespace lumiera {
39 namespace error {
40  LUMIERA_ERROR_DECLARE (INVALID_TIMECODE);
41 }}
42 
43 
44 namespace lib {
45 namespace time {
46 
47 
48  // ====== forward declarations of concrete Timecode types
49 
50  class FrameNr;
51  class SmpteTC;
52  class HmsTC;
53  class Secs;
54 
55 
56  class Quantiser; // API for grid aligning
57  using QuantR = Quantiser const&;
58  using PQuant = std::shared_ptr<const Quantiser>;
59 
60 
61  namespace format {
62 
63  using std::string;
64  using lib::meta::NoInstance; // the following types are for metaprogramming only...
65 
66 
75  struct Frames
76  : NoInstance<Frames>
77  {
78  static TimeValue parse (string const&, QuantR);
79  static void rebuild (FrameNr&, QuantR, TimeValue const&);
80  static TimeValue evaluate (FrameNr const&, QuantR);
81  };
82 
83 
90  struct Smpte
91  : NoInstance<Smpte>
92  {
93  static TimeValue parse (string const&, QuantR);
94  static void rebuild (SmpteTC&, QuantR, TimeValue const&);
95  static TimeValue evaluate (SmpteTC const&, QuantR);
96  static uint getFramerate (QuantR, TimeValue const&);
97  static void applyRangeLimitStrategy (SmpteTC&);
98  };
99 
100 
108  struct Hms
109  : NoInstance<Hms>
110  {
111  static TimeValue parse (string const&, QuantR);
112  static void rebuild (HmsTC&, QuantR, TimeValue const&);
113  static TimeValue evaluate (HmsTC const&, QuantR);
114  };
115 
116 
126  struct Seconds
127  : NoInstance<Seconds>
128  {
129  static TimeValue parse (string const&, QuantR);
130  static void rebuild (Secs&, QuantR, TimeValue const&);
131  static TimeValue evaluate (Secs const&, QuantR);
132  };
133 
134 
135 
136 
137 
138  template<class FMT>
139  struct Traits;
140 
141  template<>
142  struct Traits<Frames>
143  {
144  using TimeCode = FrameNr;
145  };
146 
147  template<>
148  struct Traits<Smpte>
149  {
150  using TimeCode = SmpteTC;
151  };
152 
153  template<>
154  struct Traits<Hms>
155  {
156  using TimeCode = HmsTC;
157  };
158 
159  template<>
160  struct Traits<Seconds>
161  {
162  using TimeCode = Secs;
163  };
164 
165 
166 
167  /* == Descriptor to define Support for specific formats == */
168 
169  using lib::meta::Types;
170  using lib::meta::Node;
171  using lib::meta::NullType;
172 
187  class Supported
188  {
189  enum { MAXID = 8 };
190 
191  std::bitset<MAXID> flags_;
192 
193  template<class F>
194  IxID
195  typeID() const
196  {
198  }
199 
200  template<class F, class FS>
201  Supported
202  define(Node<F,FS>)
203  {
204  flags_.set (typeID<F>());
205  return define(FS());
206  }
207  Supported define(NullType) { return *this;}
208 
209  Supported() { }
210 
211 
212  public:
216  template<typename TY>
217  static Supported
219  {
220  typedef typename TY::List SupportedFormats;
221  return Supported().define(SupportedFormats());
222  }
223 
225  template<class F>
226  bool
227  check() const
228  {
229  return flags_[typeID<F>()];
230  }
231  };
232 
238  : Supported
239  {
242  { }
243  };
244 
245 
246 }}} // lib::time::format
247 #endif
Frame count as timecode format.
Definition: formats.hpp:75
Creating series of type-based contexts.
Classical Timecode value reminiscent to SMPTE format.
Definition: timecode.hpp:141
A template metaprogramming technique for manipulating collections of types.
The informal hours-minutes-seconds-millisecond timecode.
Definition: formats.hpp:108
bool check() const
check if a specific Format is supported
Definition: formats.hpp:227
Widely used standard media timecode format.
Definition: formats.hpp:90
Helpers for working with lib::meta::Types (i.e.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:62
Implementation namespace for support and library code.
Metaprogramming helper to prevent an entity to be ever instantiated at runtime.
Descriptor to denote support for a specific (timecode) format.
Definition: formats.hpp:187
predefined standard configuration: Descriptor for supporting all the classical timecode formats ...
Definition: formats.hpp:237
Simple timecode specification as fractional seconds.
Definition: formats.hpp:126
Supported define(NullType)
Definition: formats.hpp:207
An Entity never to be instantiated.
Definition: no-instance.hpp:47
Lumiera public interface.
Definition: advice.cpp:104
A frame counting timecode value.
Definition: timecode.hpp:96
Provide type-IDs for a specific context.
a family of time value like entities and their relationships.
static Supported formats()
build a new Descriptor to denote support for all the Formats,
Definition: formats.hpp:218
basic constant internal time value.
Definition: timevalue.hpp:133