add script to generate single header

This commit is contained in:
ado 2022-03-30 18:14:30 +02:00
parent 999992e579
commit 62055f03c7
2 changed files with 62 additions and 0 deletions

View File

@ -17,6 +17,9 @@ namespace ss {
// number converters // number converters
//////////////// ////////////////
#define SSP_DISABLE_FAST_FLOAT
#ifndef SSP_DISABLE_FAST_FLOAT
template <typename T> template <typename T>
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num( std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
const char* const begin, const char* const end) { const char* const begin, const char* const end) {
@ -29,6 +32,31 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
return ret; return ret;
} }
#else
template <typename T>
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
const char* const begin, const char* const end) {
T ret;
try {
if constexpr (std::is_same_v<T, float>) {
ret = std::stof(std::string{begin, end});
}
if constexpr (std::is_same_v<T, double>) {
ret = std::stod(std::string{begin, end});
}
if constexpr (std::is_same_v<T, long double>) {
ret = std::stold(std::string{begin, end});
}
} catch (...) {
return std::nullopt;
}
return ret;
}
#endif
inline std::optional<short> from_char(char c) { inline std::optional<short> from_char(char c) {
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
return c - '0'; return c - '0';

View File

@ -0,0 +1,34 @@
#!/bin/python3
headers_dir = 'include/ss/'
headers = ['type_traits.hpp',
'function_traits.hpp',
'restrictions.hpp',
'common.hpp',
'setup.hpp',
'splitter.hpp',
'extract.hpp',
'converter.hpp',
'parser.hpp']
combined_file = []
includes = []
for header in headers:
with open(headers_dir + header) as f:
for line in f.read().splitlines():
if '#include "' in line or '#include <fast_float' in line:
continue
if '#include <' in line:
includes.append(line)
continue
if '#pragma once' not in line:
combined_file.append(line)
includes = sorted(set(includes))
print('\n'.join(includes))
print('#define SSP_DISABLE_FAST_FLOAT')
print('\n'.join(combined_file))