golib  0.5
goFileIO Class Reference

Reading/writing files and some utility functions. More...

#include <gofileio.h>

Static Public Member Functions

static bool readImage (const char *filename, goSignal3D< void > *signal, bool linear=false) throw (goFileIOException, goTypeException)
 
static bool writeImage (const char *filename, const goSignal3DBase< void > *signal) throw (goFileIOException, goTypeException)
 Write an image file from a goSignal3DBase<void> object. More...
 
template<class T >
static bool writeBinaryMatrix (const goMath::Matrix< T > &, FILE *f)
 Write binary matrix as described in the gnuplot manual. More...
 
template<class T >
static bool writeBinaryMatrix (const goMath::Matrix< T > &, const char *filename)
 
static FILE * createTempFile (goString &filenameRet)
 Creates a temporary file. More...
 
static bool remove (const goString &filename)
 Removes a file. More...
 
static goSize_t fileSize (const char *filename)
 Uses fseek() to find out the file size. More...
 
static bool readASCII (const char *filename, goString &target)
 Read ASCII string from file. More...
 
static bool readASCII (FILE *f, goString &target, goSize_t sz)
 Read a fixed number of characters from an ASCII file. More...
 
static bool readASCIIMax (FILE *f, goString &target, goSize_t max)
 Reads up to max characters or until 0. More...
 
static bool readASCII (FILE *f, goString &target)
 Read until 0 is read or nothing else can be read. More...
 
static bool readASCIILine (FILE *f, goString &target)
 Read a line of ascii text. More...
 
static bool writeASCII (const char *filename, const goString &str)
 Write ASCII string to file. More...
 
static bool writeASCII (FILE *f, const goString &str)
 Write a string to an already open file. More...
 
static bool fileExists (const char *filename)
 Check if a file exists. More...
 
static bool mkdir (const char *pathname)
 Create a directory. More...
 

Detailed Description

Reading/writing files and some utility functions.

Provides file reading/writing facilities.

Member Function Documentation

◆ createTempFile()

FILE * goFileIO::createTempFile ( goString filenameRet)
static

Creates a temporary file.

Parameters
filenameRetThe name of the file.
Returns
The FILE pointer to the open file. You can close it with the standard C function fclose().

◆ fileExists()

bool goFileIO::fileExists ( const char *  filename)
static

Check if a file exists.

Under Unix, uses stat() to check for existence.

Parameters
filenameFile name.
Returns
True if filename exists, false otherwise.

◆ fileSize()

goSize_t goFileIO::fileSize ( const char *  filename)
static

Uses fseek() to find out the file size.

Note
BEHOLD this does not work for 64 bit file sizes!
Bug:
Fix for 64 bit file offsets
Todo:
Fix for 64 bit file offsets
Parameters
filenameFile name.
Returns
File size.

◆ mkdir()

bool goFileIO::mkdir ( const char *  pathname)
static

Create a directory.

Parameters
pathnameDirectory to create.
Returns
True if successful, false otherwise.

◆ readASCII() [1/3]

bool goFileIO::readASCII ( const char *  filename,
goString target 
)
static

Read ASCII string from file.

Opens a file, reads it into a given goString, and closes it again.

Parameters
filenameFile name.
targetgoString to read into.
Returns
True is successful, false otherwise.

◆ readASCII() [2/3]

bool goFileIO::readASCII ( FILE *  f,
goString target 
)
static

Read until 0 is read or nothing else can be read.

The trailing 0 will be dropped.

Parameters
fFILE*
targetString is stored here
Returns
True if string was read an trailed by 0, false otherwise.

◆ readASCII() [3/3]

bool goFileIO::readASCII ( FILE *  f,
goString target,
goSize_t  sz 
)
static

Read a fixed number of characters from an ASCII file.

Parameters
fOpen file.
targetTarget string to hold the read ASCII characters.
szSize of string to read (in bytes == characters).
Returns
True if successful, false otherwise, if the number of read characters is not sz.

◆ readASCIILine()

bool goFileIO::readASCIILine ( FILE *  f,
goString target 
)
static

Read a line of ascii text.

Note
The trailing newline is overwritten with a 0 character.
Todo:
Uses a gnu extension function. Replace by something own some time (very low priority).
Parameters
fFILE pointer.
targetTarget string.
Returns

◆ readASCIIMax()

bool goFileIO::readASCIIMax ( FILE *  f,
goString target,
goSize_t  max 
)
static

Reads up to max characters or until 0.

The trailing 0 will be dropped.

Parameters
f
target
max
Returns
True if successful, false otherwise.

◆ remove()

bool goFileIO::remove ( const goString filename)
static

Removes a file.

Under Unix, uses unlink().

Parameters
filenameFile to be removed.
Returns
True if successful, false otherwise.

◆ writeASCII() [1/2]

bool goFileIO::writeASCII ( const char *  filename,
const goString str 
)
static

Write ASCII string to file.

Parameters
filenameFile name.
strString to write to the file.
Returns
True if successful, false otherwise.

◆ writeASCII() [2/2]

bool goFileIO::writeASCII ( FILE *  f,
const goString str 
)
static

Write a string to an already open file.

Parameters
fFILE pointer to the open file.
strString to write.
Returns
True if successful, false otherwise.

◆ writeBinaryMatrix()

template<class T >
bool goFileIO::writeBinaryMatrix ( const goMath::Matrix< T > &  M,
FILE *  f 
)
static

Write binary matrix as described in the gnuplot manual.

The data looks like:

  <N+1>  <y0>   <y1>   <y2>  ...  <yN>
   <x0> <z0,0> <z0,1> <z0,2> ... <z0,N>
   <x1> <z1,0> <z1,1> <z1,2> ... <z1,N>
    :      :      :      :   ...    :
Parameters
MMatrix (goFloat or goDouble type)
filenameFile name.
Returns
True if successful, false otherwise.

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