49 #ifndef __CU_TEXT_READER_H__
50 #define __CU_TEXT_READER_H__
51 #include <cugl/base/CUBase.h>
54 #include "CUPathname.h"
59 #pragma mark TextReader
96 #pragma mark Internal Methods
106 #pragma mark Constructors
114 TextReader() : _name(
""), _stream(nullptr), _ssize(-1), _scursor(-1),
115 _sbuffer(
""), _cbuffer(nullptr), _capacity(0), _bufoff(-1) {}
139 bool init(
const std::string& file) {
192 bool init(
const std::string& file,
unsigned int capacity) {
209 bool init(
const char* file,
unsigned int capacity) {
294 #pragma mark Static Constructors
310 static std::shared_ptr<TextReader>
alloc(
const std::string& file) {
311 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
312 return (result->init(file) ? result :
nullptr);
330 static std::shared_ptr<TextReader>
alloc(
const char* file) {
331 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
332 return (result->init(file) ? result :
nullptr);
351 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
352 return (result->init(file) ? result :
nullptr);
368 static std::shared_ptr<TextReader>
alloc(
const std::string& file,
unsigned int capacity) {
369 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
370 return (result->init(file,capacity) ? result :
nullptr);
386 static std::shared_ptr<TextReader>
alloc(
const char* file,
unsigned int capacity) {
387 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
388 return (result->init(file,capacity) ? result :
nullptr);
404 static std::shared_ptr<TextReader>
alloc(
const Pathname& file,
unsigned int capacity) {
405 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
406 return (result->init(file,capacity) ? result :
nullptr);
424 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
425 return (result->initWithAsset(file) ? result :
nullptr);
443 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
444 return (result->initWithAsset(file) ? result :
nullptr);
460 static std::shared_ptr<TextReader>
allocWithAsset(
const std::string& file,
unsigned int capacity) {
461 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
462 return (result->initWithAsset(file,capacity) ? result :
nullptr);
478 static std::shared_ptr<TextReader>
allocWithAsset(
const char* file,
unsigned int capacity) {
479 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
480 return (result->initWithAsset(file,capacity) ? result :
nullptr);
485 #pragma mark Stream Management
509 bool ready()
const {
return _bufoff < _sbuffer.size() || _scursor <
_ssize; }
513 #pragma mark Read Methods
538 std::string&
read(std::string& data);
563 std::string&
readUTF8(std::string& data);
593 std::string&
readLine(std::string& data);
617 std::string&
readAll(std::string& data);
Definition: CUTextReader.h:75
std::string _sbuffer
Definition: CUTextReader.h:87
bool ready() const
Definition: CUTextReader.h:509
std::string _name
Definition: CUTextReader.h:78
char * _cbuffer
Definition: CUTextReader.h:89
bool init(const char *file, unsigned int capacity)
Definition: CUTextReader.h:209
static std::shared_ptr< TextReader > alloc(const char *file)
Definition: CUTextReader.h:330
bool init(const char *file)
Definition: CUTextReader.h:158
Sint64 _ssize
Definition: CUTextReader.h:82
static std::shared_ptr< TextReader > alloc(const std::string &file)
Definition: CUTextReader.h:310
static std::shared_ptr< TextReader > alloc(const char *file, unsigned int capacity)
Definition: CUTextReader.h:386
bool init(const std::string &file)
Definition: CUTextReader.h:139
static std::shared_ptr< TextReader > alloc(const Pathname &file, unsigned int capacity)
Definition: CUTextReader.h:404
static std::shared_ptr< TextReader > alloc(const Pathname &file)
Definition: CUTextReader.h:350
static std::shared_ptr< TextReader > allocWithAsset(const char *file, unsigned int capacity)
Definition: CUTextReader.h:478
TextReader()
Definition: CUTextReader.h:114
Sint32 _bufoff
Definition: CUTextReader.h:93
bool initWithAsset(const std::string &file)
Definition: CUTextReader.h:242
SDL_RWops * _stream
Definition: CUTextReader.h:80
Uint32 _capacity
Definition: CUTextReader.h:91
static std::shared_ptr< TextReader > allocWithAsset(const std::string &file)
Definition: CUTextReader.h:423
static std::shared_ptr< TextReader > allocWithAsset(const std::string &file, unsigned int capacity)
Definition: CUTextReader.h:460
~TextReader()
Definition: CUTextReader.h:122
static std::shared_ptr< TextReader > alloc(const std::string &file, unsigned int capacity)
Definition: CUTextReader.h:368
bool initWithAsset(const std::string &file, unsigned int capacity)
Definition: CUTextReader.h:274
Definition: CUAction.h:51
Sint64 _scursor
Definition: CUTextReader.h:84
bool init(const std::string &file, unsigned int capacity)
Definition: CUTextReader.h:192
Definition: CUPathname.h:85
static std::shared_ptr< TextReader > allocWithAsset(const char *file)
Definition: CUTextReader.h:442