X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Futil.hpp;h=e9689ec0d6b4248646c91124292495b730be719a;hp=5d65694054ab2c0b2e6a9f652fc736abfc5da8cd;hb=806d3e1eb3d60e93ff95d23e79588a0486730967;hpb=4bc10a910593fda2d378d62a57448cec4b2166bf diff --git a/pv/util.hpp b/pv/util.hpp index 5d656940..e9689ec0 100644 --- a/pv/util.hpp +++ b/pv/util.hpp @@ -18,46 +18,59 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef PULSEVIEW_UTIL_H -#define PULSEVIEW_UTIL_H +#ifndef PULSEVIEW_UTIL_HPP +#define PULSEVIEW_UTIL_HPP -#include +#include +#include + +#include #include namespace pv { namespace util { +enum TimeUnit { + Time = 1, + Samples = 2 +}; + +/// Timestamp type providing yoctosecond resolution. +typedef boost::multiprecision::number< + boost::multiprecision::cpp_dec_float<24>, + boost::multiprecision::et_off> Timestamp; + extern const int FirstSIPrefixPower; /** * Formats a given value with the specified SI prefix. * @param v The value to format. * @param unit The unit of quantity. - * @param prefix The number of the prefix, from 0 for 'femto' up to - * 8 for 'giga'. If prefix is set to -1, the prefix will be calculated. + * @param prefix The number of the prefix, from 0 for 'yotta' up to + * 16 for 'yokto'. If prefix is set to -1, the prefix will be calculated. * @param precision The number of digits after the decimal separator. * @param sign Whether or not to add a sign also for positive numbers. * * @return The formated value. */ QString format_si_value( - double v, QString unit, int prefix = -1, + const Timestamp& v, QString unit, int prefix = -1, unsigned precision = 0, bool sign = true); /** * Formats a given time with the specified SI prefix. * @param t The time value in seconds to format. - * @param prefix The number of the prefix, from 0 for 'femto' up to - * 8 for 'giga'. If prefix is set to -1, the prefix will be calculated. + * @param prefix The number of the prefix, from 0 for 'yotta' up to + * 16 for 'yokto'. If prefix is set to -1, the prefix will be calculated. * @param unit The unit of quantity. - * @param precision The number of digits after the decimal separator. - * @param sign Whether or not to add a sign also for positive numbers. + * @param precision The number of digits after the decimal separator or period (.). * * @return The formated value. */ QString format_time( - double t, int prefix = -1, unsigned precision = 0, bool sign = true); + const Timestamp& t, int prefix = -1, + TimeUnit unit = Time, unsigned precision = 0); /** * Formats a given time value with a SI prefix so that the @@ -66,9 +79,11 @@ QString format_time( * * @return The formated value. */ -QString format_second(double second); +QString format_second(const Timestamp& second); } // namespace util } // namespace pv -#endif // PULSEVIEW_UTIL_H +Q_DECLARE_METATYPE(pv::util::Timestamp) + +#endif // PULSEVIEW_UTIL_HPP