ngscopeclient 0.1-dev+51fbda87c
Marker.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
35#ifndef Marker_h
36#define Marker_h
37
41class TimePoint : public std::pair<time_t, int64_t>
42{
43public:
44 TimePoint(time_t sec, int64_t fs)
45 : std::pair<time_t, int64_t>(sec, fs)
46 {}
47
48 TimePoint(double tnow)
49 {
50 first = floor(tnow);
51 second = (tnow - first) * FS_PER_SECOND;
52 }
53
54 time_t GetSec() const
55 { return first; }
56
57 int64_t GetFs() const
58 { return second; }
59
60 void SetSec(time_t sec)
61 { first = sec; }
62
63 void SetFs(int64_t fs)
64 { second = fs; }
65
66 std::string PrettyPrint() const;
67
68 int64_t operator-(const TimePoint& rhs)
69 {
70 int64_t dsec = first - rhs.first;
71 int64_t dfs = second - rhs.second;
72
73 return dsec*FS_PER_SECOND + dfs;
74 }
75};
76
83class Marker
84{
85public:
86 Marker(TimePoint t, int64_t o, const std::string& n)
87 : m_timestamp(t)
88 , m_offset(o)
89 , m_name(n)
90 {}
91
94
96 int64_t m_offset;
97
102 { return TimePoint(m_timestamp.first, m_timestamp.second + m_offset); }
103
105 std::string m_name;
106
108 bool operator<(const Marker& rhs) const
109 {
110 if(m_timestamp < rhs.m_timestamp)
111 return true;
112 if(m_timestamp > rhs.m_timestamp)
113 return false;
114 if(m_offset < rhs.m_offset)
115 return true;
116 return false;
117 }
118};
119
120#endif
Data for a marker.
Definition: Marker.h:84
TimePoint m_timestamp
Timestamp of the parent waveform (UTC)
Definition: Marker.h:93
TimePoint GetMarkerTime()
Helper to get the absolute timestamp of the marker.
Definition: Marker.h:101
bool operator<(const Marker &rhs) const
Helper for sorting.
Definition: Marker.h:108
int64_t m_offset
Position of the marker within the parent waveform (X axis units)
Definition: Marker.h:96
std::string m_name
Display name of the marker.
Definition: Marker.h:105
A timestamp, measured in seconds + femtoseconds.
Definition: Marker.h:42