Public Member Functions | Public Attributes | List of all members
gnsstk::FormattedDouble Class Reference

Detailed Description

There are numerous file formats used in GPS and probably other systems that print floating point numbers that don't conform to standard formats used by C++, including FORTRAN-esque use of 'D' to indicate the exponent, or having a fixed and/or large number of digits in the exponent. This class tries to resolve that by making a double-precision floating point value that carries formatting information along with it.

When using FormattedDouble in a file record wrapper, you would typically define the value stored in the record as a formatted double and initialize it in the record class' constructor with the FormattedDouble(double,StringUtils::FFLead,unsigned,unsigned,unsigned,char,StringUtils::FFSign,StringUtils::FFAlign) constructor, which defines all the relevant formatting information. The value is whatever you'd normally initialize it to outside the context of the formatting. The formatting information at this point is retained for output and input and the value can be treated as any other double. Additionally, you can assign a string to this class and it will interpret it according to the formatting information.

See also
RinexNavHeader for an example use.

Definition at line 70 of file FormattedDouble.hpp.

#include <FormattedDouble.hpp>

Inheritance diagram for gnsstk::FormattedDouble:
Inheritance graph
[legend]

Public Member Functions

void dump (std::ostream &s) const
 debug output all data members More...
 
 FormattedDouble (const std::string &str, unsigned width=0, char expChar='e')
 
 FormattedDouble (double d, StringUtils::FFLead lead, unsigned mantissa=0, unsigned exponent=2, unsigned width=0, char expChar='e', StringUtils::FFSign sign=StringUtils::FFSign::NegOnly, StringUtils::FFAlign align=StringUtils::FFAlign::Left)
 
 FormattedDouble (unsigned width=0, char expChar='e')
 
 operator double () const
 Cast this object to a double for math and such. More...
 
 operator double & ()
 Cast this object to a double for math and such. More...
 
 operator std::string ()
 Cast this object to a string using formatting configuration. More...
 
FormattedDouble operator* (double d) const
 
FormattedDoubleoperator++ ()
 Increment the value (prefix). More...
 
FormattedDouble operator++ (int)
 Increment the value (postfix). More...
 
FormattedDoubleoperator-- ()
 Decrement the value (prefix). More...
 
FormattedDouble operator-- (int)
 Decrement the value (postfix). More...
 
FormattedDouble operator/ (double d) const
 
FormattedDoubleoperator= (const FormattedDouble &right)=default
 Copy assignment. More...
 
FormattedDoubleoperator= (const std::string &s)
 Assign a value by decoding a string using existing formatting. More...
 
FormattedDoubleoperator= (double d)
 Assign a value without affecting formatting. More...
 

Public Attributes

StringUtils::FFAlign alignment
 Alignment when padding with space. More...
 
char exponentChar
 What character delimits the exponent. More...
 
unsigned exponentLen
 How many digits of exponent. More...
 
StringUtils::FFLead leadChar
 Leading non-space character. More...
 
StringUtils::FFSign leadSign
 How to handle signs for positive val. More...
 
unsigned mantissaLen
 How many digits of mantissa. More...
 
unsigned totalLen
 Total width of space-padded value. More...
 
double val
 The value as read or to be formatted. More...
 

Constructor & Destructor Documentation

◆ FormattedDouble() [1/3]

gnsstk::FormattedDouble::FormattedDouble ( double  d,
StringUtils::FFLead  lead,
unsigned  mantissa = 0,
unsigned  exponent = 2,
unsigned  width = 0,
char  expChar = 'e',
StringUtils::FFSign  sign = StringUtils::FFSign::NegOnly,
StringUtils::FFAlign  align = StringUtils::FFAlign::Left 
)

Prepare a value for stream output.

Parameters
[in]dThe value that is to be formatted in an ostream.
[in]leadHow the lead-in to the value is to be formatted.
[in]mantissaHow many digits of precision should be in the mantissa, e.g. mantissa=5 could result in something like 1.2345e+00.
[in]exponentHow many digits of precision should be in the exponent, e.g. exponent=3 could result in something like 1.2345e+000. Exponents will always be at least 2 characters in length.
[in]widthThe total number of characters in the formatted value. If the length of the formatted value including mantissa, exponent, sign, etc. is >= width, no additional formatting will take place. If the length of the formatted value is < width, it will be padded with spaces according to align.
[in]expCharThe character used to designate the exponent, e.g. "e" or "E" or "D".
[in]signHow numerical sign is to be handled in formatting.
[in]alignHow to pad the formatted value according to width. Left adds space to the end of the formatted value while Right inserts space at the beginning.

Definition at line 44 of file FormattedDouble.cpp.

◆ FormattedDouble() [2/3]

gnsstk::FormattedDouble::FormattedDouble ( unsigned  width = 0,
char  expChar = 'e' 
)
explicit

Prepare for stream input.

Parameters
[in]widthThe total number of characters in the formatted value. If the length of the formatted value including mantissa, exponent, sign, etc. is >= width, no additional formatting will take place. If the length of the formatted value is < width, it will be padded with spaces according to align.
[in]expCharThe character used to designate the exponent, e.g. "e" or "E" or "D".
Note
All other formatting values are quietly ignored on input. Only the exponent character is needed to properly read a formatted value.

Definition at line 55 of file FormattedDouble.cpp.

◆ FormattedDouble() [3/3]

gnsstk::FormattedDouble::FormattedDouble ( const std::string &  str,
unsigned  width = 0,
char  expChar = 'e' 
)
explicit

Decode a string containing a double-precision floating point number with the given formatting options.

Parameters
[in]strThe string to decode.
[in]widthThe total number of characters in the formatted value. If the length of the formatted value including mantissa, exponent, sign, etc. is >= width, no additional formatting will take place. If the length of the formatted value is < width, it will be padded with spaces according to align.
[in]expCharThe character used to designate the exponent, e.g. "e" or "E" or "D".
Note
All other formatting values are quietly ignored on input. Only the exponent character is needed to properly read a formatted value.

Definition at line 65 of file FormattedDouble.cpp.

Member Function Documentation

◆ dump()

void gnsstk::FormattedDouble::dump ( std::ostream &  s) const

debug output all data members

Definition at line 143 of file FormattedDouble.cpp.

◆ operator double()

gnsstk::FormattedDouble::operator double ( ) const
inline

Cast this object to a double for math and such.

Definition at line 137 of file FormattedDouble.hpp.

◆ operator double &()

gnsstk::FormattedDouble::operator double & ( )
inline

Cast this object to a double for math and such.

Definition at line 141 of file FormattedDouble.hpp.

◆ operator std::string()

gnsstk::FormattedDouble::operator std::string ( )
inline

Cast this object to a string using formatting configuration.

Definition at line 208 of file FormattedDouble.hpp.

◆ operator*()

FormattedDouble gnsstk::FormattedDouble::operator* ( double  d) const
inline

Multiply val by a scalar. This ensures that you can scale FormattedDouble objects and retain the formatting.

Definition at line 222 of file FormattedDouble.hpp.

◆ operator++() [1/2]

FormattedDouble& gnsstk::FormattedDouble::operator++ ( )
inline

Increment the value (prefix).

Definition at line 156 of file FormattedDouble.hpp.

◆ operator++() [2/2]

FormattedDouble gnsstk::FormattedDouble::operator++ ( int  )
inline

Increment the value (postfix).

Definition at line 159 of file FormattedDouble.hpp.

◆ operator--() [1/2]

FormattedDouble& gnsstk::FormattedDouble::operator-- ( )
inline

Decrement the value (prefix).

Definition at line 162 of file FormattedDouble.hpp.

◆ operator--() [2/2]

FormattedDouble gnsstk::FormattedDouble::operator-- ( int  )
inline

Decrement the value (postfix).

Definition at line 165 of file FormattedDouble.hpp.

◆ operator/()

FormattedDouble gnsstk::FormattedDouble::operator/ ( double  d) const
inline

Divide val by a scalar. This ensures that you can scale FormattedDouble objects and retain the formatting.

Definition at line 215 of file FormattedDouble.hpp.

◆ operator=() [1/3]

FormattedDouble& gnsstk::FormattedDouble::operator= ( const FormattedDouble right)
default

Copy assignment.

◆ operator=() [2/3]

FormattedDouble & gnsstk::FormattedDouble::operator= ( const std::string &  s)

Assign a value by decoding a string using existing formatting.

Definition at line 76 of file FormattedDouble.cpp.

◆ operator=() [3/3]

FormattedDouble& gnsstk::FormattedDouble::operator= ( double  d)
inline

Assign a value without affecting formatting.

Definition at line 172 of file FormattedDouble.hpp.

Member Data Documentation

◆ alignment

StringUtils::FFAlign gnsstk::FormattedDouble::alignment

Alignment when padding with space.

Definition at line 188 of file FormattedDouble.hpp.

◆ exponentChar

char gnsstk::FormattedDouble::exponentChar

What character delimits the exponent.

Definition at line 186 of file FormattedDouble.hpp.

◆ exponentLen

unsigned gnsstk::FormattedDouble::exponentLen

How many digits of exponent.

Definition at line 184 of file FormattedDouble.hpp.

◆ leadChar

StringUtils::FFLead gnsstk::FormattedDouble::leadChar

Leading non-space character.

Definition at line 182 of file FormattedDouble.hpp.

◆ leadSign

StringUtils::FFSign gnsstk::FormattedDouble::leadSign

How to handle signs for positive val.

Definition at line 187 of file FormattedDouble.hpp.

◆ mantissaLen

unsigned gnsstk::FormattedDouble::mantissaLen

How many digits of mantissa.

Definition at line 183 of file FormattedDouble.hpp.

◆ totalLen

unsigned gnsstk::FormattedDouble::totalLen

Total width of space-padded value.

Definition at line 185 of file FormattedDouble.hpp.

◆ val

double gnsstk::FormattedDouble::val

The value as read or to be formatted.

Definition at line 181 of file FormattedDouble.hpp.


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


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:44