ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
File Class Reference

Description:

This class represents nodes in FTree instances. While class FTree is just a rather small wrapper around its base class StringTree, this class File is a wrapper around class StringTree::Cursor. With that, instances of this class are very lightweight and contain only two pointers: One pointing to the FTree that an instance originates from, the second pointing to the node in the tree.

It is important to understand that this class has three interfaces.

  1. The direct interface as exposed with this class.
  2. Using operator-> the attached data instance of type FInfo is accessed.
  3. The method AsCursor casts an instance to the (otherwise protected) type Cursor of the underlying string tree.

To get a thorough understanding of why this split exists and what purpose which of the three interfaces serve, a basic understanding of container type class StringTree is very helpful. A similar design principle is implemented with class Variable of module ALib Configuration. A technical explanation to why base class FTree::Cursor is protected there in the same fashion is given here.

See also
  • For a quick tutorial about using ALib files, consult the tutorial-style Programmer's Manual of camp ALib Files.
  • For this class, a pretty printer for the GNU debugger is provided.
  • Instances of this type are appendable to class AString. If done, the full path and file name is written to the target string.

Definition at line 692 of file ftree.hpp.

#include <ftree.hpp>

Inheritance diagram for File:
[legend]
Collaboration diagram for File:
[legend]

Public Type Index:

using ConstCursor = FTree::ConstCursor
 The constant version of type Cursor.
 
using Cursor = FTree::Cursor
 

Public Method Index:

 File (const Cursor &cursor)
 
 File (FTree &pTree)
 
CursorAsCursor ()
 
const CursorAsCursor () const
 
PathAssemblePath (Path &target, lang::CurrentData targetData=lang::CurrentData::Clear) const
 
template<typename TCustom , typename... TArgs>
TCustom & AttachCustomData (TArgs &&... args)
 
template<typename TCustom >
void DeleteCustomData ()
 
lang::system::PathString Extension () const
 
ALIB_API AStringFormat (Substring format, AString &target, lang::CurrentData targetData=lang::CurrentData::Keep, NumberFormat *numberFormat=nullptr) const
 
AStringFormatAccessRights (AString &target) const
 
template<typename TCustom >
TCustom & GetCustomData ()
 
FTreeGetFTree () const
 
const NStringGetGroupName () const
 
FInfoGetMutableFInfo ()
 
const NStringGetOwnerName () const
 
bool HasCustomData () const
 
const NameType & Name () const
 
const FInfooperator-> () const
 
Fileoperator= (const Cursor &other)
 
ALIB_WARNINGS_RESTORE lang::system::PathString Stem () const
 

Additional Inherited Members

- Protected Type Index: inherited from StringTree< TAllocator, T, TNodeHandler, TRecycling >::TCursor< TConst >
using cmCursor = ATMP_IF_T_F(!TConst, baseCursor, baseConstCursor)
 
using cmNode = ATMP_IF_T_F(!TConst, baseNode, const baseNode)
 
using cmTree = ATMP_IF_T_F(!TConst, basetree, const basetree)
 
using TStringTree = ATMP_IF_T_F(!TConst, StringTree, const StringTree)
 
- Protected Method Index: inherited from StringTree< TAllocator, T, TNodeHandler, TRecycling >::TCursor< TConst >
 TCursor (cmTree *pTree, cmNode *pNode) noexcept
 
void dbgCheckTree () const
 
void dbgCheckTreeAndNode () const
 
 TCursor () noexcept=default
 
 TCursor (const TCursor &src) noexcept
 
 TCursor (TCursor &&src) noexcept
 
 ~TCursor () noexcept=default
 Trivial default destructor.
 
strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > & AssemblePath (strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > &targetString, const TCursor< true > &parent, lang::CurrentData targetData=lang::CurrentData::Clear) const
 
strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > & AssemblePath (strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > &targetString, lang::CurrentData targetData=lang::CurrentData::Clear) const
 
TCursor Child (const NameType &name) const
 
uinteger CountChildren () const
 
template<typename TCheck = CHK, typename... TArgs>
TCursor CreateChild (const NameType &childName, TArgs &&... args) const
 
template<typename... TArgs>
std::pair< TCursor, bool > CreateChildIfNotExistent (const NameType &name, TArgs &&... args)
 
template<typename... TArgs>
std::pair< TCursor, integerCreatePathIfNotExistent (const NameType &path, TArgs &&... args)
 
uinteger Delete ()
 
bool DeleteChild (const NameType &childName) const
 
void DeleteChild (TCursor &child) const
 
uinteger DeleteChildren () const
 
int Depth () const
 
int Distance (const TCursor< true > &other) const
 
CursorHandle Export ()
 
ConstCursorHandle Export () const
 
TCursor FirstChild () const
 
SubstringType GoTo (const NameType &path)
 
bool GoToChild (const NameType &name)
 
template<typename... TArgs>
bool GoToCreateChildIfNotExistent (const NameType &name, TArgs &&... args)
 
template<typename... TArgs>
integer GoToCreatedPathIfNotExistent (const NameType &path, TArgs &&... args)
 
bool GoToFirstChild ()
 
bool GoToLastChild ()
 
bool GoToNextSibling ()
 
TCursorGoToParent ()
 
bool GoToPreviousSibling ()
 
TCursorGoToRoot ()
 
bool HasChildren () const
 
bool HasNextSibling () const
 
bool HasPreviousSibling () const
 
bool IsInvalid () const
 
bool IsRoot () const
 
bool IsValid () const
 
TCursor LastChild () const
 
const NameTypeName () const
 
TCursor NextSibling () const
 
 operator TCursor<!TConst > ()
 
bool operator!= (const TCursor &other) const
 
std::pair< TCursor, SubstringTypeoperator() (const NameType &path) const
 
T & operator* ()
 
const T & operator* () const
 
T * operator-> ()
 
const T * operator-> () const
 
TCursoroperator= (const TCursor &) noexcept=default
 
TCursoroperator= (TCursor &&) noexcept=default
 
bool operator== (const TCursor &other) const
 
TCursor Parent () const
 
TCursor PreviousSibling () const
 
TCursor Root () const
 
template<typename TParent = StringTree>
const TParent & Tree ()
 
T & Value ()
 
const T & Value () const
 

Type Definition Details:

◆ ConstCursor

The constant version of type Cursor.

Definition at line 700 of file ftree.hpp.

◆ Cursor

The base cursor type of the internal StringTree. This type is used to perform cursor operations on FTree instances.

Definition at line 697 of file ftree.hpp.

Constructor(s) / Destructor Details:

◆ File() [1/2]

File ( FTree & pTree)
inline

Constructor taking a file tree. After construction, this file will point to the root node "/" of the tree.

Parameters
pTreeThe tree to associate this file instance with.

Definition at line 713 of file ftree.hpp.

◆ File() [2/2]

File ( const Cursor & cursor)
inline

Constructs an instance of this type from its base type. This constructor is for advanced use when direct operations with class StringTree and its cursor and iterator types are performed.

Parameters
cursorThe StringTree cursor representing a file.

Definition at line 720 of file ftree.hpp.

Method Details:

◆ AsCursor() [1/2]

Cursor & AsCursor ( )
inline

This is an explicit cast operator to the protected base class.

Note
For details on the code design which makes this method necessary, consult the documentation of the same concept found with method Variable::AsCursor.
Returns
This instance cast 'down' to its protected base class.

Definition at line 749 of file ftree.hpp.

◆ AsCursor() [2/2]

const Cursor & AsCursor ( ) const
inline

const version of the cast operator to the protected base class.

Returns
This instance cast 'down' to its protected base class.

Definition at line 753 of file ftree.hpp.

◆ AssemblePath()

Path & AssemblePath ( Path & target,
lang::CurrentData targetData = lang::CurrentData::Clear ) const
inline

Returns the path to this file. This excludes this files' name as well as a trailing separation character. If this file represents the root folder of the file tree, nothing is written to target.

See also
To receive the full path of this file, including this files' name, use AsCursor and invoke Cursor::AssemblePath.
Parameters
targetThe string buffer to append the path to.
targetDataDenotes whether target should be cleared before appending the path. Defaults to CurrentData::Clear.
Returns
The given AString to allow concatenated operations.

Definition at line 798 of file ftree.hpp.

Here is the call graph for this function:

◆ AttachCustomData()

template<typename TCustom , typename... TArgs>
TCustom & AttachCustomData ( TArgs &&... args)
inline

Allocates a custom object attached to this file using the PoolAllocator of the FTree.

See also
Methods GetCustomData, HasCustomData, DeleteCustomData, and FTree::DeleteAllCustomData.
Template Parameters
TCustomThe type of custom data associated to the FTree that this file belongs to.
TArgsTypes of the variadic arguments args that construct TCustom.
Parameters
argsVariadic arguments forwarded to the constructor of TCustom.
Returns
The custom data record.

Definition at line 855 of file ftree.hpp.

◆ DeleteCustomData()

template<typename TCustom >
void DeleteCustomData ( )
inline

Destructs and deletes the custom data attached to this file. With debug-compilations it is asserted that HasCustomData() returns true and that TCustom is the same as set.

See also
Methods AttachCustomData, GetCustomData, HasCustomData, and FTree::DeleteAllCustomData.
Template Parameters
TCustomThe object type to optionally store in tree nodes.

Definition at line 873 of file ftree.hpp.

◆ Extension()

lang::system::PathString Extension ( ) const
inline

Returns the file extension, which is the substring behind the last period '.' character which is not located at the start of the name. (A filename like ".profile" is not treated to have an extension).

Returns
The extension found in the filename. An empty string if none is found.

Definition at line 779 of file ftree.hpp.

Here is the call graph for this function:

◆ Format()

AString & Format ( Substring format,
AString & target,
lang::CurrentData targetData = lang::CurrentData::Keep,
NumberFormat * numberFormat = nullptr ) const

Writes formatted information on this file to given string buffer target. Within the pattern string format, different symbols are interpreted as tokens. Spaces between tokens are written as given. Strings within the format text that should not be interpreted as tokens may be given in single quotes. Two consecutive single quotes will be replaced to one single quote.

Tokens are defined in lower case letters. If given with upper case letters, the generated string is converted to upper case letters.

This method supports the following tokens:

Token
Description
a Invokes FormatAccessRights.
dm{DATEFORMAT} The modification date of this file. This token is optionally followed by a "DATEFORMAT" string given in curly braces. For specification information, see CalendarDateTime::Format.
db{DATEFORMAT} Same as 'dm', but uses the creation date of this file.
dc{DATEFORMAT} Same as 'dm', but uses the change date of this file.
da{DATEFORMAT} Same as 'dm', but uses the date of last access to this file.
fx Prints 'm' if IsCrossingFS returns true, '-' otherwise.
fa Prints 'a' if IsArtificialFS returns true, '-' otherwise.
gi[{width[,alignment]}] The ID of the user group of the file.
gn[{width[,alignment]}] The name of the user group of the file.
h The number of hard links pointing to this file.
l In case of Symbolic links, prints " -> linktarget". if the linktarget is a relative path, then the absolute path is appended in round brackets.
na The name of the file.
ns The stem of the file.
ne The extension of the file.
np The path to the file, excluding the file name and a trailing separation character.
oi[{width[,alignment]}] The ID of the owner of the file.
on[{width[,alignment]}] The name of the owner of the file.
q The scan quality as resourced with enum Qualities.
rd Recursively counted subfolders.
rf Recursively counted files.
re Recursively counted access errors.
rb Recursively counted broken links.
qqq The scan quality, encoded in three characters. The conversion is resourced with enum Qualities3Letters.
s[{unit}] The size of the file. See the explanation below.
t The type, encoded in a single character. The conversion is resourced with enum TypeNames1Letter.
tt The type, encoded in two characters. The conversion is resourced with enum TypeNames2Letters.
ttt The type, encoded in three characters. The conversion is resourced with enum TypeNames3Letters.
tttt The type, as a full word. The conversion is resourced with enum Types.
Fields and Alignment
Any of the tokens above may be followd by {width[,Alignment]}. In words: a pair of curly braces that contains an integral value specifying a field width and, optionally and seperated by a comma, an alib::lang::Alignment,alignment "Alignment,alignment" specifier. If so, a corresponding field, using spaces as padding character, is printed.
Printing sizes:
Token "s[(unit)]" is used to print file sizes. The optional unit string in curly braces may have one the following values:
  • IEC: Chooses IEC standard with automatic detection of an approiate magnitude. The unit of the magnitude found ("B", "KiB", "MiB", "GiB",...) is added to the output. This is the default, if the optional unit-partis omited.
  • SI: Chooses SI standard with automatic detection of an approiate magnitude. The unit of the magnitude found ("B", "kB", "MB", "GB",...) is added to the output.
  • One of the more than 20 possible entity names of either IEC or SI standard. In this case, the unit is not included after the number, because this way it can be optionally added to the format string by using a pair of single quotes '.
With the two automatic modes IEC and SI, namespace function lang::format::FormatByteSize is used.
For formatting the file size numbers, this method retrieves formatting hints with FTree::GetNumberFormat. With that, the details of the format can be specified "per FTree". Manipulations of this object before invoking this methods, allows specifying output widths, group characters, decimal separation character, and so forth.
Printing owner and group:
For printing owner and group names, those have to be queried from the OS. To increase performance, the resolver utility instance received with FTree::GetOGResolver is used. The use of this instance has to be protected against racing conditions in multithreaded applications. This means if two threads invoke this method on File object that belong to the same FTree, a locking mechanism has to be used, to avoid undefined behavior. (For example by using class Lock.)
Sample
As a sample, the following format string mimics the output of GNU/Linux console command ls -l:
     "ta h on gn s dm nal"
See also
This method is invoked by FFormat_File, which is an implementation of box-function FFormat. With hat, objects of this type can be used as arguments for FormatterPythonStyle. The format specifier passed to this method has to be placed behind the colon in the placeholder field, as in "{:FORMATSPEC}". If no format string is given in the placeholder, the string "ta h on gn s dm nal" is used, which is resourced in camp FILES under key "FFMT".
Parameters
formatThe format pattern string.
targetA reference to an AString that gets the result of the format processing appended.
targetDataIf CurrentData::Keep (the default) the string is appended to target. if CurrentData::Clear, target is cleared.
numberFormatThe number format specification to use. Defaults to nullptr which chooses NumberFormat::Computational.
Returns
target (for convenience).

Definition at line 72 of file file.cpp.

Here is the call graph for this function:

◆ FormatAccessRights()

AString & FormatAccessRights ( AString & target) const

Writes the permission flags to the given target string in the same format as GNU/Linux command 'ls -l' does.

Parameters
targetThe target string to write into.
Returns
The given target to allow concatenated calls.

Definition at line 29 of file file.cpp.

Here is the call graph for this function:

◆ GetCustomData()

template<typename TCustom >
TCustom & GetCustomData ( )
inline

Retrieves a custom data object. With debug-compilations it is asserted that HasCustomData() returns true and that TCustom is the same as set.

Template Parameters
TCustomThe type of custom data requested. In case no data was previously attached, yet, the constructor of this type is called on the new allocated memory.
See also
Methods AttachCustomData, HasCustomData, DeleteCustomData, and FTree::DeleteAllCustomData.
Returns
The custom data record.

Definition at line 834 of file ftree.hpp.

◆ GetFTree()

FTree & GetFTree ( ) const
inline

Returns a reference to the file tree that this file resides in.

Returns
The associated file tree instance.

Definition at line 705 of file ftree.hpp.

◆ GetGroupName()

const NString & GetGroupName ( ) const
inline

Retrieves the file's group name.

Returns
The name of the group of the file.

Definition at line 814 of file ftree.hpp.

◆ GetMutableFInfo()

FInfo & GetMutableFInfo ( )
inline

Provides access to members of contained FInfo record. Note that const access is available with method operator->.
Changes to the values should be done with caution. Usually the values are only set when scanning files or using certain interface methods of this class.

Returns
A writable pointer to the embedded FInfo data.

Definition at line 743 of file ftree.hpp.

◆ GetOwnerName()

const NString & GetOwnerName ( ) const
inline

Retrieves the file's owner's name.

Returns
The name of the owner of the file.

Definition at line 810 of file ftree.hpp.

◆ HasCustomData()

bool HasCustomData ( ) const
inline

Tests if custom data is attached to this file.

See also
Methods AttachCustomData, GetCustomData, DeleteCustomData, and FTree::DeleteAllCustomData.
Returns
true if custom data is attached to this file, false otherwise.

Definition at line 820 of file ftree.hpp.

◆ Name()

const NameType & Name ( ) const
inline

Publish protected method StringTree::TCursor::Name.

Returns
A constant reference to the name of the represented node.

Definition at line 1257 of file stringtree.hpp.

◆ operator->()

const FInfo * operator-> ( ) const
inline

Provides const access to members of contained FInfo record. Note that access to a mutable version of the type is available with method GetMutableFInfo.

Returns
A non-writable pointer to the embedded FInfo data.

Definition at line 736 of file ftree.hpp.

◆ operator=()

File & operator= ( const Cursor & other)
inline

Sets this Cursor to point to the same file (node in the FTree) as the given other.

Parameters
otherThe node to let this file instance point to.
Returns
A reference to this.

Definition at line 727 of file ftree.hpp.

◆ Stem()

Returns the substring from the beginning of Name() up to and not including the last period '.' character which is not located at the start of the name. (A filename like ".profile" is not treated as an extension).

Returns
The filename excluding the Extension.

Definition at line 767 of file ftree.hpp.

Here is the call graph for this function:

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