YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
StampWithFrame.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026-2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7
10#include <yarp/os/Time.h>
11
12#include <algorithm>
13#include <utility>
14
15
19
20namespace {
21YARP_OS_LOG_COMPONENT(STAMPWITHFRAME, "yarp.os.StampWithFrame");
22}
23
25{
26public:
29 const std::string& _frameId)
30 {
32 timeStamp = _time;
34 }
35
36 Private() = default;
37
38 void clear()
39 {
40 sequenceNumber = StampWithFrame::npos;
41 timeStamp = 0.0;
42 frameId.clear();
43 }
44
46 {
48 if (sequenceNumber == StampWithFrame::npos) {
49 // npos is not used to store a valid StampWithFrame, just restart the
50 // counter
52 }
53 timeStamp = time;
54 }
55};
56
57
59 mPriv(new Private(count, time, frameId))
60{
61 yCAssert(STAMPWITHFRAME, mPriv->frameId.find(' ') == std::string::npos);
62}
63
68
70 mPriv(new Private(*(rhs.mPriv)))
71{
72}
73
75 mPriv(std::exchange(rhs.mPriv, nullptr))
76{
77}
78
80{
81 delete mPriv;
82}
83
85{
86 if (&rhs != this) {
87 *mPriv = *(rhs.mPriv);
88 }
89 return *this;
90}
91
93{
94 if (&rhs != this) {
95 std::swap(mPriv, rhs.mPriv);
96 }
97 return *this;
98}
99
101{
102 return mPriv->sequenceNumber;
103}
104
106{
107 return mPriv->timeStamp;
108}
109
110std::string StampWithFrame::frameId() const
111{
112 return mPriv->frameId;
113}
114
116{
117 return mPriv->sequenceNumber != npos;
118}
119
121{
122 mPriv->update(Time::now());;
123}
124
126{
127 mPriv->update(time);
128}
129
130void StampWithFrame::setFrameId(std::string frameId)
131{
132 mPriv->frameId = std::move(frameId);
133}
134
136{
137 return mPriv->read(connection);
138}
139
141{
142 return mPriv->write(connection);
143}
void update(yarp::conf::float64_t time)
Private(StampWithFrame::count_t _count, yarp::conf::float64_t _time, const std::string &_frameId)
A mini-server for performing network communication in the background.
T * read(bool shouldWait=true) override
Read an available object from the port.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
An interface for reading from a network connection.
An interface for writing to a network connection.
Holds a time stamp and/or sequence number.
An abstraction for a sequence number, time stamp and/or frame id.
static constexpr count_t npos
Maximum sequence number, after which an incrementing sequence should return to zero.
std::string frameId() const
Get the frame id.
void setFrameId(std::string frameId)
Set the frame id for this StampWithFrame.
bool write(ConnectionWriter &connection) const override
Write this object to a network connection.
bool isValid() const
Check if this StampWithFrame is valid.
yarp::conf::float64_t timeStamp() const
Get the time stamp.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
~StampWithFrame() override
Destructor.
StampWithFrame()
Construct an invalid StampWithFrame.
count_t count() const
Get the sequence number.
bool read(ConnectionReader &connection) override
Read this object from a network connection.
StampWithFrame & operator=(const StampWithFrame &rhs)
Copy assignment operator.
#define yCAssert(component, x)
#define YARP_OS_LOG_COMPONENT(name, name_string)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121