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

A compunit granularity metric class. More...

Public Member Functions

bool allowed () const
 Check: are METRIC_FILTER settings such that reported instances of this metric class will be submitted to the hub? More...
 
bool always_discarded () const
 Check: are METRIC_FILTER settings such that instances of this metric class will always be ignored? More...
 
std::string as_repr () const
 Get a representation of a compunit_metricclass object that includes information useful for debugging. More...
 
std::string as_string () const
 Get a simple string representation of a compunit_metricclass object. More...
 
int cmp (const compunit_metricclass &other) const
 Comparison function for compunit_metricclass, with respect to a stable overall ordering. More...
 
std::string description () const
 Get the description (longer, human readable identifier) for a metric class (compunit_metricclass). More...
 
metricclass_flags flags () const
 Get the metricclass_flags for a compunit_metricclass. More...
 
cs_hash_t hash () const
 Get a hash value for this compunit_metricclass. More...
 
void report (compunit elt, double val) const
 Report a metric value to the hub. More...
 
void retract (compunit elt) const
 Retract a metric value. More...
 
std::string tag () const
 Get the tag (short string identifier) for a metric class (compunit_metricclass). More...
 
double value (compunit elt) const
 Get the value of a metric. More...
 

Related Functions

(Note that these are not member functions.)

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

Detailed Description

A compunit granularity metric class.

The compunit granularity metric classes are managed by compunit_metricclass_manager.

You can retrieve metric values with value(), and examine metric properties with description(), tag(), and flags().

For more information about metrics in CodeSonar, see the Metrics manual page.

Member Function Documentation

◆ allowed()

bool cs::compunit_metricclass::allowed ( ) const
inlineinherited

Check: are METRIC_FILTER settings such that reported instances of this metric class will be submitted to the hub?

Returns
true if reported instances of the class will be submitted to the hub, false otherwise.

If you have defined a custom metric class C in a plug-in, you can use a test based on C.allowed() to avoid unnecessary work in the case where C is ignored.

This is the complement of compunit_metricclass::always_discarded().

◆ always_discarded()

bool cs::compunit_metricclass::always_discarded ( ) const
inlineinherited

Check: are METRIC_FILTER settings such that instances of this metric class will always be ignored?

Returns
true if all instances of the class are being discarded, false otherwise.

If you have defined a custom metric class C in a plug-in, you can use a test based on C.always_discarded() to avoid unnecessary work in the case where C is ignored.

This is the complement of compunit_metricclass::allowed.

◆ as_repr()

std::string cs::compunit_metricclass::as_repr ( ) const
inlineinherited

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

Returns
The string representation.

◆ as_string()

std::string cs::compunit_metricclass::as_string ( ) const
inlineinherited

Get a simple string representation of a compunit_metricclass object.

Returns
The string representation.

◆ cmp()

cs::compunit_metricclass::cmp ( const compunit_metricclass other) const
inlineinherited

Comparison function for compunit_metricclass, with respect to a stable overall ordering.

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

◆ description()

std::string cs::compunit_metricclass::description ( ) const
inlineinherited

Get the description (longer, human readable identifier) for a metric class (compunit_metricclass).

Returns
The description, as a std::string.

For example, CodeSonar ships with built-in project granularity metric class Include file instances.

  • its tag is "InclF"
  • its description is "Include file instances"

◆ flags()

metricclass_flags cs::compunit_metricclass::flags ( ) const
inlineinherited

◆ hash()

cs_hash_t cs::compunit_metricclass::hash ( ) const
inlineinherited

Get a hash value for this compunit_metricclass.

◆ report()

cs::compunit_metricclass::report ( compunit   elt,
double  val 
) const

Report a metric value to the hub.

Parameters
[in]eltThe element that the metric value is associated with.
[in]valThe value to report.
Returns
void

You do not need to call this method if the metric class was created with metricclass_flags::AUTO. In that case, CodeSonar will automatically report the values calculated using the operator() method of the metric_function<T> argument provided to compunit_metricclass_manager::create() when the class was created.

Exceptions
result::FILTERED_OUTif the compunit_metricclass is filtered out by a METRIC_FILTER discard rule.
result::ERROR_INVALID_PHASE_FOR_OPERATIONif called during a traversal phase that is not consistent with the metricclass_flags for the compunit_metricclass. See the metricclass_flags::POST_ANALYSIS documentation for more information.
result::ERROR_INVALID_SLAVE_OPERATIONif called from a CodeSonar slave process.
result::GENERATED_COMPILATIONif elt was generated in the back end.

◆ retract()

void cs::compunit_metricclass::retract ( compunit   elt) const
inlineinherited

Retract a metric value.

Parameters
[in]eltThe element for which the value will be retracted.
Returns
void
Exceptions
result::ERROR_INVALID_SLAVE_OPERATIONif called from a CodeSonar slave process.
result::ELEMENT_NOT_PRESENTif retraction did not occur for any other reason.
result::ERROR_INVALID_PHASE_FOR_OPERATIONif called outside the drop traversal phase.

In typical usage, retract() is called during the drop traversal (that is, by a visitor added with one of the analysis add_*_drop_visitor() methods).

◆ tag()

std::string cs::compunit_metricclass::tag ( ) const
inlineinherited

Get the tag (short string identifier) for a metric class (compunit_metricclass).

Returns
The short tag, as a std::string.

The tag will usually be only a few characters long. Retrieve the metric class description with description() for a longer string that is generally more human-readable.

For example, CodeSonar ships with built-in project granularity metric class Include file instances.

  • its tag is "InclF"
  • its description is "Include file instances"

◆ value()

double cs::compunit_metricclass::value ( compunit   elt) const

Get the value of a metric.

Parameters
[in]eltThe element for which the metric value is required.
Returns
The metric value for elt.

You do not need to call this method if the metric class was created with metricclass_flags::AUTO. In that case, CodeSonar will automatically report the values calculated using the metric_function<T> argument provided to compunit_metricclass_manager::create() when the metric class was created.

Exceptions
result::FILTERED_OUTif the compunit_metricclass is filtered out by a METRIC_FILTER discard rule.
result::METRIC_NOT_COMPUTEDif a value for the metric has not been computed. This can happen if the compunit_metricclass was not created with metricclass_flags::AUTO and a value has not been reported with report(), or if the compunit_metricclass was not created with metricclass_flags::POST_ANALYSIS but value() is called during the serial depth-first traversal or parallel-depth first traversal.

Friends And Related Function Documentation

◆ operator!=()

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

Inequality operator for compunit_metricclass.

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

◆ operator<()

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

Less-than operator for compunit_metricclass.

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

◆ operator<<()

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

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

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

◆ operator<=()

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

Less-than-or-equal operator for compunit_metricclass.

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

◆ operator==()

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

Equality operator for compunit_metricclass.

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

◆ operator>()

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

Greater-than operator for compunit_metricclass.

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

◆ operator>=()

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

Greater-than-or-equal operator for compunit_metricclass.

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

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