CUGL 2.3
Cornell University Game Library
|
#include <CUTextWriter.h>
Public Member Functions | |
TextWriter () | |
~TextWriter () | |
bool | init (const std::string file) |
bool | init (const std::string file, unsigned int capacity) |
void | flush () |
void | close () |
void | write (char c) |
void | write (Uint8 b) |
void | write (Sint16 n) |
void | write (Uint16 n) |
void | write (Sint32 n) |
void | write (Uint32 n) |
void | write (Sint64 n) |
void | write (Uint64 n) |
void | write (bool b) |
void | write (float n) |
void | write (double n) |
void | write (const char *s) |
void | write (const std::string s) |
void | writeLine (const std::string s) |
Static Public Member Functions | |
static std::shared_ptr< TextWriter > | alloc (const std::string file) |
static std::shared_ptr< TextWriter > | alloc (const std::string file, unsigned int capacity) |
Protected Attributes | |
std::string | _name |
SDL_RWops * | _stream |
char * | _cbuffer |
Uint32 | _capacity |
Sint32 | _bufoff |
Simple text-based writer for ASCII or UTF8 files.
This class provides a simple Java-style writer for writing to text files. It supports both ASCII and UTF8 encoding. No other encodings are supported (nor should they be since they are not cross-platform).
By default, this class (and every class in the io package) accesses the application save directory {
|
inline |
Creates a text writer with no assigned file.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.
|
inline |
Deletes this writer and all of its resources.
Calls to the destructor will close the file if it is not already closed.
|
inlinestatic |
Returns a newly allocated writer for the given file.
The writer will have the default buffer capacity for writing chunks to the file.
If the file is a relative path, this reader will look for the file in the application save directory {
file | the path (absolute or relative) to the file |
|
inlinestatic |
Returns a newly allocated writer for the given file with the specified capacity.
If the file is a relative path, this reader will look for the file in the application save directory {
file | the path (absolute or relative) to the file |
capacity | the buffer capacity for reading chunks |
void cugl::TextWriter::close | ( | ) |
Closes the stream, releasing all resources
The contents of the buffer are flushed before the file is closed. Any attempts to write to a closed stream will fail. Calling this method on a previously closed stream has no effect.
void cugl::TextWriter::flush | ( | ) |
Flushes the contents of the write buffer to the file.
It is usually unnecessary to call this method. It is called automatically when the buffer fills, or just before the file is closed.
bool cugl::TextWriter::init | ( | const std::string | file | ) |
Initializes a writer for the given file.
The writer will have the default buffer capacity for writing chunks to the file.
If the file is a relative path, this reader will look for the file in the application save directory {
file | the path (absolute or relative) to the file |
bool cugl::TextWriter::init | ( | const std::string | file, |
unsigned int | capacity | ||
) |
Initializes a writer for the given file with the specified capacity.
If the file is a relative path, this reader will look for the file in the application save directory {
file | the path (absolute or relative) to the file |
capacity | the buffer capacity for reading chunks |
|
inline |
Writes a boolean value to the file.
The boolean will be written as the string "false" or "true".
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
b | the boolean value to write |
void cugl::TextWriter::write | ( | char | c | ) |
Writes a single character to the file.
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
c | the character to write |
void cugl::TextWriter::write | ( | const char * | s | ) |
Writes a string (ASCII or UTF8) to the file
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
s | the string to write |
void cugl::TextWriter::write | ( | const std::string | s | ) |
Writes a string (ASCII or UTF8) to the file
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
s | the string to write |
|
inline |
Writes a double value to the file.
The value will be written with full precision.
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
n | the double value to write |
|
inline |
Writes a float value to the file.
The value will be written with full precision.
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
n | the float value to write |
|
inline |
Writes a signed 16 bit integer to the file.
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
n | the signed 16 bit integer to write |
|
inline |
Writes a signed 32 bit integer to the file.
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
n | the signed 32 bit integer to write |
|
inline |
Writes a signed 64 bit integer to the file.
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
n | the signed 64 bit integer to write |
|
inline |
Writes a unsigned 16 bit integer to the file.
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
n | the unsigned 16 bit integer to write |
|
inline |
Writes a unsigned 32 bit integer to the file.
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
n | the unsigned 32 bit integer to write |
|
inline |
Writes a unsigned 64 bit integer to the file.
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
n | the unsigned 64 bit integer to write |
|
inline |
Writes a byte value to the file.
The value is written to the internal buffer, but is not necessarily flushed automatically. It will be written when the buffer reaches capacity or the file is closed.
b | the byte value to write |
void cugl::TextWriter::writeLine | ( | const std::string | s | ) |
Writes a string (ASCII or UTF8) to the file, followed by a newline
The newline used is a standard Unix newline '\n'. You should not expect Windows-style carriage returns (e.g. '\r'). This method automatically flushes the buffer when done.
s | the string to write |
|
protected |
The current offset in the writer buffer
|
protected |
The buffer capacity
|
protected |
The buffer for cutting down on file access
|
protected |
The (full) path for the file
|
protected |
The SDL I/O stream for writing