CodeSonar C++ API
[For improved navigation, enable JavaScript.]
Public Member Functions | Related Functions | List of all members
cs::directory Class Reference

A directory. More...

Public Member Functions

std::string as_repr () const
 Get a representation of a directory object that includes information useful for debugging. More...
 
std::string as_string () const
 Get a simple string representation of a directory object. More...
 
size_t child_count () const
 Get the number of subdirectories. More...
 
directory_children_iterator children () const
 Get an iterator over the immediate subdirectories (directory) of a directory. More...
 
int cmp (const directory &other) const
 Comparison function for directory. More...
 
csuint32 depth () const
 Get the depth or distance from root of a directory. More...
 
size_t file_count () const
 Get the number of files. More...
 
directory_files_iterator files () const
 Get an iterator over the source files (sfile) directly contained in a directory. More...
 
cs_hash_t hash () const
 Get a hash value for a directory. More...
 
std::string name () const
 Get the directory path associated with a directory. More...
 
std::string normalized_name () const
 Get the normalized directory path associated with a directory. More...
 
directory parent () const
 Get the parent directory of a directory. More...
 
int stable_cmp (const directory &other) const
 Comparison function for directory, with stable results across sufficiently-similar analyses. More...
 
csuint64 stable_hash () const
 Get a hash value for a directory, with stable results across sufficiently-similar analyses. More...
 

Related Functions

(Note that these are not member functions.)

bool operator!= (const directory &a, const directory &b)
 Inequality operator for directory. More...
 
bool operator< (const directory &a, const directory &b)
 Less-than operator for directory. More...
 
std::ostream & operator<< (std::ostream &out, const directory &a)
 Print a representation of a directory object to the specified stream. More...
 
bool operator<= (const directory &a, const directory &b)
 Less-than-or-equal operator for directory. More...
 
bool operator== (const directory &a, const directory &b)
 Equality operator for directory. More...
 
bool operator> (const directory &a, const directory &b)
 Greater-than operator for directory. More...
 
bool operator>= (const directory &a, const directory &b)
 Greater-than-or-equal operator for directory. More...
 

Detailed Description

A directory.

The following are useful for retrieving directories.

Class Methods
directory directory::children() (via a directory_children_iterator)
project project::root_directories() (via a project_root_directories_iterator)
sfile sfile::parent()

Member Function Documentation

◆ as_repr()

std::string cs::directory::as_repr ( ) const
inline

Get a representation of a directory object that includes information useful for debugging.

Returns
The string representation.

◆ as_string()

std::string cs::directory::as_string ( ) const
inline

Get a simple string representation of a directory object.

Returns
The string representation.

◆ child_count()

size_t cs::directory::child_count ( ) const
inline

Get the number of subdirectories.

Returns
The number of subdirectories that contain source files.

◆ children()

directory_children_iterator cs::directory::children ( ) const
inline

Get an iterator over the immediate subdirectories (directory) of a directory.

Returns
The initialized directory_children_iterator.

◆ cmp()

cs::directory::cmp ( const directory other) const
inline

Comparison function for directory.

Parameters
otherThe directory object to compare against.
Returns
An integer N such that:
  • N==0 if the two objects compare equal
  • N<0 if this < other
  • N>0 if this > other
this and other will only compare equal if they are the same directory object.

◆ depth()

csuint32 cs::directory::depth ( ) const
inline

Get the depth or distance from root of a directory.

Returns
The directory depth.

◆ file_count()

size_t cs::directory::file_count ( ) const
inline

Get the number of files.

Returns
The number of source files in this directory.

◆ files()

directory_files_iterator cs::directory::files ( ) const
inline

Get an iterator over the source files (sfile) directly contained in a directory.

Returns
The initialized directory_files_iterator.

◆ hash()

cs_hash_t cs::directory::hash ( ) const
inline

Get a hash value for a directory.

◆ name()

std::string cs::directory::name ( ) const
inline

Get the directory path associated with a directory.

Returns
A std::string containing the path of the directory.

◆ normalized_name()

std::string cs::directory::normalized_name ( ) const
inline

Get the normalized directory path associated with a directory.

Returns
A std::string containing the path of the directory.
  • Windows: this string is the downcased version of the one returned by name(), with backslash directory separators replaced by forward slashes.
  • Mac: this string is the downcased version of the one returned by name().
  • Otherwise: this string is the same as the one returned by name().

◆ parent()

directory cs::directory::parent ( ) const
inline

Get the parent directory of a directory.

Returns
The parent directory.
Exceptions
result::ELEMENT_NOT_PRESENTif this has no parent directory (i.e. is a root).

◆ stable_cmp()

int cs::directory::stable_cmp ( const directory other) const
inline

Comparison function for directory, with stable results across sufficiently-similar analyses.

Parameters
[in]otherThe directory to compare against.
Returns
An integer N such that:
  • N<0 if this considered less than other
  • N==0 if and other have the same normalized directory path as determined by directory::normalized_name().
  • N>0 if this considered greater than other

This function is provided so directory objects can be stored in ordered containers that provide stable iteration order.

The comparison is stable in the following sense. Suppose there are two analyses A1 and A2 generated with exactly the same inputs (including identical analyzed code, underlying build commands and ordering, command line and configuration settings, increment order and contents). Let a1 and b1 be two directory objects in A1, and a2 and b2 be the directory objects objects in A2 that correspond to a1 and b1 respectively. Then a1.stable_cmp(b1)==a2.stable_cmp(b2)

If you do not need comparison results to be stable across different analyses, use cmp(): it has better performance.

◆ stable_hash()

csuint64 cs::directory::stable_hash ( ) const
inline

Get a hash value for a directory, with stable results across sufficiently-similar analyses.

Returns
A hash derived from the directory.

This hash value is stable in the following sense. Suppose there are two analyses A1 and A2 generated with exactly the same inputs (including identical analyzed code, underlying build commands and ordering, command line and configuration settings, increment order and contents). Let b1 be a directory object in A1, and b2 be the directory object in A2 that corresponds to b1. Then b1.stable_hash()==b1.stable_hash().

If you do not need hash values to be stable across analyses, use hash(): it has better performance.

Friends And Related Function Documentation

◆ operator!=()

bool operator!= ( const directory a,
const directory b 
)
related

Inequality operator for directory.

Parameters
[in]aThe directory to compare.
[in]bThe directory to compare against.
Returns
false if a and b are equal according to directory::cmp(), true otherwise.

◆ operator<()

bool operator< ( const directory a,
const directory b 
)
related

Less-than operator for directory.

Parameters
[in]aThe directory to compare.
[in]bThe directory to compare against.
Returns
true if a < b according to directory::cmp() , false otherwise.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
const directory a 
)
related

Print a representation of a directory object to the specified stream.

Parameters
[in]outThe stream to print to.
[in]aThe directory object to print.
Returns
void

◆ operator<=()

bool operator<= ( const directory a,
const directory b 
)
related

Less-than-or-equal operator for directory.

Parameters
[in]aThe directory to compare.
[in]bThe directory to compare against.
Returns
true if a <= b according to directory::cmp() , false otherwise.

◆ operator==()

bool operator== ( const directory a,
const directory b 
)
related

Equality operator for directory.

Parameters
[in]aThe directory to compare.
[in]bThe directory to compare against.
Returns
true if a and b are equal according to directory::cmp(), false otherwise.

◆ operator>()

bool operator> ( const directory a,
const directory b 
)
related

Greater-than operator for directory.

Parameters
[in]aThe directory to compare.
[in]bThe directory to compare against.
Returns
true if a > b according to directory::cmp() , false otherwise.

◆ operator>=()

bool operator>= ( const directory a,
const directory b 
)
related

Greater-than-or-equal operator for directory.

Parameters
[in]aThe directory to compare.
[in]bThe directory to compare against.
Returns
true if a >= b according to directory::cmp() , false otherwise.

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