GammaLib
2.0.0
|
File URL class. More...
#include <GUrlFile.hpp>
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... | |
GUrlFile & | operator= (const GUrlFile &url) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear instance. More... | |
virtual GUrlFile * | clone (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... | |
GUrl & | operator= (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... | |
File URL class.
Definition at line 41 of file GUrlFile.hpp.
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.
[in] | url | File name. |
[in] | mode | File 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.
[in] | url | URL. |
Definition at line 94 of file GUrlFile.cpp.
References copy_members(), and init_members().
|
virtual |
|
inlinevirtual |
Return class name.
Implements GUrl.
Definition at line 86 of file GUrlFile.hpp.
|
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().
|
virtual |
Clone instance.
Implements GUrl.
Definition at line 185 of file GUrlFile.cpp.
References GUrlFile().
|
virtual |
Close file.
Implements GUrl.
Definition at line 234 of file GUrlFile.cpp.
References m_fptr, m_mode, and m_url.
Referenced by free_members(), open(), and GXml::save().
|
protected |
Copy class members.
[in] | url | URL. |
Definition at line 549 of file GUrlFile.cpp.
References m_fptr, m_mode, and m_url.
Referenced by GUrlFile(), and operator=().
|
protected |
Delete class members.
Definition at line 564 of file GUrlFile.cpp.
References close().
Referenced by clear(), operator=(), and ~GUrlFile().
|
virtual |
Return next character from 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 350 of file GUrlFile.cpp.
References m_fptr.
|
protected |
Initialise class members.
Definition at line 528 of file GUrlFile.cpp.
References m_fptr, m_mode, and m_url.
Referenced by clear(), GUrlFile(), and operator=().
|
virtual |
Open file.
[in] | url | File name. |
[in] | mode | File mode. |
GException::file_error | Unable to open file. |
Opens a file url
in the specified mode
. Any environment variable present in the filename will be automatically expanded.
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().
Assignment operator.
[in] | url | URL. |
Definition at line 132 of file GUrlFile.cpp.
References copy_members(), free_members(), init_members(), and GUrl::operator=().
Print URL information.
[in] | chatter | Chattiness (defaults to NORMAL). |
Implements GUrl.
Definition at line 475 of file GUrlFile.cpp.
References m_fptr, m_mode, m_url, gammalib::parformat(), SILENT, and gammalib::str().
|
virtual |
Write formatted data into file.
[in] | format | Format. |
[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 445 of file GUrlFile.cpp.
References m_fptr.
|
virtual |
Write character into file.
[in] | character | Character. |
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 377 of file GUrlFile.cpp.
References m_fptr.
|
virtual |
Read block of data from file in buffer.
[in] | buffer | Data buffer. |
[in] | nbyte | Number of Bytes to be 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 273 of file GUrlFile.cpp.
References m_fptr.
|
virtual |
Read formatted data from file.
[in] | format | Format. |
[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 405 of file GUrlFile.cpp.
References m_fptr.
|
virtual |
Write block of data buffer into file.
[in] | buffer | Data buffer. |
[in] | nbyte | Number of Bytes to be 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 314 of file GUrlFile.cpp.
References 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().
|
protected |
File mode.
Definition at line 75 of file GUrlFile.hpp.
Referenced by close(), copy_members(), init_members(), open(), and print().
|
protected |
File URL.
Definition at line 74 of file GUrlFile.hpp.
Referenced by close(), copy_members(), init_members(), open(), and print().