[installation] Change to nightly

This commit is contained in:
2025-10-30 12:04:59 +01:00
parent 2ff097f9d1
commit a31bc45cce
1441 changed files with 60368 additions and 56360 deletions

View File

@ -61,7 +61,7 @@ namespace Generic {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/** \brief A template archive interface
An archive offers an interface to read from and write to datasources.
An archive offers an interface to read from and write to datasources.
*/
template <typename ROOT_TYPE>
class Archive {
@ -130,7 +130,7 @@ class Archive {
//! Creates a new archive
virtual bool create(const char* dataSource);
virtual void close() = 0;
/**
@ -279,7 +279,7 @@ class Archive {
void read(::boost::intrusive_ptr<T> &object);
template <typename T>
void read(::boost::optional<T> &object);
void read(Optional<T> &object);
// ------------------------------------------------------------------
@ -347,7 +347,7 @@ class Archive {
void write(::boost::intrusive_ptr<T>&);
template <typename T>
void write(::boost::optional<T>&);
void write(Optional<T>&);
// ------------------------------------------------------------------
@ -361,7 +361,7 @@ class Archive {
//! Writes a smartpointer into the archive
template <typename T>
Archive& operator<<(::boost::intrusive_ptr<T>&);
//! Writes a named object into the archive
template <typename T>
Archive& operator<<(const ObjectNamer<T>&);
@ -416,12 +416,12 @@ class Archive {
//! Reads a list from the archive
template <typename T>
Archive& operator>>(const ObjectNamer<std::list<T> >&);
//! Stream operator that decides by means of the _isReading flag
//! whether a the object has to be written or to be read.
template <typename T>
Archive& operator&(ObjectNamer<T>);
// ------------------------------------------------------------------
@ -436,15 +436,15 @@ class Archive {
template <typename T>
struct TypedSerializeDispatcher : SerializeDispatcher {
TypedSerializeDispatcher(T* t = nullptr) : target(t) {}
TypedSerializeDispatcher& operator=(T* t) {
target = t;
return *this;
}
TypedSerializeDispatcher* operator->() { return this; }
virtual void operator()(Archive<ROOT_TYPE>& ar) {
virtual void operator()(Archive<ROOT_TYPE>& ar) override {
target->serialize(ar);
}
@ -454,7 +454,7 @@ class Archive {
};
bool findObject(const char *name, const char *targetClass, bool nullable);
//! Locates an object inside the archive. A derived class
//! must provide its specific location code.
virtual bool locateObjectByName(const char *name, const char *targetClass, bool nullable) = 0;
@ -510,7 +510,7 @@ class Archive {
template <typename T>
void readPtr(void*, T *&object);
//! Helper function to distinguish between pointer and non pointer
//! types to avoid nullptr pointer serialization.
template <typename T>
@ -523,8 +523,8 @@ class Archive {
void read(const char *name, ::boost::intrusive_ptr<T> &object, const char *targetClass);
template <typename T>
void read(const char *name, ::boost::optional<T> &object, const char *targetClass);
void read(const char *name, Optional<T> &object, const char *targetClass);
template <typename T>
void write(const char *name, T &object, const char *targetClass);
@ -538,7 +538,7 @@ class Archive {
//! Helper function to distinguish between C pointer and Optionals
template <typename T>
void write(const char *name, ::boost::optional<T> &object, const char *targetClass);
void write(const char *name, Optional<T> &object, const char *targetClass);
int setChildHint(int h);

View File

@ -47,10 +47,10 @@ namespace {
class IsTypeOf {
class No { };
class Yes { No no[2]; };
static Yes Test(BASECLASS*); // declared, but not defined
static No Test(...); // declared, but not defined
public:
enum { Value = sizeof(Test(static_cast<DERIVEDCLASS*>(0))) == sizeof(Yes) };
};
@ -155,7 +155,7 @@ struct ClassQuery<T,1> {
};
template <typename ROOT_TYPE, typename TYPE>
const char *checkClassName(const ::boost::optional<TYPE>*, const ::boost::optional<TYPE>&) {
const char *checkClassName(const Optional<TYPE>*, const Optional<TYPE>&) {
ClassQuery<TYPE, boost::is_base_of<ROOT_TYPE, TYPE>::value> query;
return query();
}
@ -367,7 +367,7 @@ inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(T*& object) {
return *this;
//_validObject = true;
read(classname, object, classname);
return *this;
@ -454,13 +454,13 @@ template <typename T>
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(const ObjectNamer<T>& namedObject) {
int h = setChildHint(namedObject.hint());
//setHint(h | namedObject.hint());
//_validObject = true;
ContainerReader<ROOT_TYPE,T,boost::is_const<T>::value?1:0> reader;
reader(*this, namedObject);
setHint(h);
return *this;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -516,7 +516,7 @@ inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(const ObjectNamer<std:
//setHint(h | namedObject.hint());
typedef typename boost::remove_pointer<T>::type RAW_T;
//_validObject = true;
VectorReader<ROOT_TYPE,T,
@ -544,7 +544,7 @@ inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(const ObjectNamer<std:
reader(*this, namedObject);
setHint(h);
return *this;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -600,7 +600,7 @@ inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(const ObjectNamer<std:
//setHint(h | namedObject.hint());
typedef typename boost::remove_pointer<T>::type RAW_T;
//_validObject = true;
ListReader<ROOT_TYPE,T,
boost::is_class<RAW_T>::value?
@ -626,7 +626,7 @@ inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(const ObjectNamer<std:
reader(*this, namedObject);
setHint(h);
return *this;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -673,18 +673,20 @@ inline void Archive<ROOT_TYPE>::read(::boost::intrusive_ptr<T>& object) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename ROOT_TYPE>
template <typename T>
inline void Archive<ROOT_TYPE>::read(::boost::optional<T>& object) {
inline void Archive<ROOT_TYPE>::read(Optional<T>& object) {
bool oldState = success();
object = T();
read(*object);
if ( !success() )
object = boost::none;
if ( !success() ) {
object = None;
}
// Restore old state if not in strict mode otherwise pass it through
if ( !_strict )
if ( !_strict ) {
_validObject = oldState;
}
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -698,7 +700,7 @@ inline void Archive<ROOT_TYPE>::readPtr(ROOT_TYPE*, T*& object) {
if ( (hint() & STATIC_TYPE) == 0 ) {
std::string className = determineClassName();
if ( className.empty() ) return;
if ( !ClassFactoryInterface<ROOT_TYPE>::IsTypeOf(T::ClassName(), className.c_str()) ) {
_validObject = false;
return;
@ -811,12 +813,12 @@ inline void Archive<ROOT_TYPE>::read(const char *name, ::boost::intrusive_ptr<T>
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename ROOT_TYPE>
template <typename T>
inline void Archive<ROOT_TYPE>::read(const char *name, ::boost::optional<T> &object, const char *targetClass) {
inline void Archive<ROOT_TYPE>::read(const char *name, Optional<T> &object, const char *targetClass) {
if ( findObject(name, targetClass, true) )
read(object);
else {
//_validObject = false;
object = boost::none;
object = None;
}
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -897,7 +899,7 @@ inline void Archive<ROOT_TYPE>::write(const char *name, ::boost::intrusive_ptr<T
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename ROOT_TYPE>
template <typename T>
inline void Archive<ROOT_TYPE>::write(const char *name, ::boost::optional<T> &object, const char *targetClass) {
write(name, object.get_ptr(), targetClass);
inline void Archive<ROOT_TYPE>::write(const char *name, Optional<T> &object, const char *targetClass) {
write(name, object ? std::addressof(*object) : nullptr, targetClass);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

View File

@ -63,7 +63,7 @@ class SC_SYSTEM_CORE_API Array : public Seiscomp::Core::BaseObject {
DataType dataType() const { return _datatype; }
//! Returns a clone of the array
Array* clone() const;
Array *clone() const override;
//! Returns a copy of the array of the specified data type.
virtual Array* copy(DataType dt) const = 0;

View File

@ -17,250 +17,448 @@
* gempa GmbH. *
***************************************************************************/
#ifndef SEISCOMP_CORE_DATETIME_H
#define SEISCOMP_CORE_DATETIME_H
#include <seiscomp/core.h>
#include <seiscomp/core/optional.h>
#ifdef WIN32
#include <winsock.h>
#else
#include <sys/time.h>
#endif
#include <string>
#include <cstdint>
#include <chrono>
#include <limits>
#include <iostream>
#include <cmath>
#include <string_view>
struct tm;
namespace Seiscomp {
namespace Core {
class SC_SYSTEM_CORE_API TimeSpan {
/**
* @brief The TimeSpan class holds the amount of microseconds passed between
* two times.
*
* Internally it is represented with a std::chrono::duration with microsecond
* precision. It can be constructed from a std::chrono::duration object
* Its binary represention is 64bit signed integer regardless of the
* underlying architecture.
*
* The limit of a representable time span is +/-32768 years.
*/
class TimeSpan {
public:
using Storage = int64_t;
using Weeks = std::chrono::duration<Storage, std::ratio<7*86400> >;
using Days = std::chrono::duration<Storage, std::ratio<86400> >;
using Hours = std::chrono::duration<Storage, std::ratio<3600> >;
using Minutes = std::chrono::duration<Storage, std::ratio<60> >;
using Seconds = std::chrono::duration<Storage, std::ratio<1> >;
using MilliSeconds = std::chrono::duration<Storage, std::milli>;
using MicroSeconds = std::chrono::duration<Storage, std::micro>;
using F1 = std::chrono::duration<Storage, std::ratio<1, 10> >;
using F2 = std::chrono::duration<Storage, std::ratio<1, 100> >;
using F3 = std::chrono::duration<Storage, std::ratio<1, 1000> >;
using F4 = std::chrono::duration<Storage, std::ratio<1, 10000> >;
using F5 = std::chrono::duration<Storage, std::ratio<1, 100000> >;
using F6 = std::chrono::duration<Storage, std::ratio<1, 1000000> >;
using Duration = MicroSeconds;
static const double MinSpan;
static const double MaxSpan;
static const Storage MinSeconds;
static const Storage MaxSeconds;
// ----------------------------------------------------------------------
// X'truction
// ----------------------------------------------------------------------
public:
TimeSpan() = default;
TimeSpan(const TimeSpan &other) = default;
constexpr TimeSpan(Storage secs, Storage usecs = 0);
TimeSpan(double ts);
template<typename Rep, typename Period>
constexpr TimeSpan(const std::chrono::duration<Rep, Period> &duration);
// ----------------------------------------------------------------------
// Assignment operators
// ----------------------------------------------------------------------
public:
//! Assigns integer epoch seconds
TimeSpan &operator=(int t);
//! Assigns integer epoch seconds
TimeSpan &operator=(Storage t);
//! Assigns floating point epoch seconds
TimeSpan &operator=(double t);
// ----------------------------------------------------------------------
// Comparison operators
// ----------------------------------------------------------------------
public:
constexpr bool operator==(const TimeSpan &other) const noexcept;
constexpr bool operator!=(const TimeSpan &other) const noexcept;
constexpr bool operator<=(const TimeSpan &other) const noexcept;
constexpr bool operator<(const TimeSpan &other) const noexcept;
constexpr bool operator>=(const TimeSpan &other) const noexcept;
constexpr bool operator>(const TimeSpan &other) const noexcept;
// ----------------------------------------------------------------------
// Arithmetic operators
// ----------------------------------------------------------------------
public:
constexpr TimeSpan operator+(const TimeSpan &other) const;
constexpr TimeSpan operator-(const TimeSpan &other) const;
constexpr TimeSpan operator*(int op) const;
constexpr TimeSpan operator*(size_t op) const;
constexpr TimeSpan operator*(double op) const;
constexpr TimeSpan operator/(int op) const;
constexpr TimeSpan operator/(size_t op) const;
constexpr TimeSpan operator/(double op) const;
constexpr TimeSpan operator-() const;
TimeSpan &operator+=(const TimeSpan &other);
TimeSpan &operator-=(const TimeSpan &other);
TimeSpan &operator*=(int op);
TimeSpan &operator*=(size_t op);
TimeSpan &operator*=(double op);
TimeSpan &operator/=(int op);
TimeSpan &operator/=(size_t op);
TimeSpan &operator/=(double op);
// ----------------------------------------------------------------------
// Conversion operators
// ----------------------------------------------------------------------
public:
constexpr explicit operator Duration() const noexcept;
constexpr explicit operator double() const noexcept;
//! Returns whether the timespan is empty or not.
constexpr explicit operator bool() const noexcept;
//! Returns an std::chrono::time_point
constexpr const Duration &repr() const noexcept;
// ----------------------------------------------------------------------
// Setter and getter
// ----------------------------------------------------------------------
public:
/**
* @brief Returns the maximum number of full seconds of this
* time span.
* @return Number of full seconds.
*/
constexpr Storage seconds() const;
/**
* @brief Returns the fractional part of the time span in
* microseconds.
* The number of microseconds returns is guaranteed to be less than
* one million (1000000).
* @return Fraction in microseconds.
*/
constexpr Storage microseconds() const noexcept;
/**
* @brief Returns this time span expressed in microseconds.
* @return Number of ticks in microseconds.
*/
constexpr Storage count() const noexcept;
//! Returns the absolute value of time
TimeSpan abs() const;
TimeSpan &set(Storage seconds, Storage usecs = 0);
void get(int *days, int *hours = nullptr,
int *minutes = nullptr, int *seconds = nullptr) const;
[[deprecated("Use get() instead")]]
void elapsedTime(int *days, int *hours = nullptr,
int *minutes = nullptr, int *seconds = nullptr) const;
//! Sets the microseconds
TimeSpan &setUSecs(Storage);
/**
* @brief Returns the time span in frational seconds.
* @return Fractional seconds as double.
*/
constexpr double length() const;
// ----------------------------------------------------------------------
// Public interface
// ----------------------------------------------------------------------
public:
/**
* @return A string representing the current time span.
*/
std::string toString() const;
/**
* @brief Converts a string to a time span representation.
* @param sv The input string_view
* @return The conversion result
*/
bool fromString(std::string_view sv);
// ----------------------------------------------------------------------
// Private members
// ----------------------------------------------------------------------
private:
Duration _repr{0};
friend class Time;
};
namespace Literals {
TimeSpan operator "" _weeks(long double weeks);
TimeSpan operator "" _weeks(unsigned long long int weeks);
TimeSpan operator "" _days(long double days);
TimeSpan operator "" _days(unsigned long long int days);
TimeSpan operator "" _hours(long double hours);
TimeSpan operator "" _hours(unsigned long long int hours);
TimeSpan operator "" _minutes(long double minutes);
TimeSpan operator "" _minutes(unsigned long long int minutes);
TimeSpan operator "" _seconds(long double seconds);
TimeSpan operator "" _seconds(unsigned long long int seconds);
TimeSpan operator "" _milliseconds(long double milliseconds);
TimeSpan operator "" _milliseconds(unsigned long long int milliseconds);
}
std::ostream &operator<<(std::ostream &os, const TimeSpan &ts);
/**
* @brief The Time class implements the representation of a point in time
* with microsecond precision.
*
* Internally it is represented with a date::time_point instance from the
* C++ date library of Howard Hinnant [1].
*
* Due to microseconds precision the valid date range is defined from
* -32768-01-01 to 32767-12-31.
*
* [1] https://github.com/HowardHinnant/date
*/
class Time {
// ----------------------------------------------------------------------
// Public types
// ----------------------------------------------------------------------
public:
using Storage = TimeSpan::Storage;
using Duration = TimeSpan::Duration;
using TimePoint = std::chrono::time_point<std::chrono::system_clock, Duration>;
static Time Null;
static const double MinTime;
static const double MaxTime;
// ----------------------------------------------------------------------
// Xstruction
// X'truction
// ----------------------------------------------------------------------
public:
TimeSpan();
TimeSpan(struct timeval*);
TimeSpan(const struct timeval&);
TimeSpan(double);
TimeSpan(long secs, long usecs);
//! Copy constructor
TimeSpan(const TimeSpan&);
// ----------------------------------------------------------------------
// Operators
// ----------------------------------------------------------------------
public:
//! Comparison
bool operator==(const TimeSpan&) const;
bool operator!=(const TimeSpan&) const;
bool operator< (const TimeSpan&) const;
bool operator<=(const TimeSpan&) const;
bool operator> (const TimeSpan&) const;
bool operator>=(const TimeSpan&) const;
//! Conversion
operator double() const;
operator const timeval&() const;
//! Assignment
TimeSpan& operator=(long t);
TimeSpan& operator=(double t);
TimeSpan& operator=(const TimeSpan& t);
//! Arithmetic
TimeSpan operator+(const TimeSpan&) const;
TimeSpan operator-(const TimeSpan&) const;
TimeSpan& operator+=(const TimeSpan&);
TimeSpan& operator-=(const TimeSpan&);
// ----------------------------------------------------------------------
// Interface
// ----------------------------------------------------------------------
public:
//! Returns the absolute value of time
TimeSpan abs() const;
//! Returns the seconds of the timespan
long seconds() const;
//! Returns the microseconds of the timespan
long microseconds() const;
//! Returns the (possibly negative) length of the timespan in seconds
double length() const;
//! Sets the seconds
TimeSpan& set(long seconds);
//! Sets the microseconds
TimeSpan& setUSecs(long);
//! Assigns the elapsed time to the passed out parameters
void elapsedTime(int* days, int* hours = nullptr,
int* minutes = nullptr, int* seconds = nullptr) const;
// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
protected:
struct timeval _timeval;
};
class SC_SYSTEM_CORE_API Time : public TimeSpan {
// ----------------------------------------------------------------------
// Public static data members
// ----------------------------------------------------------------------
public:
static const Time Null;
// ----------------------------------------------------------------------
// Xstruction
// ----------------------------------------------------------------------
public:
Time();
Time(long secs, long usecs);
explicit Time(const TimeSpan&);
explicit Time(const struct timeval&);
explicit Time(struct timeval*);
Time() = default;
Time(const Time &other) = default;
explicit constexpr Time(const TimePoint &tp);
explicit constexpr Time(Storage epochSeconds, Storage microSeconds = 0);
explicit Time(double);
Time(int year, int month, int day,
int hour = 0, int min = 0, int sec = 0,
int usec = 0);
//! Copy constructor
Time(const Time&);
// ----------------------------------------------------------------------
// Operators
// Assignment operators
// ----------------------------------------------------------------------
public:
//! Conversion
operator bool() const;
operator time_t() const;
//! Assignment
Time& operator=(const struct timeval& t);
Time& operator=(struct timeval* t);
Time& operator=(time_t t);
Time& operator=(double t);
//! Arithmetic
Time operator+(const TimeSpan&) const;
Time operator-(const TimeSpan&) const;
TimeSpan operator-(const Time&) const;
Time& operator+=(const TimeSpan&);
Time& operator-=(const TimeSpan&);
Time &operator=(double epoch);
// ----------------------------------------------------------------------
// Interface
// Comparison operators
// ----------------------------------------------------------------------
public:
//! Sets the time
Time& set(int year, int month, int day,
constexpr bool operator==(const Time &other) const noexcept;
constexpr bool operator!=(const Time &other) const noexcept;
constexpr bool operator<(const Time &other) const noexcept;
constexpr bool operator<=(const Time &other) const noexcept;
constexpr bool operator>(const Time &other) const noexcept;
constexpr bool operator>=(const Time &other) const noexcept;
// ----------------------------------------------------------------------
// Arithmetic operators
// ----------------------------------------------------------------------
public:
Time &operator+=(const TimeSpan &ts);
Time &operator-=(const TimeSpan &ts);
constexpr Time operator+(const TimeSpan &ts) const;
constexpr Time operator-(const TimeSpan &ts) const;
constexpr TimeSpan operator-(const Time &tp) const;
// ----------------------------------------------------------------------
// Conversion operators
// ----------------------------------------------------------------------
public:
constexpr explicit operator TimePoint() const noexcept;
constexpr explicit operator double() const noexcept;
[[deprecated("Use OPT(Time) instead")]]
constexpr explicit operator bool() const noexcept;
constexpr const TimePoint &repr() const noexcept;
// ----------------------------------------------------------------------
// Public interface
// ----------------------------------------------------------------------
public:
/**
* @brief Returns whether the time object is a valid time or not.
* Internally the minimum possible value is used to declare an invalid
* time which is for backwards compatibility 1970-01-01 00:00:00.
* @return True if valid, false otherwise.
*/
[[deprecated("Use OPT(Time) instead")]]
constexpr bool valid() const;
/**
* @brief Sets the time object with y/m/d and h/m/s/u individually.
* The resulting time will be defined in seconds from Jan. 1, 1970 UTC.
* If local time is desired then call toLocalTime() afterwards.
* \code
* Time t;
* t.set(2020,1,1,12,00,00).toLocalTime()
* \endcode
* @param year The year between -32767 and 32768
* @param month The month between 1 and 12
* @param day The day between 1 and 31
* @param hour The hour of the day between 0 and 23
* @param min The minute of the hour between 0 and 59
* @param sec The second of the minute between 0 and 59
* @param usec The microseconds of the second between 0 and 999999
* @return this instance
*/
Time &set(int year, int month, int day,
int hour, int min, int sec,
int usec);
//! Sets the time with yday intepreted as the days since January 1st
//! (0-365)
Time& set2(int year, int yday,
int hour, int min, int sec,
int usec);
//! Fill the parameters with the currently set time values
//! @return The error flag
/**
* @brief Retrieves individual date and time components.
* @param year The year between -32767 and 32768
* @param month The month of the year between 1 and 12
* @param day The day of the month between 1 and 31
* @param hour The hour of the day between 0 and 23
* @param min The minute of the hour between 0 and 59
* @param sec The second of the minute between 0 and 59
* @param usec The microseconds of the second between 0 and 999999
* @return Success flag
*/
bool get(int *year, int *month = nullptr, int *day = nullptr,
int *hour = nullptr, int *min = nullptr, int *sec = nullptr,
int *usec = nullptr) const;
//! Fill the parameters with the currently set time values with yday
//! set to the days since January 1st (0-365)
//! @return The error flag
/**
* @brief Sets the time object with y/d and h/m/s/u individually.
* The resulting time will be defined in seconds from Jan. 1, 1970 UTC.
* If local time is desired then call toLocalTime() afterwards.
* \code
* Time t;
* t.set(2020,1,1,12,00,00).toLocalTime()
* \endcode
* @param year The year between -32767 and 32768
* @param yday The day of the year between 0 and 365
* @param hour The hour of the day between 0 and 23
* @param min The minute of the hour between 0 and 59
* @param sec The second of the minute between 0 and 59
* @param usec The microseconds of the second between 0 and 999999
* @return this instance
*/
Time &set2(int year, int yday,
int hour, int min, int sec,
int usec);
/**
* @brief Retrieves individual date and time components.
* @param year The year between -32767 and 32768
* @param yday The day of the year between 0 and 365
* @param hour The hour of the day between 0 and 23
* @param min The minute of the hour between 0 and 59
* @param sec The second of the minute between 0 and 59
* @param usec The microseconds of the second between 0 and 999999
* @return Success flag
*/
bool get2(int *year, int *yday = nullptr,
int *hour = nullptr, int *min = nullptr, int *sec = nullptr,
int *usec = nullptr) const;
//! Returns the current localtime
static Time LocalTime();
/**
* @brief Alias for utc()
* @return The current time in UTC
*/
Time &now();
/**
* @return A string containing the local time zone name/abbreviation
* This is an alias for utc().
* @return The current time in UTC
*/
static std::string LocalTimeZone();
//! Returns the current gmtime
static Time UTC();
//! Alias for UTC()
static Time GMT();
/** Creates a time from the year and the day of the year
@param year The year, including the century (for example, 1988)
@param year_day The day of the year [0..365]
@return The time value
*/
static Time FromYearDay(int year, int year_day);
/**
* @return The offset from UTC/GMT time to local time, essentially
* localtime minus GMT.
*/
TimeSpan localTimeZoneOffset() const;
//! Saves the current localtime in the calling object
Time &localtime();
//! Saves the current gmtime in the calling object
Time &utc();
//! Alias for utc()
Time &gmt();
//! Converts the time to localtime
Time toLocalTime() const;
//! Converts the time to gmtime
Time toUTC() const;
//! Alias for toUTC()
Time toGMT() const;
//! Returns whether the date is valid or not
bool valid() const;
/** Converts the time to string using format fmt.
@param fmt The format string can contain any specifiers
as allowed for strftime. Additional the '%f'
specifier is replaced by the fraction of the seconds.
Example:
toString("%FT%T.%fZ") = "1970-01-01T00:00:00.0000Z"
@return A formatted string
/**
* @return The current time in UTC
*/
std::string toString(const char* fmt) const;
Time &utc();
/**
* Converts the time to a string using the ISO time description
* @return A formatted string
* @return The ISO string of the time in UTC
*/
std::string iso() const;
/**
* @return A string representing the current time point without
* time zone information, UTC time.
*/
std::string toString(const char *format) const;
/**
* @brief Converts the time point to a string in the current
* system's time zone.
* @param format The string format.
* @return The formatted string
*/
std::string toLocalString(const char *format) const;
/**
* @brief Converts the time point to a string in a given
* time zone.
* This method may throw an std::runtime_error if the provided time
* zone does not exist.
* @param format The string format.
* @return The formatted string
*/
std::string toZonedString(const char *format, const std::string &tz) const;
/**
* Converts a string into a time representation.
* @param str The string representation of the time
* @return The conversion result
*/
bool fromString(std::string_view sv);
/**
* Converts a string into a time representation.
* @param str The string representation of the time
@ -268,43 +466,120 @@ class SC_SYSTEM_CORE_API Time : public TimeSpan {
* specification (-> toString)
* @return The conversion result
*/
bool fromString(const char* str, const char* fmt);
bool fromString(std::string_view sv, const char *format);
/**
* Converts a string into a time representation.
* @brief Converts a string to a Time object.
* This method throws a runtime_error if the input string cannot
* be parsed into a valid Time.
* @param str The string representation of the time
* @return The conversion result
* @return A Time object
*/
bool fromString(const char* str);
static Time FromString(const std::string &str);
/**
* Converts a string into a time representation.
* @brief Converts a string to a Time object.
* This method throws a runtime_error if the input string cannot
* be parsed into a valid Time given the format.
* @param str The string representation of the time
* @return The conversion result
* @param fmt The format string containing the conversion
* specification (-> toString)
* @return A Time object
*/
bool fromString(const std::string &str);
static Time FromString(const std::string &str, const char *format);
/**
* Static method to create a time value from a string.
* The parameters are the same as in Time::fromString.
*/
static Time FromString(const char* str, const char* fmt);
* @brief Constructs a time object from a year and the day of the year.
* @param year The year between -32767 and 32768
* @param doy The day of the year between 1 and 366. Note that in
* contrast to set2 and get2 the doy is not starting with 0
* at January 1st but with 1.
* @return
*/
static Time FromYearDay(int year, int doy);
/**
* Static method to convert a time from a string without
* an explicit format.
* @param str The string representation of the time.
* @return None if conversion failed, a valid instance otherwise.
* @return The number of seconds since Jan. 1, 1970.
*
* Backwards compatibility alias for epochSeconds().
*/
static OPT(Time) FromString(const char* str);
[[deprecated("Use epochSeconds() instead")]]
constexpr Storage seconds() const;
/**
* Convenience method for fromString(const char*).
* @return The number of seconds since Jan. 1, 1970.
*/
static OPT(Time) FromString(const std::string &str);
constexpr Storage epochSeconds() const;
/**
* @return The number of seconds with fractional seconds since
* Jan. 1, 1970.
*/
constexpr double epoch() const;
/**
* @return Seconds fraction.
*/
constexpr int microseconds() const;
Time &setUSecs(Storage ms);
static Time FromEpoch(Storage secs, Storage usecs);
static Time FromEpoch(double secs);
//! Returns the current time in UTC. This is an alias for UTC().
static Time Now();
//! Returns the current time in GMT. This is an alias for UTC().
[[deprecated("Use UTC() instead")]] static Time GMT();
//! Returns the current time in UTC
static Time UTC();
//! Returns the current time as UTC plus the time zone offset.
static Time LocalTime();
static std::string LocalTimeZone();
//! Converts the time of the UTC representation to local time.
//! This effectively adds the local timezone offset.
Time toLocalTime() const;
//! Converts the time of the local time representation to UTC. This
//! effectively removes the local timezone offset.
Time toUTC() const;
//! Converts the time of the local time representation to UTC. This
//! effectively removes the local timezone offset.
[[deprecated("Use toUTC() instead")]] Time toGMT() const;
/**
* @brief Returns the local timezone offset with respect to the
* time currently stored.
* @return The local timezone offset as @TimeSpan
*/
TimeSpan localTimeZoneOffset() const;
/**
* @brief Returns the timezone offset for a given timezone.
*
* If the timezone is unknown then a runtime_error will be thrown.
* @return The timezone offset as @TimeSpan
*/
TimeSpan timeZoneOffset(const std::string &tzName) const;
private:
TimePoint _repr{Duration{0}};
};
std::ostream &operator<<(std::ostream &os, const Time &time);
#include "datetime.ipp"
}
}

View File

@ -0,0 +1,546 @@
// --------------------------------------------------------------------------
// Implementation of inline functions
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr TimeSpan::TimeSpan(Storage secs, Storage usecs)
: _repr(Seconds(secs) + MicroSeconds(usecs)) {}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline TimeSpan::TimeSpan(double ts) {
*this = ts;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template<typename Rep, typename Period>
inline constexpr TimeSpan::TimeSpan(const std::chrono::duration<Rep, Period> &duration)
: _repr(std::chrono::duration_cast<Duration>(duration)) {}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr bool TimeSpan::operator==(const TimeSpan &other) const noexcept {
return _repr == other._repr;
}
inline constexpr bool TimeSpan::operator!=(const TimeSpan &other) const noexcept {
return _repr != other._repr;
}
inline constexpr bool TimeSpan::operator<=(const TimeSpan &other) const noexcept {
return _repr <= other._repr;
}
inline constexpr bool TimeSpan::operator<(const TimeSpan &other) const noexcept {
return _repr < other._repr;
}
inline constexpr bool TimeSpan::operator>=(const TimeSpan &other) const noexcept {
return _repr >= other._repr;
}
inline constexpr bool TimeSpan::operator>(const TimeSpan &other) const noexcept {
return _repr > other._repr;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr TimeSpan TimeSpan::operator+(const TimeSpan &other) const {
return TimeSpan(_repr + other._repr);
}
inline constexpr TimeSpan TimeSpan::operator-(const TimeSpan &other) const {
return TimeSpan(_repr - other._repr);
}
inline constexpr TimeSpan TimeSpan::operator*(int op) const {
return TimeSpan(Duration(Storage(_repr.count() * op)));
}
inline constexpr TimeSpan TimeSpan::operator*(size_t op) const {
return TimeSpan(Duration(Storage(_repr.count() * op)));
}
inline constexpr TimeSpan TimeSpan::operator*(double op) const {
return TimeSpan(Duration(Storage(_repr.count() * op)));
}
inline constexpr TimeSpan TimeSpan::operator/(int op) const {
return TimeSpan(Duration(Storage(_repr.count() / op)));
}
inline constexpr TimeSpan TimeSpan::operator/(size_t op) const {
return TimeSpan(Duration(Storage(_repr.count() / op)));
}
inline constexpr TimeSpan TimeSpan::operator/(double op) const {
return TimeSpan(Duration(Storage(_repr.count() / op)));
}
inline constexpr TimeSpan TimeSpan::operator-() const {
return TimeSpan(Duration(Storage(-_repr.count())));
}
inline TimeSpan &TimeSpan::operator+=(const TimeSpan &other) {
_repr += other._repr;
return *this;
}
inline TimeSpan &TimeSpan::operator-=(const TimeSpan &other) {
_repr -= other._repr;
return *this;
}
inline TimeSpan &TimeSpan::operator*=(int op) {
_repr = Duration(Storage(_repr.count() * op));
return *this;
}
inline TimeSpan &TimeSpan::operator*=(size_t op) {
_repr = Duration(Storage(_repr.count() * op));
return *this;
}
inline TimeSpan &TimeSpan::operator*=(double op) {
_repr = Duration(Storage(_repr.count() * op));
return *this;
}
inline TimeSpan &TimeSpan::operator/=(int op) {
_repr = Duration(Storage(_repr.count() / op));
return *this;
}
inline TimeSpan &TimeSpan::operator/=(size_t op) {
_repr = Duration(Storage(_repr.count() / op));
return *this;
}
inline TimeSpan &TimeSpan::operator/=(double op) {
_repr = Duration(Storage(_repr.count() / op));
return *this;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr TimeSpan::operator Duration() const noexcept {
return _repr;
}
inline constexpr TimeSpan::operator double() const noexcept {
return length();
}
inline constexpr TimeSpan::operator bool() const noexcept {
return count() > 0;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr const TimeSpan::Duration &TimeSpan::repr() const noexcept {
return _repr;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
namespace Literals {
inline TimeSpan operator "" _weeks(long double weeks) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<double, std::ratio<86400*7> >(weeks));
}
inline TimeSpan operator "" _weeks(unsigned long long int weeks) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<unsigned long long int, std::ratio<86400*7> >(weeks));
}
inline TimeSpan operator "" _days(long double days) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<double, std::ratio<86400> >(days));
}
inline TimeSpan operator "" _days(unsigned long long int days) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<unsigned long long int, std::ratio<86400> >(days));
}
inline TimeSpan operator "" _hours(long double hours) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<double, std::ratio<3600> >(hours));
}
inline TimeSpan operator "" _hours(unsigned long long int hours) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<unsigned long long int, std::ratio<3600> >(hours));
}
inline TimeSpan operator "" _minutes(long double minutes) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<double, std::ratio<60> >(minutes));
}
inline TimeSpan operator "" _minutes(unsigned long long int minutes) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<unsigned long long int, std::ratio<60> >(minutes));
}
inline TimeSpan operator "" _seconds(long double seconds) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<double, std::ratio<1> >(seconds));
}
inline TimeSpan operator "" _seconds(unsigned long long int seconds) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<unsigned long long int, std::ratio<1> >(seconds));
}
inline TimeSpan operator "" _milliseconds(long double mseconds) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<double, std::ratio<1, 1000> >(mseconds));
}
inline TimeSpan operator "" _milliseconds(unsigned long long int mseconds) {
using namespace std::chrono;
return duration_cast<TimeSpan::Duration>(duration<unsigned long long int, std::ratio<1, 1000> >(mseconds));
}
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline void TimeSpan::elapsedTime(int* days, int* hours,
int* minutes, int* seconds) const {
get(days, hours, minutes, seconds);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr TimeSpan::Storage TimeSpan::seconds() const {
return std::chrono::duration_cast<Seconds>(_repr).count();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr TimeSpan::Storage TimeSpan::microseconds() const noexcept {
// _repr is microseconds
return _repr.count() % 1000000;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr TimeSpan::Storage TimeSpan::count() const noexcept {
return _repr.count();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline TimeSpan &TimeSpan::set(Storage secs, Storage usecs) {
using namespace std::chrono;
_repr = MicroSeconds(secs * 1000000 + usecs);
return *this;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline TimeSpan &TimeSpan::setUSecs(Storage usecs) {
using namespace std::chrono;
_repr = MicroSeconds(seconds() * 1000000 + usecs);
return *this;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr double TimeSpan::length() const {
return std::chrono::duration_cast<MicroSeconds>(_repr).count() * 1E-6;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr Time::Time(Storage epochSeconds, Storage epochMicroSeconds)
: _repr(TimePoint(TimeSpan::Seconds(epochSeconds) + TimeSpan::MicroSeconds(epochMicroSeconds)))
{}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr Time::Time(const TimePoint &tp) : _repr(tp) {}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr bool Time::operator==(const Time &other) const noexcept {
return _repr == other._repr;
}
inline constexpr bool Time::operator!=(const Time &other) const noexcept {
return _repr != other._repr;
}
inline constexpr bool Time::operator<(const Time &other) const noexcept {
return _repr < other._repr;
}
inline constexpr bool Time::operator<=(const Time &other) const noexcept {
return _repr <= other._repr;
}
inline constexpr bool Time::operator>(const Time &other) const noexcept {
return _repr > other._repr;
}
inline constexpr bool Time::operator>=(const Time &other) const noexcept {
return _repr >= other._repr;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline Time &Time::operator+=(const TimeSpan &ts) {
_repr += ts._repr;
return *this;
}
inline Time &Time::operator-=(const TimeSpan &ts) {
_repr -= ts._repr;
return *this;
}
inline constexpr Time Time::operator+(const TimeSpan &ts) const {
return Time(_repr + ts._repr);
}
inline constexpr Time Time::operator-(const TimeSpan &ts) const {
return Time(_repr - ts._repr);
}
inline constexpr TimeSpan Time::operator-(const Time &tp) const {
return TimeSpan(_repr - tp._repr);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr Time::operator TimePoint() const noexcept {
return _repr;
}
inline constexpr Time::operator double() const noexcept {
return epoch();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr bool Time::valid() const {
return *this != Null;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr Time::operator bool() const noexcept {
return *this != Null;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr const Time::TimePoint &Time::repr() const noexcept {
return _repr;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr Time::Storage Time::seconds() const {
return epochSeconds();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr Time::Storage Time::epochSeconds() const {
return std::chrono::duration_cast<std::chrono::seconds>(_repr.time_since_epoch()).count();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr double Time::epoch() const {
return std::chrono::duration_cast<std::chrono::microseconds>(_repr.time_since_epoch()).count() * 1E-6;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline Time &Time::setUSecs(Storage usecs) {
using namespace std::chrono;
_repr = TimePoint(
std::chrono::duration_cast<Duration>(
TimeSpan::MicroSeconds(
static_cast<Storage>(
std::chrono::duration_cast<std::chrono::seconds>(
_repr.time_since_epoch()
).count() * 1000000 + usecs
)
)
)
);
return *this;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline constexpr int Time::microseconds() const {
return std::chrono::duration_cast<std::chrono::microseconds>(_repr.time_since_epoch()).count() % 1000000;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline Time &Time::gmt() {
return utc();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline Time Time::UTC() {
return Now();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline Time Time::LocalTime() {
return UTC().toLocalTime();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline Time Time::GMT() {
return Now();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline Time Time::Now() {
return Time().now();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline Time Time::toLocalTime() const {
return *this + localTimeZoneOffset();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline Time Time::toUTC() const {
return *this - localTimeZoneOffset();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
inline Time Time::toGMT() const {
return toUTC();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

View File

@ -30,9 +30,7 @@ namespace Core {
template <typename T>
struct SmartPointer {
typedef ::boost::intrusive_ptr<T> Impl;
};
using SmartPointer = ::boost::intrusive_ptr<T>;
template <typename B, typename D>
@ -52,10 +50,10 @@ struct isTypeOf {
#define TYPEDEF_SMARTPOINTER(classname) \
typedef Seiscomp::Core::SmartPointer<classname>::Impl classname##Ptr
using classname##Ptr = Seiscomp::Core::SmartPointer<classname>
#define TYPEDEF_CONST_SMARTPOINTER(classname) \
typedef Seiscomp::Core::SmartPointer<const classname>::Impl classname##CPtr
using classname##CPtr = Seiscomp::Core::SmartPointer<const classname>
#define DEFINE_SMARTPOINTER(classname) \
class classname; \

View File

@ -25,6 +25,7 @@
#include <seiscomp/core/io.h>
#include <ostream>
#include <string_view>
#include <fmt/ostream.h>
@ -48,7 +49,7 @@ class SC_SYSTEM_CORE_API Enumeration {
* case sensitive.
* @return The result of the conversion
*/
virtual bool fromString(const std::string &str) = 0;
virtual bool fromString(std::string_view sv) = 0;
/**
* Converts an enumeration value to an integer
@ -160,7 +161,7 @@ class Enum : public Enumeration {
// ------------------------------------------------------------------
public:
const char *toString() const override;
bool fromString(const std::string &str) override;
bool fromString(std::string_view sv) override;
int toInt() const override;
bool fromInt(int value) override;

View File

@ -90,13 +90,15 @@ inline const char* Enum<ENUMTYPE, END, NAMES>::toString() const {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
inline bool
Enum<ENUMTYPE, END, NAMES>::fromString(const std::string& str) {
Enum<ENUMTYPE, END, NAMES>::fromString(std::string_view sv) {
int index = int(0);
while( str != std::string(NAMES::name(index-0)) ) {
while ( sv != NAMES::name(index - 0) ) {
++index;
if ( index >= int(END) )
if ( index >= int(END) ) {
return false;
}
}
_value = static_cast<ENUMTYPE>(index);

View File

@ -37,8 +37,8 @@ class SC_SYSTEM_CORE_API GeneralException : public std::exception {
GeneralException( const std::string& str);
virtual ~GeneralException() throw();
virtual const char* what( void ) const throw();
virtual const char* what( void ) const throw() override;
private:
std::string _descr;

View File

@ -62,8 +62,9 @@ class ClassFactoryInterface {
using RootType = ROOT_TYPE;
using ClassPool = std::map<std::string, ClassFactoryInterface<ROOT_TYPE>*>;
using ClassNames = std::map<const RTTI*, std::string>;
using NameList = std::list<std::string>;
// ----------------------------------------------------------------------
// X'truction
// ----------------------------------------------------------------------
@ -93,12 +94,17 @@ class ClassFactoryInterface {
static const char* ClassName(const RTTI *rtti);
//! Looks up a class factory for a given class name
static ClassFactoryInterface* FindByClassName(const char *className);
static ClassFactoryInterface *FindByClassName(const char *className);
static ClassFactoryInterface *FindByClassName(const std::string &className);
static bool IsTypeOf(const char *baseName, const char *derivedName);
//! Returns the number of registered classes
static unsigned int NumberOfRegisteredClasses();
//! Returns the number of registered classes. This is equal to
//! Classes().size().
static size_t NumberOfRegisteredClasses();
//! Returns the registered classes.
static const ClassNames &RegisteredClasses();
//! Returns the name of the class (as given during construction) which can be created
//! by this factory
@ -167,7 +173,7 @@ class AbstractClassFactory : public ClassFactoryInterface<ROOT_TYPE> {
protected:
//! Always returns nullptr
ROOT_TYPE *create() const;
ROOT_TYPE *create() const override;
};
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -200,7 +206,7 @@ class ClassFactory : public ClassFactoryInterface<ROOT_TYPE> {
protected:
//! The actual creation
ROOT_TYPE* create() const;
ROOT_TYPE* create() const override;
};

View File

@ -124,12 +124,14 @@ const char *ClassFactoryInterface<ROOT_TYPE>::ClassName(const RTTI *info) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename ROOT_TYPE>
ClassFactoryInterface<ROOT_TYPE> *ClassFactoryInterface<ROOT_TYPE>::FindByClassName(const char *className) {
if ( !className )
if ( !className ) {
return nullptr;
}
typename ClassPool::iterator it = Classes().find(className);
if ( it == Classes().end() )
auto it = Classes().find(className);
if ( it == Classes().end() ) {
return nullptr;
}
return (*it).second;
}
@ -140,8 +142,33 @@ ClassFactoryInterface<ROOT_TYPE> *ClassFactoryInterface<ROOT_TYPE>::FindByClassN
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename ROOT_TYPE>
unsigned int ClassFactoryInterface<ROOT_TYPE>::NumberOfRegisteredClasses() {
return static_cast<unsigned int>(Classes().size());
ClassFactoryInterface<ROOT_TYPE> *
ClassFactoryInterface<ROOT_TYPE>::FindByClassName(const std::string &className) {
if ( auto it = Classes().find(className); it != Classes().end() ) {
return it->second;
}
return nullptr;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename ROOT_TYPE>
size_t ClassFactoryInterface<ROOT_TYPE>::NumberOfRegisteredClasses() {
return Classes().size();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename ROOT_TYPE>
const typename ClassFactoryInterface<ROOT_TYPE>::ClassNames &
ClassFactoryInterface<ROOT_TYPE>::RegisteredClasses() {
return Names();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -216,7 +243,7 @@ bool ClassFactoryInterface<ROOT_TYPE>::RegisterFactory(ClassFactoryInterface<ROO
Classes()[factory->className()] = factory;
Names()[factory->typeInfo()] = factory->className();
return true;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

View File

@ -42,7 +42,7 @@ class GenericMessage : public ::Seiscomp::Core::Message {
// ----------------------------------------------------------------------
public:
using AttachmentType = T;
using AttachmentList = std::list<typename Seiscomp::Core::SmartPointer<T>::Impl>;
using AttachmentList = std::list<Seiscomp::Core::SmartPointer<T>>;
typedef typename AttachmentList::iterator iterator;
typedef typename AttachmentList::const_iterator const_iterator;
@ -70,8 +70,8 @@ class GenericMessage : public ::Seiscomp::Core::Message {
* @retval true The operation was successfull and the object has been attached properly
* @retval false The object is nullptr or the object has been attached already
*/
bool attach(AttachmentType* attachment);
bool attach(typename Seiscomp::Core::SmartPointer<AttachmentType>::Impl& attachment);
bool attach(AttachmentType *attachment);
bool attach(typename Seiscomp::Core::SmartPointer<AttachmentType> &attachment);
/**
* Detaches an already attached object from the message
@ -79,8 +79,8 @@ class GenericMessage : public ::Seiscomp::Core::Message {
* @retval true The object has been detached successfully
* @retval false The object has not been attached before
*/
bool detach(AttachmentType* attachment);
bool detach(typename Seiscomp::Core::SmartPointer<AttachmentType>::Impl& attachment);
bool detach(AttachmentType *attachment);
bool detach(typename Seiscomp::Core::SmartPointer<AttachmentType> &attachment);
/**
* Detaches an object from the message
@ -91,7 +91,7 @@ class GenericMessage : public ::Seiscomp::Core::Message {
iterator detach(iterator it);
//! Removes all attachments from the message
void clear();
virtual void clear() override;
//! Returns the iterators for begin and end of
//! the attachment list
@ -102,19 +102,19 @@ class GenericMessage : public ::Seiscomp::Core::Message {
const_iterator end() const;
//! Implemented from baseclass
bool empty() const;
bool empty() const override;
/**
* @return Returns the number of objects attached to a message
*/
int size() const;
int size() const override;
// ----------------------------------------------------------------------
// Protected interface
// ----------------------------------------------------------------------
protected:
MessageIterator::Impl* iterImpl() const;
MessageIterator::Impl* iterImpl() const override;
// ----------------------------------------------------------------------
// Implementation
@ -132,7 +132,7 @@ class GenericMessage : public ::Seiscomp::Core::Message {
class APIDef TYPENAME : public ::Seiscomp::Core::GenericMessage<CLASS> { \
DECLARE_SC_CLASS(TYPENAME); \
}; \
typedef ::Seiscomp::Core::SmartPointer<TYPENAME>::Impl TYPENAME##Ptr
using TYPENAME##Ptr = ::Seiscomp::Core::SmartPointer<TYPENAME>
#define IMPLEMENT_MESSAGE_FOR(CLASS, TYPENAME, NAME) \
IMPLEMENT_SC_CLASS_DERIVED(TYPENAME, ::Seiscomp::Core::Message, NAME)

View File

@ -26,15 +26,15 @@ class MessageIteratorImplT : public MessageIterator::Impl {
: _it(it), _end(end) {}
public:
MessageIterator::Impl* clone() const {
MessageIterator::Impl* clone() const override {
return new MessageIteratorImplT<T>(_it, _end);
}
Seiscomp::Core::BaseObject* get() const {
Seiscomp::Core::BaseObject* get() const override {
return _it == _end?nullptr:(*_it).get();
}
void next() {
void next() override {
++_it;
}
@ -86,10 +86,10 @@ inline bool GenericMessage<T>::attach(AttachmentType* attachment) {
iterator it = std::find(_attachments.begin(), _attachments.end(), attachment);
if ( it != _attachments.end() )
return false;
_attachments.push_back(attachment);
return true;
return true;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -98,9 +98,9 @@ inline bool GenericMessage<T>::attach(AttachmentType* attachment) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename T>
inline bool GenericMessage<T>::attach(typename Seiscomp::Core::SmartPointer<AttachmentType>::Impl& attachment) {
inline bool GenericMessage<T>::attach(typename Seiscomp::Core::SmartPointer<AttachmentType> &attachment) {
return attach(attachment.get());
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -124,7 +124,7 @@ inline bool GenericMessage<T>::detach(AttachmentType* attachment) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename T>
inline bool GenericMessage<T>::detach(typename Seiscomp::Core::SmartPointer<AttachmentType>::Impl& attachment) {
inline bool GenericMessage<T>::detach(typename Seiscomp::Core::SmartPointer<AttachmentType> &attachment) {
return detach(attachment.get());
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

View File

@ -44,23 +44,23 @@ class SC_SYSTEM_CORE_API GenericRecord : public Record {
public:
//! Default Constructor
GenericRecord(Array::DataType dt = Array::DOUBLE, Hint h = DATA_ONLY);
//! Initializing Constructor
GenericRecord(std::string net, std::string sta,
std::string loc, std::string cha,
Core::Time stime, double fsamp, int tqual = -1,
Array::DataType dt = Array::DOUBLE,
Hint h = DATA_ONLY);
//! Copy Constructor
GenericRecord(const GenericRecord& rec);
//! Another Constructor
GenericRecord(const Record& rec);
//! Destructor
virtual ~GenericRecord();
// ----------------------------------------------------------------------
// Operators
@ -68,7 +68,7 @@ class SC_SYSTEM_CORE_API GenericRecord : public Record {
public:
//! Assignment operator
GenericRecord& operator=(const GenericRecord& rec);
// ----------------------------------------------------------------------
// Public interface
@ -78,20 +78,20 @@ class SC_SYSTEM_CORE_API GenericRecord : public Record {
void setSamplingFrequency(double freq);
//! Returns the data samples if the data is available; otherwise 0
Array* data();
Array *data();
//! Returns the data samples if the data is available; otherwise 0
const Array* data() const;
const Array* data() const override;
//! Same as data()
const Array* raw() const;
const Array* raw() const override;
//! Returns the clipmask. The size of the clipmask matches the size
//! of the data array and each element (bit) is set to one if the
//! sample at the same index is clipped. The returned pointer is
//! managed by this instance and must not be deleted. But it is safe
//! to store it in a smart pointer.
const BitSet *clipMask() const;
const BitSet *clipMask() const override;
//! Sets the data sample array. The ownership goes over to the record.
//! Note that this call will remove any clip mask set with previous
@ -113,14 +113,14 @@ class SC_SYSTEM_CORE_API GenericRecord : public Record {
void dataUpdated();
//! This method does nothing.
void saveSpace() const;
void saveSpace() const override;
//! Returns a deep copy of the calling object.
Record* copy() const;
Record* copy() const override;
void read(std::istream &in) override;
void write(std::ostream &out) override;
void read(std::istream &in);
void write(std::ostream &out);
// ----------------------------------------------------------------------
// Private members
@ -129,7 +129,7 @@ class SC_SYSTEM_CORE_API GenericRecord : public Record {
ArrayPtr _data;
BitSetPtr _clipMask;
};
}
#endif

View File

@ -114,7 +114,7 @@ class InterfaceFactory : public InterfaceFactoryInterface<T> {
public:
//! The actual creation
typename InterfaceFactoryInterface<T>::Interface* create() const { return new TYPE; }
typename InterfaceFactoryInterface<T>::Interface* create() const override { return new TYPE; }
};
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

View File

@ -39,7 +39,19 @@ namespace Core {
class BaseObject;
typedef boost::any MetaValue;
using MetaValue = boost::any;
template<typename ValueType>
inline ValueType metaValueCast(const MetaValue &operand) {
return boost::any_cast<ValueType>(operand);
}
template<typename ValueType>
inline ValueType metaValueCast(MetaValue &&operand) {
return boost::any_cast<ValueType>(operand);
}
using BadMetaValueCast = boost::bad_any_cast;
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

View File

@ -36,7 +36,7 @@ class Yes { No no[2]; };
template <typename T>
Yes isOptionalTester(boost::optional<T>*);
Yes isOptionalTester(Optional<T>*);
No isOptionalTester(void*);
@ -84,13 +84,13 @@ class MetaEnumImpl : public MetaEnum {
MetaEnumImpl() : MetaEnum() {}
public:
int keyCount() const { return T::Quantity; }
int keyCount() const override { return T::Quantity; }
//! Returns the key name at a given index
const char *key(int index) const;
const char *key(int index) const override;
const char *valueToKey(int value) const;
int keyToValue(const char *key) const;
const char *valueToKey(int value) const override;
int keyToValue(const char *key) const override;
};
#define DECLARE_METAENUM(CLASS, var) Seiscomp::Core::MetaEnumImpl<CLASS> var
@ -148,7 +148,7 @@ class MetaClassProperty : public MetaProperty {
public:
BaseObject *createClass() const {
BaseObject *createClass() const override {
return new T();
}
};
@ -235,14 +235,14 @@ class SimplePropertyHelper<T,U,F1,F2,0> : public MetaProperty {
SimplePropertyHelper(F1 setter, F2 getter)
: _setter(setter), _getter(getter) {}
bool write(BaseObject *object, MetaValue value) const {
bool write(BaseObject *object, MetaValue value) const override {
T *target = T::Cast(object);
if ( !target ) return false;
(target->*_setter)(boost::any_cast<U>(value));
(target->*_setter)(metaValueCast<U>(value));
return true;
}
bool writeString(BaseObject *object, const std::string &value) const {
bool writeString(BaseObject *object, const std::string &value) const override {
T *target = T::Cast(object);
if ( !target ) return false;
@ -254,13 +254,13 @@ class SimplePropertyHelper<T,U,F1,F2,0> : public MetaProperty {
return true;
}
MetaValue read(const BaseObject *object) const {
MetaValue read(const BaseObject *object) const override {
const T *target = T::ConstCast(object);
if ( !target ) throw GeneralException("invalid object");
return (target->*_getter)();
}
std::string readString(const BaseObject *object) const {
std::string readString(const BaseObject *object) const override {
const T *target = T::ConstCast(object);
if ( !target ) throw GeneralException("invalid object");
return toString((target->*_getter)());
@ -277,18 +277,18 @@ class SimplePropertyHelper<T,U,F1,F2,1> : public MetaProperty {
SimplePropertyHelper(F1 setter, F2 getter)
: _setter(setter), _getter(getter) {}
bool write(BaseObject *object, MetaValue value) const {
bool write(BaseObject *object, MetaValue value) const override {
T *target = T::Cast(object);
if ( !target ) return false;
if ( value.empty() )
(target->*_setter)(Core::None);
else
(target->*_setter)(boost::any_cast<U>(value));
(target->*_setter)(metaValueCast<U>(value));
return true;
}
bool writeString(BaseObject *object, const std::string &value) const {
bool writeString(BaseObject *object, const std::string &value) const override {
T *target = T::Cast(object);
if ( !target ) return false;
@ -298,19 +298,19 @@ class SimplePropertyHelper<T,U,F1,F2,1> : public MetaProperty {
typename Core::Generic::remove_optional<U>::type tmp;
if ( !fromString(tmp, value) )
return false;
(target->*_setter)(tmp);
}
return true;
}
MetaValue read(const BaseObject *object) const {
MetaValue read(const BaseObject *object) const override {
const T *target = T::ConstCast(object);
if ( !target ) throw GeneralException("invalid object");
return (target->*_getter)();
}
std::string readString(const BaseObject *object) const {
std::string readString(const BaseObject *object) const override {
const T *target = T::ConstCast(object);
if ( !target ) throw GeneralException("invalid object");
return toString((target->*_getter)());

View File

@ -21,41 +21,66 @@
#ifndef SEISCOMP_CORE_OPTIONAL_H
#define SEISCOMP_CORE_OPTIONAL_H
#include <seiscomp/core.h>
#include <exception>
#include <boost/optional.hpp>
#include <boost/none.hpp>
#include <exception>
#include <optional>
#include <type_traits>
namespace Seiscomp {
namespace Core {
/** \brief Redefines boost::optional<T>
/** \brief Redefines std::optional<T>
* Optional values can be set or unset.
* \code
* void print(const Optional<int>::Impl& v) {
* void print(const Optional<int> &v) {
* if ( !v )
* cout << "value of v is not set" << endl;
* else
* cout << *v << endl;
* }
*
* Optional<int>::Impl a = 5;
* Optional<int> a = 5;
* print(a); // output: "5"
* a = None;
* print(a); // output: "value of v is not set"
* \endcode
*/
template <typename T>
struct Optional {
typedef ::boost::optional<T> Impl;
};
using Optional = ::std::optional<T>;
using NoneType = ::std::nullopt_t;
/** Defines None */
SC_SYSTEM_CORE_API extern ::boost::none_t const None;
SC_SYSTEM_CORE_API extern NoneType const None;
template <class...>
struct False : std::integral_constant<bool, false> {};
template <class...>
struct True : std::integral_constant<bool, true> {};
// Checks whether a type is wrapped with optional or not.
template <typename>
struct isOptional : std::false_type {};
template<template<class...> class U, typename ...Args>
struct isOptional<U<Args...>>
: std::integral_constant<
bool,
std::is_base_of<std::optional<Args...>, U<Args...>>::value
|| std::is_base_of<boost::optional<Args...>, U<Args...>>::value
> {};
template <typename T>
T value(const boost::optional<T>&);
T value(const Optional<T>&);
class SC_SYSTEM_CORE_API ValueError : public std::exception {
public:
@ -63,16 +88,19 @@ class SC_SYSTEM_CORE_API ValueError : public std::exception {
~ValueError() throw();
public:
const char* what() const throw();
const char* what() const throw() override;
};
/** Macro to use optional values easily */
#define OPT(T) Seiscomp::Core::Optional<T>::Impl
#define OPT(T) Seiscomp::Core::Optional<T>
/** Macro to use optional values as const reference */
#define OPT_CR(T) const Seiscomp::Core::Optional<T>::Impl&
#define OPT_CR(T) const Seiscomp::Core::Optional<T>&
#include <seiscomp/core/optional.inl>
}
}

View File

@ -19,7 +19,7 @@
template <typename T>
T value(const boost::optional<T>& v) {
T value(const Optional<T>& v) {
if ( v )
return *v;

View File

@ -43,8 +43,8 @@ class SC_SYSTEM_CORE_API RecordSequence : public std::deque<RecordCPtr> {
// Public types
// ----------------------------------------------------------------------
public:
typedef std::deque<Core::TimeWindow> TimeWindowArray;
typedef std::pair<double,double> Range;
using TimeWindowArray = std::deque<Core::TimeWindow>;
using Range = std::pair<double,double>;
// ----------------------------------------------------------------------
@ -81,28 +81,36 @@ class SC_SYSTEM_CORE_API RecordSequence : public std::deque<RecordCPtr> {
//! Set the time tolerance in samples
void setTolerance(double);
/**
* @brief Returns the lowest iterator to the element which intersects
* or is after a given timestamp.
* @param ts The timestamp.
* @return The iterator
*/
const_iterator lowerBound(const Core::Time &ts) const;
/**
* @brief Returns a highest iterator to the element which intersects
* or is before a given timestamp.
* @param ts The timestamp.
* @return The iterator.
*/
const_iterator upperBound(const Core::Time &ts) const;
//! Return Record's as one contiguous record. Compiled in is support for
//! float, double and int. If interpolation is enabled gaps will be linearly
//! interpolated between the last and the next sample.
template <typename T>
GenericRecord *contiguousRecord(const Seiscomp::Core::TimeWindow *tw = nullptr,
GenericRecord *contiguousRecord(const Core::TimeWindow *tw = nullptr,
bool interpolate = false) const;
//! DECPRECATED: For backward compatibility, does exactly the same as
//! contiguousRecord. Please use contiguousRecord in your
//! code. This method will be removed in future releases.
template <typename T>
GenericRecord *continuousRecord(const Seiscomp::Core::TimeWindow *tw = nullptr,
bool interpolate = false) const;
//! Time window currently in buffer, irrespective of gaps
Core::TimeWindow timeWindow() const;
//! The amplitude range in a given time window.
//! Returns (0,0) if the sequence is empty or no records fall inside
//! the given optional time window.
Range amplitudeRange(const Seiscomp::Core::TimeWindow *tw = nullptr) const;
Range amplitudeRange(const Core::TimeWindow *tw = nullptr) const;
//! returns the continuous time windows available
//! This is usually one time window but may be split into
@ -163,9 +171,9 @@ class SC_SYSTEM_CORE_API TimeWindowBuffer : public RecordSequence {
// Public RecordSequence interface overrides
// ----------------------------------------------------------------------
public:
virtual bool feed(const Record*);
virtual RecordSequence *copy() const;
virtual RecordSequence *clone() const;
virtual bool feed(const Record*) override;
virtual RecordSequence *copy() const override;
virtual RecordSequence *clone() const override;
// ----------------------------------------------------------------------
@ -215,9 +223,9 @@ class SC_SYSTEM_CORE_API RingBuffer : public RecordSequence {
// Public RecordSequence interface overrides
// ----------------------------------------------------------------------
public:
virtual bool feed(const Record*);
virtual RecordSequence *copy() const;
virtual RecordSequence *clone() const;
virtual bool feed(const Record*) override;
virtual RecordSequence *copy() const override;
virtual RecordSequence *clone() const override;
// ----------------------------------------------------------------------
@ -229,7 +237,7 @@ class SC_SYSTEM_CORE_API RingBuffer : public RecordSequence {
//! Return the maximum number of records the RingBuffer stores
unsigned int numberOfRecordsToStore() const;
//! Return the TimeSpan the RingBuffer stores
const Core::TimeSpan &timeSpanToStore() const;
@ -266,11 +274,11 @@ inline const Core::TimeWindow &TimeWindowBuffer::timeWindowToStore() const {
inline unsigned int RingBuffer::numberOfRecordsToStore() const {
return _nmax;
}
inline const Core::TimeSpan &RingBuffer::timeSpanToStore() const {
return _span;
}
}
#endif

View File

@ -131,13 +131,13 @@ class ObjectContainer {
typedef T Type;
//typedef C<T, std::allocator<T> > ContainerType;
typedef C ContainerType;
ObjectContainer(ContainerType& c, ADD a) : _container(&c), _add(a) {}
ContainerType& container() const {
return *_container;
}
bool add(T& v) const {
_add(v);
return true;
@ -188,9 +188,9 @@ ObjectContainer<C<T, std::allocator<T> >, T, ADD> containerMember(C<T, std::allo
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename Tgt, class ret, class T>
std::function<ret (const typename Core::SmartPointer<Tgt>::Impl &ptr)>
std::function<ret (const Core::SmartPointer<Tgt> &ptr)>
bindMemberFunction(ret (T::*f)(Tgt*), T* c) {
return [c,f](const typename Core::SmartPointer<Tgt>::Impl &ptr) {
return [c,f](const Core::SmartPointer<Tgt> &ptr) {
return (c->*f)(ptr.get());
};
}

View File

@ -32,6 +32,7 @@
#include <limits>
#include <string>
#include <string_view>
#include <vector>
#include <complex>
@ -72,10 +73,10 @@ template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
std::string toString(const Enum<ENUMTYPE, END, NAMES> &value);
template <typename T>
std::string toString(const std::vector<T> &v);
std::string toString(const std::vector<T> &v, char delimiter = ' ');
template <typename T>
std::string toString(const ::boost::optional<T> &v);
std::string toString(const Optional<T> &v);
template <typename T>
@ -102,20 +103,28 @@ std::ostream &operator<<(std::ostream &os, const Number<double> &s);
* @param str The source string
*/
template <typename T>
bool fromString(T &value, const std::string &str);
bool fromString(T &value, std::string_view sv);
template <typename T>
bool fromString(std::complex<T> &value, const std::string &str);
bool fromString(std::complex<T> &value, std::string_view sv);
SC_SYSTEM_CORE_API bool fromString(Time &value, const std::string &str);
SC_SYSTEM_CORE_API bool fromString(Enumeration &value, const std::string &str);
SC_SYSTEM_CORE_API bool fromString(std::string &value, const std::string &str);
template <>
bool fromString(TimeSpan &value, std::string_view sv);
template <>
bool fromString(Time &value, std::string_view sv);
template <>
bool fromString(Enumeration &value, std::string_view sv);
template <>
bool fromString(std::string &value, std::string_view sv);
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
bool fromString(Enum<ENUMTYPE, END, NAMES> &value, const std::string &str);
bool fromString(Enum<ENUMTYPE, END, NAMES> &value, std::string_view sv);
template <typename T>
bool fromString(std::vector<T> &vec, const std::string &str);
bool fromString(std::vector<T> &vec, std::string_view sv, char delimiter = ' ');
/**
@ -142,12 +151,12 @@ int split(std::vector<std::string> &tokens, const char *source,
const char *delimiter, bool compressOn = true);
/**
* @brief Convenience function which takes an std::string as source parameter
* @brief Convenience function which takes an std::string_view as source parameter
* rather than a const char pointer.
* See @ref split(std::vector<std::string> &, const char *, const char *, bool).
*/
SC_SYSTEM_CORE_API
int split(std::vector<std::string> &tokens, const std::string &source,
int split(std::vector<std::string> &tokens, std::string_view source,
const char *delimiter, bool compressOn = true);
/**
@ -205,13 +214,7 @@ SC_SYSTEM_CORE_API bool isEmpty(const char*);
* A case-insensitive comparison.
* @return Result as defined by strcmp
*/
SC_SYSTEM_CORE_API int compareNoCase(const std::string &a, const std::string &b);
/** Removes whitespace at the beginning and end of the string.
* @param string to be trimmed (in/out parameter)
* @return returns the trimmed string
*/
SC_SYSTEM_CORE_API std::string &trim(std::string &str);
SC_SYSTEM_CORE_API int compareNoCase(std::string_view a, std::string_view b);
template <typename T>
void toHex(std::string &target, T source);
@ -237,25 +240,17 @@ SC_SYSTEM_CORE_API bool wildcmp(const std::string &wild, const std::string &str)
SC_SYSTEM_CORE_API bool wildicmp(const char *wild, const char *str);
SC_SYSTEM_CORE_API bool wildicmp(const std::string &wild, const std::string &str);
// -------------------------------------------------------------------------
// Plain C string functions which do not modify the input string and work
// mostly with length rather than an terminating null byte.
// -------------------------------------------------------------------------
/**
* @brief Tokenizes an input string. Empty tokens will be skipped and not
* returned (also referred to as compression).
* @param str The input string. The address is modified that it will point to
* the next token.
* @param sv The input string. The address is modified that it will point to
* the next token.
* @param delim A string of characters of allowed delimiters
* @param len_source The source length. This parameter will be modified
* to match the remaining length of the string.
* @param len_tok The length of the returned token.
* @return The address to the token found or nullptr.
* @return The matching substring as string_view. If the data pointer is
* nullptr then no further matches are possible.
*/
template <typename T>
T *tokenize(T *&str, const char *delim, size_t &len_source, size_t &len_tok);
SC_SYSTEM_CORE_API
std::string_view tokenize(std::string_view &sv, const char *delim);
/**
* @brief Works like tokenize but does not compress empty tokens.
@ -267,6 +262,18 @@ T *tokenize(T *&str, const char *delim, size_t &len_source, size_t &len_tok);
* @param len_tok The length of the returned token.
* @return The address to the token found or nullptr.
*/
SC_SYSTEM_CORE_API
std::string_view tokenize2(std::string_view &sv, const char *delim);
// -------------------------------------------------------------------------
// Plain C string functions which do not modify the input string and work
// mostly with length rather than an terminating null byte.
// -------------------------------------------------------------------------
template <typename T>
T *tokenize(T *&str, const char *delim, size_t &len_source, size_t &len_tok);
template <typename T>
T *tokenize2(T *&str, const char *delim, size_t &len_source, size_t &len_tok);
@ -298,7 +305,7 @@ const char *tokenizeExt(size_t &lenTok, size_t &lenSource, const char *&source,
const char *whitespaces = " \t\n\v\f\r",
const char *quotes = "\"'");
/**
/**split(
* @brief Splits a string into several tokens separated by one of the specified
* delimiter characters. A delimiter character is ignored if it occurs in
* a quoted string or if it is protected by a backslash. Likewise quotes
@ -343,6 +350,7 @@ SC_SYSTEM_CORE_API bool isEmpty(const char*);
*/
char *trimFront(char *&data, size_t &len);
const char *trimFront(const char *&data, size_t &len);
SC_SYSTEM_CORE_API std::string_view trimFront(std::string_view sv);
/**
* @brief Removes whitespaces from the back of a string.
@ -353,6 +361,7 @@ const char *trimFront(const char *&data, size_t &len);
*/
char *trimBack(char *data, size_t &len);
const char *trimBack(const char *data, size_t &len);
SC_SYSTEM_CORE_API std::string_view trimBack(std::string_view sv);
/**
* @brief Strips whitespaces from the front and the back of the string.
@ -364,6 +373,9 @@ const char *trimBack(const char *data, size_t &len);
*/
char *trim(char *&data, size_t &len);
const char *trim(const char *&data, size_t &len);
SC_SYSTEM_CORE_API std::string_view trim(std::string_view sv);
SC_SYSTEM_CORE_API std::string &trim(std::string &str);
char *strnchr(char *p, size_t n, char c);
const char *strnchr(const char *p, size_t n, char c);
@ -460,6 +472,26 @@ class ContainerSource {
};
struct InputStringViewBuf : std::streambuf {
InputStringViewBuf(std::string_view sv) {
auto d = const_cast<char*>(sv.data());
this->setg(d, d, d + sv.size());
}
virtual pos_type seekoff(off_type off, std::ios_base::seekdir,
std::ios_base::openmode) override {
return off ? -1 : gptr() - eback();
}
};
struct InputStringViewStream : virtual InputStringViewBuf, std::istream {
InputStringViewStream(std::string_view sv)
: InputStringViewBuf(sv)
, std::istream(static_cast<std::streambuf*>(this)) {}
};
}
}

View File

@ -18,11 +18,8 @@
***************************************************************************/
#include <seiscomp/core/enumeration.h>
#include <cctype>
#include <sstream>
#include <complex>
namespace Seiscomp {
@ -92,18 +89,20 @@ std::string toString(const Enum<ENUMTYPE, END, NAMES>& value) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename T>
inline std::string toString(const std::vector<T>& v) {
typename std::vector<T>::const_iterator it = v.begin();
inline std::string toString(const std::vector<T>& v, char delimiter) {
auto it = v.begin();
std::string str;
if ( it != v.end() )
if ( it != v.end() ) {
str += toString(*it);
else
}
else {
return "";
}
++it;
while ( it != v.end() ) {
str += " ";
str += delimiter;
str += toString(*it);
++it;
}
@ -117,7 +116,7 @@ inline std::string toString(const std::vector<T>& v) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename T>
inline std::string toString(const ::boost::optional<T>& v) {
inline std::string toString(const Seiscomp::Core::Optional<T> &v) {
if ( !v )
return "None";
@ -128,6 +127,36 @@ inline std::string toString(const ::boost::optional<T>& v) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#if __cplusplus >= 201703L
template <typename T>
bool fromString(boost::optional<T> &value, const std::string &str) {
static_assert(
False<T>::value,
"String conversion for boost optional values is not supported"
);
return false;
}
#endif
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename T>
bool fromString(Optional<T> &value, const std::string &str) {
static_assert(
False<T>::value,
"String conversion for optional values is not supported"
);
return false;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
bool fromString(Enum<ENUMTYPE, END, NAMES>& value, const std::string& str) {
@ -154,7 +183,7 @@ inline bool fromString(std::complex<T>& value, const std::string& str) {
return false;
T realPart, imgPart;
if ( !fromString(realPart, str.substr(s+1, delimPos-s-1)) ) return false;
if ( !fromString(imgPart, str.substr(delimPos+1, e-delimPos-1)) ) return false;
@ -169,13 +198,16 @@ inline bool fromString(std::complex<T>& value, const std::string& str) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename T>
inline bool fromString(std::vector<T>& vec, const std::string& str) {
inline bool fromString(std::vector<T>& vec, std::string_view sv, char delimiter) {
std::vector<std::string> tokens;
split(tokens, str.c_str(), " ");
char tmp[2] = { delimiter, '\0' };
split(tokens, sv, tmp);
vec.clear();
for ( size_t i = 0; i < tokens.size(); ++i ) {
T v;
if ( !fromString(v, tokens[i]) )
if ( !fromString(v, tokens[i]) ) {
return false;
}
vec.push_back(v);
}
@ -188,28 +220,39 @@ inline bool fromString(std::vector<T>& vec, const std::string& str) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename T>
inline bool fromString(std::vector<std::complex<T> >& vec, const std::string& str) {
inline bool fromString(std::vector<std::complex<T> >& vec, std::string_view sv, char delimiter) {
std::vector<std::string> tokens;
split(tokens, str.c_str(), " ");
char tmp[2] = { delimiter, '\0' };
split(tokens, sv, tmp);
vec.clear();
for ( size_t i = 0; i < tokens.size(); ++i ) {
std::complex<T> v;
int count = 1;
size_t countPos = tokens[i].find_first_not_of(' ');
size_t countPos = tokens[i].find_first_not_of(delimiter);
if ( countPos != std::string::npos ) {
if ( tokens[i][countPos] != '(' ) {
size_t bracketPos = tokens[i].find('(', countPos);
// Invalid complex string
if ( bracketPos == std::string::npos ) continue;
if ( !fromString(count, tokens[i].substr(countPos, bracketPos-countPos)) )
if ( bracketPos == std::string::npos ) {
continue;
}
if ( !fromString(count, tokens[i].substr(countPos, bracketPos-countPos)) ) {
return false;
}
tokens[i] = tokens[i].substr(bracketPos);
}
}
if ( !fromString(v, tokens[i]) ) return false;
for ( int i = 0; i < count; ++i )
if ( !fromString(v, tokens[i]) ) {
return false;
}
for ( int c = 0; c < count; ++c ) {
vec.push_back(v);
}
}
return true;
@ -428,7 +471,7 @@ std::string join(const CONT &tokens, const std::string &separator) {
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <typename S, typename... Args>
inline std::string stringify(const S &format, Args &&...args) {
return fmt::vsprintf(format, fmt::make_printf_args(args...));
return fmt::sprintf(format, args...);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

View File

@ -21,44 +21,80 @@
#ifndef SC_CORE_TIMESPAN_H
#define SC_CORE_TIMESPAN_H
#include<seiscomp/core.h>
#include<seiscomp/core/datetime.h>
#include <seiscomp/core.h>
#include <seiscomp/core/datetime.h>
#include <seiscomp/core/optional.h>
#include <ostream>
namespace Seiscomp {
namespace Core {
class SC_SYSTEM_CORE_API TimeWindow {
// Xstruction
// ----------------------------------------------------------------------
// X'truction
// ----------------------------------------------------------------------
public:
TimeWindow();
TimeWindow() = default;
TimeWindow(const Time &startTime, double length);
TimeWindow(const Time &startTime, const TimeSpan length);
TimeWindow(const Time &startTime, const Time &endTime);
TimeWindow(const TimeWindow &tw);
~TimeWindow() {}
TimeWindow(const TimeWindow &other);
// Operators
// ----------------------------------------------------------------------
// Assignment operators
// ----------------------------------------------------------------------
public:
TimeWindow &operator=(const TimeWindow&);
// ----------------------------------------------------------------------
// Comparison operators
// ----------------------------------------------------------------------
public:
bool operator==(const TimeWindow&) const;
bool operator!=(const TimeWindow&) const;
// ----------------------------------------------------------------------
// Arithmetic operators
// ----------------------------------------------------------------------
public:
//! Returns the minimal timewindow including this and other
TimeWindow operator|(const TimeWindow &other) const;
//! Sets the minimal timewindow including this and other
TimeWindow &operator|=(const TimeWindow &other);
//! Returns the intersection of this and other
TimeWindow operator&(const TimeWindow &other) const;
//! Sets the intersection of this and other
TimeWindow &operator&=(const TimeWindow &other);
// ----------------------------------------------------------------------
// Cast operators
// ----------------------------------------------------------------------
public:
//! Returns if the time window has length larger than 0.
operator bool() const;
//! Returns the minimal timewindow including this and other
TimeWindow operator|(const TimeWindow &other) const;
// more operators :-)
// Interface
// ----------------------------------------------------------------------
// Public interface
// ----------------------------------------------------------------------
public:
Time startTime() const;
Time endTime() const;
double length() const;
TimeSpan length() const;
void set(const Time &t1, const Time &t2);
void setStartTime(const Time &t);
void setEndTime(const Time &t);
//! set length in seconds, affects endTime
void setLength(double length);
void setLength(TimeSpan length);
//! does it contain time t?
bool contains(const Time &t) const;
@ -68,111 +104,102 @@ class SC_SYSTEM_CORE_API TimeWindow {
//! is equal to time window?
//! +/- tolerance in seconds
bool equals(const TimeWindow &tw, double tolerance=0.0) const;
bool equals(const TimeWindow &tw, TimeSpan tolerance = TimeSpan(0, 0)) const;
//! does it overlap with time window tw?
bool overlaps(const TimeWindow &tw) const;
//! compute overlap with time window tw
TimeWindow overlap(const TimeWindow &tw) const;
//! test if this+other would form a contiguous time window
bool contiguous(const TimeWindow&, double tolerance=0) const;
bool contiguous(const TimeWindow &, TimeSpan tolerance = TimeSpan(0, 0)) const;
//! extend time window by appending the other (without check!)
void extend(const TimeWindow&);
//! Sets the intersection time window with this and other
TimeWindow &overlap(const TimeWindow &other);
//! merges this and other to the minimal timewindow overlapping both
TimeWindow merge(const TimeWindow&) const;
//! Computes the intersection with time window other
TimeWindow overlapped(const TimeWindow &other) const;
// Implementation
//! Merges other into this to the minimal timewindow overlapping both.
TimeWindow &merge(const TimeWindow &other);
//! Returns the minimal timewindow including this and other
TimeWindow merged(const TimeWindow &other) const;
// ----------------------------------------------------------------------
// Private members
// ----------------------------------------------------------------------
private:
Time _startTime, _endTime;
Time _startTime;
Time _endTime;
};
inline TimeWindow::TimeWindow()
{
set(Time(), Time());
}
inline TimeWindow::TimeWindow(const Time &startTime, double length)
{
set(startTime, startTime + Time(length)); // FIXME
}
class SC_SYSTEM_CORE_API OpenTimeWindow {
// ----------------------------------------------------------------------
// X'truction
// ----------------------------------------------------------------------
public:
OpenTimeWindow() = default;
OpenTimeWindow(const OPT(Time) &startTime, const OPT(Time) &endTime);
OpenTimeWindow(const OpenTimeWindow &other);
inline TimeWindow::TimeWindow(const Time &startTime, const Time &endTime)
{
set(startTime, endTime);
}
inline TimeWindow::TimeWindow(const TimeWindow &tw)
{
set(tw._startTime, tw._endTime);
}
// ----------------------------------------------------------------------
// Assignment operators
// ----------------------------------------------------------------------
public:
OpenTimeWindow &operator=(const OpenTimeWindow&);
inline bool TimeWindow::operator==(const TimeWindow &tw) const
{
return _startTime == tw._startTime && _endTime == tw._endTime;
}
inline bool TimeWindow::operator!=(const TimeWindow &tw) const
{
return _startTime != tw._startTime || _endTime != tw._endTime;
}
// ----------------------------------------------------------------------
// Comparison operators
// ----------------------------------------------------------------------
public:
bool operator==(const OpenTimeWindow&) const;
bool operator!=(const OpenTimeWindow&) const;
inline TimeWindow::operator bool() const
{
return (bool)_startTime && (bool)_endTime;
}
inline Time TimeWindow::startTime() const
{
return _startTime;
}
// ----------------------------------------------------------------------
// Public interface
// ----------------------------------------------------------------------
public:
OPT(Time) startTime() const;
OPT(Time) endTime() const;
OPT(TimeSpan) length() const;
inline Time TimeWindow::endTime() const
{
return _endTime;
}
void set(const OPT(Time) &t1, const OPT(Time) &t2);
void setStartTime(const OPT(Time) &t);
void setEndTime(const OPT(Time) &t);
inline double TimeWindow::length() const
{
return (double)(_endTime-_startTime);
}
//! does it contain time t?
bool contains(const Time &t) const;
inline void TimeWindow::set(const Time &startTime, const Time &endTime)
{
_startTime = startTime;
_endTime = endTime;
}
//! does it contain time window tw completely?
bool contains(const OpenTimeWindow &tw) const;
inline void TimeWindow::setStartTime(const Time &t)
{
_startTime = t;
}
//! does it overlap with time window tw?
bool overlaps(const OpenTimeWindow &tw) const;
inline void TimeWindow::setEndTime(const Time &t)
{
_endTime = t;
}
inline void TimeWindow::setLength(double length)
{
_endTime = _startTime + Time(length); // FIXME
}
// ----------------------------------------------------------------------
// Private members
// ----------------------------------------------------------------------
private:
OPT(Time) _startTime;
OPT(Time) _endTime;
};
inline bool TimeWindow::contains(const Time &t) const
{
return t >= _startTime && t < _endTime;
}
inline bool TimeWindow::contains(const TimeWindow &tw) const
{
return tw._startTime >= _startTime && tw._endTime <= _endTime;
}
std::ostream &operator<<(std::ostream &os, const TimeWindow &timeWindow);
std::ostream &operator<<(std::ostream &os, const OpenTimeWindow &timeWindow);
#include "timewindow.ipp"
}
}
#endif

View File

@ -31,12 +31,12 @@ namespace Seiscomp {
namespace Core {
/* #if (SC_API_VERSION >= SC_API_VERSION_CHECK(16, 4, 0)) */
/* #if (SC_API_VERSION >= SC_API_VERSION_CHECK(17, 0, 0)) */
#define SC_API_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
/* SC_API_VERSION is (major << 16) + (minor << 8) + patch. */
#define SC_API_VERSION 0x100400
#define SC_API_VERSION 0x110000
#define SC_API_VERSION_MAJOR(v) (v >> 16)
#define SC_API_VERSION_MINOR(v) ((v >> 8) & 0xff)
@ -46,6 +46,62 @@ namespace Core {
/******************************************************************************
API Changelog
******************************************************************************
"17.0.0" 0x110000
- Added Seiscomp::Gui::Scheme::records.showEngineeringValues
- Added Seiscomp::Gui::RecordView::showEngineeringValues(bool)
- Added Seiscomp::Gui::RecordWidget::showEngineeringValues(bool)
- Added Seiscomp::Client::Application::handleSOH
- Added Seiscomp::Processing::MagnitudeProcessor_MLc _c6, _H and _minDepth.
- Added Seiscomp::Processing::AmplitudeProcessor::parameter
- Made Seiscomp::IO::DatabaseInterface::escape a const method
- Increased TILESTORE_API version to 5
- Added Seiscomp::Processing::WaveformProcessor::Status enumeration PeriodOutOfRange
- Renamed Seiscomp::Core::Time::seconds() to Time::epochSeconds()
- Added Seiscomp::Core::Time::epoch()
- Deprecated Seiscomp::Core::Time::valid()
- Removed implicit Seiscomp::Core::TimeSpan and Seiscomp::Core::Time double cast
- Removed Seiscomp::System::CommandLine::parse(inv argc, char **argv, *)
- Added Seiscomp::System::CommandLine::parse(std::vector<std::string>, *)
- Changed Seiscomp::Core::Time in Seiscomp::IO::RecordStream::addStream,
Seiscomp::IO::RecordStream::setStartTime and
Seiscomp::IO::RecordStream::setEndTime to OPT(Seiscomp::Core::Time)
- Changed Seiscomp::Core::Time in Seiscomp::Client::StreamApplication::setStartTime
and Seiscomp::Client::StreamApplication::setEndTime to OPT(Seiscomp::Core::Time)
- Rename Seiscomp::Wired::ClientSession::inAvail to outputBufferSize and
remove virtual declaration
- Added abstract virtual function MagnitudeProcessor::setDefaults() which must
be implemented by all derived classes.
- Changed Seiscomp::Core::TimeWindow cast to bool semantic
- Changed Seiscomp::Core::TimeWindow::length return type, from double to
Seiscomp::Core::TimeSpan
- Changed Seiscomp::Core::TimeWindow::setLength length argument from double
to Seiscomp::Core::TimeSpan
- Changed Seiscomp::Core::TimeWindow::equals tolerance argument from double
to Seiscomp::Core::TimeSpan
- Changed Seiscomp::Core::TimeWindow::contiguous tolerance argument from double
to Seiscomp::Core::TimeSpan
- Added Seiscomp::Core::metaValueCast
- Removed typedef Seiscomp::Core::SmartPointer::Impl
- Added Seiscomp::Core::SmartPointer as typedef for boost::instrusive_ptr
- Removed typedef Seiscomp::Core::Optional::Impl
- Added Seiscomp::Core::Optional as typedef for boost::optional
- Added Seiscomp::Math::Geo::WGS84_MEAN_RADIUS
- Added Seiscomp::Math::Geo::WGS84_KM_OF_DEGREE
- Added Seiscomp::Math::Geo::WGS84_SEMI_MAJOR_AXIS
- Added Seiscomp::Math::Geo::WGS84_FLATTENING
- Removed defined KM_OF_DEGREE
- Renamed Seiscomp::ellipcorr to Seiscomp::ellipticityCorrection
- Removed Seiscomp::DataModel::DatabaseQuery::getStation
- Added Seiscomp::Geo::readFEP
- Added Seiscomp::Geo::writeGeoJSON
- Added Seiscomp::Math::Matrix3<T> ostream output operator
- Added Seiscomp::Math::Vector3<T> ostream output operator
- Added Seiscomp::Math::Matrix3<T>::operator*
- Added Seiscomp::Math::Matrix3<T>::operator=
- Added static Seiscomp::Math::Matrix3<T>::Rotate[X|Y|Z]
- Added unary Seiscomp::Math::Vector3<T>::operator+
- Added unary Seiscomp::Math::Vector3<T>::operator-
- Added Seiscomp::Math::Vector3<T>::normalized
"16.4.0" 0x100400
- Added Seiscomp::Math::double2frac