GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GUrlFile Class Reference

File URL class. More...

#include <GUrlFile.hpp>

Inheritance diagram for GUrlFile:
GUrl GBase

Public Member Functions

 GUrlFile (void)
 Void constructor. More...
 
 GUrlFile (const std::string &url, const std::string &mode)
 Opening constructor. More...
 
 GUrlFile (const GUrlFile &url)
 Copy constructor. More...
 
virtual ~GUrlFile (void)
 Destructor. More...
 
GUrlFileoperator= (const GUrlFile &url)
 Assignment operator. More...
 
virtual void clear (void)
 Clear instance. More...
 
virtual GUrlFileclone (void) const
 Clone instance. More...
 
virtual std::string classname (void) const
 Return class name. More...
 
virtual void open (const std::string &url, const std::string &mode)
 Open file. More...
 
virtual void close (void)
 Close file. More...
 
virtual int read (void *buffer, const int &nbyte)
 Read block of data from file in buffer. More...
 
virtual int write (const void *buffer, const int &nbyte)
 Write block of data buffer into file. More...
 
virtual int get_char (void) const
 Return next character from file. More...
 
virtual void put_char (const int &character)
 Write character into file. More...
 
virtual void scanf (const char *format,...)
 Read formatted data from file. More...
 
virtual void printf (const char *format,...)
 Write formatted data into file. More...
 
virtual std::string print (const GChatter &chatter=NORMAL) const
 Print URL information. More...
 
- Public Member Functions inherited from GUrl
 GUrl (void)
 Void constructor. More...
 
 GUrl (const GUrl &url)
 Copy constructor. More...
 
virtual ~GUrl (void)
 Destructor. More...
 
GUrloperator= (const GUrl &url)
 Assignment operator. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Protected Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GUrlFile &url)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
- Protected Member Functions inherited from GUrl
void init_members (void)
 Initialise class members. More...
 
void copy_members (const GUrl &url)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 

Protected Attributes

std::string m_url
 File URL. More...
 
std::string m_mode
 File mode. More...
 
FILE * m_fptr
 File pointer. More...
 

Detailed Description

File URL class.

Definition at line 41 of file GUrlFile.hpp.

Constructor & Destructor Documentation

GUrlFile::GUrlFile ( void  )

Void constructor.

Definition at line 56 of file GUrlFile.cpp.

References init_members().

Referenced by clone().

GUrlFile::GUrlFile ( const std::string &  url,
const std::string &  mode 
)

Opening constructor.

Parameters
[in]urlFile name.
[in]modeFile mode.

Constructs GUrlFile object by opening a file url in the specified mode. Any environment variable present in the file name will be automatically expanded.

Definition at line 76 of file GUrlFile.cpp.

References init_members(), and open().

GUrlFile::GUrlFile ( const GUrlFile url)

Copy constructor.

Parameters
[in]urlURL.

Definition at line 94 of file GUrlFile.cpp.

References copy_members(), and init_members().

GUrlFile::~GUrlFile ( void  )
virtual

Destructor.

Definition at line 110 of file GUrlFile.cpp.

References free_members().

Member Function Documentation

std::string GUrlFile::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GUrlFile").

Implements GUrl.

Definition at line 86 of file GUrlFile.hpp.

void GUrlFile::clear ( void  )
virtual

Clear instance.

Implements GUrl.

Definition at line 165 of file GUrlFile.cpp.

References free_members(), GUrl::free_members(), init_members(), and GUrl::init_members().

GUrlFile * GUrlFile::clone ( void  ) const
virtual

Clone instance.

Returns
Pointer to deep copy of file URL.

Implements GUrl.

Definition at line 185 of file GUrlFile.cpp.

References GUrlFile().

void GUrlFile::close ( void  )
virtual

Close file.

Implements GUrl.

Definition at line 232 of file GUrlFile.cpp.

References m_fptr, m_mode, and m_url.

Referenced by free_members(), open(), and GXml::save().

void GUrlFile::copy_members ( const GUrlFile url)
protected

Copy class members.

Parameters
[in]urlURL.
Todo:
The simple copying of the file pointer is not clean as we have no control anymore over the object. The file pointer should be cloned somehow.

Definition at line 547 of file GUrlFile.cpp.

References m_fptr, m_mode, and m_url.

Referenced by GUrlFile(), and operator=().

void GUrlFile::free_members ( void  )
protected

Delete class members.

Definition at line 562 of file GUrlFile.cpp.

References close().

Referenced by clear(), operator=(), and ~GUrlFile().

int GUrlFile::get_char ( void  ) const
virtual

Return next character from file.

Returns
Next character in file.

Returns the character currently pointed by the internal file position indicator of the file. The internal file position indicator is then advanced to the next character.

If the stream is at the end-of-file when called, the function returns EOF and sets the end-of-file indicator for the file.

If a read error occurs, the method returns EOF.

If no file has been opened, the method returns EOF.

Implements GUrl.

Definition at line 348 of file GUrlFile.cpp.

References m_fptr.

void GUrlFile::init_members ( void  )
protected

Initialise class members.

Definition at line 526 of file GUrlFile.cpp.

References m_fptr, m_mode, and m_url.

Referenced by clear(), GUrlFile(), and operator=().

void GUrlFile::open ( const std::string &  url,
const std::string &  mode 
)
virtual

Open file.

Parameters
[in]urlFile name.
[in]modeFile mode.
Exceptions
GException::file_open_errorUnable to open file.

Opens a file url in the specified mode. Any environment variable present in the filename will be automatically expanded.

Todo:
Strip any file:// prefix

Implements GUrl.

Definition at line 206 of file GUrlFile.cpp.

References close(), gammalib::expand_env(), G_OPEN, m_fptr, m_mode, and m_url.

Referenced by GUrlFile().

GUrlFile & GUrlFile::operator= ( const GUrlFile url)

Assignment operator.

Parameters
[in]urlURL.
Returns
URL.

Definition at line 132 of file GUrlFile.cpp.

References copy_members(), free_members(), init_members(), and GUrl::operator=().

std::string GUrlFile::print ( const GChatter chatter = NORMAL) const
virtual

Print URL information.

Parameters
[in]chatterChattiness (defaults to NORMAL).
Returns
String containing URL information.

Implements GUrl.

Definition at line 473 of file GUrlFile.cpp.

References m_fptr, m_mode, m_url, gammalib::parformat(), SILENT, and gammalib::str().

void GUrlFile::printf ( const char *  format,
  ... 
)
virtual

Write formatted data into file.

Parameters
[in]formatFormat.
[in]...Optional parameters.

Writes the C string pointed by format to the file. If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.

After the format parameter, the function expects at least as many additional arguments as specified by format.

If no file has been opened, the method does nothing.

Implements GUrl.

Definition at line 443 of file GUrlFile.cpp.

References m_fptr.

void GUrlFile::put_char ( const int &  character)
virtual

Write character into file.

Parameters
[in]characterCharacter.

Writes a character to the file and advances the position indicator.

If no file has been opened, the method does nothing.

Implements GUrl.

Definition at line 375 of file GUrlFile.cpp.

References m_fptr.

int GUrlFile::read ( void *  buffer,
const int &  nbyte 
)
virtual

Read block of data from file in buffer.

Parameters
[in]bufferData buffer.
[in]nbyteNumber of Bytes to be read.
Returns
Number of Bytes that were effectively read.

Reads nbyte Bytes from the file into a buffer. The position indicator of the file is advanced by the total amount of bytes read.

The total number of Bytes successfully read is returned. If this number differs from the nbyte parameter, either a reading error occurred or the end-of-file was reached while reading. In both cases, the proper indicator is set.

If either buffer is NULL or nbyte is zero, the method returns zero and both the file state and the content pointed by buffer remain unchanged.

If no file has been opened, the method returns zero and both the file state and the content pointed by buffer remain unchanged.

Implements GUrl.

Definition at line 271 of file GUrlFile.cpp.

References m_fptr.

void GUrlFile::scanf ( const char *  format,
  ... 
)
virtual

Read formatted data from file.

Parameters
[in]formatFormat.
[in]...Optional parameters.

Reads data from a file and stores them according to the parameter format into the locations pointed by the additional arguments. The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string.

If no file has been opened, the method does nothing.

Implements GUrl.

Definition at line 403 of file GUrlFile.cpp.

References m_fptr.

int GUrlFile::write ( const void *  buffer,
const int &  nbyte 
)
virtual

Write block of data buffer into file.

Parameters
[in]bufferData buffer.
[in]nbyteNumber of Bytes to be written.
Returns
Number of Bytes that were effectively written.

Writes nbyte Bytes from a buffer into the file. The position indicator of the file is advanced by the total amount of bytes written.

The total number of Bytes successfully written is returned. If this number differs from the nbyte parameter, a writing error prevented the function from completing.

If either buffer is NULL or nbyte is zero, the method returns zero and both the file state and the content pointed by buffer remain unchanged.

If no file has been opened, the method returns zero and both the file state and the content pointed by buffer remain unchanged.

Implements GUrl.

Definition at line 312 of file GUrlFile.cpp.

References m_fptr.

Member Data Documentation

FILE* GUrlFile::m_fptr
protected

File pointer.

Definition at line 76 of file GUrlFile.hpp.

Referenced by close(), copy_members(), get_char(), init_members(), open(), print(), printf(), put_char(), read(), scanf(), and write().

std::string GUrlFile::m_mode
protected

File mode.

Definition at line 75 of file GUrlFile.hpp.

Referenced by close(), copy_members(), init_members(), open(), and print().

std::string GUrlFile::m_url
protected

File URL.

Definition at line 74 of file GUrlFile.hpp.

Referenced by close(), copy_members(), init_members(), open(), and print().


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