ComPPare 1.0.0
Loading...
Searching...
No Matches
comppare::internal::policy::MetricValue< T > Class Template Reference

Wrapper for a value that can be streamed to an output stream. More...

#include <policy.hpp>

Collaboration diagram for comppare::internal::policy::MetricValue< T >:
[legend]

Public Member Functions

 MetricValue (T v)
 
 MetricValue (T v, bool is_fail)
 
 MetricValue (T v, bool is_fail, bool valid, std::string_view msg)
 

Private Attributes

value_
 
bool is_fail_ {false}
 
bool valid_ {true}
 
std::string_view err_msg_
 

Friends

std::ostream & operator<< (std::ostream &os, MetricValue< T > const &mv)
 Overloaded operator<< to stream the value or error message.
 

Detailed Description

template<comppare::internal::concepts::Streamable T>
class comppare::internal::policy::MetricValue< T >

Wrapper for a value that can be streamed to an output stream.

Template Parameters
TThe type of the value to be wrapped. Must satisfy Streamable (i.e. it can be inserted into a std::ostream).

Implementation Details:

  • Private Data Members:
    1. value_ – the value of the metric
    2. is_fail_ – indicates if the metric has failed
    3. valid_ – indicates if the metric is valid. (eg. invalid if size mismatch between 2 vectors)
    4. err_msg_ – is an error message if the metric is invalid. (eg. outputs "size mismatch" if the size of 2 vectors is different)
  • operator<<:
    1. Copies the current formatting state of the stream with copyfmt
    2. Streams the value value_ into a temporary std::ostringstream
    3. If the metric is valid and not failed, writes the value to the original stream. If the metric is valid but failed, writes the value in red color to the original stream. If the metric is invalid, writes the error message in red color to the original stream.
    4. Restores the saved formatting state

Constructor & Destructor Documentation

◆ MetricValue() [1/3]

◆ MetricValue() [2/3]

comppare::internal::policy::MetricValue< T >::MetricValue ( v,
bool  is_fail 
)
inline

◆ MetricValue() [3/3]

comppare::internal::policy::MetricValue< T >::MetricValue ( v,
bool  is_fail,
bool  valid,
std::string_view  msg 
)
inline

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
MetricValue< T > const &  mv 
)
friend

Overloaded operator<< to stream the value or error message.

Parameters
osThe output stream
mvThe MetricValue to stream
Returns
The modified output stream

Output Behavior:

  • If the metric is valid and not failed, writes the value to the original stream.
  • If the metric is valid but failed, writes the value in red color to the original stream.
  • If the metric is invalid, writes the error message in red color to the original stream.

Member Data Documentation

◆ err_msg_

std::string_view comppare::internal::policy::MetricValue< T >::err_msg_
private

◆ is_fail_

◆ valid_

◆ value_


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