CUGL 2.3
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cugl::JsonWriter Class Reference

#include <CUJsonWriter.h>

Inheritance diagram for cugl::JsonWriter:
cugl::TextWriter

Public Member Functions

void writeJson (const std::shared_ptr< JsonValue > &json, bool format=true)
 
void writeJson (const JsonValue *json, bool format=true)
 
- Public Member Functions inherited from cugl::TextWriter
 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< JsonWriteralloc (const std::string file)
 
static std::shared_ptr< JsonWriteralloc (const std::string file, unsigned int capacity)
 
- Static Public Member Functions inherited from cugl::TextWriter
static std::shared_ptr< TextWriteralloc (const std::string file)
 
static std::shared_ptr< TextWriteralloc (const std::string file, unsigned int capacity)
 

Additional Inherited Members

- Protected Attributes inherited from cugl::TextWriter
std::string _name
 
SDL_RWops * _stream
 
char * _cbuffer
 
Uint32 _capacity
 
Sint32 _bufoff
 

Detailed Description

Simple JSON extension to TextWriter.

This class not require that the entire file conform to JSON standards; it can write a JSON string embedded in a larger text file. This allows for maximum flexibility in encoding/decoding JSON data.

By default, this class (and every class in the io package) accesses the application save directory {

See also
Application::getSaveDirectory()}. If you want to access another directory, you will need to specify an absolute path for the file name. Keep in mind that absolute paths are very dangerous on mobile devices, because they do not have proper file systems. You should confine all files to either the asset or the save directory.

Member Function Documentation

◆ alloc() [1/2]

static std::shared_ptr< JsonWriter > cugl::JsonWriter::alloc ( const std::string  file)
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 {

See also
Application::getSaveDirectory()}. If you wish to write a file in any other directory, you must provide an absolute path. Be warned, however, that write priviledges are heavily restricted on mobile platforms.
Parameters
filethe path (absolute or relative) to the file
Returns
a newly allocated writer for the given file.

◆ alloc() [2/2]

static std::shared_ptr< JsonWriter > cugl::JsonWriter::alloc ( const std::string  file,
unsigned int  capacity 
)
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 {

See also
Application::getSaveDirectory()}. If you wish to write a file in any other directory, you must provide an absolute path. Be warned, however, that write priviledges are heavily restricted on mobile platforms.
Parameters
filethe path (absolute or relative) to the file
capacitythe buffer capacity for reading chunks
Returns
a newly allocated writer for the given file with the specified capacity.

◆ writeJson() [1/2]

void cugl::JsonWriter::writeJson ( const JsonValue json,
bool  format = true 
)

Writes a JsonValue to the file, appending a newline at the end.

The JSON may either be pretty-printed or condensed depending on the value of format. By default, we pretty-print all JSON strings.

This method automatically flushes the buffer when done.

Parameters
jsonThe JSON value to write
formatWhether to pretty-print the JSON string

◆ writeJson() [2/2]

void cugl::JsonWriter::writeJson ( const std::shared_ptr< JsonValue > &  json,
bool  format = true 
)
inline

Writes a JsonValue to the file, appending a newline at the end.

The JSON may either be pretty-printed or condensed depending on the value of format. By default, we pretty-print all JSON strings.

This method automatically flushes the buffer when done.

Parameters
jsonThe JSON value to write
formatWhether to pretty-print the JSON string

The documentation for this class was generated from the following file: