1 #include "timecounter.hpp"
5 timecounter::timecounter(const std::string
& spec
)
7 uint64_t base
= 1000000000;
12 throw std::runtime_error("Empty fps spec is not legal");
14 for(size_t i
= 0; i
< spec
.length(); i
++) {
15 if(readfpu
> 1844674407370955160ULL)
16 throw std::runtime_error("Overflow reading number");
18 if(spec
[i
] >= '0' && spec
[i
] <= '9')
19 readfpu
= 10 * readfpu
+ (spec
[i
] - '0');
20 else if(spec
[i
] == '.')
23 std::stringstream str
;
24 str
<< "Expected number or '.', got '" << spec
[i
] << "'";
25 throw std::runtime_error(str
.str());
28 if(spec
[i
] >= '0' && spec
[i
] <= '9') {
29 if(base
== 10000000000000000000ULL) {
30 std::stringstream str
;
31 str
<< "fps number has more than 10 decimal digits";
32 throw std::runtime_error(str
.str());
35 readfpu
= 10 * readfpu
+ (spec
[i
] - '0');
37 std::stringstream str
;
38 str
<< "Expected number, got '" << spec
[i
] << "'";
39 throw std::runtime_error(str
.str());
44 throw std::runtime_error("0 is not valid fps value");
46 step_w
= base
/ readfpu
;
47 step_n
= base
% readfpu
;
53 timecounter::timecounter(uint32_t spec
)
56 step_w
= 1000000000 / spec
;
57 step_n
= 1000000000 % spec
;
67 timecounter::timecounter(uint32_t n
, uint32_t d
)
69 step_w
= (1000000000ULL * d
) / n
;
70 step_n
= (1000000000ULL * d
) % n
;
76 timecounter::operator uint64_t()
81 timecounter
& timecounter::operator++()
85 while(current_n
>= step_d
) {
92 timecounter
timecounter::operator++(int)
94 timecounter scratch
= *this;