99constexpr int32_t HOUR_MAX = 10 ;
1010
1111class Hour {
12- public:
13- explicit Hour (const int32_t hour) : hour_{hour} {}
14- static std::optional<Hour> create_hour (const int32_t hour) {
15- if (hour < 0 || hour >= HOUR_MAX) {
16- std::cerr << " [Error] Hour should be 0 < x < 10, but got " << std::to_string (hour) << std::endl;
17- return std::nullopt ;
18- }
19- return Hour (hour);
12+ public:
13+ explicit Hour (const int32_t hour) : hour{hour} {}
14+ static std::optional<Hour> create_hour (const int32_t hour) {
15+ if (hour < 0 || hour >= HOUR_MAX) {
16+ std::cerr << " [Error] Hour should be 0 < x < 10, but got " << hour << std::endl;
17+ return std::nullopt ;
2018 }
21- const int32_t get_hour () const { return hour_; }
22-
23- private:
24- const int32_t hour_;
19+ return Hour (hour);
20+ }
21+ int32_t get_hour () const { return hour; }
22+ private:
23+ int32_t hour;
2524};
2625
2726class Minute {
28- public:
29- explicit Minute (const int32_t minute) : minute_{minute} {}
30- static std::optional<Minute> create_minute (const int32_t minute) {
31- if (minute < 0 || minute >= 60 ) {
32- std::cerr << " [Error] Minute should be 0 < x < 60, but got " << std::to_string (minute) << std::endl;
33- return std::nullopt ;
34- }
35- return Minute (minute);
27+ public:
28+ explicit Minute (const int32_t minute) : minute{minute} {}
29+ static std::optional<Minute> create_minute (const int32_t minute) {
30+ if (minute < 0 || minute >= 60 ) {
31+ std::cerr << " [Error] Minute should be 0 < x < 60, but got " << minute << std::endl;
32+ return std::nullopt ;
3633 }
37- const int32_t get_minute () const { return minute_; }
38-
39- private:
40- const int32_t minute_;
34+ return Minute (minute);
35+ }
36+ int32_t get_minute () const { return minute; }
37+ private:
38+ int32_t minute;
4139};
4240
4341class Second {
44- public:
45- explicit Second (const float second) : second_{second} {}
46- static std::optional<Second> create_second (const float second) {
47- if (second < 0 || second >= 60 ) {
48- std::cerr << " [Error] Second should be 0 < x < 60, but got " << std::to_string (second) << std::endl;
49- return std::nullopt ;
50- }
51- return Second (second);
42+ public:
43+ explicit Second (const float second) : second{second} {}
44+ static std::optional<Second> create_second (const float second) {
45+ if (second < 0 || second >= 60 ) {
46+ std::cerr << " [Error] Second should be 0 < x < 60, but got " << second << std::endl;
47+ return std::nullopt ;
5248 }
53- const float get_second () const { return second_; }
54-
55- private:
56- const float second_;
49+ return Second (second);
50+ }
51+ float get_second () const { return second; }
52+ private:
53+ float second;
5754};
5855
5956struct TimeStamp {
@@ -63,47 +60,39 @@ struct TimeStamp {
6360};
6461
6562class FrameTimeCode {
66- public:
67- explicit FrameTimeCode (const int32_t frame_num, const float fps);
68- FrameTimeCode (const FrameTimeCode& timecode);
69-
70- float get_framerate () const { return framerate_; }
71- int32_t get_frame_num () const { return frame_num_; }
72-
73- std::optional<int32_t > parse_timecode_string (const std::string& timecode_str) const ;
74- int32_t parse_timecode_number (const int32_t seconds) const ;
75- int32_t parse_timecode_number (const float seconds) const ;
76- std::string to_string () const ;
77- std::string to_string_second () const ;
78-
79- bool operator ==(const FrameTimeCode& other) const ;
80- bool operator !=(const FrameTimeCode& other) const ;
81- bool operator <(const FrameTimeCode& other) const ;
82- bool operator >(const FrameTimeCode& other) const ;
83- bool operator <=(const FrameTimeCode& other) const ;
84- bool operator >=(const FrameTimeCode& other) const ;
85-
86- FrameTimeCode operator +(const FrameTimeCode& other) const ;
87- FrameTimeCode operator -(const FrameTimeCode& other) const ;
88-
89- static std::optional<FrameTimeCode> from_timecode_string (const std::string& timecode_str, const float fps);
90- static std::optional<FrameTimeCode> from_frame_nums (const int32_t frame_num, const float fps);
91- static std::optional<FrameTimeCode> from_seconds (const int32_t seconds, const float fps);
92- static std::optional<FrameTimeCode> from_seconds (const float seconds, const float fps);
93-
94- private:
95- std::optional<TimeStamp> _parse_hrs_mins_secs_to_second (const std::string& timecode_str) const ;
96- float framerate_;
97- int32_t frame_num_;
63+ public:
64+ explicit FrameTimeCode (const int32_t frame_num, const float fps);
65+ FrameTimeCode (const FrameTimeCode& timecode);
66+ float get_framerate () const { return framerate; }
67+ int32_t get_frame_num () const { return frame_num; }
68+ std::optional<int32_t > parse_timecode_string (const std::string& timecode_str) const ;
69+ int32_t parse_timecode_number (const int32_t seconds) const ;
70+ int32_t parse_timecode_number (const float seconds) const ;
71+ std::string to_string () const ;
72+ std::string to_string_second () const ;
73+ bool operator ==(const FrameTimeCode& other) const ;
74+ bool operator !=(const FrameTimeCode& other) const ;
75+ bool operator <(const FrameTimeCode& other) const ;
76+ bool operator >(const FrameTimeCode& other) const ;
77+ bool operator <=(const FrameTimeCode& other) const ;
78+ bool operator >=(const FrameTimeCode& other) const ;
79+ FrameTimeCode operator +(const FrameTimeCode& other) const ;
80+ FrameTimeCode operator -(const FrameTimeCode& other) const ;
81+ static std::optional<FrameTimeCode> from_timecode_string (const std::string& timecode_str, const float fps);
82+ static std::optional<FrameTimeCode> from_frame_nums (const int32_t frame_num, const float fps);
83+ static std::optional<FrameTimeCode> from_seconds (const int32_t seconds, const float fps);
84+ static std::optional<FrameTimeCode> from_seconds (const float seconds, const float fps);
85+ private:
86+ std::optional<TimeStamp> parse_hrs_mins_secs (const std::string& timecode_str) const ;
87+ float framerate;
88+ int32_t frame_num;
9889};
9990
10091namespace frame_timecode {
101-
102- constexpr float MIN_FPS_DELTA = 1.0 / 100000 ;
103- constexpr float _SECONDS_PER_MINUTE = 60.0 ;
104- constexpr float _SECONDS_PER_HOUR = 60.0 * _SECONDS_PER_MINUTE;
105- constexpr float _MINUTES_PER_HOUR = 60.0 ;
106-
92+ constexpr float MIN_FPS_DELTA = 1 .0f / 100000 ;
93+ constexpr float SECONDS_PER_MINUTE = 60 .0f ;
94+ constexpr float SECONDS_PER_HOUR = 60 .0f * SECONDS_PER_MINUTE;
95+ constexpr float MINUTES_PER_HOUR = 60 .0f ;
10796}
10897
10998float calculate_total_seconds (const TimeStamp& timestamp);
0 commit comments