PulseView  0.3.0
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, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef PULSEVIEW_UTIL_HPP
22 #define PULSEVIEW_UTIL_HPP
23 
24 #include <cmath>
25 
26 #ifndef Q_MOC_RUN
27 #include <boost/multiprecision/cpp_dec_float.hpp>
28 #endif
29 
30 #include <QMetaType>
31 #include <QString>
32 
33 namespace pv {
34 namespace util {
35 
36 enum class TimeUnit {
37  Time = 1,
38  Samples = 2
39 };
40 
41 enum class SIPrefix {
42  unspecified = -1,
43  yocto, zepto,
44  atto, femto, pico,
45  nano, micro, milli,
46  none,
47  kilo, mega, giga,
48  tera, peta, exa,
49  zetta, yotta
50 };
51 
53 int exponent(SIPrefix prefix);
54 
56 typedef boost::multiprecision::number<
57  boost::multiprecision::cpp_dec_float<24>,
58  boost::multiprecision::et_off> Timestamp;
59 
78 QString format_time_si(
79  const Timestamp& t,
81  unsigned precision = 0,
82  QString unit = "s",
83  bool sign = true);
84 
101  const Timestamp& t,
102  SIPrefix prefix,
103  unsigned precision = 0,
104  QString unit = "s",
105  bool sign = true);
106 
120 QString format_time_minutes(
121  const Timestamp& t,
122  signed precision = 0,
123  bool sign = true);
124 
125 } // namespace util
126 } // namespace pv
127 
129 
130 #endif // PULSEVIEW_UTIL_HPP
SIPrefix
Definition: util.hpp:41
QString format_time_si(const Timestamp &v, SIPrefix prefix, unsigned int precision, QString unit, bool sign)
Definition: util.cpp:107
QString format_time_si_adjusted(const Timestamp &t, SIPrefix prefix, unsigned precision, QString unit, bool sign)
Definition: util.cpp:149
int exponent(SIPrefix prefix)
Returns the exponent that corresponds to a given prefix.
Definition: util.cpp:62
QString format_time_minutes(const Timestamp &t, signed precision, bool sign)
Definition: util.cpp:174
TimeUnit
Definition: util.hpp:36
Q_DECLARE_METATYPE(std::shared_ptr< sigrok::Driver >)
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 24 >, boost::multiprecision::et_off > Timestamp
Timestamp type providing yoctosecond resolution.
Definition: util.hpp:58