version 3.16.0

new PISystemTime::Frequency type
This commit is contained in:
2024-03-05 17:55:25 +03:00
parent 154fb7d9fd
commit f47bc411bc
6 changed files with 249 additions and 16 deletions

View File

@@ -220,3 +220,17 @@ double PITimeMeasurer::elapsed_s() const {
PISystemTime PITimeMeasurer::elapsed() const {
return (PISystemTime::current(true) - t_st);
}
// PISystemTime::Frequency
PISystemTime PISystemTime::Frequency::toSystemTime() const {
if (value_hz <= 0.) return PISystemTime();
return PISystemTime::fromSeconds(1. / value_hz);
}
PISystemTime::Frequency PISystemTime::Frequency::fromSystemTime(const PISystemTime & st) {
if (st == PISystemTime()) return Frequency();
return Frequency(1. / st.toSeconds());
}

View File

@@ -48,6 +48,143 @@ public:
checkOverflows();
}
//! \~english Contructs time with "s" seconds and "ns" nanoseconds
//! \~russian Создает время с секундами "s" и наносекундами "ns"
PISystemTime(std::pair<int, int> s_ns) {
seconds = s_ns.first;
nanoseconds = s_ns.second;
checkOverflows();
}
//! \ingroup Types
//! \~\brief
//! \~english Frequency type.
//! \~russian Тип частоты.
class PIP_EXPORT Frequency {
public:
//! \~english Contructs null frequency
//! \~russian Создает нулевую частоту
Frequency() {}
//! \~english Returns frequency as hertz
//! \~russian Возвращает частоту в герцах
double toHertz() const { return value_hz; }
//! \~english Returns frequency as kilohertz
//! \~russian Возвращает частоту в килогерцах
double toKHertz() const { return value_hz / 1E+3; }
//! \~english Returns frequency as megahertz
//! \~russian Возвращает частоту в мегагерцах
double toMHertz() const { return value_hz / 1E+6; }
//! \~english Returns frequency as gigahertz
//! \~russian Возвращает частоту в гигагерцах
double toGHertz() const { return value_hz / 1E+9; }
//! \~english Returns frequency as \a PISystemTime time interval
//! \~russian Возвращает частоту как \a PISystemTime временной интервал
PISystemTime toSystemTime() const;
//! \~english Returns frequency as \a PISystemTime time interval
//! \~russian Возвращает частоту как \a PISystemTime временной интервал
operator PISystemTime() const { return toSystemTime(); }
//! \~english Returns \a Frequency contains "hz" hertz
//! \~russian Возвращает \a Frequency содержащую "hz" герц
static Frequency fromHertz(double hz) { return Frequency(hz); }
//! \~english Returns \a Frequency contains "khz" kilohertz
//! \~russian Возвращает \a Frequency содержащую "khz" килогерц
static Frequency fromKHertz(double khz) { return Frequency(khz * 1E+3); }
//! \~english Returns \a Frequency contains "mhz" megahertz
//! \~russian Возвращает \a Frequency содержащую "mhz" мегагерц
static Frequency fromMHertz(double mhz) { return Frequency(mhz * 1E+6); }
//! \~english Returns \a Frequency contains "ghz" gigahertz
//! \~russian Возвращает \a Frequency содержащую "ghz" гигагерц
static Frequency fromGHertz(double ghz) { return Frequency(ghz * 1E+9); }
//! \~english Returns \a Frequency that corresponds "st" time interval
//! \~russian Возвращает \a Frequency соответствующую временному интервалу "st"
static Frequency fromSystemTime(const PISystemTime & st);
//! \~english Returns sum between this frequency and "f"
//! \~russian Возвращает сумму этой частоты с "f"
Frequency operator+(const Frequency & f) const { return Frequency(value_hz + f.value_hz); }
//! \~english Returns difference between this frequency and "f"
//! \~russian Возвращает разницу этой частоты с "f"
Frequency operator-(const Frequency & f) const { return Frequency(value_hz - f.value_hz); }
//! \~english Returns multiplication between this frequency and "v"
//! \~russian Возвращает эту частоту умноженную на "v"
Frequency operator*(const double & v) const { return Frequency(value_hz * v); }
//! \~english Returns division between this frequency and "v"
//! \~russian Возвращает эту частоту поделённую на "v"
Frequency operator/(const double & v) const { return Frequency(value_hz / v); }
//! \~english Multiply frequency by "v"
//! \~russian Умножает частоту на "v"
Frequency & operator*=(const double & v) {
value_hz *= v;
return *this;
}
//! \~english Divide frequency by "v"
//! \~russian Делит частоту на "v"
Frequency & operator/=(const double & v) {
value_hz /= v;
return *this;
}
//! \~english Add to frequency "f"
//! \~russian Добавляет к частоте "f"
Frequency & operator+=(const Frequency & f) {
value_hz += f.value_hz;
return *this;
}
//! \~english Subtract from frequency "f"
//! \~russian Вычитает из частоты "f"
Frequency & operator-=(const Frequency & f) {
value_hz -= f.value_hz;
return *this;
}
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator==(const Frequency & f) const { return value_hz == f.value_hz; }
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator!=(const Frequency & f) const { return value_hz != f.value_hz; }
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator>(const Frequency & f) const { return value_hz > f.value_hz; }
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator<(const Frequency & f) const { return value_hz < f.value_hz; }
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator>=(const Frequency & f) const { return value_hz >= f.value_hz; }
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator<=(const Frequency & f) const { return value_hz <= f.value_hz; }
private:
Frequency(double hz): value_hz(hz) {}
double value_hz = 0.;
};
//! \~english Returns time value in seconds
//! \~russian Возвращает значение времени в секундах
@@ -128,11 +265,11 @@ public:
}
//! \~english Returns multiplication between this time and "t"
//! \~russian Возвращает это временя умноженное на "t"
//! \~russian Возвращает это время умноженное на "t"
PISystemTime operator*(const double & v) const { return fromMilliseconds(toMilliseconds() * v); }
//! \~english Returns division between this time and "t"
//! \~russian Возвращает это временя поделённое на "t"
//! \~russian Возвращает это время поделённое на "t"
PISystemTime operator/(const double & v) const { return fromMilliseconds(toMilliseconds() / v); }
//! \~english Add to time "t"
@@ -269,6 +406,17 @@ inline PICout operator<<(PICout s, const PISystemTime & v) {
return s;
}
//! \relatesalso PICout
//! \~english \brief Output operator to PICout
//! \~russian \brief Оператор вывода в PICout
inline PICout operator<<(PICout s, const PISystemTime::Frequency & f) {
s.space();
s.saveAndSetControls(0);
s << f.toHertz() << " Hz";
s.restoreControls();
return s;
}
//! \ingroup Types
//! \~\brief