MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
memorystream.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _resourcememorystream_h
41 #define _resourcememorystream_h
42 
43 #include "Resource/datastream.h"
44 
45 /// @file
46 /// @brief Declaration of MemoryStream
47 
48 namespace Mezzanine
49 {
50  namespace Resource
51  {
52 #ifdef USENEWDATASTREAM
53  /// @todo Implement this
54 #else //USENEWDATASTREAM
55  ///////////////////////////////////////////////////////////////////////////////
56  /// @brief This represents a stream to a buffer in memory.
57  /// @details
58  ///////////////////////////////////////
60  {
61  protected:
62  bool FreeBuffer;
63  UInt8* BufferStart;
64  UInt8* BufferPos;
65  UInt8* BufferEnd;
66  public:
67  /// @brief Buffer creation constructor.
68  /// @param BufferSize The size of the buffer to be created.
69  /// @param FreeOnClose If true this will delete the memory buffer when the stream is closed.
70  /// @param ReadOnly If true, writing operations on this stream will be prohibited.
71  MemoryStream(const size_t& BufferSize, bool FreeOnClose = true, bool ReadOnly = false);
72  /// @brief Pre-made buffer constructor.
73  /// @param Buffer The premade buffer to stream from.
74  /// @param BufferSize The size of the buffer to stream to/from.
75  /// @param FreeOnClose If true this will delete the memory buffer when the stream is closed.
76  /// @param ReadOnly If true, writing operations on this stream will be prohibited.
77  MemoryStream(void* Buffer, const size_t& BufferSize, bool FreeOnClose = false, bool ReadOnly = false);
78  /// @brief Class destructor.
79  virtual ~MemoryStream();
80 
81  ///////////////////////////////////////////////////////////////////////////////
82  // Utility
83 
84  /// @brief Gets a pointer to the start of the memory buffer used by this stream.
85  /// @return Returns a pointer to the start of the memory buffer.
86  UInt8* GetBufferStart() const;
87  /// @brief Gets a pointer to the current position in the memory buffer used by this stream.
88  /// @return Returns a pointer to the current position in the memory buffer.
89  UInt8* GetBufferPosition() const;
90  /// @brief Gets a pointer to the end of the memory buffer used by this stream.
91  /// @return Returns a pointer to the end of the memory buffer.
92  UInt8* GetBufferEnd() const;
93  /// @brief Sets whether or not you want this stream to free the memory buffer when it closes.
94  /// @param True if you want this stream to free the buffer when it closes, false if you want it preserved.
95  void SetFreeOnClose(bool FreeOnClose);
96 
97  ///////////////////////////////////////////////////////////////////////////////
98  // Stream Access and Manipulation
99 
100  /// @copydoc DataStream::Read(void* Buffer, const size_t& Count)
101  virtual size_t Read(void* Buffer, const size_t& Count);
102  /// @copydoc DataStream::Write(const void* Buffer, const size_t& Count)
103  virtual size_t Write(const void* Buffer, const size_t& Count);
104  /// @copydoc DataStream::Advance(const StreamOff Count)
105  virtual void Advance(const StreamOff Count);
106  /// @copydoc DataStream::SetStreamPosition(StreamPos Position)
107  virtual void SetStreamPosition(StreamPos Position);
108  /// @copydoc DataStream::SetStreamPosition(StreamOff Offset, SeekOrigin Origin)
109  virtual void SetStreamPosition(StreamOff Offset, SeekOrigin Origin);
110  /// @copydoc DataStream::GetStreamPosition(bool Read = true)
111  virtual StreamPos GetStreamPosition(bool Read = true);
112  /// @copydoc DataStream::EoF() const
113  virtual bool EoF() const;
114  /// @copydoc DataStream::Close()
115  virtual void Close();
116 
117  ///////////////////////////////////////////////////////////////////////////////
118  // Formatting Methods
119 
120  /// @copydoc DataStream::ReadLine(Char8* Buffer, size_t MaxCount, const String& Delim = "\n")
121  virtual size_t ReadLine(Char8* Buffer, size_t MaxCount, const String& Delim = "\n");
122  /// @copydoc DataStream::SkipLine(const String& Delim = "\n")
123  virtual size_t SkipLine(const String& Delim = "\n");
124  };//MemoryStream
125 #endif //USENEWDATASTREAM
126  }//Resource
127 }//Mezzanine
128 
129 #endif