19 #include <mrpt/otherlibs/mapbox/variant.hpp>
21 #include <type_traits>
55 virtual size_t Read(
void* Buffer,
size_t Count) = 0;
60 virtual size_t Write(
const void* Buffer,
size_t Count) = 0;
107 template <
typename T>
110 #if !MRPT_IS_BIG_ENDIAN
112 return ReadBuffer(ptr, ElementCount *
sizeof(T));
115 const size_t nread =
ReadBuffer(ptr, ElementCount *
sizeof(T));
116 for (
size_t i = 0; i < ElementCount; i++)
139 void WriteBuffer(
const void* Buffer,
size_t Count);
158 template <
typename T>
161 #if !MRPT_IS_BIG_ENDIAN
166 for (
size_t i = 0; i < ElementCount; i++) (*
this) << ptr[i];
216 template <
typename T>
224 if (strClassName !=
"nullptr")
230 obj.get() , strClassName, isOldFormat,
234 return typename T::Ptr();
238 return std::dynamic_pointer_cast<T>(
obj);
243 template <
typename RET>
250 template <
typename RET,
typename T,
typename...
R>
255 if (
IS_CLASS(ptr,
typename T::element_type))
256 return std::dynamic_pointer_cast<typename T::element_type>(ptr);
260 template <
typename RET,
typename T,
typename...
R>
265 if (
IS_CLASS(ptr, T))
return dynamic_cast<T&
>(*ptr);
281 template <
typename... T>
292 "Stored object has class '%s' which is not registered!",
293 strClassName.c_str())
294 if (strClassName !=
"nullptr")
311 template <
typename T>
324 template <
typename T>
352 template <
typename STORED_TYPE,
typename CAST_TO_TYPE>
357 read_here =
static_cast<CAST_TO_TYPE
>(var);
363 virtual int printf(
const char* fmt, ...)
369 template <typename CONTAINER_TYPE>
371 const
char* fmt, const CONTAINER_TYPE& V,
char separator = ',')
374 const size_t N = V.size();
375 for (
size_t i = 0; i < N; i++)
378 if (i != (N - 1)) this->
printf(
"%c", separator);
433 #define DECLARE_CSTREAM_READ_WRITE_SIMPLE_TYPE(T) \
434 CStream& operator<<(mrpt::utils::CStream& out, const T a); \
435 CStream& operator>>(mrpt::utils::CStream& in, T& a);
449 #ifdef HAVE_LONG_DOUBLE
453 #define MRPT_READ_POD(_STREAM, _VARIABLE) \
456 const std::remove_cv_t<std::remove_reference_t<decltype(_VARIABLE)>> \
457 val = _STREAM.ReadPOD<std::remove_cv_t< \
458 std::remove_reference_t<decltype(_VARIABLE)>>>(); \
459 ::memcpy(&_VARIABLE, &val, sizeof(val)); \
482 #if MRPT_WORD_SIZE != 32
508 #if MRPT_WORD_SIZE != 32
512 template <
typename T, std::enable_if_t<std::is_base_of<
521 template <
typename... T>
529 template <
typename... T>
533 pObj.match([&](
auto&
t) { out <<
t; });
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
#define DECLARE_CSTREAM_READ_WRITE_SIMPLE_TYPE(T)
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
The virtual base class which provides a unified interface for all persistent objects in MRPT.
std::shared_ptr< CSerializable > Ptr
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
void WriteObject(const CSerializable &o)
virtual size_t Write(const void *Buffer, size_t Count)=0
Introduces a pure virtual method responsible for writing to the stream.
virtual size_t Read(void *Buffer, size_t Count)=0
Introduces a pure virtual method responsible for reading from the stream.
void internal_ReadObjectHeader(std::string &className, bool &isOldFormat, int8_t &version)
Read the object Header.
virtual int void printf_vector(const char *fmt, const CONTAINER_TYPE &V, char separator=',')
Prints a vector in the format [A,B,C,...] using CStream::printf, and the fmt string for each vector e...
RET ReadVariant_helper(CSerializable::Ptr &ptr, std::enable_if_t< is_shared_ptr< T >::value > *=nullptr)
void WriteObject(const CSerializable *o)
Writes an object to the stream.
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
bool getline(std::string &out_str)
Reads from the stream until a ' ' character is found ('\r' characters are ignored).
virtual uint64_t getPosition()=0
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the l...
size_t ReadBuffer(void *Buffer, size_t Count)
Reads a block of bytes from the stream into Buffer.
virtual uint64_t Seek(uint64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning)=0
Introduces a pure virtual method for moving to a specified position in the streamed resource.
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
RET ReadVariant_helper(CSerializable::Ptr &ptr, std::enable_if_t<!is_shared_ptr< T >::value > *=nullptr)
bool receiveMessage(utils::CMessage &msg)
Tries to receive a message from the device.
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...
mrpt::utils::variant< T... > ReadVariant()
Reads a variant from stream, its class determined at runtime, and returns a variant to the object.
virtual uint64_t getTotalBytesCount()=0
Returns the total amount of bytes in the stream.
RET ReadVariant_helper(CSerializable::Ptr &ptr)
virtual size_t ReadBufferImmediate(void *Buffer, size_t Count)
Reads a block of bytes from the stream into Buffer, and returns the amound of bytes actually read,...
TSeekOrigin
Used in CStream::Seek.
void WriteVariant(T t)
Writes a Variant to the stream.
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...
void internal_ReadObject(CSerializable *newObj, const std::string &className, bool isOldFormat, int8_t version)
Read the object.
T::Ptr ReadObject()
Reads an object from stream, its class determined at runtime, and returns a smart pointer to the obje...
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
CStream & operator>>(CSerializable::Ptr &pObj)
CStream & operator<<(const CSerializable::Ptr &pObj)
Write an object to a stream in the binary MRPT format.
CSerializable::Ptr ReadObject()
Reads an object from stream, its class determined at runtime, and returns a smart pointer to the obje...
T ReadPOD()
Reads a simple POD type and returns by value.
void sendMessage(const utils::CMessage &msg)
Send a message to the device.
GLsizei GLsizei GLuint * obj
GLubyte GLubyte GLubyte a
GLsizei const GLfloat * value
GLsizei const GLchar ** string
std::vector< int16_t > vector_signed_word
std::vector< uint8_t > vector_byte
std::vector< uint16_t > vector_word
std::vector< int64_t > vector_long
std::vector< bool > vector_bool
A type for passing a vector of bools.
std::vector< uint32_t > vector_uint
std::vector< int32_t > vector_int
std::vector< int8_t > vector_signed_byte
#define THROW_EXCEPTION(msg)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
void reverseBytesInPlace(bool &v_in_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian)
const TRuntimeClassId * findRegisteredClass(const std::string &className)
Return info about a given class by its name, or nullptr if the class is not registered.
CStream & operator>>(mrpt::utils::CStream &in, char *a)
mapbox::util::variant< T... > variant
CStream & operator<<(mrpt::utils::CStream &s, const char *a)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned __int16 uint16_t
unsigned __int32 uint32_t
unsigned __int64 uint64_t
A structure that holds runtime class type information.
mrpt::utils::CObject * createObject() const
This is useful for checking ::Ptr types.