dvander@441: /** dvander@441: * vim: set ts=4 : ds@1330: * ============================================================================= dvander@1226: * SourceMod ds@1947: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. ds@1330: * ============================================================================= dvander@441: * ds@1330: * This program is free software; you can redistribute it and/or modify it under ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the ds@1330: * Free Software Foundation. dvander@441: * ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1330: * details. dvander@1226: * ds@1330: * You should have received a copy of the GNU General Public License along with ds@1330: * this program. If not, see . dvander@1226: * ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1330: * this exception to all derivative works. AlliedModders LLC defines further ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1330: * or . dvander@441: * dvander@441: * Version: $Id$ dvander@441: */ dvander@441: dvander@441: #ifndef _INCLUDE_SOURCEMOD_INTERFACE_DATAPACK_H_ dvander@441: #define _INCLUDE_SOURCEMOD_INTERFACE_DATAPACK_H_ dvander@441: dvander@441: #include dvander@441: dvander@441: /** dvander@441: * @file IDataPack.h dvander@441: * @brief Contains functions for packing data abstractly to/from plugins. The wrappers dvander@441: * for creating these are contained in ISourceMod.h dvander@441: */ dvander@441: dvander@441: namespace SourceMod dvander@441: { dvander@441: /** dvander@441: * @brief Specifies a data pack that can only be read. dvander@441: */ dvander@441: class IDataReader dvander@441: { dvander@441: public: dvander@441: /** dvander@441: * @brief Resets the position in the data stream to the beginning. dvander@441: */ dvander@441: virtual void Reset() const =0; dvander@441: dvander@441: /** dvander@441: * @brief Retrieves the current stream position. dvander@441: * dvander@441: * @return Index into the stream. dvander@441: */ dvander@441: virtual size_t GetPosition() const =0; dvander@441: dvander@441: /** dvander@441: * @brief Sets the current stream position. dvander@441: * dvander@441: * @param pos Index to set the stream at. dvander@441: * @return True if succeeded, false if out of bounds. dvander@441: */ dvander@441: virtual bool SetPosition(size_t pos) const =0; dvander@441: dvander@441: /** dvander@441: * @brief Reads one cell from the data stream. dvander@441: * dvander@441: * @return A cell read from the current position. dvander@441: */ dvander@441: virtual cell_t ReadCell() const =0; dvander@441: dvander@441: /** dvander@441: * @brief Reads one float from the data stream. dvander@441: * dvander@441: * @return A float read from the current position. dvander@441: */ dvander@441: virtual float ReadFloat() const =0; dvander@441: dvander@441: /** faluco@484: * @brief Returns whether or not a specified number of bytes from the current stream faluco@484: * position to the end can be read. dvander@441: * dvander@441: * @param bytes Number of bytes to simulate reading. dvander@441: * @return True if can be read, false otherwise. dvander@441: */ dvander@441: virtual bool IsReadable(size_t bytes) const =0; dvander@441: dvander@441: /** dvander@441: * @brief Reads a string from the data stream. dvander@441: * dvander@441: * @param len Optional pointer to store the string length. dvander@441: * @return Pointer to the string, or NULL if out of bounds. dvander@441: */ dvander@441: virtual const char *ReadString(size_t *len) const =0; dvander@441: dvander@441: /** dvander@441: * @brief Reads the current position as a generic address. dvander@441: * dvander@441: * @return Pointer to the memory. dvander@441: */ dvander@441: virtual void *GetMemory() const =0; faluco@488: faluco@488: /** faluco@488: * @brief Reads the current position as a generic data type. faluco@488: * faluco@488: * @param size Optional pointer to store the size of the data type. faluco@488: * @return Pointer to the data, or NULL if out of bounds. faluco@488: */ faluco@488: virtual void *ReadMemory(size_t *size) const =0; dvander@441: }; dvander@441: dvander@441: /** faluco@484: * @brief Specifies a data pack that can only be written. dvander@441: */ dvander@441: class IDataPack : public IDataReader dvander@441: { dvander@441: public: dvander@441: /** faluco@484: * @brief Resets the used size of the stream back to zero. faluco@484: */ faluco@484: virtual void ResetSize() =0; faluco@484: faluco@484: /** dvander@441: * @brief Packs one cell into the data stream. dvander@441: * dvander@441: * @param cell Cell value to write. dvander@441: */ dvander@441: virtual void PackCell(cell_t cell) =0; dvander@441: dvander@441: /** dvander@441: * @brief Packs one float into the data stream. dvander@441: * dvander@441: * @param val Float value to write. dvander@441: */ dvander@441: virtual void PackFloat(float val) =0; dvander@441: dvander@441: /** dvander@441: * @brief Packs one string into the data stream. dvander@441: * The length is recorded as well for buffer overrun protection. dvander@441: * dvander@441: * @param string String to write. dvander@441: */ dvander@441: virtual void PackString(const char *string) =0; dvander@441: dvander@441: /** dvander@441: * @brief Creates a generic block of memory in the stream. dvander@441: * dvander@441: * Note that the pointer it returns can be invalidated on further dvander@441: * writing, since the stream size may grow. You may need to double back dvander@441: * and fetch the pointer again. dvander@441: * dvander@441: * @param size Size of the memory to create in the stream. dvander@441: * @param addr Optional pointer to store the relocated memory address. dvander@441: * @return Current position of the stream beforehand. dvander@441: */ dvander@441: virtual size_t CreateMemory(size_t size, void **addr) =0; dvander@441: }; ds@455: } dvander@441: dvander@441: #endif //_INCLUDE_SOURCEMOD_INTERFACE_DATAPACK_H_