class methods
ofBuffer is a convenience class that provides easy methods for reading from and writing to files. It makes heavy use of the standard C++ ostream and istream classes, but also adds in easy ways to convert file data to strings, like:
ofBuffer buffer = ofBufferFromFile("someFile.txt"); // reading into the buffer
cout << buffer.getText(); // let's see what it says
You can also use the ofBufferFromFile() method to create a buffer from a file:
ofBuffer fileBuffer = ofBufferFromFile("someFile.txt");
Documentation from code comments
A buffer of data which can be accessed as simple bytes or text.
ofBuffer(...)
ofBuffer::ofBuffer(const char *buffer, size_t size)
Create a buffer with a character array.
string giantDataString;
ofBuffer buff(giantDataString.c_str(), giantDataString.size());
Documentation from code comments
Create a buffer and set its contents from a raw byte pointer.
Parameters:
buffer pointer to the raw byte buffer to copy data from
size the number of bytes to read
Warning: buffer must not be NULL
Warning: size must be <= the number of bytes allocated in buffer
ofBuffer(...)
ofBuffer::ofBuffer(istream &stream, size_t ioBlockSize)
Copy constructor, allows you to do:
ofBuffer aBuff;
// put some stuff in aBuff
ofBuffer bBuff(aBuff); // now it's in bBuff as well
Documentation from code comments
Create a buffer and set its contents from an input stream.
Parameters:
ioBlockSize the number of bytes to read from the stream in chunks
allocate(...)
void ofBuffer::allocate(size_t size)
Allocate memory for the buffer to use. This sizes the char vector that the ofBuffer instance contains.
Documentation from code comments
Request that the buffer capacity be at least enough to contain a specified number of bytes.
Parameters:
size number of bytes to reserve space for
append(...)
void ofBuffer::append(const char *buffer, size_t size)
Documentation from code comments
Append bytes to the end of the buffer from a raw byte pointer.
Warning: buffer must not be NULL
Warning: size must be <= the number of bytes allocated in buffer
Parameters:
buffer pointer to the raw byte buffer to copy data from
size the number of bytes to read
append(...)
void ofBuffer::append(const string &buffer)
Documentation from code comments
Append bytes to the end of buffer from a string.
Parameters:
buffer string to copy bytes from
clear()
void ofBuffer::clear()
Clears all the data from the buffer.
Documentation from code comments
Remove all bytes from the buffer, leaving a size of 0.
getData()
char * ofBuffer::getData()
Documentation from code comments
Access the buffer's contents using a raw byte pointer.
Warning: Do not access bytes at indices beyond size()!
Returns: pointer to internal raw bytes
getData()
const char * ofBuffer::getData()
Documentation from code comments
access the buffer's contents using a const raw byte pointer.
Warning: Do not access bytes at indices beyond size()!
Returns: const pointer to internal raw bytes
getLines()
ofBuffer::Lines ofBuffer::getLines()
Documentation from code comments
Access the contents of the buffer as a series of text lines.
If the buffer loads a text file with lines separated by an endline char '\n', you can access each line individually using Line structs.
Returns: buffer text lines
getReverseLines()
ofBuffer::RLines ofBuffer::getReverseLines()
Documentation from code comments
Access the contents of the buffer as a series of text lines in reverse order
If the buffer loads a text file with lines separated by an endline char '\n' or '\r\n', you can access each line individually using Line structs.
Returns: buffer text lines
getText()
string ofBuffer::getText()
Return the buffer data as a string.
Documentation from code comments
get the contents of the buffer as a string.
Returns: buffer contents as a string
operator=(...)
ofBuffer & ofBuffer::operator=(const string &text)
Documentation from code comments
set contents of the buffer from a string
reserve(...)
void ofBuffer::reserve(size_t size)
Documentation from code comments
Request that the buffer capacity be at least enough to contain a specified number of bytes.
Parameters:
size number of bytes to reserve space for
resize(...)
void ofBuffer::resize(size_t size)
Documentation from code comments
Resize the buffer to contain a specified number of bytes.
If size is < the current buffer size, the contents are reduced to size bytes & remaining bytes are removed. If size is > the current buffer size, the buffer's size is increased to size_ bytes.
Parameters:
size number of bytes to resize the buffer to
set(...)
void ofBuffer::set(const char *buffer, size_t size)
Set the buffer from a string.
string giantDataString;
ofBuffer buff;
buff.set(giantDataString.c_str(), giantDataString.size());
Documentation from code comments
Set the contents of the buffer from a raw byte pointer.
Warning: buffer must not be NULL
Warning: size must be <= the number of bytes allocated in buffer
Parameters:
buffer pointer to the raw byte buffer to copy data from
size the number of bytes to read
set(...)
void ofBuffer::set(const string &text)
Documentation from code comments
Set contents of the buffer from a string.
Parameters:
text string to copy data from
set(...)
bool ofBuffer::set(istream &stream, size_t ioBlockSize)
Set the buffer from an istream.
Documentation from code comments
Set contents of the buffer from an input stream.
Parameters:
stream input stream to copy data from
ioBlockSize the number of bytes to read from the stream in chunks
setall(...)
void ofBuffer::setall(char mem)
Documentation from code comments
Set all bytes in the buffer to a given value.
Parameters:
mem byte value to set
size()
size_t ofBuffer::size()
Get the size of the buffer data.
Documentation from code comments
Check the buffer's size.
Returns: the size of the buffer's content in bytes
writeTo(...)
bool ofBuffer::writeTo(ostream &stream)
Documentation from code comments
Write contents of the buffer to an output stream.
Last updated 星期二, 19 十一月 2024 17:25:44 UTC - 2537ee49f6d46d5fe98e408849448314fd1f180e
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue