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

Filename class. More...

#include <GFilename.hpp>

Inheritance diagram for GFilename:
GBase

Public Member Functions

 GFilename (void)
 Void constructor. More...
 
 GFilename (const std::string &filename)
 Filename constructor. More...
 
 GFilename (const char *filename)
 Filename constructor. More...
 
 GFilename (const GFilename &filename)
 Copy constructor. More...
 
virtual ~GFilename (void)
 Destructor. More...
 
GFilenameoperator= (const GFilename &filename)
 Assignment operator. More...
 
void clear (void)
 Clear file name. More...
 
GFilenameclone (void) const
 Clone file name. More...
 
std::string classname (void) const
 Return class name. More...
 
bool is_empty (void) const
 Signal if filename is empty. More...
 
int length (void) const
 Return length of filename. More...
 
std::string url (void) const
 Return Uniform Resource Locator (URL) More...
 
std::string protocol (void) const
 Return access protocol. More...
 
std::string path (void) const
 Return access path. More...
 
std::string file (void) const
 Return name of file. More...
 
std::string type (void) const
 Return file type. More...
 
bool exists (void) const
 Checks whether file exists. More...
 
bool is_fits (void) const
 Checks whether file is a FITS file. More...
 
void remove (void) const
 Remove file from disk. More...
 
std::string extname (const std::string &defaultname="") const
 Return extension name. More...
 
const std::string & expression (void) const
 Return expression name. More...
 
int extno (const int &defaultno=-1) const
 Return extension number. More...
 
int extver (const int &defaultver=0) const
 Return extension version number. More...
 
bool has_extname (void) const
 Signal if filename has an extension name. More...
 
bool has_extno (void) const
 Signal if filename has an extension number. More...
 
bool has_extver (void) const
 Signal if filename has an extension version. More...
 
bool has_expression (void) const
 Signal if filename has an expression. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print file name information. 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 GFilename &filename)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void set_filename (const std::string &filename)
 Set file name. More...
 

Protected Attributes

std::string m_filename
 Full file name. More...
 
std::string m_url
 File name (with stripped extension info) More...
 
std::string m_protocol
 Access protocol. More...
 
std::string m_path
 Access path. More...
 
std::string m_file
 Name of file. More...
 
std::string m_extname
 Extension name ("": not set) More...
 
int m_extno
 Extension number (-1: not set) More...
 
int m_extver
 Extension version (0: not set) More...
 
std::string m_expression
 Selection expression ("": not set) More...
 

Friends

std::string operator+ (const GFilename &filename, const std::string &string)
 String addition operator. More...
 
std::string operator+ (const std::string &string, const GFilename &filename)
 String addition operator. More...
 
bool operator== (const GFilename &a, const GFilename &b)
 Filename equality operator. More...
 
bool operator!= (const GFilename &a, const GFilename &b)
 Filename inequality operator. More...
 

Detailed Description

Filename class.

This class handles filenames. A filename is a string composed of an optional protocol (http:, ftp:, file:), an absolute or relative access path, a file, and optionally a FITS extension. Examples of valid file names are

myfits.fits
myfile.fits[EVENTS]
./data/myfile.fits
~/data/myfile.fits
/home/myuser/data/myfile.fits
http://www.irap.omp.eu/data/myfile.fits
ftp://www.irap.omp.eu/data/myfile.fits
file:///home/myuser/data/myfile.fits

A filename without the optional FITS extension is called a Uniform Resource Locator (URL) an is accessed using the url() method. The URL can be decomposed into the protocol, access path and the filename using the protocol(), path(), and file().

The FITS extension is implemente using the GFitsExtension class.

Definition at line 62 of file GFilename.hpp.

Constructor & Destructor Documentation

GFilename::GFilename ( void  )

Void constructor.

Definition at line 65 of file GFilename.cpp.

References init_members().

Referenced by clone().

GFilename::GFilename ( const std::string &  filename)

Filename constructor.

Parameters
[in]filenameFile name.

Constructs GFilename object by assigning a filename.

Definition at line 82 of file GFilename.cpp.

References init_members(), and set_filename().

GFilename::GFilename ( const char *  filename)

Filename constructor.

Parameters
[in]filenameFile name.

Constructs GFilename object by assigning a filename.

Definition at line 102 of file GFilename.cpp.

References init_members(), and set_filename().

GFilename::GFilename ( const GFilename filename)

Copy constructor.

Parameters
[in]filenameFile name.

Definition at line 120 of file GFilename.cpp.

References copy_members(), and init_members().

GFilename::~GFilename ( void  )
virtual

Destructor.

Definition at line 136 of file GFilename.cpp.

References free_members().

Member Function Documentation

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

Return class name.

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

Implements GBase.

Definition at line 148 of file GFilename.hpp.

GFilename * GFilename::clone ( void  ) const
virtual

Clone file name.

Returns
Pointer to deep copy of file name.

Implements GBase.

Definition at line 206 of file GFilename.cpp.

References GFilename().

void GFilename::copy_members ( const GFilename filename)
protected

Copy class members.

Parameters
[in]filenameFile name.

Definition at line 562 of file GFilename.cpp.

References m_expression, m_extname, m_extno, m_extver, m_file, m_filename, m_path, m_protocol, and m_url.

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

bool GFilename::exists ( void  ) const

Checks whether file exists.

Returns
True if file exists.

Checks whether a file exists on disk. In case that the file is a FITS file, the method also checks whether a compressed version of the file (with a .gz, .Z, .z, or .zip extension) exists on disk (see is_fits() method).

Definition at line 223 of file GFilename.cpp.

References is_fits(), and url().

Referenced by GCaldb::cifname(), GCTAEdisp2D::fetch(), GCTAResponseIrf::irf_filename(), GCOMInstChars::load(), GCOMD1Response::load(), GCOMD2Response::load(), GCOMResponse::load(), GXml::load(), GCTAResponseIrf::load_aeff(), GCTAResponseIrf::load_background(), GCTAResponseIrf::load_edisp(), GCTAResponseIrf::load_psf(), remove(), GCsv::save(), and GFits::saveto().

const std::string & GFilename::expression ( void  ) const
inline

Return expression name.

Returns
String containing file expression.

Definition at line 243 of file GFilename.hpp.

References m_expression.

std::string GFilename::extname ( const std::string &  defaultname = "") const
int GFilename::extno ( const int &  defaultno = -1) const

Return extension number.

Parameters
[in]defaultnoDefault extension number (default: -11).
Returns
Integer containing extension number.

Returns the extension number. If no extension number is given the number provided by the defaultno argument will be used. By default, the defaultno parameter is set to -1.

Definition at line 410 of file GFilename.cpp.

References has_extno(), and m_extno.

Referenced by GMWLSpectrum::load(), GCTAModelSpatialLookup::load(), and GSkyMap::load().

int GFilename::extver ( const int &  defaultver = 0) const

Return extension version number.

Parameters
[in]defaultverDefault extension version number (default: 0).
Returns
Integer containing extension version number.

Returns the extension version number. If no extension version number is given the number provided by the defaultver argument will be used. By default, the defaultextver parameter is set to 0.

Definition at line 435 of file GFilename.cpp.

References has_extver(), and m_extver.

Referenced by set_filename().

std::string GFilename::file ( void  ) const
inline

Return name of file.

Returns
File name.

Returns the name of the file.

Definition at line 231 of file GFilename.hpp.

References gammalib::expand_env(), and m_file.

Referenced by type(), and gammalib::xml_file_reduce().

void GFilename::free_members ( void  )
protected

Delete class members.

Definition at line 583 of file GFilename.cpp.

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

bool GFilename::has_expression ( void  ) const
inline

Signal if filename has an expression.

Returns
True if filename has an expression, false otherwise.

Definition at line 291 of file GFilename.hpp.

References m_expression.

Referenced by print(), and GCTAEventList::read().

bool GFilename::has_extname ( void  ) const
inline

Signal if filename has an extension name.

Returns
True if filename has an extension name, false otherwise.

Definition at line 255 of file GFilename.hpp.

References m_extname.

Referenced by extname(), GMWLSpectrum::load(), GCTAModelSpatialLookup::load(), GSkyMap::load(), GCTAResponseIrf::load_aeff(), GCTAResponseIrf::load_edisp(), GCTAResponseIrf::load_psf(), print(), GCOMIaq::save(), GCTAObservation::save(), and GSkyMap::save().

bool GFilename::has_extno ( void  ) const
inline

Signal if filename has an extension number.

Returns
True if filename has an extension number, false otherwise.

Definition at line 267 of file GFilename.hpp.

References m_extno.

Referenced by extno(), GMWLSpectrum::load(), GCTAModelSpatialLookup::load(), GSkyMap::load(), and print().

bool GFilename::has_extver ( void  ) const
inline

Signal if filename has an extension version.

Returns
True if filename has an extension version, false otherwise.

Definition at line 279 of file GFilename.hpp.

References m_extver.

Referenced by extver(), and print().

void GFilename::init_members ( void  )
protected

Initialise class members.

Definition at line 539 of file GFilename.cpp.

References m_expression, m_extname, m_extno, m_extver, m_file, m_filename, m_path, m_protocol, and m_url.

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

bool GFilename::is_fits ( void  ) const

Checks whether file is a FITS file.

Returns
True if file is a FITS file.

Test if the file or a compressed version of the file (with a .gz, .Z, .z, or .zip extension) is a FITS file. This method is thread safe.

Definition at line 313 of file GFilename.cpp.

References url().

Referenced by exists(), GCOMResponse::load(), GCTAResponseIrf::load_aeff(), GCTAResponseIrf::load_background(), GCTAResponseIrf::load_edisp(), and GCTAResponseIrf::load_psf().

int GFilename::length ( void  ) const
inline

Return length of filename.

Returns
Length of filename.

Returns the length of the filename, excluding any FITS extension.

Definition at line 174 of file GFilename.hpp.

References m_url.

Referenced by GCTAObservation::has_events(), and set_filename().

GFilename & GFilename::operator= ( const GFilename filename)

Assignment operator.

Parameters
[in]filenameFile name.
Returns
File name.

Definition at line 158 of file GFilename.cpp.

References copy_members(), free_members(), and init_members().

std::string GFilename::path ( void  ) const
inline

Return access path.

Returns
Access path.

Returns the access path of the file.

Definition at line 217 of file GFilename.hpp.

References gammalib::expand_env(), and m_path.

Referenced by GSPIResponse::load_irfs(), gammalib::spi_hdu(), gammalib::spi_num_hdus(), gammalib::xml_file_expand(), and gammalib::xml_file_reduce().

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

Print file name information.

Parameters
[in]chatterChattiness (default: NORMAL).
Returns
String containing file name information.

Implements GBase.

Definition at line 456 of file GFilename.cpp.

References has_expression(), has_extname(), has_extno(), has_extver(), m_expression, m_extname, m_extno, m_extver, m_file, m_filename, m_path, m_protocol, m_url, gammalib::parformat(), SILENT, and gammalib::str().

std::string GFilename::protocol ( void  ) const
inline

Return access protocol.

Returns
Access protocol.

Returns the access protocol of the file.

Definition at line 203 of file GFilename.hpp.

References gammalib::expand_env(), and m_protocol.

void GFilename::remove ( void  ) const

Remove file from disk.

Removes file or a compressed version of the file (with a .gz, .Z, .z, or .zip extension) if it exists on disk.

Definition at line 345 of file GFilename.cpp.

References exists(), and url().

Referenced by GFits::open(), and GFits::saveto().

void GFilename::set_filename ( const std::string &  filename)
protected

Set file name.

Parameters
[in]filenameFile name.
Exceptions
GException::invalid_argumentInvalid file name specified.

Sets all attributes of the object by parsing the file name. The file name can have one of the following formats:

 file.fits            No extension
 file.fits[1]         Extension number 1 (starting from 0)
 file.fits[EVENTS]    EVENTS extension
 file.fits[EVENTS,2]  Version 2 of the EVENTS extension

Definition at line 606 of file GFilename.cpp.

References clear(), extname(), extver(), G_SET_FILENAME, length(), m_expression, m_extname, m_extno, m_extver, m_file, m_filename, m_path, m_protocol, m_url, gammalib::strip_whitespace(), gammalib::toint(), and gammalib::toupper().

Referenced by GFilename().

std::string GFilename::type ( void  ) const

Return file type.

Returns
File type.

Returns the file type based on the file extension name. Possible file types are

   Type   Extension names
   fits   .fits / .fit

For any other file types an empty string will be returned. Any compression extensions such as .gz, .Z, .z or .zip will be stripped.

Definition at line 264 of file GFilename.cpp.

References file(), and m_file.

Referenced by GObservations::likelihood::save().

std::string GFilename::url ( void  ) const
inline

Return Uniform Resource Locator (URL)

Returns
Uniform Resource Locator without FITS extension.

Returns the Uniform Resource Locator without FITS extension. Any environment variable in the URL string will be expanded.

Definition at line 189 of file GFilename.hpp.

References gammalib::expand_env(), and m_url.

Referenced by exists(), is_fits(), GCTABackgroundPerfTable::load(), GCTAAeffPerfTable::load(), GCTAPsfPerfTable::load(), GSkyRegions::load(), GCsv::load(), GApplicationPars::load(), GCTAEdispPerfTable::load(), GCTAModelSpatialLookup::load(), GRmf::load(), GArf::load(), GCTAObservation::load(), GObservations::load(), GPha::load(), GModels::load(), GXml::load(), GSPIResponse::load_irf(), GSPIResponse::load_irfs(), GModelSpectralFunc::load_nodes(), GLog::open(), GFits::open(), GLog::operator<<(), GSPIObservation::print(), GModelTemporalLightCurve::print(), GModelSpectralTable::print(), GSPIResponse::print(), GModelSpectralFunc::print(), GModelTemporalPhaseCurve::print(), GSPIEventCube::read(), GMWLSpectrum::read(), GSPIEventCube::read_models(), remove(), GCOMIaq::save(), GCOMTim::save(), GCTAEventList::save(), GSkyRegions::save(), GCsv::save(), GCTABackground3D::save(), GApplicationPars::save(), GGti::save(), GCTAAeff2D::save(), GCTAModelSpatialLookup::save(), GRmf::save(), GModelSpectralTable::save(), GEnergies::save(), GArf::save(), GNodeArray::save(), GEbounds::save(), GCTAPsfTable::save(), GCTAPsf2D::save(), GCTAPsfKing::save(), GCTAObservation::save(), GPha::save(), GCTAEdisp2D::save(), GSkyMap::save(), GXml::save(), and GCTAObservation::write().

Friends And Related Function Documentation

bool operator!= ( const GFilename a,
const GFilename b 
)
friend

Filename inequality operator.

Parameters
[in]aFirst filename.
[in]bSecond filename.
Returns
True if filenames are not equal.

Definition at line 347 of file GFilename.hpp.

std::string operator+ ( const GFilename filename,
const std::string &  string 
)
friend

String addition operator.

Parameters
[in]filenameFilename.
[in]stringString.
Returns
String with filename + string.

Definition at line 305 of file GFilename.hpp.

std::string operator+ ( const std::string &  string,
const GFilename filename 
)
friend

String addition operator.

Parameters
[in]stringString.
[in]filenameFilename.
Returns
String with string + filename.

Definition at line 319 of file GFilename.hpp.

bool operator== ( const GFilename a,
const GFilename b 
)
friend

Filename equality operator.

Parameters
[in]aFirst filename.
[in]bSecond filename.
Returns
True if filenames are equal.

Definition at line 333 of file GFilename.hpp.

Member Data Documentation

std::string GFilename::m_expression
protected

Selection expression ("": not set)

Definition at line 124 of file GFilename.hpp.

Referenced by copy_members(), expression(), has_expression(), init_members(), print(), and set_filename().

std::string GFilename::m_extname
protected

Extension name ("": not set)

Definition at line 121 of file GFilename.hpp.

Referenced by copy_members(), extname(), has_extname(), init_members(), print(), and set_filename().

int GFilename::m_extno
protected

Extension number (-1: not set)

Definition at line 122 of file GFilename.hpp.

Referenced by copy_members(), extno(), has_extno(), init_members(), print(), and set_filename().

int GFilename::m_extver
protected

Extension version (0: not set)

Definition at line 123 of file GFilename.hpp.

Referenced by copy_members(), extver(), has_extver(), init_members(), print(), and set_filename().

std::string GFilename::m_file
protected

Name of file.

Definition at line 120 of file GFilename.hpp.

Referenced by copy_members(), file(), init_members(), print(), set_filename(), and type().

std::string GFilename::m_filename
protected

Full file name.

Definition at line 116 of file GFilename.hpp.

Referenced by copy_members(), init_members(), is_empty(), print(), and set_filename().

std::string GFilename::m_path
protected

Access path.

Definition at line 119 of file GFilename.hpp.

Referenced by copy_members(), init_members(), path(), print(), and set_filename().

std::string GFilename::m_protocol
protected

Access protocol.

Definition at line 118 of file GFilename.hpp.

Referenced by copy_members(), init_members(), print(), protocol(), and set_filename().

std::string GFilename::m_url
protected

File name (with stripped extension info)

Definition at line 117 of file GFilename.hpp.

Referenced by copy_members(), init_members(), length(), print(), set_filename(), and url().


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