PLCnext API Documentation 25.0.2.69
MemoryStream.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/System/Commons/Io/Stream.hpp"
9#include "Arp/System/Commons/Exceptions/Exceptions.h"
10#include <vector>
11#include <cstring>
12
13namespace Arp { namespace System { namespace Commons { namespace Io
14{
15
16class MemoryStream : public Stream
17{
18public: // construction/destruction
19 MemoryStream(void);
20 explicit MemoryStream(size_t capacity);
21 MemoryStream(byte* buffer, size_t bufferSize);
22 MemoryStream(byte* buffer, size_t bufferSize, boolean writable);
23 MemoryStream(byte* buffer, size_t bufferSize, size_t index, size_t count);
24 MemoryStream(byte* buffer, size_t bufferSize, size_t index, size_t count, boolean writable);
25 MemoryStream(byte* buffer, size_t bufferSize, size_t index, size_t count, boolean writable, boolean publiclyVisible);
27 MemoryStream(const MemoryStream& arg) = delete;
29 MemoryStream& operator=(const MemoryStream& arg) = delete;
30 virtual ~MemoryStream(void);
31
32public: // setter/getter operations
33 size_t GetLength(void);
34 void SetLength(size_t value);
35 size_t GetPosition(void) override;
36 void SetPosition(size_t value) override;
37 size_t GetCapacity(void);
38 void SetCapacity(size_t value);
39
40public: // overridden operations
41 size_t Seek(size_t offset, SeekOrigin origin)override;
42 size_t Read(byte* pBuffer, size_t bufferSize, size_t offset, size_t count)override;
43 void Write(const byte* pBuffer, size_t bufferSize, size_t offset, size_t count)override;
44 void Flush(void)override;
45
46public: // operations
47 std::vector<byte> ToArray(void);
48
49private: // methods
50 void Construct(byte* buffer, size_t bufferSize, size_t index, size_t count, boolean publicallyVisible);
51 void EnsureSize(size_t newSize);
52
53private: // fields
54 // The underlying buffer of this stream.
55 byte* streamBuffer;
56 size_t streamBufferSize;
57 // The actual position of this stream
58 size_t position;
59 // The actual length of the stream.
60 size_t length;
61 // Is true, if the stream is expandable
62 boolean expandable;
63 // The capacity of the stream
64 size_t capacity;
65 // The initial start index in the buffer
66 size_t bufferOffset;
67 // Is true if it is allowed to get the underlying buffer
68 boolean allowGetBuffer;
69 // Is true, the buffer created by the memory stream self
70 boolean selfCreated;
71
72private: // static fields
73 static size_t minCapacity;
74};
75
76}}}} // end of namespace Arp::System::Commons::Io
This abstract class shall be the base class of all stream implementations.
Definition: Stream.hpp:20
Definition: MemoryStream.hpp:17
MemoryStream(const MemoryStream &arg)=delete
Copy constructor.
size_t GetPosition(void) override
Gets the position of the stream, if it can seek.
Definition: MemoryStream.cpp:190
virtual ~MemoryStream(void)
Destructs this instance and frees all resources.
Definition: MemoryStream.cpp:118
void SetPosition(size_t value) override
Sets the position of the stream, if it can seek.
Definition: MemoryStream.cpp:195
MemoryStream(void)
Initializes a new instance of the T:System.IO.MemoryStream class with an expandable capacity initiali...
Definition: MemoryStream.cpp:14
MemoryStream & operator=(const MemoryStream &arg)=delete
Assignment operator.
Root namespace for the PLCnext API