Rhino C++ API  7.21
Public Types | Public Member Functions | Static Public Member Functions | List of all members
ON_Buffer Class Reference

#include <opennurbs_archive.h>

Public Types

enum  { seek_from_beginning_of_file = 0, seek_from_current_position = 1, seek_from_end_of_file = 2 }
 

Public Member Functions

 ON_Buffer ()
 
 ON_Buffer (const ON_Buffer &src)
 
 ~ON_Buffer ()
 
bool AtEnd () const
 
bool ChangeSize (ON__UINT64 buffer_size)
 
void ClearLastError ()
 
bool Compact ()
 
bool Compress (ON_Buffer &compressed_buffer) const
 
ON__UINT32 CRC32 (ON__UINT32 current_remainder) const
 
ON__UINT64 CurrentPosition () const
 
void Destroy ()
 
void EmergencyDestroy ()
 
ON_Buffer_ErrorHandler ErrorHandler () const
 
bool IsValid (const ON_TextLog *text_log) const
 
ON__UINT32 LastError () const
 
ON_Bufferoperator= (const ON_Buffer &src)
 
ON__UINT64 Read (ON__UINT64 size, void *buffer)
 
bool ReadFromBinaryArchive (ON_BinaryArchive &)
 
bool Seek (ON__INT64 offset, int origin)
 
bool SeekFromCurrentPosition (ON__INT64 offset)
 
bool SeekFromEnd (ON__INT64 offset)
 
bool SeekFromStart (ON__INT64 offset)
 
void SetErrorHandler (ON_Buffer_ErrorHandler error_handler)
 
ON__UINT64 Size () const
 
bool Uncompress (ON_Buffer &uncompressed_buffer) const
 
ON__UINT64 Write (ON__UINT64 size, const void *buffer)
 
bool WriteToBinaryArchive (ON_BinaryArchive &) const
 

Static Public Member Functions

static int Compare (const ON_Buffer &a, const ON_Buffer &b)
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
seek_from_beginning_of_file 
seek_from_current_position 
seek_from_end_of_file 

Constructor & Destructor Documentation

◆ ON_Buffer() [1/2]

ON_Buffer::ON_Buffer ( )

◆ ~ON_Buffer()

ON_Buffer::~ON_Buffer ( )

◆ ON_Buffer() [2/2]

ON_Buffer::ON_Buffer ( const ON_Buffer src)

Member Function Documentation

◆ AtEnd()

bool ON_Buffer::AtEnd ( ) const

Returns: True if Size() == CurrentPosition(). Remarks: It is possible to seek beyond the end of the buffer. In this case, the current position will be past the end of the buffer and AtEnd() will return false.

◆ ChangeSize()

bool ON_Buffer::ChangeSize ( ON__UINT64  buffer_size)

Parameters: buffer_size - [in] new size of buffer. Returns: True if successful.
Remarks: The current position is not changed and may be beyond the end of the file. Use Seek to set the current position after calling ChangeSize().

◆ ClearLastError()

void ON_Buffer::ClearLastError ( )

◆ Compact()

bool ON_Buffer::Compact ( )

Description: Return unused memory to heap. Remarks: Call this function after creating an ON_Buffer that will persist for and extended amount of time. There are never more than 16 pages of unsued memory (16*4096 bytes on most computers) in an ON_Buffer. Compact() can be called at any time, but calling Compact() the then writing at the end of the buffer is not an efficient use of time or memory.

◆ Compare()

static int ON_Buffer::Compare ( const ON_Buffer a,
const ON_Buffer b 
)
static

Description: Compare contents of buffers. Paramters: a - [in] b - [in] Returns: -1: a < b 0: a == b 1: a > b

◆ Compress()

bool ON_Buffer::Compress ( ON_Buffer compressed_buffer) const

Description: Compress this buffer

Parameters: compressed_buffer - [out] (The reference can be *this)

Example:

/ compress a buffer in place ON_Buffer buffer; buffer = ...; if ( !buffer.Compress(buffer) ) { / compression failed } else { / buffer is now compressed }

Returns: True if successful. False if failed.

◆ CRC32()

ON__UINT32 ON_Buffer::CRC32 ( ON__UINT32  current_remainder) const

Returns: 32-bit CRC of the buffer contents. Remarks:

◆ CurrentPosition()

ON__UINT64 ON_Buffer::CurrentPosition ( ) const

Returns: Current position in the buffer. Remarks: It is possible to seek beyond the end of the buffer. In this case, the current position will be past the end of the buffer and CurrentPosition() will be greater than Size().

◆ Destroy()

void ON_Buffer::Destroy ( )

◆ EmergencyDestroy()

void ON_Buffer::EmergencyDestroy ( )

◆ ErrorHandler()

ON_Buffer_ErrorHandler ON_Buffer::ErrorHandler ( ) const

◆ IsValid()

bool ON_Buffer::IsValid ( const ON_TextLog text_log) const

Returns True if the ON_Buffer is valid.

◆ LastError()

ON__UINT32 ON_Buffer::LastError ( ) const

Returns: Value that identifies most recent error. 0: no error 1: attempt to seek to a negative position

◆ operator=()

ON_Buffer& ON_Buffer::operator= ( const ON_Buffer src)

◆ Read()

ON__UINT64 ON_Buffer::Read ( ON__UINT64  size,
void *  buffer 
)

Parameters: size - [in] number of bytes to read. buffer - [out] read values are returned in buffer. Returns: Number of bytes read into buffer. For example, if CurrentPosition() <= Size() and size > (Size() - CurrentPosition()) and buffer is not null, then the value (Size() - CurrentPosition()) is returned. Remarks: If the size parameter is zero, then nothing is done. When CurrentPosition() <= Size(), attempts to read more than (Size() - CurrentPosition()) bytes do not generate an error. When CurrentPosition() > Size(), any attempt to read generates an error.

◆ ReadFromBinaryArchive()

bool ON_Buffer::ReadFromBinaryArchive ( ON_BinaryArchive )

Description: Use ReadFromBinaryArchive() to retrieve an entire ON_Buffer that was written using WriteToBinaryArchive().

◆ Seek()

bool ON_Buffer::Seek ( ON__INT64  offset,
int  origin 
)

Parameters: offset - [in] number of bytes to seek from origin origin - [in] initial position. 0 (SEEK_SET) Seek from beginning of file. 1 (SEEK_CUR) Seek from current position. 2 (SEEK_END) Seek from end of file. Returns: True if successful. False if the seek would result in a file position before the beginning of the file. If false is returned, the current position is not changed. Remarks: Seeking beyond the end of the buffer is succeeds. Seeking before the beginning of the buffer fails.

◆ SeekFromCurrentPosition()

bool ON_Buffer::SeekFromCurrentPosition ( ON__INT64  offset)

Parameters: offset - [in] number of bytes to seek from the current position. Returns: True if successful. False if the seek would result in a file position before the beginning of the file. If false is returned, the current position is not changed. Remarks: Seeking beyond the end of the buffer is succeeds. Seeking before the beginning of the buffer fails.

◆ SeekFromEnd()

bool ON_Buffer::SeekFromEnd ( ON__INT64  offset)

Parameters: offset - [in] number of bytes to seek from the end fo the buffer. Returns: True if successful. False if the seek would result in a file position before the beginning of the file. If false is returned, the current position is not changed. Remarks: Seeking beyond the end of the buffer is succeeds. Seeking before the beginning of the buffer fails.

◆ SeekFromStart()

bool ON_Buffer::SeekFromStart ( ON__INT64  offset)

Parameters: offset - [in] (>= 0) number of bytes to seek from the start of the buffer. Returns: True if successful. False if the seek would result in a file position before the beginning of the file. If false is returned, the current position is not changed. Remarks: Seeking beyond the end of the buffer is succeeds. Seeking before the beginning of the buffer fails.

◆ SetErrorHandler()

void ON_Buffer::SetErrorHandler ( ON_Buffer_ErrorHandler  error_handler)

◆ Size()

ON__UINT64 ON_Buffer::Size ( ) const

Returns: Number of bytes currently in the buffer. Remarks: It is possible to seek beyond the end of the buffer. In this case, the current position will be past the end of the buffer and CurrentPosition() will be greater than Size().

◆ Uncompress()

bool ON_Buffer::Uncompress ( ON_Buffer uncompressed_buffer) const

Description: Uncompress this buffer which must have been compressed using ON_Buffer::Compress().

Parameters: uncompressed_buffer - [out] (The reference can be *this)

Example: / silly example that compresses and then uncompresses a buffer in place / to show how to call the functions. ON_Buffer buffer; buffer = ...; ///< buffer is in it uncompressed form if ( buffer.Compress(buffer) ) { / buffer is now compressed if ( buffer.Uncompress(buffer) ) { / buffer is uncompressed again. } }

Returns: True if successful. False if failed.

◆ Write()

ON__UINT64 ON_Buffer::Write ( ON__UINT64  size,
const void *  buffer 
)

Parameters: size - [in] number of bytes to write. buffer - [in] values to write. Returns: Number of bytes written buffer.

◆ WriteToBinaryArchive()

bool ON_Buffer::WriteToBinaryArchive ( ON_BinaryArchive ) const

Description: Use WriteToBinaryArchive() to save an entire ON_Buffer inside a binary archive. Use ReadFromBinaryArchive() to retrieve the ON_Buffer from the ON_BinaryArchive.