FC++  v0.7.1-1067
FileCatalyst Fast File Transfers - C++ Library
fc::Name Class Referenceabstract

To prevent mixing up local path and remote path parameters when calling the FC++ API, the path and/or filenames are wrapped using the simple fc::Local and fc::Remote classes. More...

#include <FCPath.hpp>

Inheritance diagram for fc::Name:
Collaboration diagram for fc::Name:

Public Member Functions

virtual ~Name (void)
 
 Name (const std::string &n)
 
virtual bool empty (void) const
 
virtual const char * c_str (void) const
 
virtual operator const char * (void) const
 
virtual operator const std::string & (void) const
 
virtual const std::string & str (void) const
 
virtual Nameoperator+= (const std::string &rhs)
 Append a filename to an existing Local or Remote object. More...
 
virtual void setDefaultDir (const std::string &dir) const =0
 Set the default directory. Will ensure it is terminated by a slash or backslash. More...
 
virtual const std::string & defaultDir (void) const =0
 Get the default directory. This is guaranteed to be terminated by a slash or backslash. More...
 
virtual const std::string & separator (void) const =0
 Return the usual path separator, such as slash or backslash. More...
 
virtual bool isAbsolute (void) const
 Original name is absolute, such as /tmp/test.txt or C:\Files. More...
 
virtual bool isRelative (void) const
 Original name is relative, such as test.txt or ..\test.txt. More...
 
virtual const std::string & name (void) const
 The original name specified when this object was first instantiated. More...
 
virtual const std::string & parentDir (void) const
 Get the parent directory if known, or a blank string if unknown. More...
 
virtual const std::string & filename (void) const
 Get the last component in full() which normally would be the filename. More...
 
virtual const std::string & full (void) const
 Get the full name. More...
 

Protected Member Functions

std::string findSeparator (void) const
 Logic to extract the directory separator from the default directory or the explicit name. More...
 
virtual NameclearCache (void)
 Clear the mutable cache items. More...
 

Protected Attributes

std::string explicitName
 The name used when the object was instantiated. More...
 
std::string fileName
 the last component from full() More...
 
std::string parentDirectory
 the parent directory including the terminating slash More...
 
std::string fullDirAndName
 the name combined with the default directory More...
 

Detailed Description

To prevent mixing up local path and remote path parameters when calling the FC++ API, the path and/or filenames are wrapped using the simple fc::Local and fc::Remote classes.

This guarantees at compile-time that the local and remote paths cannot be accidentally inverted.

Consider these 2 similar examples:

ftp.uploadFile( "projectA/output.txt", "testing/readme.txt" );
ftp.uploadFile( fc::Local("projectA/output.txt"), fc::Remote("testing/readme.txt") );

In the first example, it isn't immediately obvious if the file output.txt is being uploaded as readme.txt, or if it is the other way around. In the second example, not only is it immediately obvious, but if the filename parameters are ever swapped, the code wouldn't compile.

Normally, when provided with a Local or Remote object, the method you'll want to call is fc::Name::full().

Constructor & Destructor Documentation

fc::Name::~Name ( void  )
virtual
fc::Name::Name ( const std::string &  n)
explicit

Member Function Documentation

virtual bool fc::Name::empty ( void  ) const
inlinevirtual

References name().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual const char* fc::Name::c_str ( void  ) const
inlinevirtual

References full().

Here is the call graph for this function:

virtual fc::Name::operator const char * ( void  ) const
inlinevirtual

References full().

Here is the call graph for this function:

virtual fc::Name::operator const std::string & ( void  ) const
inlinevirtual

References full().

Here is the call graph for this function:

virtual const std::string& fc::Name::str ( void  ) const
inlinevirtual

References defaultDir(), filename(), findSeparator(), full(), isAbsolute(), isRelative(), name(), operator+=(), parentDir(), separator(), and setDefaultDir().

Here is the call graph for this function:

Here is the caller graph for this function:

fc::Name & fc::Name::operator+= ( const std::string &  rhs)
virtual

Append a filename to an existing Local or Remote object.

References clearCache(), explicitName, and separator().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void fc::Name::setDefaultDir ( const std::string &  dir) const
pure virtual

Set the default directory. Will ensure it is terminated by a slash or backslash.

See also
fc::Name::defaultDir()

Implemented in fc::Remote, and fc::Local.

Here is the caller graph for this function:

virtual const std::string& fc::Name::defaultDir ( void  ) const
pure virtual

Get the default directory. This is guaranteed to be terminated by a slash or backslash.

See also
fc::Name::setDefaultDir()

Implemented in fc::Remote, and fc::Local.

Here is the caller graph for this function:

virtual const std::string& fc::Name::separator ( void  ) const
pure virtual

Return the usual path separator, such as slash or backslash.

See also
fc::Name::defaultDir()

Implemented in fc::Remote, and fc::Local.

Here is the caller graph for this function:

bool fc::Name::isAbsolute ( void  ) const
virtual

Original name is absolute, such as /tmp/test.txt or C:\Files.

See also
fc::Name::isRelative()

References empty(), explicitName, and regex.

Here is the call graph for this function:

Here is the caller graph for this function:

bool fc::Name::isRelative ( void  ) const
virtual

Original name is relative, such as test.txt or ..\test.txt.

See also
fc::Name::isAbsolute()

References empty(), and isAbsolute().

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string & fc::Name::name ( void  ) const
virtual

The original name specified when this object was first instantiated.

References explicitName.

Here is the caller graph for this function:

const std::string & fc::Name::parentDir ( void  ) const
virtual

Get the parent directory if known, or a blank string if unknown.

The directory name (if not empty) will always be terminated with / or \. For example:

Original Name parentDir()
test.txt
../test.txt ../
/tmp/foo/bar/name.txt /tmp/foo/bar/
/testing/123/ /testing/
/ /

References full(), parentDirectory, and separator().

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string & fc::Name::filename ( void  ) const
virtual

Get the last component in full() which normally would be the filename.

References fileName, full(), and separator().

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string & fc::Name::full ( void  ) const
virtual

Get the full name.

  • If name is absolute, then this returns the name.
  • If name is relative, then this returns the name combined with the default directory.

Most of the time, this is the method you'll want to call to generate a path or filename.

Examples when the default directory is set to /tmp/:

Directory Name full()
/test.txt /test.txt
test.txt /tmp/test.txt
../test.txt /tmp/../test.txt
C:\MyFiles\test.txt C:\MyFiles\test.txt
Returns
the full name, combined with the default directory when appropriate

References defaultDir(), fullDirAndName, name(), and separator().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string fc::Name::findSeparator ( void  ) const
protected

Logic to extract the directory separator from the default directory or the explicit name.

References defaultDir(), and explicitName.

Here is the call graph for this function:

Here is the caller graph for this function:

fc::Name & fc::Name::clearCache ( void  )
protectedvirtual

Clear the mutable cache items.

References fileName, fullDirAndName, and parentDirectory.

Here is the caller graph for this function:

Member Data Documentation

std::string fc::Name::explicitName
protected

The name used when the object was instantiated.

std::string fc::Name::fileName
mutableprotected

the last component from full()

std::string fc::Name::parentDirectory
mutableprotected

the parent directory including the terminating slash

std::string fc::Name::fullDirAndName
mutableprotected

the name combined with the default directory


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