31#ifndef CFGFILE__FORMAT_HPP__INCLUDED
32#define CFGFILE__FORMAT_HPP__INCLUDED
43#ifdef CFGFILE_QT_SUPPORT
56template<
class T,
class Trait >
60 static typename Trait::string_t
to_string(
const T & );
64 const typename Trait::string_t & );
68#ifndef CFGFILE_DISABLE_STL
76 return std::to_string( value );
86 int result = std::stoi( value, &pos );
88 if( pos != value.length() )
99 catch(
const std::exception & )
118 return std::to_wstring( value );
128 int result = std::stoi( value, &pos );
130 if( pos != value.length() )
141 catch(
const std::exception & )
157#ifdef CFGFILE_QT_SUPPORT
164 return QString::number( value );
189#ifndef CFGFILE_DISABLE_STL
197 return std::to_string( value );
207 unsigned long result = std::stoul( value, &
pos );
209 if(
pos != value.length() ||
210 result > std::numeric_limits< unsigned int >::max() )
219 return (
unsigned int)
result;
221 catch(
const std::exception & )
241 return std::to_wstring( value );
251 unsigned long result = std::stoul( value, &
pos );
253 if(
pos != value.length() ||
254 result > std::numeric_limits< unsigned int >::max() )
263 return (
unsigned int)
result;
265 catch(
const std::exception & )
281#ifdef CFGFILE_QT_SUPPORT
288 return QString::number( value );
313#ifndef CFGFILE_DISABLE_STL
321 return std::to_string( value );
333 if(
pos != value.length() )
344 catch(
const std::exception & )
364 return std::to_wstring( value );
376 if(
pos != value.length() )
387 catch(
const std::exception & )
403#ifdef CFGFILE_QT_SUPPORT
410 return QString::number( value );
435#ifndef CFGFILE_DISABLE_STL
443 return std::to_string( value );
453 unsigned long result = std::stoul( value, &
pos );
455 if(
pos != value.length() )
466 catch(
const std::exception & )
486 return std::to_wstring( value );
496 unsigned long result = std::stoul( value, &
pos );
498 if(
pos != value.length() )
509 catch(
const std::exception & )
525#ifdef CFGFILE_QT_SUPPORT
532 return QString::number( value );
557#ifndef CFGFILE_DISABLE_STL
565 return std::to_string( value );
575 long long result = std::stoll( value, &
pos );
577 if(
pos != value.length() )
588 catch(
const std::exception & )
608 return std::to_wstring( value );
618 long long result = std::stoll( value, &
pos );
620 if(
pos != value.length() )
631 catch(
const std::exception & )
647#ifdef CFGFILE_QT_SUPPORT
654 return QString::number( value );
679#ifndef CFGFILE_DISABLE_STL
687 return std::to_string( value );
697 unsigned long long result = std::stoull( value, &
pos );
699 if(
pos != value.length() )
710 catch(
const std::exception & )
730 return std::to_wstring( value );
740 unsigned long long result = std::stoull( value, &
pos );
742 if(
pos != value.length() )
753 catch(
const std::exception & )
769#ifdef CFGFILE_QT_SUPPORT
776 return QString::number( value );
801#ifndef CFGFILE_DISABLE_STL
809 return std::to_string( value );
819 double result = std::stod( value, &
pos );
821 if(
pos != value.length() )
832 catch(
const std::exception & )
852 return std::to_wstring( value );
862 double result = std::stod( value, &
pos );
864 if(
pos != value.length() )
875 catch(
const std::exception & )
891#ifdef CFGFILE_QT_SUPPORT
898 return QString::number( value,
'g', 999 );
923template<
typename Trait >
927 static typename Trait::string_t
to_string(
const typename Trait::string_t & value )
934 const typename Trait::string_t & value )
941#ifndef CFGFILE_DISABLE_STL
950 res.assign( value.cbegin(), value.cend() );
961 for(
const auto &
ch : value )
962 res.push_back(
static_cast< char > (
ch ) );
971#if defined(CFGFILE_QT_SUPPORT) && !defined(CFGFILE_DISABLE_STL)
978 return QString::fromStdString( value );
985 return ((
QString)value).toStdString();
991#ifndef CFGFILE_DISABLE_STL
1001 for(
const auto &
ch : value )
1002 res.push_back(
static_cast< char > (
ch ) );
1012 res.assign( value.cbegin(), value.cend() );
1021#if defined(CFGFILE_QT_SUPPORT) && !defined(CFGFILE_DISABLE_STL)
1028 return QString::fromStdWString( value );
1035 return ((
QString)value).toStdWString();
1041#if defined(CFGFILE_QT_SUPPORT) && !defined(CFGFILE_DISABLE_STL)
1048 return value.toStdString();
1055 return QString::fromStdString( value );
1066 return value.toStdWString();
1073 return QString::fromStdWString( value );
1079#ifdef CFGFILE_QT_SUPPORT
1099template<
typename Trait >
1103 static typename Trait::string_t
to_string(
const bool & value )
1111 const typename Trait::string_t & value )
1125 Trait::from_ascii(
"Invalid value: \"" ) +
1126 value + Trait::from_ascii(
"\". In file \"" ) +
1127 info.file_name() + Trait::from_ascii(
"\" on line " ) +
1128 Trait::to_string(
info.line_number() ) +
1129 Trait::from_ascii(
"." ) );
Definition exceptions.hpp:85
Exception in the library.
Definition exceptions.hpp:51
Information about parsed file and current state of parsing.
Definition parser_info.hpp:46
const Trait::string_t & file_name() const
Definition parser_info.hpp:58
Trait::pos_t line_number() const
Definition parser_info.hpp:64
QString wrapper.
Definition types.hpp:282
Trait for QString support.
Definition types.hpp:502
static string_t from_ascii(const std::string &str)
Definition types.hpp:526
static string_t to_string(pos_t pos)
Definition types.hpp:521
Trait for std::string support.
Definition types.hpp:170
std::string string_t
String type.
Definition types.hpp:172
static string_t from_ascii(const std::string &str)
Definition types.hpp:194
static string_t to_string(pos_t pos)
Definition types.hpp:189
Trait for std::wstring support.
Definition types.hpp:59
static string_t to_string(pos_t pos)
Definition types.hpp:78
std::wstring string_t
String type.
Definition types.hpp:61
static string_t from_ascii(const std::string &str)
Definition types.hpp:83