49 #ifndef __CU_TEXT_READER_H__
50 #define __CU_TEXT_READER_H__
53 #include "CUPathname.h"
58 #pragma mark TextReader
95 #pragma mark Internal Methods
105 #pragma mark Constructors
113 TextReader() : _name(
""), _stream(nullptr), _ssize(-1), _scursor(-1),
114 _sbuffer(
""), _cbuffer(nullptr), _capacity(0), _bufoff(-1) {}
138 bool init(
const std::string& file) {
191 bool init(
const std::string& file,
unsigned int capacity) {
208 bool init(
const char* file,
unsigned int capacity) {
293 #pragma mark Static Constructors
309 static std::shared_ptr<TextReader>
alloc(
const std::string& file) {
310 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
311 return (result->init(file) ? result :
nullptr);
329 static std::shared_ptr<TextReader>
alloc(
const char* file) {
330 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
331 return (result->init(file) ? result :
nullptr);
350 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
351 return (result->init(file) ? result :
nullptr);
367 static std::shared_ptr<TextReader>
alloc(
const std::string& file,
unsigned int capacity) {
368 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
369 return (result->init(file,capacity) ? result :
nullptr);
385 static std::shared_ptr<TextReader>
alloc(
const char* file,
unsigned int capacity) {
386 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
387 return (result->init(file,capacity) ? result :
nullptr);
403 static std::shared_ptr<TextReader>
alloc(
const Pathname& file,
unsigned int capacity) {
404 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
405 return (result->init(file,capacity) ? result :
nullptr);
423 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
424 return (result->initWithAsset(file) ? result :
nullptr);
442 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
443 return (result->initWithAsset(file) ? result :
nullptr);
459 static std::shared_ptr<TextReader>
allocWithAsset(
const std::string& file,
unsigned int capacity) {
460 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
461 return (result->initWithAsset(file,capacity) ? result :
nullptr);
477 static std::shared_ptr<TextReader>
allocWithAsset(
const char* file,
unsigned int capacity) {
478 std::shared_ptr<TextReader> result = std::make_shared<TextReader>();
479 return (result->initWithAsset(file,capacity) ? result :
nullptr);
484 #pragma mark Stream Management
508 bool ready()
const {
return _bufoff < _sbuffer.size() || _scursor <
_ssize; }
512 #pragma mark Read Methods
537 std::string&
read(std::string& data);
562 std::string&
readUTF8(std::string& data);
592 std::string&
readLine(std::string& data);
616 std::string&
readAll(std::string& data);
Definition: CUTextReader.h:74
std::string _sbuffer
Definition: CUTextReader.h:86
bool ready() const
Definition: CUTextReader.h:508
std::string _name
Definition: CUTextReader.h:77
char * _cbuffer
Definition: CUTextReader.h:88
bool init(const char *file, unsigned int capacity)
Definition: CUTextReader.h:208
static std::shared_ptr< TextReader > alloc(const char *file)
Definition: CUTextReader.h:329
bool init(const char *file)
Definition: CUTextReader.h:157
Sint64 _ssize
Definition: CUTextReader.h:81
static std::shared_ptr< TextReader > alloc(const std::string &file)
Definition: CUTextReader.h:309
static std::shared_ptr< TextReader > alloc(const char *file, unsigned int capacity)
Definition: CUTextReader.h:385
bool init(const std::string &file)
Definition: CUTextReader.h:138
static std::shared_ptr< TextReader > alloc(const Pathname &file, unsigned int capacity)
Definition: CUTextReader.h:403
static std::shared_ptr< TextReader > alloc(const Pathname &file)
Definition: CUTextReader.h:349
static std::shared_ptr< TextReader > allocWithAsset(const char *file, unsigned int capacity)
Definition: CUTextReader.h:477
TextReader()
Definition: CUTextReader.h:113
Sint32 _bufoff
Definition: CUTextReader.h:92
bool initWithAsset(const std::string &file)
Definition: CUTextReader.h:241
SDL_RWops * _stream
Definition: CUTextReader.h:79
Uint32 _capacity
Definition: CUTextReader.h:90
static std::shared_ptr< TextReader > allocWithAsset(const std::string &file)
Definition: CUTextReader.h:422
static std::shared_ptr< TextReader > allocWithAsset(const std::string &file, unsigned int capacity)
Definition: CUTextReader.h:459
~TextReader()
Definition: CUTextReader.h:121
static std::shared_ptr< TextReader > alloc(const std::string &file, unsigned int capacity)
Definition: CUTextReader.h:367
bool initWithAsset(const std::string &file, unsigned int capacity)
Definition: CUTextReader.h:273
Definition: CUAnimationNode.h:52
Sint64 _scursor
Definition: CUTextReader.h:83
bool init(const std::string &file, unsigned int capacity)
Definition: CUTextReader.h:191
Definition: CUPathname.h:85
static std::shared_ptr< TextReader > allocWithAsset(const char *file)
Definition: CUTextReader.h:441