##// END OF EJS Templates
Removed useless function in Variable class...
Removed useless function in Variable class Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r17:895ab1d87afd
r29:ab4890d233e8
Show More
DateTimeRange.h
224 lines | 5.9 KiB | text/x-c | CLexer
Added more features in DateTimeRange to prepare variable synchronization...
r8 #ifndef SCIQLOP_DATETIMERANGE_H
#define SCIQLOP_DATETIMERANGE_H
First init from SciQLop Core module...
r0
Added DateTimeRange unit Tests...
r6 #include <cmath>
First init from SciQLop Core module...
r0 #include <QObject>
#include <QDebug>
Added DateTimeRange unit Tests...
r6 #include <opaque/numeric_typedef.hpp>
First init from SciQLop Core module...
r0 #include <Common/DateUtils.h>
#include <Common/MetaTypes.h>
Added DateTimeRange unit Tests...
r6 #include <Common/Numeric.h>
First init from SciQLop Core module...
r0
Introduced opaque library from Kyle Markley and improved DateTimeRange...
r4
template <typename T>
struct Seconds : opaque::numeric_typedef<T, Seconds<T>> ,
opaque::binop::multipliable <Seconds<T>, true , Seconds<T>, T, T>,
opaque::binop::dividable <Seconds<T>, true , Seconds<T>, T, T>,
opaque::binop::addable <Seconds<T>, true , Seconds<T>, T, T>,
opaque::binop::subtractable <Seconds<T>, true , Seconds<T>, T, T>
{
using base = opaque::numeric_typedef<T, Seconds<T>>;
using base::base;
Added DateTimeRange unit Tests...
r6 operator T () const {return this->value;}
Introduced opaque library from Kyle Markley and improved DateTimeRange...
r4 };
Many fixes plus implemented var synchronization...
r9 struct InvalidDateTimeRangeTransformation{};
Added more features in DateTimeRange to prepare variable synchronization...
r8 struct DateTimeRangeTransformation
{
double zoom;
Seconds<double> shift;
bool operator==(const DateTimeRangeTransformation& other) const
{
Many fixes plus implemented var synchronization...
r9 return SciQLop::numeric::almost_equal(zoom, other.zoom, 1) &&
SciQLop::numeric::almost_equal<double>(shift, other.shift, 1);
Added more features in DateTimeRange to prepare variable synchronization...
r8 }
Basic asynchronous variable update, still a lot to do...
r17 DateTimeRangeTransformation merge(const DateTimeRangeTransformation& other) const
{
return DateTimeRangeTransformation{zoom*other.zoom,shift+other.shift};
}
Added more features in DateTimeRange to prepare variable synchronization...
r8 };
First init from SciQLop Core module...
r0 /**
* @brief The SqpRange struct holds the information of time parameters
*/
struct DateTimeRange {
Many fixes plus implemented var synchronization...
r9 DateTimeRange()
:m_TStart(std::nan("")), m_TEnd(std::nan(""))
{}
DateTimeRange(double TStart, double TEnd)
:m_TStart(TStart), m_TEnd(TEnd)
{}
First init from SciQLop Core module...
r0 /// Creates SqpRange from dates and times
static DateTimeRange fromDateTime(const QDate &startDate, const QTime &startTime,
const QDate &endDate, const QTime &endTime)
{
return {DateUtils::secondsSinceEpoch(QDateTime{startDate, startTime, Qt::UTC}),
DateUtils::secondsSinceEpoch(QDateTime{endDate, endTime, Qt::UTC})};
}
Added DateTimeRange unit Tests...
r6 static DateTimeRange fromDateTime(const QDateTime &start, const QDateTime &end)
{
return {DateUtils::secondsSinceEpoch(start),
DateUtils::secondsSinceEpoch(end)};
}
First init from SciQLop Core module...
r0 /// Start time (UTC)
double m_TStart;
/// End time (UTC)
double m_TEnd;
Added more features in DateTimeRange to prepare variable synchronization...
r8 Seconds<double> delta()const noexcept{return Seconds<double>{this->m_TEnd - this->m_TStart};}
First init from SciQLop Core module...
r0
bool contains(const DateTimeRange &dateTime) const noexcept
{
return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
}
Added more features in DateTimeRange to prepare variable synchronization...
r8 Seconds<double> center() const noexcept
{
return Seconds<double>((m_TStart + m_TEnd) / 2.);
}
First init from SciQLop Core module...
r0 bool intersect(const DateTimeRange &dateTime) const noexcept
{
return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd);
}
Added more features in DateTimeRange to prepare variable synchronization...
r8 inline DateTimeRange transform(const DateTimeRangeTransformation& tr)const noexcept;
First init from SciQLop Core module...
r0 bool operator==(const DateTimeRange &other) const
{
Many fixes plus implemented var synchronization...
r9 return SciQLop::numeric::almost_equal(m_TStart, other.m_TStart, 1) &&
SciQLop::numeric::almost_equal(m_TEnd, other.m_TEnd, 1);
First init from SciQLop Core module...
r0 }
Added DateTimeRange unit Tests...
r6
First init from SciQLop Core module...
r0 bool operator!=(const DateTimeRange &other) const { return !(*this == other); }
Introduced opaque library from Kyle Markley and improved DateTimeRange...
r4
Added more features in DateTimeRange to prepare variable synchronization...
r8 void grow(double factor)noexcept
Introduced opaque library from Kyle Markley and improved DateTimeRange...
r4 {
double grow_v{delta()*(factor - 1.)/2.};
m_TStart -= grow_v;
m_TEnd += grow_v;
}
Added more features in DateTimeRange to prepare variable synchronization...
r8 void shrink(double factor)noexcept
Introduced opaque library from Kyle Markley and improved DateTimeRange...
r4 {
double shrink_v{this->delta()*(1. - factor)/2.};
m_TStart += shrink_v;
m_TEnd -= shrink_v;
}
DateTimeRange& operator*=(double k)
{
this->grow(k);
return *this;
}
DateTimeRange& operator/=(double k)
{
this->shrink(k);
return *this;
}
Many fixes plus implemented var synchronization...
r9 // compute set difference
std::vector<DateTimeRange> operator-(const DateTimeRange& other)const
{
std::vector<DateTimeRange> result;
if(std::isnan(other.m_TStart)||std::isnan(other.m_TEnd)||!this->intersect(other))
{
Followed Clazy and Clang advises and disabled few old tests...
r14 result.emplace_back(m_TStart, m_TEnd);
Many fixes plus implemented var synchronization...
r9 }
else
{
if(this->m_TStart<other.m_TStart)
{
Followed Clazy and Clang advises and disabled few old tests...
r14 result.emplace_back(this->m_TStart, other.m_TStart);
Many fixes plus implemented var synchronization...
r9 }
if(this->m_TEnd>other.m_TEnd)
{
Followed Clazy and Clang advises and disabled few old tests...
r14 result.emplace_back(this->m_TEnd, other.m_TEnd);
Many fixes plus implemented var synchronization...
r9 }
}
return result;
}
First init from SciQLop Core module...
r0 };
Introduced opaque library from Kyle Markley and improved DateTimeRange...
r4 template <class T>
DateTimeRange& operator+=(DateTimeRange&r, Seconds<T> offset)
{
shift(r,offset);
return r;
}
template <class T>
DateTimeRange& operator-=(DateTimeRange&r, Seconds<T> offset)
{
shift(r,-offset);
Basic asynchronous variable update, still a lot to do...
r17 return r;
Introduced opaque library from Kyle Markley and improved DateTimeRange...
r4 }
template <class T>
void shift(DateTimeRange& r, Seconds<T> offset)
{
r.m_TEnd+=static_cast<double>(offset);
r.m_TStart+=static_cast<double>(offset);
}
inline DateTimeRange operator*(const DateTimeRange& r, double k)
{
DateTimeRange result{r};
result.grow(k);
return result;
}
inline DateTimeRange operator/(const DateTimeRange& r, double k)
{
DateTimeRange result{r};
result.shrink(k);
return result;
}
template<class T>
DateTimeRange operator+(const DateTimeRange& r, Seconds<T> offset)
{
DateTimeRange result{r};
shift(result,offset);
return result;
}
template<class T>
DateTimeRange operator-(const DateTimeRange& r, Seconds<T> offset)
{
DateTimeRange result{r};
shift(result,-offset);
return result;
}
First init from SciQLop Core module...
r0 const auto INVALID_RANGE
= DateTimeRange{std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()};
inline QDebug operator<<(QDebug d, DateTimeRange obj)
{
auto tendDateTimeStart = DateUtils::dateTime(obj.m_TStart);
auto tendDateTimeEnd = DateUtils::dateTime(obj.m_TEnd);
d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
return d;
}
Added more features in DateTimeRange to prepare variable synchronization...
r8
DateTimeRange DateTimeRange::transform(const DateTimeRangeTransformation &tr) const noexcept
{
return DateTimeRange{*this} * tr.zoom + tr.shift;
}
First init from SciQLop Core module...
r0 // Required for using shared_ptr in signals/slots
SCIQLOP_REGISTER_META_TYPE(SQPRANGE_REGISTRY, DateTimeRange)
Added more features in DateTimeRange to prepare variable synchronization...
r8 #endif // SCIQLOP_DATETIMERANGE_H