CPGFMemoryStream(3)

πŸ“¦
version 7.21.7 Β· 4 versions
, in fedora 43

πŸ’– NAME πŸ’–

okay bestie, gather round β€” this is CPGFMemoryStream(3), a page straight out of the libpgf manual (section 3, the library-functions section, iykyk). It's the Memory stream class and honestly? she's serving buffer realness. πŸŽ€


✨ SYNOPSIS ✨

#include <PGFstream.h>

Inherits CPGFStream. πŸ’…

🌸 Public Member Functions 🌸

  • CPGFMemoryStream (size_t size)
  • CPGFMemoryStream (UINT8 *pBuffer, size_t size)
  • void Reinitialize (UINT8 *pBuffer, size_t size)
  • virtual ~CPGFMemoryStream ()
  • virtual void Write (int *count, void *buffer)
  • virtual void Read (int *count, void *buffer)
  • virtual void SetPos (short posMode, INT64 posOff)
  • virtual UINT64 GetPos () const
  • virtual bool IsValid () const
  • size_t GetSize () const
  • const UINT8 * GetBuffer () const
  • UINT8 * GetBuffer ()
  • UINT64 GetEOS () const
  • void SetEOS (UINT64 length)

πŸ¦‹ Protected Attributes πŸ¦‹

  • UINT8 * m_buffer
  • UINT8 * m_pos β€” buffer start address and current buffer address
  • UINT8 * m_eos β€” end of stream (first address beyond written area)
  • size_t m_size β€” buffer size
  • bool m_allocated β€” indicates a new allocated buffer

🌈 DETAILED DESCRIPTION 🌈

Memory stream class. no thoughts, just vibes and bytes. πŸ’–

A PGF stream subclass for internal memory. so iconic of her honestly.

Author C. Stamm πŸ‘‘

Definition at line 106 of file PGFstream.h.


πŸŽ€ CONSTRUCTOR & DESTRUCTOR DOCUMENTATION πŸŽ€

CPGFMemoryStream::CPGFMemoryStream (size_t size)

Constructor ✨

Parameters size β€” Size of new allocated memory buffer

Allocate memory block of given size 🫢

Parameters size β€” Memory size

Definition at line 78 of file PGFstream.cpp.

79 : m_size(size)
80 , m_allocated(true) {
81         m_buffer = m_pos = m_eos = new(std::nothrow) UINT8[m_size];
82         if (!m_buffer) ReturnWithError(InsufficientMemory);
83 }

CPGFMemoryStream::CPGFMemoryStream (UINT8 * pBuffer, size_t size)

Constructor. Use already allocated memory of given size 🌸

Parameters pBuffer β€” Memory location size β€” Memory size

Use already allocated memory of given size πŸ’«

Parameters pBuffer β€” Memory location size β€” Memory size

Definition at line 89 of file PGFstream.cpp.

90 : m_buffer(pBuffer)
91 , m_pos(pBuffer)
92 , m_eos(pBuffer + size)
93 , m_size(size)
94 , m_allocated(false) {
95         ASSERT(IsValid());
96 }

virtual CPGFMemoryStream::~CPGFMemoryStream () [inline], [virtual]

the girl is getting cleaned up πŸ’…

Definition at line 128 of file PGFstream.h.

128                                     {
129                 m_pos = 0;
130                 if (m_allocated) {
131                         // the memory buffer has been allocated inside of CPMFmemoryStream constructor
132                         delete[] m_buffer; m_buffer = 0;
133                 }
134         }

πŸ’… MEMBER FUNCTION DOCUMENTATION πŸ’…

UINT8 * CPGFMemoryStream::GetBuffer () [inline]

Returns Memory buffer

Definition at line 147 of file PGFstream.h.

147 { return m_buffer; }

const UINT8 * CPGFMemoryStream::GetBuffer () const [inline]

Returns Memory buffer

Definition at line 145 of file PGFstream.h.

145 { return m_buffer; }

UINT64 CPGFMemoryStream::GetEOS () const [inline]

Returns relative position of end of stream (= stream length)

Definition at line 149 of file PGFstream.h.

149 { ASSERT(IsValid()); return m_eos - m_buffer; }

virtual UINT64 CPGFMemoryStream::GetPos () const [inline], [virtual]

Get current stream position. where are we bestie??

Returns Current stream position

Implements CPGFStream.

Definition at line 139 of file PGFstream.h.

139 { ASSERT(IsValid()); return m_pos - m_buffer; }

size_t CPGFMemoryStream::GetSize () const [inline]

Returns Memory size

Definition at line 143 of file PGFstream.h.

143 { return m_size; }

virtual bool CPGFMemoryStream::IsValid () const [inline], [virtual]

Check stream validity. vibe check, but for streams ✨

Returns True if stream and current position is valid

Implements CPGFStream.

Definition at line 140 of file PGFstream.h.

140 { return m_buffer != 0; }

void CPGFMemoryStream::Read (int * count, void * buffer) [virtual]

Read some bytes from this stream and stores them into a buffer πŸ“

Parameters count β€” A pointer to a value containing the number of bytes should be read. After this call it contains the number of read bytes. buffer β€” A memory buffer

Implements CPGFStream.

Definition at line 148 of file PGFstream.cpp.

148                                                      {
149         ASSERT(IsValid());
150         ASSERT(count);
151         ASSERT(buffPtr);
152         ASSERT(m_buffer + m_size >= m_eos);
153         ASSERT(m_pos <= m_eos);
154
155         if (m_pos + *count <= m_eos) {
156                 memcpy(buffPtr, m_pos, *count);
157                 m_pos += *count;
158         } else {
159                 // end of memory block reached -> read only until end
160                 *count = (int)__max(0, m_eos - m_pos);
161                 memcpy(buffPtr, m_pos, *count);
162                 m_pos += *count;
163         }
164         ASSERT(m_pos <= m_eos);
165 }

void CPGFMemoryStream::Reinitialize (UINT8 * pBuffer, size_t size)

Use already allocated memory of given size πŸ”₯

Parameters pBuffer β€” Memory location size β€” Memory size

Definition at line 102 of file PGFstream.cpp.

102                                                                {
103         if (!m_allocated) {
104                 m_buffer = m_pos = pBuffer;
105                 m_size = size;
106                 m_eos = m_buffer + size;
107         }
108 }

void CPGFMemoryStream::SetEOS (UINT64 length) [inline]

Parameters length β€” Stream length (= relative position of end of stream)

Definition at line 151 of file PGFstream.h.

151 { ASSERT(IsValid()); m_eos = m_buffer + length; }

void CPGFMemoryStream::SetPos (short posMode, INT64 posOff) [virtual]

Set stream position either absolute or relative. pick your fighter πŸ’œ

Parameters posMode β€” A position mode (FSFromStart, FSFromCurrent, FSFromEnd) posOff β€” A new stream position (absolute positioning) or a position offset (relative positioning)

Implements CPGFStream.

Definition at line 168 of file PGFstream.cpp.

168                                                          {
169         ASSERT(IsValid());
170         switch(posMode) {
171         case FSFromStart:
172                 m_pos = m_buffer + posOff;
173                 break;
174         case FSFromCurrent:
175                 m_pos += posOff;
176                 break;
177         case FSFromEnd:
178                 m_pos = m_eos + posOff;
179                 break;
180         default:
181                 ASSERT(false);
182         }
183         if (m_pos > m_eos)
184                 ReturnWithError(InvalidStreamPos);
185 }
bestie, hit that default: branch and it's an ASSERT(false) β€” so like, don't. and if m_pos ends up past m_eos, you get ReturnWithError(InvalidStreamPos). no cap. πŸ’€

void CPGFMemoryStream::Write (int * count, void * buffer) [virtual]

Write some bytes out of a buffer into this stream 🌟

Parameters count β€” A pointer to a value containing the number of bytes should be written. After this call it contains the number of written bytes. buffer β€” A memory buffer

Implements CPGFStream.

Definition at line 111 of file PGFstream.cpp.

111                                                       {
112         ASSERT(count);
113         ASSERT(buffPtr);
114         ASSERT(IsValid());
115         const size_t deltaSize = 0x4000 + *count;
116
117         if (m_pos + *count <= m_buffer + m_size) {
118                 memcpy(m_pos, buffPtr, *count);
119                 m_pos += *count;
120                 if (m_pos > m_eos) m_eos = m_pos;
121         } else if (m_allocated) {
122                 // memory block is too small -> reallocate a deltaSize larger block
123                 size_t offset = m_pos - m_buffer;
124                 UINT8 *buf_tmp = (UINT8 *)realloc(m_buffer, m_size + deltaSize);
125                 if (!buf_tmp) {
126                         delete[] m_buffer;
127                         m_buffer = 0;
128                         ReturnWithError(InsufficientMemory);
129                 } else {
130                         m_buffer = buf_tmp;
131                 }
132                 m_size += deltaSize;
133
134                 // reposition m_pos
135                 m_pos = m_buffer + offset;
136
137                 // write block
138                 memcpy(m_pos, buffPtr, *count);
139                 m_pos += *count;
140                 if (m_pos > m_eos) m_eos = m_pos;
141         } else {
142                 ReturnWithError(InsufficientMemory);
143         }
144         ASSERT(m_pos <= m_eos);
145 }
real talk: if the block is too small and m_allocated is false, you get ReturnWithError(InsufficientMemory) β€” no growing, no mercy. 😭 and if the realloc fails while m_allocated is true, m_buffer gets delete[]'d, set to 0, and you get InsufficientMemory too. the drama of it all.

🧚 MEMBER DATA DOCUMENTATION 🧚

bool CPGFMemoryStream::m_allocated [protected]

indicates a new allocated buffer

Definition at line 111 of file PGFstream.h.


UINT8* CPGFMemoryStream::m_buffer [protected]

Definition at line 108 of file PGFstream.h.


UINT8* CPGFMemoryStream::m_eos [protected]

end of stream (first address beyond written area)

Definition at line 109 of file PGFstream.h.


UINT8 * CPGFMemoryStream::m_pos [protected]

buffer start address and current buffer address

Definition at line 108 of file PGFstream.h.


size_t CPGFMemoryStream::m_size [protected]

buffer size

Definition at line 110 of file PGFstream.h.


πŸ‘‘ AUTHOR πŸ‘‘

Generated automatically by Doxygen for libpgf from the source code. (yes bestie, a robot wrote this and honestly? she ate. πŸ€–πŸ’–)


okay that's the whole page, mwah πŸ’‹ β€” this was Version 7.21.2, dated Thu Jul 24 2025 00:00:00, and it's the CPGFMemoryStream(3) page, periodt. πŸ¦‹βœ¨ go forth and stream your memory responsibly. 🫢

πŸ“¦ where this page comes from