LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 109 of file hexfloat.h.

Member Typedef Documentation

Definition at line 140 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 113 of file hexfloat.h.

113 : active(start_active) {}
bool active
whether we are writing in base 16
Definition: hexfloat.h:142

Member Function Documentation

void lar::OptionalHexFloat::disable ( )
inline

Disables base 16 printing.

Definition at line 122 of file hexfloat.h.

References lar::details::OptionalHexFloatFormatter< T >::active.

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

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

Definition at line 119 of file hexfloat.h.

References lar::details::OptionalHexFloatFormatter< T >::active, and enable().

Referenced by enable().

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

Returns whether base 16 printing is enabled.

Definition at line 116 of file hexfloat.h.

References lar::details::OptionalHexFloatFormatter< T >::active.

116 { return active; }
bool active
whether we are writing in base 16
Definition: hexfloat.h:142
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 126 of file hexfloat.h.

References lar::details::OptionalHexFloatFormatter< T >::active, and lar::details::OptionalHexFloatFormatter< T >::value.

127  {
128  return formatter_t<T>(value, active);
129  }
double value
Definition: spectrum.C:18
bool active
whether we are writing in base 16
Definition: hexfloat.h:142
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 133 of file hexfloat.h.

References lar::details::OptionalHexFloatFormatter< T >::value.

134  {
135  return formatter_t<T>(this_active, value);
136  }
double value
Definition: spectrum.C:18

Member Data Documentation

bool lar::OptionalHexFloat::active
private

whether we are writing in base 16

Definition at line 142 of file hexfloat.h.


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