UCommon
Public Types | Public Member Functions | Static Public Attributes
ucommon::file Class Reference

Access standard files through character protocol. More...

#include <file.h>

Inheritance diagram for ucommon::file:
Inheritance graph
[legend]
Collaboration diagram for ucommon::file:
Collaboration graph
[legend]

Public Types

typedef ::fpos_t bookmark_t
 

Public Member Functions

size_t __isoc99_scanf (const char *format,...)
 
void append (void)
 
int cancel (void)
 Cancel pipe and close file. More...
 
void clear (void)
 Clear error state.
 
int close (void)
 Close an open file. More...
 
bool eof (void) const
 
int err (void) const
 
 file (FILE *file)
 Construct a file from an existing FILE pointer. More...
 
 file (const char *path, const char *mode, size_t size=2)
 Construct an open file based on a path and mode. More...
 
 file (const char *path, char **argv, const char *mode, char **envp=((void *) 0))
 Construct an open file based on a pipe. More...
 
 file ()
 Construct an unopened file.
 
void flush (void)
 
size_t get (void *data, size_t size)
 
int get (void)
 
void get (bookmark_t &pos)
 
char * gets (char *data, size_t size)
 
bool good (void) const
 Check if file is good, no error or eof... More...
 
bool is_tty (void) const
 
void move (long offset)
 
template<typename T >
void offset (long pos)
 
void open (const char *path, const char *mode, size_t size=2)
 Open file path. More...
 
void open (const char *path, char **argv, const char *mode, char **envp=((void *) 0))
 Open an executable path. More...
 
 operator bool () const
 Test if file is opened. More...
 
 operator FILE * () const
 
bool operator! () const
 Test if file is not opened. More...
 
FILE * operator* () const
 
size_t printf (const char *format,...)
 
int push (char value)
 
size_t put (const void *data, size_t size)
 
int put (char value)
 
int puts (const char *data)
 
template<typename T >
size_t read (T *data, size_t count)
 
template<typename T >
size_t read (T &data)
 
void rewind (void)
 
void seek (long offset)
 
void set (bookmark_t &pos)
 
template<typename T >
size_t write (const T *data, size_t count)
 
template<typename T >
size_t write (const T &data)
 
 ~file ()
 Destroy object and close associated file.
 
- Public Member Functions inherited from ucommon::CharacterProtocol
int getchar (void)
 Get the next character. More...
 
size_t getline (char *string, size_t size)
 Get text as a line of input from the buffer. More...
 
size_t getline (String &buffer)
 Get a string as a line of input from the buffer. More...
 
size_t input (InputProtocol &format)
 
size_t load (StringPager *list)
 Load input to a string list. More...
 
size_t print (const PrintProtocol &format)
 
int putchar (int code)
 Put the next character. More...
 
size_t putchars (const char *string, size_t count=0)
 
size_t putline (const char *string)
 Put a string as a line of output to the buffer. More...
 
size_t save (const StringPager *list)
 Save output from a string list. More...
 

Static Public Attributes

static file cerr
 
static file cin
 
static file cout
 

Additional Inherited Members

- Protected Member Functions inherited from ucommon::CharacterProtocol
void putback (int code)
 Write to back buffer. More...
 
void seteol (const char *string)
 Set end of line marker. More...
 
- Protected Attributes inherited from ucommon::CharacterProtocol
int back
 
const char * eol
 

Detailed Description

Access standard files through character protocol.

This can also be used as an alternative means to access files that manages file pointers.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 60 of file file.h.

Constructor & Destructor Documentation

ucommon::file::file ( FILE *  file)

Construct a file from an existing FILE pointer.

Parameters
fileto use.
ucommon::file::file ( const char *  path,
const char *  mode,
size_t  size = 2 
)

Construct an open file based on a path and mode.

Parameters
pathof file to open.
modeof file.
sizeof buffer, 0 = none, 1 = line mode, 2 = default
ucommon::file::file ( const char *  path,
char **  argv,
const char *  mode,
char **  envp = ((void *) 0) 
)

Construct an open file based on a pipe.

Parameters
pathof file to pipe.
argvof executable.
modeof file.
envpto give executable.

Member Function Documentation

int ucommon::file::cancel ( void  )

Cancel pipe and close file.

Returns
process exit code if pipe.
int ucommon::file::close ( void  )

Close an open file.

Returns
process exit code if pipe.
bool ucommon::file::good ( void  ) const

Check if file is good, no error or eof...

Returns
bool if file stream is good.
void ucommon::file::open ( const char *  path,
const char *  mode,
size_t  size = 2 
)

Open file path.

If a file is already opened, it is closed.

Parameters
pathof file to open.
modeof file to open.
sizeof buffering, 0 = none, 1 = line mode.
void ucommon::file::open ( const char *  path,
char **  argv,
const char *  mode,
char **  envp = ((void *) 0) 
)

Open an executable path.

Parameters
pathof executable.
argvto pass to executable.
modeof pipe (only "r" and "w" are valid).
ucommon::file::operator bool ( ) const
inline

Test if file is opened.

Returns
true if opened.

Definition at line 121 of file file.h.

bool ucommon::file::operator! ( ) const
inline

Test if file is not opened.

Returns
true if not opened.

Definition at line 129 of file file.h.


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