47 #ifndef _MIRA_STAMPED_H_ 48 #define _MIRA_STAMPED_H_ 50 #include <serialization/adapters/boost/shared_ptr.hpp> 84 const std::string& iFrameID, uint32 iSequenceID = 0) :
91 template<
typename Reflector>
96 "The id of the transformation frame, this data belongs to",
98 r.member(
"SequenceID",
sequenceID,
"A user defined sequence ID", 0);
148 template <
typename T>
168 Stamped(
const T& iData,
const Time& iTimestamp, uint32 iSequenceID = 0) :
172 Stamped(T&& iData,
const Time& iTimestamp, uint32 iSequenceID = 0) :
180 const std::string& iFrameID, uint32 iSequenceID = 0) :
181 StampedHeader(iTimestamp, iFrameID, iSequenceID), T(iData) {}
185 const std::string& iFrameID, uint32 iSequenceID = 0) :
190 template<
typename Reflector>
194 r.member(
"Value", (T&)*
this,
"The value");
207 const T&
value()
const {
return *
this; }
237 template <
typename T>
240 static_assert(std::is_base_of<mira::Object,T>::value,
241 "Pointers that are used with Stamped<T> must be of polymorphic" 242 " classes that are derived from mira::Object. Pointers to other" 243 " classes cannot be used with Stamped<T>.");
260 Stamped(T* iData,
const Time& iTimestamp, uint32 iSequenceID = 0) :
267 Stamped(T* iData,
const Time& iTimestamp,
const std::string& iFrameID,
268 uint32 iSequenceID = 0) :
269 StampedHeader(iTimestamp, iFrameID, iSequenceID), mPointer(iData) {}
273 template<
typename Reflector>
277 r.member(
"Value", mPointer,
"The value");
285 T*
value() {
return dynamic_cast<T*
>(mPointer.get()); }
290 const T*
value()
const {
return dynamic_cast<T*
>(mPointer.get()); }
293 operator const T*()
const {
return value(); }
296 operator T*() {
return value(); }
299 T*
operator=(T* iValue) {mPointer.reset(iValue);
return iValue; }
319 template <
typename U>
322 "The following is safe as long as all Stamped<T*> have the same size");
323 return reinterpret_cast<const Stamped<U*>&
>(*this);
327 template <
typename U>
330 "The following is safe as long as all Stamped<T*> have the same size");
337 boost::shared_ptr<Object> mPointer;
356 template <
typename T>
373 uint32 iSequenceID = 0) :
381 const std::string& iFrameID, uint32 iSequenceID = 0) :
382 StampedHeader(iTimestamp, iFrameID, iSequenceID), mValue(iData) {}
386 template<
typename Reflector>
390 r.member(
"Value", mValue,
"The value");
403 const T&
value()
const {
return mValue; }
406 operator const T&()
const {
return mValue; }
409 operator T&() {
return mValue; }
412 const T&
operator=(
const T& iValue) {
return mValue = iValue; }
435 #define MIRA_DECLARE_STAMPED_PRIMITIVE_SPECIALIZATION(T) \ 437 class Stamped<T> : public StampedPrimitive<T> \ 441 Stamped(const T& iData, const Time& iTimestamp, uint32 iSequenceID=0) : \ 442 StampedPrimitive<T>(iData, iTimestamp,iSequenceID) {} \ 443 Stamped(const T& iData, const Time& iTimestamp, \ 444 const std::string& iFrameID, uint32 iSequenceID=0) : \ 445 StampedPrimitive<T>(iData, iTimestamp, iFrameID, iSequenceID) {} \ 470 template <
typename T>
472 const std::string& frameID = std::string(),
473 uint32 sequenceID = 0)
481 template <
typename T>
486 template <
typename T>
T * value_type
Definition: Stamped.h:243
T & value()
Returns a read-write reference to the underlying data.
Definition: Stamped.h:398
Stamped(T *iData, const Time &iTimestamp, uint32 iSequenceID=0)
Constructs the Stamped data from its time stamp and the actual data.
Definition: Stamped.h:260
T & value()
Returns a read-write reference to the underlying data.
Definition: Stamped.h:202
const T & internalValueRep() const
Returns a read-only reference to the underlying data representation.
Definition: Stamped.h:422
T value_type
Definition: Stamped.h:153
StampedPrimitive(const T &iData, const Time &iTimestamp, uint32 iSequenceID=0)
Constructs the Stamped data from its time stamp and the actual data.
Definition: Stamped.h:372
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Stamped()
Default constructor, that does not initialize time or frame id.
Definition: Stamped.h:161
Stamped(T &&iData, const Time &iTimestamp, const std::string &iFrameID, uint32 iSequenceID=0)
Same as above, for rvalue reference (move semantics)
Definition: Stamped.h:184
Stamped(const T &iData, const Time &iTimestamp, uint32 iSequenceID=0)
Constructs the Stamped data from its time stamp and the actual data.
Definition: Stamped.h:168
const T & internalValueRep() const
Returns a read-only reference to the underlying data representation.
Definition: Stamped.h:217
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
Time and Duration wrapper class.
Stamped class specialization for polymorphic pointers.
Definition: Stamped.h:238
StampedHeader & stampedHeader(Stamped< T > &data)
Helper to extract the header from stamped data.
Definition: Stamped.h:482
boost::shared_ptr< Object > & internalValueRep()
Returns a read-write reference to the underlying data representation.
Definition: Stamped.h:304
T & internalValueRep()
Returns a read-write reference to the underlying data representation.
Definition: Stamped.h:417
const T & value() const
Returns a read-only reference to the underlying data.
Definition: Stamped.h:403
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:416
T & internalValueRep()
Returns a read-write reference to the underlying data representation.
Definition: Stamped.h:212
Stamped(const T &iData, const Time &iTimestamp, const std::string &iFrameID, uint32 iSequenceID=0)
Constructs the Stamped data from its time stamp, the frame id it belongs to and the actual data...
Definition: Stamped.h:179
Stamped(T *iData, const Time &iTimestamp, const std::string &iFrameID, uint32 iSequenceID=0)
Constructs the Stamped data from its time stamp, the frame id and the actual data.
Definition: Stamped.h:267
void reflect(Reflector &r)
Definition: Stamped.h:274
Stamped()
Default constructor, no time is set and data pointer is null.
Definition: Stamped.h:254
const T & value() const
Returns a read-only reference to the underlying data.
Definition: Stamped.h:207
const boost::shared_ptr< Object > & internalValueRep() const
Returns a read-only reference to the underlying data representation.
Definition: Stamped.h:309
Mix in for adding a time stamp, an optional frame id and an optional sequence id to data types like P...
Definition: Stamped.h:149
json_spirit::mObject Object
A representation of an object (class, struct) in JSON.
Definition: JSON.h:183
StampedPrimitive()
Default constructor, that does not initializes anything.
Definition: Stamped.h:366
Stamped< typename std::decay< T >::type > makeStamped(T &&value, const Time ×tamp=Time::now(), const std::string &frameID=std::string(), uint32 sequenceID=0)
Declare stamped classes for all standard data types including std::string.
Definition: Stamped.h:471
const T * value() const
Returns the underlying pointer as constant pointer.
Definition: Stamped.h:290
StampedPrimitive(const T &iData, const Time &iTimestamp, const std::string &iFrameID, uint32 iSequenceID=0)
Constructs the Stamped data from its time stamp, the frame id and the actual data.
Definition: Stamped.h:380
Stamped class for primitive types like int, float, etc.
Definition: Stamped.h:357
Stamped(T &&iData, const Time &iTimestamp, uint32 iSequenceID=0)
Same as above, for rvalue reference (move semantics)
Definition: Stamped.h:172
T * value()
Returns the underlying pointer.
Definition: Stamped.h:285
T * operator=(T *iValue)
Assignment operator that can assign T to this.
Definition: Stamped.h:299
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:479
#define MIRA_DECLARE_STAMPED_PRIMITIVE_SPECIALIZATION(T)
Macro for specializing template class Stamped for primitive types.
Definition: Stamped.h:435
const T & operator=(const T &iValue)
Assignment operator that can assign T to this.
Definition: Stamped.h:412
void reflect(Reflector &r)
Definition: Stamped.h:191
void reflect(Reflector &r)
Definition: Stamped.h:387
T value_type
Definition: Stamped.h:361