Public Member Functions | Private Types | Private Attributes | List of all members
lar::OptionalHexFloat Class Reference

Helper for formatting floats in base 16. More...

#include <hexfloat.h>

Public Member Functions

 OptionalHexFloat (bool start_active=true)
 Constructor: if start_active is true, it will print floats in base 16. More...
 
bool enabled () const
 Returns whether base 16 printing is enabled. More...
 
void enable (bool enable=true)
 Enables base 16 printing (or disables it if enable is false) More...
 
void disable ()
 Disables base 16 printing. More...
 
template<typename T >
auto operator() (T value) const
 Returns an object that knows what to do with an output stream. More...
 
template<typename T >
auto operator() (bool this_active, T value) const
 Returns an object that knows what to do with an output stream. More...
 

Private Types

template<typename T >
using formatter_t = details::OptionalHexFloatFormatter< T >
 

Private Attributes

bool active
 whether we are writing in base 16 More...
 

Detailed Description

Helper for formatting floats in base 16.

Example of use:

lar::OptionalHexFloat hexfloat;
constexpr double value = 0.375;

std::cout << "Hex: " << hexfloat(value) << std::endl;

hexfloat.disable();

std::cout << "Dec: " << hexfloat(value) << std::endl;

The first printout is expected to be in base 16, the second one in base 10.

Definition at line 105 of file hexfloat.h.

Member Typedef Documentation

Definition at line 134 of file hexfloat.h.

Constructor & Destructor Documentation

lar::OptionalHexFloat::OptionalHexFloat ( bool  start_active = true)
inline

Constructor: if start_active is true, it will print floats in base 16.

Definition at line 110 of file hexfloat.h.

111  : active(start_active)
112  {}
bool active
whether we are writing in base 16
Definition: hexfloat.h:136

Member Function Documentation

void lar::OptionalHexFloat::disable ( )
inline

Disables base 16 printing.

Definition at line 121 of file hexfloat.h.

121 { active = false; }
bool active
whether we are writing in base 16
Definition: hexfloat.h:136
void lar::OptionalHexFloat::enable ( bool  enable = true)
inline

Enables base 16 printing (or disables it if enable is false)

Definition at line 118 of file hexfloat.h.

118 { active = enable; }
void enable(bool enable=true)
Enables base 16 printing (or disables it if enable is false)
Definition: hexfloat.h:118
bool active
whether we are writing in base 16
Definition: hexfloat.h:136
bool lar::OptionalHexFloat::enabled ( ) const
inline

Returns whether base 16 printing is enabled.

Definition at line 115 of file hexfloat.h.

115 { return active; }
bool active
whether we are writing in base 16
Definition: hexfloat.h:136
template<typename T >
auto lar::OptionalHexFloat::operator() ( value) const
inline

Returns an object that knows what to do with an output stream.

Definition at line 125 of file hexfloat.h.

125 { return formatter_t<T>(value, active); }
bool active
whether we are writing in base 16
Definition: hexfloat.h:136
template<typename T >
auto lar::OptionalHexFloat::operator() ( bool  this_active,
value 
) const
inline

Returns an object that knows what to do with an output stream.

Definition at line 129 of file hexfloat.h.

130  { return formatter_t<T>(this_active, value); }

Member Data Documentation

bool lar::OptionalHexFloat::active
private

whether we are writing in base 16

Definition at line 136 of file hexfloat.h.


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