FormattedDouble.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include "FormattedDouble.hpp"
40 
41 namespace gnsstk
42 {
44  FormattedDouble(double d, StringUtils::FFLead lead, unsigned mantissa,
45  unsigned exponent, unsigned width, char expChar,
47  : val(d), leadChar(lead), mantissaLen(mantissa), exponentLen(exponent),
48  totalLen(width), exponentChar(expChar), leadSign(sign),
49  alignment(align)
50  {
51  }
52 
53 
55  FormattedDouble(unsigned width, char expChar)
56  : val(0), leadChar(StringUtils::FFLead::NonZero), mantissaLen(0),
57  exponentLen(2), totalLen(width), exponentChar(expChar),
58  leadSign(StringUtils::FFSign::NegOnly),
59  alignment(StringUtils::FFAlign::Left)
60  {
61  }
62 
63 
65  FormattedDouble(const std::string& str, unsigned width, char expChar)
66  : val(0), leadChar(StringUtils::FFLead::NonZero), mantissaLen(0),
67  exponentLen(2), totalLen(width), exponentChar(expChar),
68  leadSign(StringUtils::FFSign::NegOnly),
69  alignment(StringUtils::FFAlign::Left)
70  {
71  this->operator=(str);
72  }
73 
74 
76  operator=(const std::string& s)
77  {
78  if ((exponentChar != 'e') && (exponentChar != 'E'))
79  {
80  // If the exponent character is different from standard,
81  // we need to do some tweaking.
82  // have to make a copy to modify
83  std::string copy(s);
84  std::string::size_type pos = copy.find(exponentChar);
85  if (pos != std::string::npos)
86  {
87  copy[pos] = 'e'; // change exponent character to a readable one
88  }
89  std::istringstream iss(copy);
90  iss >> val;
91  }
92  else
93  {
94  // If the exponent character is standard, the standard
95  // istream double reading should work fine regardless of
96  // any other tweaks.
97  std::istringstream iss(s);
98  iss >> val;
99  }
100  return *this;
101  }
102 
103 
104  std::ostream& operator<<(std::ostream& s, const FormattedDouble& d)
105  {
108  d.leadSign, d.alignment);
109  return s;
110  }
111 
112 
113  std::istream& operator>>(std::istream& s, FormattedDouble& d)
114  {
115  if (d.totalLen)
116  s >> std::setw(d.totalLen);
117  if ((d.exponentChar != 'e') && (d.exponentChar != 'E'))
118  {
119  // If the exponent character is different from standard,
120  // we need to do some tweaking.
121  std::string str;
122  s >> str;
123  std::string::size_type pos = str.find(d.exponentChar);
124  if (pos != std::string::npos)
125  {
126  str[pos] = 'e'; // change exponent character to a readable one
127  }
128  std::istringstream iss(str);
129  iss >> d.val;
130  }
131  else
132  {
133  // If the exponent character is standard, the standard
134  // istream double reading should work fine regardless of
135  // any other tweaks.
136  s >> d.val;
137  }
138  return s;
139  }
140 
141 
142  void FormattedDouble ::
143  dump(std::ostream& s) const
144  {
145  s << "FormattedDouble(" << val << "," << static_cast<int>(leadChar) << ","
146  << mantissaLen << "," << exponentLen << "," << totalLen << ","
147  << exponentChar << "," << static_cast<int>(leadSign) << ","
148  << static_cast<int>(alignment) << ")" << std::endl;
149  }
150 } // namespace gnsstk
gnsstk::FormattedDouble::operator=
FormattedDouble & operator=(const FormattedDouble &right)=default
Copy assignment.
gnsstk::FormattedDouble::exponentLen
unsigned exponentLen
How many digits of exponent.
Definition: FormattedDouble.hpp:184
gnsstk::StringUtils::FFAlign::Left
@ Left
Formatted output will be left-aligned.
gnsstk::operator>>
std::istream & operator>>(FFStream &i, FFData &f)
Definition: FFData.cpp:65
gnsstk::FormattedDouble::exponentChar
char exponentChar
What character delimits the exponent.
Definition: FormattedDouble.hpp:186
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::StringUtils::FFLead
FFLead
Leading character for floatFormat(), after any whitespace or sign.
Definition: StringUtils.hpp:109
gnsstk::StringUtils::floatFormat
std::string floatFormat(double d, FFLead lead, unsigned mantissa, unsigned exponent, unsigned width, char expChar, FFSign sign, FFAlign align)
Definition: StringUtils.cpp:210
gnsstk::FormattedDouble
Definition: FormattedDouble.hpp:70
gnsstk::StringUtils::FFSign::NegOnly
@ NegOnly
Prefix output with a minus sign (neg) or nothing (pos)
gnsstk::FormattedDouble::alignment
StringUtils::FFAlign alignment
Alignment when padding with space.
Definition: FormattedDouble.hpp:188
gnsstk::FormattedDouble::dump
void dump(std::ostream &s) const
debug output all data members
Definition: FormattedDouble.cpp:143
gnsstk::FormattedDouble::leadSign
StringUtils::FFSign leadSign
How to handle signs for positive val.
Definition: FormattedDouble.hpp:187
gnsstk::operator<<
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
Definition: ObsEpochMap.cpp:54
gnsstk::StringUtils::FFLead::NonZero
@ NonZero
Start with the first non-zero digit, e.g. 1.2345.
gnsstk::FormattedDouble::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)
Definition: FormattedDouble.cpp:44
FormattedDouble.hpp
gnsstk::FormattedDouble::mantissaLen
unsigned mantissaLen
How many digits of mantissa.
Definition: FormattedDouble.hpp:183
example4.pos
pos
Definition: example4.py:125
gnsstk::FormattedDouble::totalLen
unsigned totalLen
Total width of space-padded value.
Definition: FormattedDouble.hpp:185
gnsstk::FormattedDouble::leadChar
StringUtils::FFLead leadChar
Leading non-space character.
Definition: FormattedDouble.hpp:182
gnsstk::StringUtils::FFSign
FFSign
How to handle sign in floatFormat()
Definition: StringUtils.hpp:117
gnsstk::StringUtils::FFAlign
FFAlign
Alignment of data for floatFormat()
Definition: StringUtils.hpp:125
gnsstk::FormattedDouble::val
double val
The value as read or to be formatted.
Definition: FormattedDouble.hpp:181


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