PulseView  unreleased development snapshot
A Qt-based sigrok GUI
util.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef PULSEVIEW_PV_UTIL_HPP
21 #define PULSEVIEW_PV_UTIL_HPP
22 
23 #include <cmath>
24 #include <string>
25 #include <vector>
26 
27 #ifndef Q_MOC_RUN
28 // Workaround for https://github.com/boostorg/serialization/issues/186
29 #include <boost/serialization/nvp.hpp>
30 
31 #include <boost/multiprecision/cpp_dec_float.hpp>
32 #endif
33 
34 #include <QMetaType>
35 #include <QString>
36 #include <QFontMetrics>
37 
38 using std::string;
39 using std::vector;
40 
41 namespace pv {
42 namespace util {
43 
44 enum class TimeUnit {
45  None = 0,
46  Time = 1,
47  Samples = 2
48 };
49 
50 enum class SIPrefix {
51  unspecified = -1,
52  yocto, zepto,
53  atto, femto, pico,
54  nano, micro, milli,
55  none,
56  kilo, mega, giga,
57  tera, peta, exa,
58  zetta, yotta
59 };
60 
62 int exponent(SIPrefix prefix);
63 
65 typedef boost::multiprecision::number<
66  boost::multiprecision::cpp_dec_float<24>,
67  boost::multiprecision::et_off> Timestamp;
68 
73 
92 QString format_time_si(const Timestamp& v,
93  SIPrefix prefix = SIPrefix::unspecified, unsigned precision = 0,
94  QString unit = "s", bool sign = true);
95 
110 QString format_value_si(double v,
111  SIPrefix prefix = SIPrefix::unspecified, unsigned precision = 0,
112  QString unit = "", bool sign = true);
113 
129 QString format_time_si_adjusted(const Timestamp& t, SIPrefix prefix,
130  unsigned precision = 0, QString unit = "s", bool sign = true);
131 
145 QString format_time_minutes(const Timestamp& t, signed precision = 0,
146  bool sign = true);
147 
148 vector<string> split_string(string text, string separator);
149 
157 std::streamsize text_width(const QFontMetrics &metric, const QString &string);
158 
159 } // namespace util
160 } // namespace pv
161 
163 
164 #endif // PULSEVIEW_PV_UTIL_HPP
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t t(t+t)") define_sfop3(16
SIPrefix
Definition: util.hpp:50
QString format_time_si(const Timestamp &v, SIPrefix prefix, unsigned int precision, QString unit, bool sign)
Definition: util.cpp:132
std::streamsize text_width(const QFontMetrics &metric, const QString &string)
Definition: util.cpp:290
QString format_value_si(double v, SIPrefix prefix, unsigned precision, QString unit, bool sign)
Definition: util.cpp:153
QString format_time_si_adjusted(const Timestamp &t, SIPrefix prefix, unsigned precision, QString unit, bool sign)
Definition: util.cpp:180
int exponent(SIPrefix prefix)
Returns the exponent that corresponds to a given prefix.
Definition: util.cpp:68
vector< string > split_string(string text, string separator)
Definition: util.cpp:268
Q_DECLARE_METATYPE(SharedPtrToSegment)
SIPrefix determine_value_prefix(double v)
Definition: util.cpp:113
QString format_time_minutes(const Timestamp &t, signed precision, bool sign)
Definition: util.cpp:200
TimeUnit
Definition: util.hpp:44
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 24 >, boost::multiprecision::et_off > Timestamp
Timestamp type providing yoctosecond resolution.
Definition: util.hpp:67
util
Definition: CMakeCache.txt:655