VTK  9.4.20241108
vtkNumberToString.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
49#ifndef vtkNumberToString_h
50#define vtkNumberToString_h
51
52#include "vtkCommonCoreModule.h" // For export macro
53#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_3_0
54#include "vtkTypeTraits.h"
55
56#include <ostream>
57#include <string>
58
59VTK_ABI_NAMESPACE_BEGIN
60class VTKCOMMONCORE_EXPORT vtkNumberToString
61{
62public:
64
73 void SetLowExponent(int lowExponent);
76
78
86 void SetHighExponent(int highExponent);
89
91 {
94 Fixed
95 };
96
98
108 void SetNotation(int notation);
111
113
121 void SetPrecision(int precision);
124
126
131 std::string Convert(double val);
132 std::string Convert(float val);
133 template <typename T>
134 std::string Convert(const T& val)
135 {
136 return std::to_string(val);
137 }
139
141 {
142 double Value;
143 TagDouble(const double& value)
144 : Value(value)
145 {
146 }
147 };
148
149 struct TagFloat
150 {
151 float Value;
152 TagFloat(const float& value)
153 : Value(value)
154 {
155 }
156 };
157
158 template <typename T>
159 const T& operator()(const T& val) const
160 {
161 return val;
162 }
163 VTK_DEPRECATED_IN_9_3_0("Use vtkNumberToString::Convert instead.")
164 TagDouble operator()(const double& val) const { return TagDouble(val); }
165 VTK_DEPRECATED_IN_9_3_0("Use vtkNumberToString::Convert instead.")
166 TagFloat operator()(const float& val) const { return TagFloat(val); }
167
168private:
169 int LowExponent = -6;
170 int HighExponent = 20;
171 int Notation = Mixed;
172 int Precision = 2;
173};
174
175VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& stream, const vtkNumberToString::TagDouble& tag);
176VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& stream, const vtkNumberToString::TagFloat& tag);
177
178VTK_ABI_NAMESPACE_END
179#endif
180// VTK-HeaderTest-Exclude: vtkNumberToString.h
Convert floating and fixed point numbers to strings.
const T & operator()(const T &val) const
int GetHighExponent()
Set/Get the HighExponent for string conversion.
void SetNotation(int notation)
Set/Get the notation used for string conversion.
int GetLowExponent()
Set/Get the LowExponent for string conversion.
int GetNotation()
Set/Get the notation used for string conversion.
void SetLowExponent(int lowExponent)
Set/Get the LowExponent for string conversion.
std::string Convert(float val)
Convert a number to an accurate string representation of that number.
void SetHighExponent(int highExponent)
Set/Get the HighExponent for string conversion.
std::string Convert(const T &val)
Convert a number to an accurate string representation of that number.
void SetPrecision(int precision)
Set/Get the floating-point precision used for string conversion.
std::string Convert(double val)
Convert a number to an accurate string representation of that number.
int GetPrecision()
Set/Get the floating-point precision used for string conversion.
#define VTK_DEPRECATED_IN_9_3_0(reason)
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &stream, const vtkNumberToString::TagDouble &tag)