| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- //
- // Urho3D Engine
- // Copyright (c) 2008-2011 Lasse Öörni
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #ifndef COMMON_VECTORBUFFER_H
- #define COMMON_VECTORBUFFER_H
- #include "Deserializer.h"
- #include "Serializer.h"
- #include <cstdio>
- #include <vector>
- //! A dynamically sized buffer that can be read and written to as a stream
- class VectorBuffer : public Deserializer, public Serializer
- {
- public:
- //! Construct an empty buffer
- VectorBuffer();
- //! Construct from another buffer
- VectorBuffer(const std::vector<unsigned char>& data);
- //! Construct from a memory area
- VectorBuffer(const void* data, unsigned size);
- //! Construct from a stream
- VectorBuffer(Deserializer& source, unsigned size);
-
- //! Read bytes from the buffer
- virtual void read(void* dest, unsigned size);
- //! Set position from the beginning of the buffer
- virtual unsigned seek(unsigned position);
- //! Write bytes to the buffer
- virtual void write(const void* data, unsigned size);
-
- //! Set data from another buffer
- void setData(const std::vector<unsigned char>& data);
- //! Set data from a memory area
- void setData(const void* data, unsigned size);
- //! Set data from a stream
- void setData(Deserializer& source, unsigned size);
- //! Reset to zero size
- void clear();
- //! Set size
- void resize(unsigned size);
-
- //! Return data
- const unsigned char* getData() const { return mSize ? &mBuffer[0] : 0; }
- //! Return non-const data
- unsigned char* getModifiableData() { return mSize ? &mBuffer[0] : 0; }
- //! Return the buffer
- const std::vector<unsigned char>& getBuffer() const { return mBuffer; }
-
- private:
- //! Dynamic sized buffer
- std::vector<unsigned char> mBuffer;
- };
- #endif // COMMON_VECTORBUFFER_H
|