79 virtual bool valid(
void) {
return file && !ferror(file); };
82 virtual bool eof(
void) {
return !file || feof(file); };
85 virtual std::string
errmsg(
void) {
86 return std::string(file && !ferror(file) ?
"" : strerror(errno));
96 virtual bool reopen(
void) {
return true; };
99 virtual bool close(
void) { file=NULL;
return true; };
110 return file ? fread(buf, 1, n, file) : 0;
115 return file ? fgetc(file) : EOF;
125 virtual bool flush(
void) {
return file && fflush(file) != EOF; };
128 virtual bool write(
const char *buf,
size_t n) {
129 return file ? (fwrite(buf,1,n,file) == n) :
false;
134 return file ? (fputc(c,file) != EOF) :
false;
138 virtual bool puts(
const char *s) {
139 return file ? (fputs(s,file) >= 0) :
false;
142 virtual bool puts(
const std::string &s) {
143 return file ? (fwrite(s.data(),1,s.size(),
file) == s.size()) :
false;
148 virtual bool vprintf(
const char *fmt, va_list &ap) {
149 return file ? (vfprintf(file,fmt,ap) >= 0) :
false;
166 std::string default_mode;
180 mfstream(
const char *filename,
const char *open_mode=NULL)
183 open(filename,open_mode);
197 inline bool open(
const char *filename,
const char *open_mode=NULL) {
199 if (open_mode) mode = open_mode;
204 inline bool open(
const std::string &filename,
const std::string &open_mode=
"") {
213 if (mode.empty()) mode = default_mode;
216 if (mode.find(
'w') != mode.npos) file = stdout;
219 file = fopen(
name.c_str(), mode.c_str());
221 return file && !ferror(file);
225 virtual bool close(
void) {
226 if (!file)
return true;
227 else if (file==stdin || file==stdout || file==stderr) {
232 bool rc = fclose(file) == 0;
244 inline void setparams(
int level=0,
int strategy=0) {};
269 mifstream(
const char *filename,
const char *mode=NULL)
276 mifstream(
const std::string &filename,
const std::string &mode=
"")
308 mofstream(
const char *filename,
const char *mode=NULL) {
314 mofstream(
const std::string &filename,
const std::string &mode=
"") {
virtual bool close(void)
Definition: mootCIO.h:103
virtual bool write(const char *buf, size_t n)
Definition: mootCIO.h:138
virtual bool flush(void)
Definition: mootCIO.h:133
FILE * file
underlying FILE*
Definition: mootCIO.h:59
virtual int getbyte(void)
Definition: mootCIO.h:120
virtual bool eof(void)
Definition: mootCIO.h:84
Wrapper class for named file i/o using C FILE*s.
Definition: mootCIO.h:175
Wrapper class for named file input using C FILE*s.
Definition: mootCIO.h:286
Abstract base class for output stream wrappers.
Definition: mootIO.h:194
std::string name
symbolic name of this stream
Definition: mootIO.h:82
mcstream mocstream
Alias for FILE* output stream wrappers.
Definition: mootCIO.h:363
~mcstream(void)
Definition: mootCIO.h:72
virtual bool vprintf(const char *fmt, va_list &ap)
Definition: mootCIO.h:160
virtual bool reopen(void)
Definition: mootCIO.h:100
Wrapper class for named file output using C FILE*s.
Definition: mootCIO.h:327
Namespace for I/O stream wrappers.
Definition: mootBufferIO.h:45
generic I/O abstraction layer
mcstream(FILE *f=__null)
Definition: mootCIO.h:67
virtual bool putbyte(unsigned char c)
Definition: mootCIO.h:143
Wrapper class for C FILE* streams.
Definition: mootCIO.h:54
virtual ByteCount read(char *buf, size_t n)
Definition: mootCIO.h:115
virtual std::string errmsg(void)
Definition: mootCIO.h:87
int ByteCount
typedef for byte counts (should be signed, for compatibility)
Definition: mootIO.h:52
mcstream micstream
Alias for FILE* input stream wrappers.
Definition: mootCIO.h:362
virtual bool puts(const char *s)
Definition: mootCIO.h:150
virtual bool valid(void)
Definition: mootCIO.h:81
Abstract base class for input stream wrappers.
Definition: mootIO.h:129