File indexing completed on 2025-09-16 08:29:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_IMPL_CONFIG_HPP
0012 #define BOOST_ASIO_IMPL_CONFIG_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <cerrno>
0020 #include <cstdlib>
0021 #include <limits>
0022 #include <stdexcept>
0023
0024 #include <boost/asio/detail/push_options.hpp>
0025
0026 namespace boost {
0027 namespace asio {
0028 namespace detail {
0029
0030 template <typename T>
0031 T config_get(const config_service& service, const char* section,
0032 const char* key, T default_value, false_type )
0033 {
0034 if (is_unsigned<T>::value)
0035 {
0036 char buf[std::numeric_limits<unsigned long long>::digits10
0037 + 1 + 1 + 1 ];
0038 if (const char* str = service.get_value(section, key, buf, sizeof(buf)))
0039 {
0040 char* end = nullptr;
0041 errno = 0;
0042 unsigned long long result = std::strtoull(str, &end, 0);
0043 if (errno == ERANGE
0044 || result > static_cast<unsigned long long>(
0045 (std::numeric_limits<T>::max)()))
0046 detail::throw_exception(std::out_of_range("config out of range"));
0047 return static_cast<T>(result);
0048 }
0049 }
0050 else
0051 {
0052 char buf[std::numeric_limits<unsigned long long>::digits10
0053 + 1 + 1 + 1 ];
0054 if (const char* str = service.get_value(section, key, buf, sizeof(buf)))
0055 {
0056 char* end = nullptr;
0057 errno = 0;
0058 long long result = std::strtoll(str, &end, 0);
0059 if (errno == ERANGE || result < (std::numeric_limits<T>::min)()
0060 || result > (std::numeric_limits<T>::max)())
0061 detail::throw_exception(std::out_of_range("config out of range"));
0062 return static_cast<T>(result);
0063 }
0064 }
0065 return default_value;
0066 }
0067
0068 template <typename T>
0069 T config_get(const config_service& service, const char* section,
0070 const char* key, T default_value, true_type )
0071 {
0072 char buf[std::numeric_limits<unsigned long long>::digits10
0073 + 1 + 1 + 1 ];
0074 if (const char* str = service.get_value(section, key, buf, sizeof(buf)))
0075 {
0076 char* end = nullptr;
0077 errno = 0;
0078 unsigned long long result = std::strtoll(str, &end, 0);
0079 if (errno == ERANGE || (result != 0 && result != 1))
0080 detail::throw_exception(std::out_of_range("config out of range"));
0081 return static_cast<T>(result != 0);
0082 }
0083 return default_value;
0084 }
0085
0086 }
0087
0088 template <typename T>
0089 constraint_t<is_integral<T>::value, T>
0090 config::get(const char* section, const char* key, T default_value) const
0091 {
0092 return detail::config_get(service_, section,
0093 key, default_value, is_same<T, bool>());
0094 }
0095
0096 }
0097 }
0098
0099 #include <boost/asio/detail/pop_options.hpp>
0100
0101 #endif