VTK  9.3.0
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
36 #ifndef vtkNumberToString_h
37 #define vtkNumberToString_h
38 
39 #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_3_0
40 #include "vtkIOCoreModule.h" // For export macro
41 #include "vtkTypeTraits.h"
42 
43 #include <ostream>
44 #include <string>
45 
46 VTK_ABI_NAMESPACE_BEGIN
47 class VTKIOCORE_EXPORT vtkNumberToString
48 {
49 public:
51 
59  void SetLowExponent(int lowExponent);
62 
64 
71  void SetHighExponent(int highExponent);
73 
75 
80  std::string Convert(double val);
81  std::string Convert(float val);
82  template <typename T>
83  std::string Convert(const T& val)
84  {
85  return std::to_string(val);
86  }
88 
89  struct TagDouble
90  {
91  double Value;
92  TagDouble(const double& value)
93  : Value(value)
94  {
95  }
96  };
97 
98  struct TagFloat
99  {
100  float Value;
101  TagFloat(const float& value)
102  : Value(value)
103  {
104  }
105  };
106 
107  template <typename T>
108  const T& operator()(const T& val) const
109  {
110  return val;
111  }
112  VTK_DEPRECATED_IN_9_3_0("Use vtkNumberToString::Convert instead.")
113  TagDouble operator()(const double& val) const { return TagDouble(val); }
114  VTK_DEPRECATED_IN_9_3_0("Use vtkNumberToString::Convert instead.")
115  TagFloat operator()(const float& val) const { return TagFloat(val); }
116 
117 private:
118  int LowExponent = -6;
119  int HighExponent = 20;
120 };
121 
122 VTKIOCORE_EXPORT ostream& operator<<(ostream& stream, const vtkNumberToString::TagDouble& tag);
123 VTKIOCORE_EXPORT ostream& operator<<(ostream& stream, const vtkNumberToString::TagFloat& tag);
124 
125 VTK_ABI_NAMESPACE_END
126 #endif
127 // VTK-HeaderTest-Exclude: vtkNumberToString.h
Convert floating and fixed point numbers to strings.
int GetHighExponent()
Set/Get the HighExponent for string conversion.
int GetLowExponent()
Set/Get the LowExponent for string conversion.
void SetLowExponent(int lowExponent)
Set/Get the LowExponent for string conversion.
std::string Convert(float val)
Set/Get the HighExponent for string conversion.
void SetHighExponent(int highExponent)
Set/Get the HighExponent for string conversion.
std::string Convert(const T &val)
Set/Get the HighExponent for string conversion.
std::string Convert(double val)
Convert a number to an accurate string representation of that number.
const T & operator()(const T &val) const
@ value
Definition: vtkX3D.h:220
@ string
Definition: vtkX3D.h:490
TagDouble(const double &value)
TagFloat(const float &value)
#define VTK_DEPRECATED_IN_9_3_0(reason)
VTKIOCORE_EXPORT ostream & operator<<(ostream &stream, const vtkNumberToString::TagDouble &tag)