VTK  9.5.20250822
Namespaces | Macros
vtkStringScanner.h File Reference

Optimized C++ utilities for scanning values from strings and files. More...

#include "vtkCharConvCompatibility.h"
#include "vtkCommonCoreModule.h"
#include "vtkLogger.h"
#include "vtkfast_float.h"
#include "vtk_scn.h"
#include <VTK_SCN(scn/chrono.h)>
#include <VTK_SCN(scn/scan.h)>
#include <array>
#include <string_view>
Include dependency graph for vtkStringScanner.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  vtk
 Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
 

Macros

#define VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND(from_chars_result, value, command)
 
#define VTK_FROM_CHARS_RESULT_IF_ERROR_BREAK(from_chars_result, value)    VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND(from_chars_result, value, break)
 
#define VTK_FROM_CHARS_RESULT_IF_ERROR_RETURN(from_chars_result, value, returnValue)    VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND(from_chars_result, value, return returnValue)
 
#define VTK_FROM_CHARS_CONCAT_INNER(a, b)   a##b
 
#define VTK_FROM_CHARS_CONCAT(a, b)   VTK_FROM_CHARS_CONCAT_INNER(a, b)
 
#define VTK_FROM_CHARS_IF_ERROR_COMMAND(string, value, command)
 
#define VTK_FROM_CHARS_IF_ERROR_BREAK(string, value)    VTK_FROM_CHARS_IF_ERROR_COMMAND(string, value, break)
 
#define VTK_FROM_CHARS_IF_ERROR_RETURN(string, value, returnValue)    VTK_FROM_CHARS_IF_ERROR_COMMAND(string, value, return returnValue)
 
#define VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_COMMAND(string, value, param, command)
 
#define VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_BREAK(string, value, param)    VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_COMMAND(string, value, param, break)
 
#define VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_RETURN(string, value, param, returnValue)    VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_COMMAND(string, value, param, return returnValue)
 

Functions

template<typename T , typename = FASTFLOAT_ENABLE_IF(fast_float::is_supported_float_type<T>::value)>
VTK_ALWAYS_INLINE auto vtk::from_chars (const char *first, const char *last, T &value, std::chars_format format=std::chars_format::general) -> std::from_chars_result
 Given a char* first and char* last, convert it to a number, and return a from_chars_result;.
 
template<typename T , typename = FASTFLOAT_ENABLE_IF(fast_float::is_supported_integer_type<T>::value)>
VTK_ALWAYS_INLINE auto vtk::from_chars (const char *first, const char *last, T &value, int base=10) -> std::from_chars_result
 Given a char* first and char* last, convert it to a number, and return a from_chars_result;.
 
template<typename T , typename = FASTFLOAT_ENABLE_IF(fast_float::is_supported_float_type<T>::value)>
VTK_ALWAYS_INLINE auto vtk::from_chars (const std::string_view str, T &value, std::chars_format format=std::chars_format::general) -> std::from_chars_result
 Given a std::string_view str, convert it to a number, and return a from_chars_result;.
 
template<typename T , typename = FASTFLOAT_ENABLE_IF(fast_float::is_supported_integer_type<T>::value)>
VTK_ALWAYS_INLINE auto vtk::from_chars (const std::string_view str, T &value, int base=10) -> std::from_chars_result
 Given a std::string_view str, convert it to a number, and return a from_chars_result;.
 

Detailed Description

Optimized C++ utilities for scanning values from strings and files.

This header provides efficient, alternatives to common C/C++ string handling functions such as scanf, atoi etc.

It includes utilities for converting strings to numbers and scanning values from strings and files.

Refer to the documentation for guidance on replacing standard C functions with their modern, type-safe counterparts provided here.

  1. C/C++ has the following functions to convert one/many char* or string to a number.
    1. atof, atoi, atol, atoll,
    2. std::stof, std::stod, std::stold, std::stoi, std::stol, std::stoll, std::stoul, std::stoull
    3. strtof, strtod, strtold, strtol, strtoll/_strtoi64, strtoul, strtoull
    4. sscanf, sscanf_s, vsscanf, vsscanf_s
    5. strptime
    6. std::from_chars
    7. std::get_time These functions should be replaced by:
    1. vtk::from_chars, vtk::scan_int, vtk::scan_value, if one number needs to be converted
    2. vtk::scan, if one/many numbers need to be converted (optionally with a specific format)
  2. C/C++ has the following functions to scan one/many numbers from a stdin/file.
    1. scanf, scanf_s, vscanf, vscanf_s,
    2. fscanf, fscanf_s, vfscanf, vfscanf_s,
    3. std::cin, std::ifstream, vtksys::ifstream These functions should be replaced by:
    1. vtk::scan_value, if one number needs to be converted
    2. vtk::input, vtk::scan, if one/many numbers need to be converted (optionally with a specific format)

Definition in file vtkStringScanner.h.

Macro Definition Documentation

◆ VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND

#define VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND (   from_chars_result,
  value,
  command 
)
Value:
switch (from_chars_result.ec) \
{ \
case std::errc::invalid_argument: \
{ \
vtkLogF(ERROR, "The given argument was invalid, failed to get the converted " #value "."); \
command; \
} \
case std::errc::result_out_of_range: \
{ \
vtkLogF(ERROR, "The result is out of range, failed to get the converted " #value "."); \
command; \
} \
default: \
{ \
} \
}

Definition at line 113 of file vtkStringScanner.h.

◆ VTK_FROM_CHARS_RESULT_IF_ERROR_BREAK

#define VTK_FROM_CHARS_RESULT_IF_ERROR_BREAK (   from_chars_result,
  value 
)     VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND(from_chars_result, value, break)

Definition at line 131 of file vtkStringScanner.h.

◆ VTK_FROM_CHARS_RESULT_IF_ERROR_RETURN

#define VTK_FROM_CHARS_RESULT_IF_ERROR_RETURN (   from_chars_result,
  value,
  returnValue 
)     VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND(from_chars_result, value, return returnValue)

Definition at line 134 of file vtkStringScanner.h.

◆ VTK_FROM_CHARS_CONCAT_INNER

#define VTK_FROM_CHARS_CONCAT_INNER (   a,
 
)    a##b

Definition at line 138 of file vtkStringScanner.h.

◆ VTK_FROM_CHARS_CONCAT

#define VTK_FROM_CHARS_CONCAT (   a,
 
)    VTK_FROM_CHARS_CONCAT_INNER(a, b)

Definition at line 139 of file vtkStringScanner.h.

◆ VTK_FROM_CHARS_IF_ERROR_COMMAND

#define VTK_FROM_CHARS_IF_ERROR_COMMAND (   string,
  value,
  command 
)
Value:
auto VTK_FROM_CHARS_CONCAT(_from_chars_result_, __LINE__) = vtk::from_chars(string, value); \
VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND( \
VTK_FROM_CHARS_CONCAT(_from_chars_result_, __LINE__), value, command)
VTK_ALWAYS_INLINE auto from_chars(const char *first, const char *last, T &value, std::chars_format format=std::chars_format::general) -> std::from_chars_result
Given a char* first and char* last, convert it to a number, and return a from_chars_result;.
#define VTK_FROM_CHARS_CONCAT(a, b)

Definition at line 142 of file vtkStringScanner.h.

◆ VTK_FROM_CHARS_IF_ERROR_BREAK

#define VTK_FROM_CHARS_IF_ERROR_BREAK (   string,
  value 
)     VTK_FROM_CHARS_IF_ERROR_COMMAND(string, value, break)

Definition at line 147 of file vtkStringScanner.h.

◆ VTK_FROM_CHARS_IF_ERROR_RETURN

#define VTK_FROM_CHARS_IF_ERROR_RETURN (   string,
  value,
  returnValue 
)     VTK_FROM_CHARS_IF_ERROR_COMMAND(string, value, return returnValue)

Definition at line 150 of file vtkStringScanner.h.

◆ VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_COMMAND

#define VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_COMMAND (   string,
  value,
  param,
  command 
)
Value:
auto VTK_FROM_CHARS_CONCAT(_from_chars_result_, __LINE__) = \
vtk::from_chars(string, value, param); \
VTK_FROM_CHARS_RESULT_IF_ERROR_COMMAND( \
VTK_FROM_CHARS_CONCAT(_from_chars_result_, __LINE__), value, command)

Definition at line 154 of file vtkStringScanner.h.

◆ VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_BREAK

#define VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_BREAK (   string,
  value,
  param 
)     VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_COMMAND(string, value, param, break)

Definition at line 160 of file vtkStringScanner.h.

◆ VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_RETURN

#define VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_RETURN (   string,
  value,
  param,
  returnValue 
)     VTK_FROM_CHARS_WITH_PARAM_IF_ERROR_COMMAND(string, value, param, return returnValue)

Definition at line 163 of file vtkStringScanner.h.