Kea  1.9.9-git
isc::util::Filename Class Reference

Class to Manipulate Filenames. More...

#include <filename.h>

Public Member Functions

 Filename (const std::string &name)
 Constructor. More...
 
std::string directory () const
 
std::string expandWithDefault (const std::string &defname) const
 Expand Name with Default. More...
 
std::string extension () const
 
std::string fullName () const
 
std::string name () const
 
std::string nameAndExtension () const
 
void setDirectory (const std::string &new_directory)
 Set directory for the file. More...
 
void setName (const std::string &name)
 Sets Stored Filename. More...
 
std::string useAsDefault (const std::string &name) const
 Use as Default and Substitute into String. More...
 

Detailed Description

Class to Manipulate Filenames.

This is a utility class to manipulate filenames. It repeats some of the features found in the Boost filename class, but is self-contained so avoids the need to link in the Boost library.

A Unix-style filename comprises three parts:

Directory - everything up to and including the last "/". If there is no "/" in the string, there is no directory component. Note that the requirement of a trailing slash eliminates the ambiguity of whether a component is a directory or not, e.g. in /alpha/beta", "beta" could be the name of a directory or is could be a file. The interpretation here is that "beta" is the name of a file (although that file could be a directory).

Note: Under Windows, the drive letter is considered to be part of the directory specification. Unless this class becomes more widely-used on Windows, there is no point in adding redundant code.

Name - everything from the character after the last "/" up to but not including the last ".".

Extension - everything from the right-most "." (after the right-most "/") to the end of the string. If there is no "." after the last "/", there is no file extension.

(Note that on Windows, this function will replace all "\" characters with "/" characters on input strings.)

This class provides functions for extracting the components and for substituting components.

Definition at line 50 of file filename.h.

Constructor & Destructor Documentation

isc::util::Filename::Filename ( const std::string &  name)
inline

Constructor.

Definition at line 54 of file filename.h.

References setName().

+ Here is the call graph for this function:

Member Function Documentation

std::string isc::util::Filename::directory ( ) const
inline
Returns
Directory of Given File Name

Definition at line 76 of file filename.h.

string isc::util::Filename::expandWithDefault ( const std::string &  defname) const

Expand Name with Default.

A default file specified is supplied and used to fill in any missing fields. For example, if the name stored is "/a/b" and the supplied name is "c.d", the result is "/a/b.d": the only field missing from the stored name is the extension, which is supplied by the default. Another example would be to store "a.b" and to supply a default of "/c/d/" - the result is "/c/d/a.b". (Note that if the supplied default was "/c/d", the result would be "/c/a.b", even if "/c/d" were actually a directory.)

Parameters
defnameDefault name
Returns
Name expanded with defname.

Definition at line 79 of file filename.cc.

References name_, isc::util::str::normalizeSlash(), and isc::util::str::trim().

+ Here is the call graph for this function:

std::string isc::util::Filename::extension ( ) const
inline
Returns
Extension of Given File Name

Definition at line 93 of file filename.h.

Referenced by sentinel().

std::string isc::util::Filename::fullName ( ) const
inline
Returns
Stored Filename

Definition at line 71 of file filename.h.

Referenced by writeHeaderFile(), and writeProgramFile().

std::string isc::util::Filename::name ( ) const
inline
Returns
Name of Given File Name

Definition at line 88 of file filename.h.

Referenced by isc::process::Daemon::checkConfigFile(), isc::process::Daemon::makePIDFileName(), sentinel(), writeHeaderFile(), and writeProgramFile().

std::string isc::util::Filename::nameAndExtension ( ) const
inline
Returns
Name + extension of Given File Name

Definition at line 98 of file filename.h.

void isc::util::Filename::setDirectory ( const std::string &  new_directory)

Set directory for the file.

Parameters
new_directoryThe directory to set. If this is an empty string, the directory this filename object currently has will be removed.

Definition at line 129 of file filename.cc.

References name_.

Referenced by writeHeaderFile(), and writeProgramFile().

void isc::util::Filename::setName ( const std::string &  name)
inline

Sets Stored Filename.

Parameters
nameNew name to replaced currently stored name

Definition at line 62 of file filename.h.

References isc::util::str::normalizeSlash(), and isc::util::str::trim().

Referenced by Filename().

+ Here is the call graph for this function:

string isc::util::Filename::useAsDefault ( const std::string &  name) const

Use as Default and Substitute into String.

Does essentially the inverse of expand(); that filled in the stored name with a default and returned the result. This treats the stored name as the default and uses it to fill in a given name. In essence, the code:

Filename f("/a/b");
result = f.expandWithdefault("c.d");

gives as a result "/a/b.d". This is the same as:

Filename f("c.d");
result = f.useAsDefault("/a/b");
Parameters
nameName to expand
Returns
Name expanded with stored name

Definition at line 105 of file filename.cc.

References name_, isc::util::str::normalizeSlash(), and isc::util::str::trim().

+ Here is the call graph for this function:


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