update.h
Go to the documentation of this file.
/*
* Copyright © 2012-2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Thomas Voß <thomas.voss@canonical.com>
*/
#ifndef LOCATION_SERVICE_COM_LOMIRI_LOCATION_UPDATE_H_
#define LOCATION_SERVICE_COM_LOMIRI_LOCATION_UPDATE_H_
#include <com/lomiri/location/clock.h>
#include <ostream>
namespace com
{
namespace lomiri
{
namespace location
{
template<typename T>
struct Update
{
inline Update(const T& value = T{},
const Clock::Timestamp& when = Clock::now())
: value{value}, when{when}
{
}
inline bool operator==(const Update<T>& rhs) const
{
return value == rhs.value && when == rhs.when;
}
inline bool operator!=(const Update<T>& rhs) const
{
return !(value == rhs.value && when == rhs.when);
}
T value;
Clock::Timestamp when = Clock::beginning_of_time();
};
template<typename T>
inline std::ostream& operator<<(std::ostream& out, const Update<T>& update)
{
out << "Update(" << update.value << ", " << update.when.time_since_epoch().count() << ")";
return out;
}
}
}
}
#endif // LOCATION_SERVICE_COM_LOMIRI_LOCATION_UPDATE_H_
clock.h
com::lomiri::location
Definition accuracy.h:28
com::lomiri::location::operator<<
std::ostream & operator<<(std::ostream &out, const Accuracy< T > &update)
Definition accuracy.h:68
com::lomiri
Definition accuracy.h:26
com
Definition accuracy.h:24
com::lomiri::location::Clock::now
static Timestamp now()
Samples a timestamp from the clock.
Definition clock.h:51
com::lomiri::location::Clock::Timestamp
std::chrono::high_resolution_clock::time_point Timestamp
Timestamp type of the location service clock.
Definition clock.h:45
com::lomiri::location::Clock::beginning_of_time
static Timestamp beginning_of_time()
Samples a timestamp from the clock.
Definition clock.h:60
com::lomiri::location::Update
Templated class that wraps a value and timestamp.
Definition update.h:37
com::lomiri::location::Update::operator!=
bool operator!=(const Update< T > &rhs) const
operator != checks if two updates are unequal.
Definition update.h:64
com::lomiri::location::Update::operator==
bool operator==(const Update< T > &rhs) const
operator == checks if two updates are equal.
Definition update.h:54
com::lomiri::location::Update::value
T value
Definition update.h:70
com::lomiri::location::Update::Update
Update(const T &value=T{}, const Clock::Timestamp &when=Clock::now())
Constructs a valid update with the given value and timestamp.
Definition update.h:43
com::lomiri::location::Update::when
Clock::Timestamp when
Definition update.h:73