/*! \file pimemoryblock.h * \ingroup Core * \~\brief * \~english Base types and functions * \~russian Базовые типы и методы */ /* PIP - Platform Independent Primitives Base types and functions Ivan Pelipenko peri4ko@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 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 . */ #ifndef PIMEMORYBLOCK_H #define PIMEMORYBLOCK_H //! \ingroup Core //! \include pimemoryblock.h //! \brief //! \~english Help struct to store/restore custom blocks of data to/from PIBinaryStream //! \~russian Вспомогательная структура для сохранения/извлечения произвольного блока данных в/из PIBinaryStream struct PIMemoryBlock { public: //! \~english Constructs data block //! \~russian Создает блок данных PIMemoryBlock() {} //! \~english Constructs data block //! \~russian Создает блок данных PIMemoryBlock(const void * data_, const int size_) { d = const_cast(data_); s = size_; } PIMemoryBlock(const PIMemoryBlock & o) { d = o.d; s = o.s; } PIMemoryBlock & operator=(const PIMemoryBlock & o) { d = o.d; s = o.s; return *this; } //! \~english Pointer to data //! \~russian Указатель на данные void * data() { return d; } //! \~english Pointer to data //! \~russian Указатель на данные const void * data() const { return d; } //! \~english Size of data in bytes //! \~russian Размер данных в байтах int size() const { return s; } //! \~english Returns if this block points to nothing //! \~russian Возвращает пустой ли указатель на данные bool isNull() const { return d; } private: void * d = nullptr; int s = 0; }; //! \~english Returns PIMemoryBlock from pointer to variable "ptr" with type "T" //! \~russian Возвращает PIMemoryBlock из указателя "ptr" типа "T" template PIMemoryBlock createMemoryBlock(const T * ptr) { return PIMemoryBlock(ptr, sizeof(T)); } #endif // PIMEMORYBLOCK_H