mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Upfront of refs #369
* consolidated ICoordinateGeodetic (e.g. fixed nested properties) * shifted common functionality for objects/containers with callsign into interface * shifted common functionality for objects/containers with geo position into interface * shifted common functionality for objects/containers with timestamp into interface * updated corresponding value objects / specialized lists * adjusted all places where renamed functions are used
This commit is contained in:
95
src/blackmisc/timestampbased.h
Normal file
95
src/blackmisc/timestampbased.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_TIMESTAMPBASED_H
|
||||
#define BLACKMISC_TIMESTAMPBASED_H
|
||||
|
||||
#include "propertyindex.h"
|
||||
#include <QDateTime>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
//! Entity with timestamp
|
||||
class ITimestampBased
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexUtcTimestamp = BlackMisc::CPropertyIndex::GlobalIndexTimestampBased,
|
||||
IndexUtcTimestampFormatted,
|
||||
IndexMSecsSinceEpoch
|
||||
};
|
||||
|
||||
//! Get timestamp
|
||||
QDateTime getUtcTimestamp() const;
|
||||
|
||||
//! Timestamp as ms value
|
||||
qint64 getMSecsSinceEpoch() const { return m_timestampMSecsSinceEpoch; }
|
||||
|
||||
//! Timestamp as ms value
|
||||
void setMSecsSinceEpoch(qint64 mSecsSinceEpoch) { m_timestampMSecsSinceEpoch = mSecsSinceEpoch; }
|
||||
|
||||
//! Formatted timestamp
|
||||
QString getFormattedUtcTimestamp() const;
|
||||
|
||||
//! Set timestamp
|
||||
void setUtcTimestamp(const QDateTime ×tamp);
|
||||
|
||||
//! Is this newer than other?
|
||||
bool isNewerThan(const ITimestampBased &otherTimestampObj) const;
|
||||
|
||||
//! Is newer than epoch value?
|
||||
bool isNewerThan(qint64 mSecsSinceEpoch) const;
|
||||
|
||||
//! Is this older than other?
|
||||
bool isOlderThan(const ITimestampBased &otherTimestampObj) const;
|
||||
|
||||
//! Is this older than other?
|
||||
bool isOlderThan(qint64 mSecsSinceEpoch) const;
|
||||
|
||||
//! Older than now-offset
|
||||
bool isOlderThanNowMinusOffset(int offsetMs) const;
|
||||
|
||||
//! Same timestamp
|
||||
bool isSame(const ITimestampBased &otherTimestampObj) const;
|
||||
|
||||
//! Time difference
|
||||
qint64 msecsTo(const ITimestampBased &otherTimestampObj) const;
|
||||
|
||||
//! Time difference
|
||||
qint64 msecsToAbs(const ITimestampBased &otherTimestampObj) const;
|
||||
|
||||
//! Set the current time as timestamp
|
||||
void setCurrentUtcTime();
|
||||
|
||||
//! Can given index be handled
|
||||
static bool canHandleIndex(const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
int i = index.frontCasted<int>();
|
||||
return (i >= static_cast<int>(IndexUtcTimestamp)) && (i <= static_cast<int>(IndexMSecsSinceEpoch));
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
virtual CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
virtual void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
qint64 m_timestampMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch(); //!< timestamp value
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user