12 #include <mrpt/config.h> 19 #include <type_traits> 25 #if defined(__clang__) && (__GLIBCXX__ <= 20180419) 26 #define HAS_BROKEN_CLANG_STD_VISIT 90 #if !MRPT_IS_BIG_ENDIAN 92 return ReadBuffer(ptr, ElementCount *
sizeof(T));
95 const size_t nread =
ReadBuffer(ptr, ElementCount *
sizeof(T));
96 for (
size_t i = 0; i < ElementCount; i++)
107 void WriteBuffer(
const void* Buffer,
size_t Count);
126 template <
typename T>
129 #if !MRPT_IS_BIG_ENDIAN 134 for (
size_t i = 0; i < ElementCount; i++) (*
this) << ptr[i];
140 template <
typename STORED_TYPE,
typename CAST_TO_TYPE>
145 read_here =
static_cast<CAST_TO_TYPE
>(var);
148 template <
typename STORED_TYPE>
155 template <
typename TYPE_TO_STORE,
typename TYPE_FROM_ACTUAL>
158 (*this) <<
static_cast<TYPE_TO_STORE
>(
value);
180 template <
typename T>
188 if (strClassName !=
"nullptr")
194 "Stored object has class '%s' which is not registered!",
195 strClassName.c_str());
199 obj.get() , strClassName, isOldFormat,
203 return typename T::Ptr();
207 return std::dynamic_pointer_cast<T>(
obj);
212 template <
typename RET>
215 throw std::runtime_error(
"Can't match variant type");
219 template <
typename RET,
typename T,
typename...
R>
224 if (
IS_CLASS(ptr,
typename T::element_type))
225 return std::dynamic_pointer_cast<
typename T::element_type>(ptr);
229 template <
typename RET,
typename T,
typename...
R>
234 if (
IS_CLASS(ptr, T))
return dynamic_cast<T&
>(*ptr);
250 template <
typename... T>
262 "Stored object has class '%s' which is not registered!",
263 strClassName.c_str());
264 if (strClassName !=
"nullptr")
271 return std::variant<T...>();
279 #ifndef HAS_BROKEN_CLANG_STD_VISIT 282 template <
typename T>
296 template <
typename T>
371 virtual size_t write(
const void* buf,
size_t len) = 0;
376 virtual size_t read(
void* buf,
size_t len) = 0;
391 #define DECLARE_CArchive_READ_WRITE_SIMPLE_TYPE(T) \ 392 CArchive& operator<<(CArchive& out, const T a); \ 393 CArchive& operator>>(CArchive& in, T& a) 412 #define MRPT_READ_POD(_STREAM, _VARIABLE) \ 415 const std::remove_cv_t<std::remove_reference_t<decltype(_VARIABLE)>> \ 416 val = _STREAM.ReadPOD<std::remove_cv_t< \ 417 std::remove_reference_t<decltype(_VARIABLE)>>>(); \ 418 ::memcpy(&_VARIABLE, &val, sizeof(val)); \ 430 CArchive& operator<<(CArchive&, const std::vector<int32_t>&
a);
431 CArchive& operator<<(CArchive&, const std::vector<uint32_t>&
a);
432 CArchive& operator<<(CArchive&, const std::vector<uint16_t>&
a);
433 CArchive& operator<<(CArchive&, const std::vector<int16_t>&
a);
434 CArchive& operator<<(CArchive&, const std::vector<uint32_t>&
a);
435 CArchive& operator<<(CArchive&, const std::vector<int64_t>&
a);
436 CArchive& operator<<(CArchive&, const std::vector<uint8_t>&
a);
437 CArchive& operator<<(CArchive&, const std::vector<int8_t>&
a);
439 CArchive& operator<<(CArchive&, const std::vector<bool>&
a);
440 CArchive& operator<<(CArchive&, const std::vector<std::string>&);
442 #if MRPT_WORD_SIZE != 32 // If it's 32 bit, size_t <=> uint32_t 443 CArchive& operator<<(CArchive&, const std::vector<size_t>&
a);
451 CArchive&
operator>>(CArchive&
in, std::vector<uint32_t>&
a);
452 CArchive&
operator>>(CArchive&
in, std::vector<uint16_t>&
a);
459 CArchive&
operator>>(CArchive&
in, std::vector<std::string>&
a);
463 CArchive&
operator>>(CArchive&
s, std::vector<float>&
a);
464 CArchive&
operator>>(CArchive&
s, std::vector<double>&
a);
465 CArchive& operator<<(CArchive& s, const std::vector<float>&
a);
466 CArchive& operator<<(CArchive& s, const std::vector<double>&
a);
468 #if MRPT_WORD_SIZE != 32 // If it's 32 bit, size_t <=> uint32_t 469 CArchive&
operator>>(CArchive&
s, std::vector<size_t>&
a);
474 typename T, std::enable_if_t<std::is_base_of<
478 pObj =
in.ReadObject<T>();
482 template <
typename... T>
489 template <
typename... T>
492 pObj.match([&](
auto&
t) { out <<
t; });
498 class T, std::enable_if_t<!std::is_base_of<
500 CArchive& operator<<(CArchive& out, const std::shared_ptr<T>& pObj)
504 out << mrpt::typemeta::TTypeName<T>::get();
516 class T, std::enable_if_t<!std::is_base_of<
539 template <
class STREAM>
548 size_t write(
const void* d,
size_t n)
override {
return m_s.Write(d,
n); }
549 size_t read(
void* d,
size_t n)
override {
return m_s.Read(d,
n); }
554 template <
class STREAM>
T ReadPOD()
Reads a simple POD type and returns by value.
CExceptionEOF(const std::string &s)
unsigned __int16 uint16_t
size_t read(void *d, size_t n) override
Reads a block of bytes.
std::chrono::time_point< Clock > time_point
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
A structure that holds runtime class type information.
void WriteObject(const CSerializable &o)
void WriteAs(const TYPE_FROM_ACTUAL &value)
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
RET ReadVariant_helper(CSerializable::Ptr &ptr, std::enable_if_t<!mrpt::is_shared_ptr< T >::value > *=nullptr)
void sendMessage(const CMessage &msg)
Send a message to the device.
void reverseBytesInPlace(bool &v_in_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
GLsizei GLsizei GLuint * obj
virtual size_t read(void *buf, size_t len)=0
Reads a block of bytes.
CArchive & operator>>(CSerializable &obj)
Reads a CSerializable object from the stream.
This is useful for checking ::Ptr types.
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream, std::istream, std::ostream, std::stringstream
void internal_ReadObjectHeader(std::string &className, bool &isOldFormat, int8_t &version)
Read the object Header.
DECLARE_CArchive_READ_WRITE_SIMPLE_TYPE(bool)
void WriteVariant(T t)
Writes a Variant to the stream.
void ReadAsAndCastTo(CAST_TO_TYPE &read_here)
Read a value from a stream stored in a type different of the target variable, making the conversion v...
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
STORED_TYPE ReadAs()
De-serialize a variable and returns it by value.
CArchiveStreamBase(STREAM &s)
size_t write(const void *d, size_t n) override
Writes a block of bytes.
CArchive & operator<<(const CSerializable &obj)
Write a CSerializable object to a stream in the binary MRPT format.
T::Ptr ReadObject()
Reads an object from stream, its class determined at runtime, and returns a smart pointer to the obje...
GLsizei const GLchar ** string
bool receiveMessage(CMessage &msg)
Tries to receive a message from the device.
virtual size_t write(const void *buf, size_t len)=0
Writes a block of bytes.
const TRuntimeClassId * findRegisteredClass(const std::string &className)
Return info about a given class by its name, or nullptr if the class is not registered.
CArchive for mrpt::io::CStream classes (use as template argument).
CArchive & operator>>(CArchive &s, mrpt::aligned_std_vector< float > &a)
unsigned __int64 uint64_t
Virtual base class for "archives": classes abstracting I/O streams.
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
void internal_ReadObject(CSerializable *newObj, const std::string &className, bool isOldFormat, int8_t version)
Read the object.
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
RET ReadVariant_helper(CSerializable::Ptr &ptr)
RET ReadVariant_helper(CSerializable::Ptr &ptr, std::enable_if_t< mrpt::is_shared_ptr< T >::value > *=nullptr)
CSerializable::Ptr ReadObject()
Reads an object from stream, its class determined at runtime, and returns a smart pointer to the obje...
CArchive & operator<<(CArchive &s, const mrpt::aligned_std_vector< float > &a)
The virtual base class which provides a unified interface for all persistent objects in MRPT...
size_t ReadBuffer(void *Buffer, size_t Count)
Reads a block of bytes from the stream into Buffer.
void WriteObject(const CSerializable *o)
Writes an object to the stream.
GLsizei const GLfloat * value
mrpt::rtti::CObject * createObject() const
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
unsigned __int32 uint32_t
size_t ReadBufferFixEndianness(T *ptr, size_t ElementCount)
Reads a sequence of elemental datatypes, taking care of reordering their bytes from the MRPT stream s...
GLubyte GLubyte GLubyte a
std::variant< T... > ReadVariant()
Reads a variant from stream, its class determined at runtime, and returns a variant to the object...
Used in mrpt::serialization::CArchive.