X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Futil.hpp;h=f2740d409d9af018b3dc92e290e404ea8335aa0f;hb=d001f416aec37d5b13b804dec9ee9e1c011ffabb;hp=572bed31814e6bba0baa670027e1762f04b261c9;hpb=2acdb232d6bb452cfdfaea3ef5218fb4da592329;p=pulseview.git diff --git a/pv/util.hpp b/pv/util.hpp index 572bed3..f2740d4 100644 --- a/pv/util.hpp +++ b/pv/util.hpp @@ -18,32 +18,70 @@ * 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 { -extern const int FirstSIPrefixPower; +enum class TimeUnit { + Time = 1, + Samples = 2 +}; + +enum class SIPrefix { + unspecified = -1, + yocto, zepto, + atto, femto, pico, + nano, micro, milli, + none, + kilo, mega, giga, + tera, peta, exa, + zetta, yotta +}; + +/// Returns the exponent that corresponds to a given prefix. +int exponent(SIPrefix prefix); + +/// Timestamp type providing yoctosecond resolution. +typedef boost::multiprecision::number< + boost::multiprecision::cpp_dec_float<24>, + boost::multiprecision::et_off> Timestamp; /** - * Formats a given time value 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'. - * @parma precision The number of digits after the decimal separator. + * Formats a given value with the specified SI prefix. + * @param v The value to format. + * @param unit The unit of quantity. + * @param prefix The prefix to use. + * @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_time( - double t, unsigned int prefix, +QString format_si_value( + const Timestamp& v, QString unit, SIPrefix prefix = SIPrefix::unspecified, 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 prefix to use. + * @param unit The unit of quantity. + * @param precision The number of digits after the decimal separator or period (.). + * + * @return The formated value. + */ +QString format_time( + const Timestamp& t, SIPrefix prefix = SIPrefix::unspecified, + TimeUnit unit = TimeUnit::Time, unsigned precision = 0); + /** * Formats a given time value with a SI prefix so that the * value is between 1 and 999. @@ -51,9 +89,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