ActiveLib
Loading...
Searching...
No Matches
StackBufferOut.h
1
6#ifndef ACTIVE_UTILITY_STACK_BUFFER_OUT
7#define ACTIVE_UTILITY_STACK_BUFFER_OUT
8
9#include "Active/Utility/BufferOut.h"
10
11namespace active::file {
12
13 class File;
14
15}
16
17namespace active::utility {
18
19 //Class to buffer data to a specified destination using stack-based storage (no heap allocation)
20 template<size_t S>
21 class StackBufferOut: public BufferOut {
22 public:
31 StackBufferOut(file::File& destFile) : BufferOut(destFile) {}
36 StackBufferOut(Memory& memory) : BufferOut(memory) {}
41 StackBufferOut(String& destString) : BufferOut(destString) {}
42 //No move constructor
43 StackBufferOut(BufferOut&& source) noexcept = delete;
44 //No copy constructor
45 StackBufferOut(const BufferOut& source) = delete;
46
47 //MARK: - Operators
48
49 //No assignment
50 StackBufferOut& operator= (BufferOut&& source) noexcept = delete;
51 //No assignment
52 StackBufferOut& operator= (const BufferOut&) = delete;
53
54 protected:
59 virtual bool isMyBuffer() const override { return true; }
60
65 virtual bool confirmBuffer() const override {
66 if (getBuffer().data() != m_fixed)
67 setBuffer(m_fixed, S);
68 return true;
69 }
70
71 private:
72 mutable char m_fixed[S];
73 };
74
75}
76
77#endif //ACTIVE_UTILITY_STACK_BUFFER_OUT
Class to represent a file.
Definition File.h:21
Definition BufferOut.h:23
void setBuffer(void *buffer, Memory::size_type size) const
Definition BufferOut.h:239
const Memory & getBuffer() const
Definition BufferOut.h:233
Class representing (and optionally allocating) memory with a specified location and size.
Definition Memory.h:18
Definition StackBufferOut.h:21
StackBufferOut()
Definition StackBufferOut.h:26
virtual bool confirmBuffer() const override
Definition StackBufferOut.h:65
virtual bool isMyBuffer() const override
Definition StackBufferOut.h:59
StackBufferOut(String &destString)
Definition StackBufferOut.h:41
StackBufferOut(file::File &destFile)
Definition StackBufferOut.h:31
StackBufferOut(Memory &memory)
Definition StackBufferOut.h:36
A Unicode-aware string class.
Definition String.h:51
Definition Directory.h:12
Definition Base64Transport.h:11