File: clocktypes

package info (click to toggle)
bobcat 6.11.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 21,370; fortran: 6,507; makefile: 2,787; sh: 724; perl: 401; ansic: 26
file content (63 lines) | stat: -rw-r--r-- 1,860 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef INCLUDED_BOBCAT_CLOCKTYPES_
#define INCLUDED_BOBCAT_CLOCKTYPES_

#include <chrono>

// assignning a later value to an earlier value is OK
// (minutes min = 1h -> min = 60
//
// nanoseconds      duration<int64_t, nano>         1ns
// microseconds     duration<int64_t, micro>        1us
// milliseconds     duration<int64_t, milli>        1ms
// seconds          duration<int64_t>               1s
// minutes          duration<int64_t, ratio<60>>    1min
// hours            duration<int64_t, ratio<3600>>  1h
//
//  members:    count()
//  static members: zero(), min(), max()
// 
// Duration types: =, -, +(=) -(=)

namespace FBB
{

using nanoseconds   = std::chrono::nanoseconds;
using microseconds  = std::chrono::microseconds;
using milliseconds  = std::chrono::milliseconds;
using seconds       = std::chrono::seconds;
using minutes       = std::chrono::minutes;
using hours         = std::chrono::hours;

template <typename Dest, typename Src>  // less precise to more precise
Dest toDuration(Src const &src);

template <typename Dest, typename Src>
auto toClock(Src const &src);

template <typename Dest, typename Src>
double toDouble(Src const &src);

struct ClockTypes
{
    using Duration = std::chrono::duration<int64_t, std::nano>;
    using Period = Duration::period;
    using DenType = decltype(Period::den);
    using NumType = decltype(Period::num);

    static Period period();                                 // .f
    static DenType den();                                   // .f
    static NumType num();                                   // .f
    static Duration zero();                                 // .f

    template <typename TimePoint>
    static Duration elapsed(TimePoint const &tp);

    template <typename TimePoint>
    static size_t count(TimePoint const &tp);
};

#include "clocktypes.f"

} // FBB        
#endif