CUGL
Cornell University Game Library
Public Member Functions | Static Public Member Functions | List of all members
cugl::JsonReader Class Reference

#include <CUJsonReader.h>

Inheritance diagram for cugl::JsonReader:
cugl::TextReader

Public Member Functions

std::string readJsonString ()
 
std::shared_ptr< JsonValuereadJson ()
 
- Public Member Functions inherited from cugl::TextReader
 TextReader ()
 
 ~TextReader ()
 
bool init (const std::string &file)
 
bool init (const char *file)
 
bool init (const Pathname &file)
 
bool init (const std::string &file, unsigned int capacity)
 
bool init (const char *file, unsigned int capacity)
 
bool init (const Pathname &file, unsigned int capacity)
 
bool initWithAsset (const std::string &file)
 
bool initWithAsset (const char *file)
 
bool initWithAsset (const std::string &file, unsigned int capacity)
 
bool initWithAsset (const char *file, unsigned int capacity)
 
void reset ()
 
void close ()
 
bool ready () const
 
char read ()
 
std::string & read (std::string &data)
 
std::string readUTF8 ()
 
std::string & readUTF8 (std::string &data)
 
std::string readLine ()
 
std::string & readLine (std::string &data)
 
std::string readAll ()
 
std::string & readAll (std::string &data)
 
void skip ()
 

Static Public Member Functions

static std::shared_ptr< JsonReaderalloc (const std::string &file)
 
static std::shared_ptr< JsonReaderalloc (const char *file)
 
static std::shared_ptr< JsonReaderalloc (const Pathname &file)
 
static std::shared_ptr< JsonReaderalloc (const std::string &file, unsigned int capacity)
 
static std::shared_ptr< JsonReaderalloc (const char *file, unsigned int capacity)
 
static std::shared_ptr< JsonReaderalloc (const Pathname &file, unsigned int capacity)
 
static std::shared_ptr< JsonReaderallocWithAsset (const std::string &file)
 
static std::shared_ptr< JsonReaderallocWithAsset (const char *file)
 
static std::shared_ptr< JsonReaderallocWithAsset (const std::string &file, unsigned int capacity)
 
static std::shared_ptr< JsonReaderallocWithAsset (const char *file, unsigned int capacity)
 
- Static Public Member Functions inherited from cugl::TextReader
static std::shared_ptr< TextReaderalloc (const std::string &file)
 
static std::shared_ptr< TextReaderalloc (const char *file)
 
static std::shared_ptr< TextReaderalloc (const Pathname &file)
 
static std::shared_ptr< TextReaderalloc (const std::string &file, unsigned int capacity)
 
static std::shared_ptr< TextReaderalloc (const char *file, unsigned int capacity)
 
static std::shared_ptr< TextReaderalloc (const Pathname &file, unsigned int capacity)
 
static std::shared_ptr< TextReaderallocWithAsset (const std::string &file)
 
static std::shared_ptr< TextReaderallocWithAsset (const char *file)
 
static std::shared_ptr< TextReaderallocWithAsset (const std::string &file, unsigned int capacity)
 
static std::shared_ptr< TextReaderallocWithAsset (const char *file, unsigned int capacity)
 

Additional Inherited Members

- Protected Member Functions inherited from cugl::TextReader
void fill ()
 
- Protected Attributes inherited from cugl::TextReader
std::string _name
 
SDL_RWops * _stream
 
Sint64 _ssize
 
Sint64 _scursor
 
std::string _sbuffer
 
char * _cbuffer
 
Uint32 _capacity
 
Sint32 _bufoff
 

Detailed Description

Simple JSON extension to TextReader.

This class not require that the entire file conform to JSON standards; it can read 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

static std::shared_ptr<JsonReader> cugl::JsonReader::alloc ( const std::string &  file)
inlinestatic

Returns a newly allocated reader for the given file.

The reader will have the default buffer capacity for reading chunks from 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 read a file in any other directory, you must provide an absolute path.
Parameters
filethe path (absolute or relative) to the file
Returns
a newly allocated reader for the given file.
static std::shared_ptr<JsonReader> cugl::JsonReader::alloc ( const char *  file)
inlinestatic

Returns a newly allocated reader for the given file.

The reader will have the default buffer capacity for reading chunks from 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 read a file in any other directory, you must provide an absolute path.
Parameters
filethe path (absolute or relative) to the file
Returns
a newly allocated reader for the given file.
static std::shared_ptr<JsonReader> cugl::JsonReader::alloc ( const Pathname file)
inlinestatic

Returns a newly allocated reader for the given file.

The reader will have the default buffer capacity for reading chunks from 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 read a file in any other directory, you must provide an absolute path.
Parameters
filethe path (absolute or relative) to the file
Returns
a newly allocated reader for the given file.
static std::shared_ptr<JsonReader> cugl::JsonReader::alloc ( const std::string &  file,
unsigned int  capacity 
)
inlinestatic

Returns a newly allocated reader 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 read a file in any other directory, you must provide an absolute path.
Parameters
filethe path (absolute or relative) to the file
capacitythe buffer capacity for reading chunks
Returns
a newly allocated reader for the given file with the specified capacity.
static std::shared_ptr<JsonReader> cugl::JsonReader::alloc ( const char *  file,
unsigned int  capacity 
)
inlinestatic

Returns a newly allocated reader 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 read a file in any other directory, you must provide an absolute path.
Parameters
filethe path (absolute or relative) to the file
capacitythe buffer capacity for reading chunks
Returns
a newly allocated reader for the given file with the specified capacity.
static std::shared_ptr<JsonReader> cugl::JsonReader::alloc ( const Pathname file,
unsigned int  capacity 
)
inlinestatic

Returns a newly allocated reader 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 read a file in any other directory, you must provide an absolute path.
Parameters
filethe path (absolute or relative) to the file
capacitythe buffer capacity for reading chunks
Returns
a newly allocated reader for the given file with the specified capacity.
static std::shared_ptr<JsonReader> cugl::JsonReader::allocWithAsset ( const std::string &  file)
inlinestatic

Returns a newly allocated reader for the given file.

The reader will have the default buffer capacity for reading chunks from the file.

This initializer assumes that the file name is a relative path. It will search the application assert directory {

See also
Application::getAssetDirectory()} for the file and return false if it cannot find it there.
Parameters
filethe relative path to the file
Returns
a newly allocated reader for the given file.
static std::shared_ptr<JsonReader> cugl::JsonReader::allocWithAsset ( const char *  file)
inlinestatic

Returns a newly allocated reader for the given file.

The reader will have the default buffer capacity for reading chunks from the file.

This initializer assumes that the file name is a relative path. It will search the application assert directory {

See also
Application::getAssetDirectory()} for the file and return false if it cannot find it there.
Parameters
filethe relative path to the file
Returns
a newly allocated reader for the given file.
static std::shared_ptr<JsonReader> cugl::JsonReader::allocWithAsset ( const std::string &  file,
unsigned int  capacity 
)
inlinestatic

Returns a newly allocated reader for the given file with the specified capacity.

This initializer assumes that the file name is a relative path. It will search the application assert directory {

See also
Application::getAssetDirectory()} for the file and return false if it cannot find it there.
Parameters
filethe relative path to the file
capacitythe buffer capacity for reading chunks
Returns
a newly allocated reader for the given file with the specified capacity.
static std::shared_ptr<JsonReader> cugl::JsonReader::allocWithAsset ( const char *  file,
unsigned int  capacity 
)
inlinestatic

Returns a newly allocated reader for the given file with the specified capacity.

This initializer assumes that the file name is a relative path. It will search the application assert directory {

See also
Application::getAssetDirectory()} for the file and return false if it cannot find it there.
Parameters
filethe relative path to the file
capacitythe buffer capacity for reading chunks
Returns
a newly allocated reader for the given file with the specified capacity.
std::shared_ptr<JsonValue> cugl::JsonReader::readJson ( )

Returns a newly allocated JsonValue for the next available JSON string.

This method uses readJsonString() to extract the next available JSON string and constructs a JsonValue from that.

If there is a parsing error, this method will return nullptr. Detailed information about the parsing error will be passed to an assert. Hence error messages are suppressed if asserts are turned off.

Returns
a newly allocated JsonValue for the next available JSON string.
std::string cugl::JsonReader::readJsonString ( )

Returns the next available JSON string

A JSON string is defined to be any string within matching braces {}. This method will skip over any whitespace to find the first brace. If the first non-whitespace character is not a brace, this method will fail.

If the first non-whitespace character is a brace, it will advance until it reaches the matching brace, or the end of the file, whichever is first. If it finds no matching brace, it will fail.

Returns
the next available JSON string

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