CodeSonar C++ API
[For improved navigation, enable JavaScript.]
Public Member Functions | List of all members
cs::metric_function< T > Class Template Referenceabstract

The calculation function for a metric class. More...

Public Member Functions

 metric_function ()
 Constructor. More...
 
 metric_function (const metric_function &)
 Copy constructor. More...
 
virtual ~metric_function ()
 Destructor. More...
 
virtual double operator() (T)=0
 Evaluate the metric function on the specified element. More...
 

Detailed Description

template<typename T> class cs::metric_function< T >

The calculation function for a metric class.

Template Parameters
TThe granularity of the corresponding metric class: project, compunit, sfile, or procedure, as shown in the following table.

If you are defining a custom metric class and wish CodeSonar to compute and report its values automatically (that is, you are creating the class with metricclass_flags::AUTO), provide a suitable metric_function (one whose whose operator() implementation computes the metric value when applied to an argument of type T) when you create the metric class with *_metricclass_manager::create(). If a suitable metric_function subclass does not exist, you will need to implement one.

T Corresponding metric class Create class with
project project_metricclass project_metricclass_manager::create()
compunit compunit_metricclass compunit_metricclass_manager::create()
sfile sfile_metricclass sfile_metricclass_manager::create()
procedure procedure_metricclass procedure_metricclass_manager::create()

If you are not creating the class with metricclass_flags::AUTO, you do not need to provide a metric_function argument to *_metricclass_manager::create(). Instead, implement the report() method for the metric class and invoke it from a suitable visitor.

Constructor & Destructor Documentation

◆ metric_function() [1/2]

template<typename T>
cs::metric_function< T >::metric_function ( )
inline

Constructor.

◆ metric_function() [2/2]

template<typename T>
cs::metric_function< T >::metric_function ( const metric_function< T > &  )
inline

Copy constructor.

◆ ~metric_function()

template<typename T>
virtual cs::metric_function< T >::~metric_function ( )
inlinevirtual

Destructor.

Exceptions
result::ERROR_IMMUTABLE_DATA_STRUCTUREif the metric has been registered and so cannot be deleted.

Member Function Documentation

◆ operator()()

template<typename T>
virtual double cs::metric_function< T >::operator() ( )
pure virtual

Evaluate the metric function on the specified element.

When you subclass metric_function, implement this operator with the logic for computing the metric.

For metric classes created with metricclass_flags::AUTO (alone or in combination with metricclass_flags::POST_ANALYSIS), CodeSonar will automatically apply operator() to compute metric values during the designated analysis phase.

For metric classes created created without metricclass_flags::AUTO, you must explicitly report metric values by invoking the appropriate *_metricclass::report() method from a suitable visitor, even if you specified a metric_function when you created the class.

The result::ERROR_INVALID_PHASE_FOR_OPERATION documentation lists the add_*_visitor() methods associated with the different phases.


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