Compare commits

..

8 Commits

Author SHA1 Message Date
ToruNiina
da98b6558d fix: ctor of time and null 2024-07-27 18:27:16 +09:00
ToruNiina
c433577120 feat: add key_format_info to basic_value ctor 2024-07-27 18:26:52 +09:00
ToruNiina
a39300f9d9 feat: add detail::change_region_of_key 2024-07-27 16:39:46 +09:00
ToruNiina
2193c5c201 feat(WIP): use default arg instead of overloads 2024-07-26 02:49:11 +09:00
ToruNiina
e2bbf550a0 feat(WIP): init key_region and key_fmt 2024-07-26 00:54:31 +09:00
ToruNiina
1809484542 feat: add key_fmt/region to value 2024-07-26 00:13:23 +09:00
ToruNiina
0571dd74ca feat: add key format to fwd 2024-07-26 00:11:53 +09:00
ToruNiina
19199ac82c feat: add key_format 2024-07-25 01:24:55 +09:00
25 changed files with 504 additions and 1038 deletions

View File

@@ -45,9 +45,6 @@ jobs:
- {compiler: '12', standard: '20'} - {compiler: '12', standard: '20'}
- {compiler: '11', standard: '20'} - {compiler: '11', standard: '20'}
steps: steps:
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
@@ -78,9 +75,6 @@ jobs:
- {compiler: 'g++-8', standard: '17'} - {compiler: 'g++-8', standard: '17'}
- {compiler: 'g++-8', standard: '20'} - {compiler: 'g++-8', standard: '20'}
steps: steps:
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
@@ -113,9 +107,6 @@ jobs:
- {compiler: '8', standard: '20'} - {compiler: '8', standard: '20'}
- {compiler: '9', standard: '20'} - {compiler: '9', standard: '20'}
steps: steps:
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
@@ -135,58 +126,6 @@ jobs:
run: | run: |
ctest --output-on-failure --test-dir build/ ctest --output-on-failure --test-dir build/
build-osx-latest:
runs-on: macos-latest
strategy:
matrix:
standard: ['11', '14', '17', '20']
precompile: ['ON', 'OFF']
steps:
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores
- name: Set xcode latest unstable
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Configure
run: |
cmake -B build/ -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_BUILD_TESTS=ON -DTOML11_PRECOMPILE=${{ matrix.precompile }}
- name: Build
run: |
cmake --build build/ -j${{ steps.cpu-cores.outputs.count }}
- name: Test
run: |
ctest --output-on-failure --test-dir build/
build-osx-14:
runs-on: macos-14
strategy:
matrix:
standard: ['11', '14', '17', '20']
precompile: ['ON', 'OFF']
steps:
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Configure
run: |
cmake -B build/ -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_BUILD_TESTS=ON -DTOML11_PRECOMPILE=${{ matrix.precompile }}
- name: Build
run: |
cmake --build build/ -j${{ steps.cpu-cores.outputs.count }}
- name: Test
run: |
ctest --output-on-failure --test-dir build/
build-osx-13: build-osx-13:
runs-on: macos-13 runs-on: macos-13
strategy: strategy:
@@ -194,9 +133,6 @@ jobs:
standard: ['11', '14', '17', '20'] standard: ['11', '14', '17', '20']
precompile: ['ON', 'OFF'] precompile: ['ON', 'OFF']
steps: steps:
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
@@ -218,9 +154,6 @@ jobs:
standard: ['11', '14', '17', '20'] standard: ['11', '14', '17', '20']
precompile: ['ON', 'OFF'] precompile: ['ON', 'OFF']
steps: steps:
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
@@ -243,9 +176,6 @@ jobs:
config: ['Release', 'Debug'] config: ['Release', 'Debug']
precompile: ['ON', 'OFF'] precompile: ['ON', 'OFF']
steps: steps:
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:

View File

@@ -493,22 +493,10 @@ For details on possible formatting specifications, please refer to the [document
### Configuring Types ### Configuring Types
Many types in `toml::value`, such as `integer_type`, `array_type`, `table_type`, etc, can be modified by changing the `type_config` type. Many types held by `toml::value`, such as `integer_type` and `array_type`, can be modified by changing the `type_config` type.
One commonly used example is an `ordered_map` that keeps the added order. Refer to the [`examples` directory](https://github.com/ToruNiina/toml11/tree/main/examples) for complex use cases such as using multi-precision integers, changing containers, and normalizing Unicode.
toml11 provides a`type_config` that changes `table_type` to `ordered_map` as `toml::ordered_type_config`.
```cpp
const toml::ordered_value input = toml::parse<toml::ordered_type_config>("input.toml");
```
Here, `toml::ordered_value` is an alias of `toml::basic_value<toml::ordered_type_config>`.
Note that, since `toml::value` uses `std::unordered_map`, once you convert it to `toml::value`, then the order of the values will be randomized.
For more details about how to implement `type_config` variant, please refer to the [documentation](https://toruniina.github.io/toml11/docs/features/configure_types/).
Also, refer to the [`examples` directory](https://github.com/ToruNiina/toml11/tree/main/examples) for complex use cases such as using multi-precision integers, changing containers, and normalizing Unicode.
Use these examples as references for implementing such configurations. Use these examples as references for implementing such configurations.
## Examples ## Examples
@@ -618,8 +606,6 @@ I appreciate the help of the contributors who introduced the great feature to th
- Ken Matsui (@ken-matsui) - Ken Matsui (@ken-matsui)
- Support user-defined error message prefix - Support user-defined error message prefix
- Support dynamic color mode - Support dynamic color mode
- Support `std::optional` members for `TOML11_DEFINE_CONVERSION_NON_INTRUSIVE`
- Make `thread_local` for `color_mode` optional
- Giel van Schijndel (@muggenhor) - Giel van Schijndel (@muggenhor)
- Remove needless copy in `parse` function - Remove needless copy in `parse` function
- Lukáš Hrázký (@lukash) - Lukáš Hrázký (@lukash)
@@ -658,10 +644,6 @@ I appreciate the help of the contributors who introduced the great feature to th
- Fix not checking for \r\n when parsing line comments - Fix not checking for \r\n when parsing line comments
- 萧迩珀 (@CDK6182CHR) - 萧迩珀 (@CDK6182CHR)
- Support template into_toml members - Support template into_toml members
- Pino Toscano (@pinotree)
- Suppress warnings by manually cast file size to `std::streamsize`
- Jack W (@jackwil1)
- Fix typos in documentation template syntax
## Licensing terms ## Licensing terms

View File

@@ -495,20 +495,10 @@ std::cout << toml::format(output) << std::endl;
`toml::value`が持つ型の多く、`integer_type``array_type`などは`type_config`型を変更することで変更可能です。 `toml::value`が持つ型の多く、`integer_type``array_type`などは`type_config`型を変更することで変更可能です。
よくある例として、値を追加した順序を保つ`map`型である`ordered_map`を使うというものがあります。
toml11は`toml::ordered_map`を使用する`type_config`型として、`toml::ordered_type_config`を提供しています。
```cpp
const toml::ordered_value input = toml::parse<toml::ordered_type_config>("input.toml");
```
ここで、`toml::ordered_value``toml::basic_value<toml::ordered_type_config>`のエイリアスです。
ただし、`toml::value``std::unordered_map`を使用しているため、一度`toml::ordered_value`から`toml::value`に変換してしまうと、順序は失われてしまうことに注意してください。
[`examples`ディレクトリ](https://github.com/ToruNiina/toml11/tree/main/examples)には、 [`examples`ディレクトリ](https://github.com/ToruNiina/toml11/tree/main/examples)には、
多倍長整数を使用する場合やコンテナを変更する場合、ユニコードを正規化する場合などの複雑な使用例を用意しています。 多倍長整数を使用する場合やコンテナを変更する場合、ユニコードを正規化する場合などの複雑な使用例を用意しています。
`type_config`を実装する際の例として参照してください。
そのような状況での実装例として参照してください。
## Examples ## Examples
@@ -656,10 +646,6 @@ toml11 v3からは複数の破壊的変更が追加されています。
- Fix not checking for \r\n when parsing line comments - Fix not checking for \r\n when parsing line comments
- 萧迩珀 (@CDK6182CHR) - 萧迩珀 (@CDK6182CHR)
- Support template into_toml members - Support template into_toml members
- Pino Toscano (@pinotree)
- Suppress warnings by manually cast file size to `std::streamsize`
- Jack W (@jackwil1)
- Fix typos in documentation template syntax
## Licensing terms ## Licensing terms

View File

@@ -6,24 +6,6 @@ weight = 4
# Change Log # Change Log
# v4.2.0
## Added
- Support `std::optional` members for `TOML11_DEFINE_CONVERSION_NON_INTRUSIVE` (by Ken Matsui)
- Make `thread_local` for `color_mode` optional (by Ken Matsui)
- add usage with CPM to README
- add explanation about `ordered_map` to README and update doc
## Fixed
- Manually cast file size to `std::streamsize` (by Pino Toscano)
- Typographical error in `table_format` output
- Format an empty array specified as array-of-table in one line
- Added a missing include file
- Fix typos in documentation template syntax (by Jack W)
- Fix `toml::find_or` for deeply nested tables
# v4.1.0 # v4.1.0
## Added ## Added

View File

@@ -82,17 +82,6 @@ Using this, `toml::ordered_value` is defined, along with aliases for its array a
You can use `toml::ordered_value` by calling `toml::parse(...)` as `toml::parse<toml::ordered_type_config>(...)`. You can use `toml::ordered_value` by calling `toml::parse(...)` as `toml::parse<toml::ordered_type_config>(...)`.
```cpp
#include <toml.hpp>
int main()
{
toml::ordered_value input = toml::parse<toml::ordered_type_config>("example.toml");
std::cout << toml::format(input) << std::endl;
return 0;
}
```
## Not Preserving Comments ## Not Preserving Comments
The `type_config` defines a container for storing comments via `comment_type`. The `type_config` defines a container for storing comments via `comment_type`.

View File

@@ -595,7 +595,7 @@ namespace toml
template<> template<>
struct from<extlib::foo> struct from<extlib::foo>
{ {
template<typename TC> template<typename <TC>
static extlib::foo from_toml(const toml::basic_value<TC>& v) static extlib::foo from_toml(const toml::basic_value<TC>& v)
{ {
return extlib::foo{ return extlib::foo{

View File

@@ -12,23 +12,14 @@ In terminals or other output destinations that do not support ANSI escape code,
## Macros ## Macros
### `TOML11_COLORIZE_ERROR_MESSAGE` ```cpp
TOML11_COLORIZE_ERROR_MESSAGE
```
If this macro is defined during compilation (`-DTOML11_COLORIZE_ERROR_MESASGE`), error messages are colored by default. If this macro is defined during compilation (`-DTOML11_COLORIZE_ERROR_MESASGE`), error messages are colored by default.
If not defined, colors are not applied by default. You need to specify them using `toml::color::enable()`. If not defined, colors are not applied by default. You need to specify them using `toml::color::enable()`.
### `TOML11_USE_THREAD_LOCAL_COLORIZATION`
If this macro is defined during compilation (`-DTOML11_USE_THREAD_LOCAL_COLORIZATION`), the colorization flag becomes `thread_local`.
In this case, `toml::color::enable()` or `toml::color::disable()` will only affect the colorization flag in the thread that called it.
This means that if you want to use a different setting from the default, you will need to set it again when starting a new thread.
This makes `toml::color::enable()` and `toml::color::disable()` thread safe.
By default, the setting is global.
When it is global, if one thread executes `toml::color::enable()`, the error messages will be colored in all threads.
However, if one thread executes `enable()` or `disable()` while another executes `enable()`, `disable()` or `should_color()`, the result is undefined.
## Functions ## Functions
### `enable()` ### `enable()`

View File

@@ -6,24 +6,6 @@ weight = 4
# Change Log # Change Log
# v4.2.0
## Added
- `TOML11_DEFINE_CONVERSION_NON_INTRUSIVE``std::optional` なメンバをサポート (by Ken Matsui @ken-matsui)
- `thread_local`だった`color_mode`をデフォルトでグローバルにし、`thread_local`にするオプションを追加 (by Ken Matsui @ken-matsui)
- CPMでの使い方を`README`に追加
- `README``ordered_map`への言及を追加し、ドキュメントでの説明を追加
## Fixed
- ファイルサイズの`std::streamsize`への変換で警告が出ることがある問題を修正 (by Pino Toscano @pinotree)
- `table_format`に不正な値が与えられた際の出力のtypoを修正
- `array`のフォーマットが`array_of_tables`と指定されていてかつ空の場合の出力を修正
- 特定の環境で`include`が足りずにコンパイルできない問題を修正
- ドキュメントに含まれる文法エラーを修正 (by Jack W)
- `toml::find_or` を深くネストされたテーブルに使用した際にコンパイルが失敗する問題を修正
# v4.1.0 # v4.1.0
## Added ## Added

View File

@@ -101,17 +101,6 @@ parse_float(const std::string& str, const source_location src, const bool is_hex
`toml::parse(...)``toml::parse<toml::ordered_type_config>(...)` として呼び出すことで、 `toml::parse(...)``toml::parse<toml::ordered_type_config>(...)` として呼び出すことで、
`toml::ordered_value` を使用することができます。 `toml::ordered_value` を使用することができます。
```cpp
#include <toml.hpp>
int main()
{
toml::ordered_value input = toml::parse<toml::ordered_type_config>("example.toml");
std::cout << toml::format(input) << std::endl;
return 0;
}
```
## コメントを保存しない ## コメントを保存しない
`type_config``comment_type` でコメントを保存するコンテナを定義しています。 `type_config``comment_type` でコメントを保存するコンテナを定義しています。

View File

@@ -622,7 +622,7 @@ namespace toml
template<> template<>
struct from<extlib::foo> struct from<extlib::foo>
{ {
template<typename TC> template<typename <TC>
static extlib::foo from_toml(const toml::basic_value<TC>& v) static extlib::foo from_toml(const toml::basic_value<TC>& v)
{ {
return extlib::foo{ return extlib::foo{

View File

@@ -12,7 +12,9 @@ ANSIエスケープシーケンスをサポートしていないターミナル
## マクロ ## マクロ
### `TOML11_COLORIZE_ERROR_MESSAGE` ```cpp
TOML11_COLORIZE_ERROR_MESSAGE
```
コンパイル時にこのマクロが定義されていた場合(`-DTOML11_COLORIZE_ERROR_MESASGE`)、 コンパイル時にこのマクロが定義されていた場合(`-DTOML11_COLORIZE_ERROR_MESASGE`)、
デフォルトでエラーメッセージに色が付きます。 デフォルトでエラーメッセージに色が付きます。
@@ -20,17 +22,6 @@ ANSIエスケープシーケンスをサポートしていないターミナル
定義されていなかった場合、デフォルトでは色は付きません。以下の `toml::color::enable()` 定義されていなかった場合、デフォルトでは色は付きません。以下の `toml::color::enable()`
使用して指定する必要があります。 使用して指定する必要があります。
### `TOML11_USE_THREAD_LOCAL_COLORIZATION`
コンパイル時にこのマクロが定義されていた場合(`-DTOML11_COLORIZE_ERROR_MESASGE`)、
`toml::color::enable`の設定が`thread_local`になります。
この場合、`toml::color::enable()``toml::color::disable()`は、それを呼び出したスレッドでの設定しか変更しません。
つまり、新しいスレッドを起動した際にデフォルトと異なる設定にしたい場合は、再度設定が必要になります。
その代わり、`toml::color::enable()``toml::color::disable()`はスレッドセーフになります。
デフォルトでは設定はグローバルです。
グローバルの場合、一つのスレッドが`toml::color::enable()`を実行した場合、すべてのスレッドで色が付きます。
ただし、あるスレッドが`enable()`または`disable()`を実行している間に別のスレッドが`enable()``disable()``should_color()`を実行した場合、その結果は未定義です。
## 関数 ## 関数

View File

@@ -1,88 +1,9 @@
#ifndef TOML11_CONVERSION_HPP #ifndef TOML11_CONVERSION_HPP
#define TOML11_CONVERSION_HPP #define TOML11_CONVERSION_HPP
#include "find.hpp"
#include "from.hpp" // IWYU pragma: keep #include "from.hpp" // IWYU pragma: keep
#include "into.hpp" // IWYU pragma: keep #include "into.hpp" // IWYU pragma: keep
#if defined(TOML11_HAS_OPTIONAL)
#include <optional>
namespace toml
{
namespace detail
{
template<typename T>
inline constexpr bool is_optional_v = false;
template<typename T>
inline constexpr bool is_optional_v<std::optional<T>> = true;
template<typename T, typename TC>
void find_member_variable_from_value(T& obj, const basic_value<TC>& v, const char* var_name)
{
if constexpr(is_optional_v<T>)
{
if(v.contains(var_name))
{
obj = toml::find<typename T::value_type>(v, var_name);
}
else
{
obj = std::nullopt;
}
}
else
{
obj = toml::find<T>(v, var_name);
}
}
template<typename T, typename TC>
void assign_member_variable_to_value(const T& obj, basic_value<TC>& v, const char* var_name)
{
if constexpr(is_optional_v<T>)
{
if(obj.has_value())
{
v[var_name] = obj.value();
}
}
else
{
v[var_name] = obj;
}
}
} // detail
} // toml
#else
namespace toml
{
namespace detail
{
template<typename T, typename TC>
void find_member_variable_from_value(T& obj, const basic_value<TC>& v, const char* var_name)
{
obj = toml::find<T>(v, var_name);
}
template<typename T, typename TC>
void assign_member_variable_to_value(const T& obj, basic_value<TC>& v, const char* var_name)
{
v[var_name] = obj;
}
} // detail
} // toml
#endif // optional
// use it in the following way. // use it in the following way.
// ```cpp // ```cpp
// namespace foo // namespace foo
@@ -167,10 +88,10 @@ void assign_member_variable_to_value(const T& obj, basic_value<TC>& v, const cha
#define TOML11_FIND_MEMBER_VARIABLE_FROM_VALUE(VAR_NAME)\ #define TOML11_FIND_MEMBER_VARIABLE_FROM_VALUE(VAR_NAME)\
toml::detail::find_member_variable_from_value(obj.VAR_NAME, v, TOML11_STRINGIZE(VAR_NAME)); obj.VAR_NAME = toml::find<decltype(obj.VAR_NAME)>(v, TOML11_STRINGIZE(VAR_NAME));
#define TOML11_ASSIGN_MEMBER_VARIABLE_TO_VALUE(VAR_NAME)\ #define TOML11_ASSIGN_MEMBER_VARIABLE_TO_VALUE(VAR_NAME)\
toml::detail::assign_member_variable_to_value(obj.VAR_NAME, v, TOML11_STRINGIZE(VAR_NAME)); v[TOML11_STRINGIZE(VAR_NAME)] = obj.VAR_NAME;
#define TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...)\ #define TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...)\
namespace toml { \ namespace toml { \

View File

@@ -333,14 +333,16 @@ find_or(const basic_value<TC>& v, const K& ky, T opt)
namespace detail namespace detail
{ {
template<typename T>
template<typename ...Ts> T& last_one(T& arg)
auto last_one(Ts&&... args)
-> decltype(std::get<sizeof...(Ts)-1>(std::forward_as_tuple(std::forward<Ts>(args)...)))
{ {
return std::get<sizeof...(Ts)-1>(std::forward_as_tuple(std::forward<Ts>(args)...)); return arg;
}
template<typename T1, typename T2, typename ...Ts>
auto last_one(T1&, T2& arg, Ts& ... args) -> decltype(last_one(arg, args...))
{
return last_one(arg, args...);
} }
} // detail } // detail
template<typename Value, typename K1, typename K2, typename K3, typename ... Ks> template<typename Value, typename K1, typename K2, typename K3, typename ... Ks>

View File

@@ -9,12 +9,6 @@
#define TOML11_ERROR_MESSAGE_COLORIZED false #define TOML11_ERROR_MESSAGE_COLORIZED false
#endif #endif
#ifdef TOML11_USE_THREAD_LOCAL_COLORIZATION
#define TOML11_THREAD_LOCAL_COLORIZATION thread_local
#else
#define TOML11_THREAD_LOCAL_COLORIZATION
#endif
namespace toml namespace toml
{ {
namespace color namespace color
@@ -50,7 +44,7 @@ class color_mode
inline color_mode& color_status() noexcept inline color_mode& color_status() noexcept
{ {
static TOML11_THREAD_LOCAL_COLORIZATION color_mode status; static thread_local color_mode status;
return status; return status;
} }

View File

@@ -4,7 +4,6 @@
// to use __has_builtin // to use __has_builtin
#include "../version.hpp" // IWYU pragma: keep #include "../version.hpp" // IWYU pragma: keep
#include <exception>
#include <initializer_list> #include <initializer_list>
#include <iterator> #include <iterator>
#include <stdexcept> #include <stdexcept>

View File

@@ -214,6 +214,29 @@ struct table_format_info
bool operator==(const table_format_info&, const table_format_info&) noexcept; bool operator==(const table_format_info&, const table_format_info&) noexcept;
bool operator!=(const table_format_info&, const table_format_info&) noexcept; bool operator!=(const table_format_info&, const table_format_info&) noexcept;
// ----------------------------------------------------------------------------
// key
enum class key_format : std::uint8_t
{
bare = 0,
quoted = 1, // ""
quoted_literal = 2 // ''
};
std::ostream& operator<<(std::ostream& os, const key_format f);
std::string to_string(const key_format);
struct key_format_info
{
key_format fmt = key_format::bare;
std::int32_t spaces_before_equal = 1;
std::int32_t spaces_after_equal = 1;
};
bool operator==(const key_format_info&, const key_format_info&) noexcept;
bool operator!=(const key_format_info&, const key_format_info&) noexcept;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wrapper // wrapper

View File

@@ -267,7 +267,7 @@ TOML11_INLINE std::ostream& operator<<(std::ostream& os, const table_format f)
case table_format::implicit : {os << "implicit" ; break;} case table_format::implicit : {os << "implicit" ; break;}
default: default:
{ {
os << "unknown table_format: " << static_cast<std::uint8_t>(f); os << "unknown array_format: " << static_cast<std::uint8_t>(f);
break; break;
} }
} }
@@ -293,5 +293,41 @@ TOML11_INLINE bool operator!=(const table_format_info& lhs, const table_format_i
return !(lhs == rhs); return !(lhs == rhs);
} }
// ----------------------------------------------------------------------------
// key
TOML11_INLINE std::ostream& operator<<(std::ostream& os, const key_format f)
{
switch(f)
{
case key_format::bare : {os << "bare" ; break;}
case key_format::quoted : {os << "quoted" ; break;}
case key_format::quoted_literal : {os << "quoted_literal"; break;}
default:
{
os << "unknown key_format: " << static_cast<std::uint8_t>(f);
break;
}
}
return os;
}
TOML11_INLINE std::string to_string(const key_format c)
{
std::ostringstream oss;
oss << c;
return oss.str();
}
TOML11_INLINE bool operator==(const key_format_info& lhs, const key_format_info& rhs) noexcept
{
return lhs.fmt == rhs.fmt &&
lhs.spaces_before_equal == rhs.spaces_before_equal &&
lhs.spaces_after_equal == rhs.spaces_after_equal ;
}
TOML11_INLINE bool operator!=(const key_format_info& lhs, const key_format_info& rhs) noexcept
{
return !(lhs == rhs);
}
} // namespace toml } // namespace toml
#endif // TOML11_FORMAT_IMPL_HPP #endif // TOML11_FORMAT_IMPL_HPP

View File

@@ -172,7 +172,7 @@ parse_boolean(location& loc, const context<TC>& ctx)
// no format info for boolean // no format info for boolean
boolean_format_info fmt; boolean_format_info fmt;
return ok(basic_value<TC>(val, std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(val, std::move(fmt), {}, {}, std::move(reg)));
} }
/* ============================================================================ /* ============================================================================
@@ -221,7 +221,7 @@ parse_bin_integer(location& loc, const context<TC>& ctx)
const auto val = TC::parse_int(str, source_location(region(loc)), 2); const auto val = TC::parse_int(str, source_location(region(loc)), 2);
if(val.is_ok()) if(val.is_ok())
{ {
return ok(basic_value<TC>(val.as_ok(), std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(val.as_ok(), std::move(fmt), {}, {}, std::move(reg)));
} }
else else
{ {
@@ -273,7 +273,7 @@ parse_oct_integer(location& loc, const context<TC>& ctx)
const auto val = TC::parse_int(str, source_location(region(loc)), 8); const auto val = TC::parse_int(str, source_location(region(loc)), 8);
if(val.is_ok()) if(val.is_ok())
{ {
return ok(basic_value<TC>(val.as_ok(), std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(val.as_ok(), std::move(fmt), {}, {}, std::move(reg)));
} }
else else
{ {
@@ -331,7 +331,7 @@ parse_hex_integer(location& loc, const context<TC>& ctx)
const auto val = TC::parse_int(str, source_location(region(loc)), 16); const auto val = TC::parse_int(str, source_location(region(loc)), 16);
if(val.is_ok()) if(val.is_ok())
{ {
return ok(basic_value<TC>(val.as_ok(), std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(val.as_ok(), std::move(fmt), {}, {}, std::move(reg)));
} }
else else
{ {
@@ -402,7 +402,7 @@ parse_dec_integer(location& loc, const context<TC>& ctx)
fmt.suffix = sfx; fmt.suffix = sfx;
} }
return ok(basic_value<TC>(val.as_ok(), std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(val.as_ok(), std::move(fmt), {}, {}, std::move(reg)));
} }
template<typename TC> template<typename TC>
@@ -667,7 +667,7 @@ parse_floating(location& loc, const context<TC>& ctx)
fmt.suffix = sfx; fmt.suffix = sfx;
} }
return ok(basic_value<TC>(val, std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(val, std::move(fmt), {}, {}, std::move(reg)));
} }
/* ============================================================================ /* ============================================================================
@@ -785,7 +785,7 @@ parse_local_date(location& loc, const context<TC>& ctx)
auto fmt = std::move(std::get<1>(val_fmt_reg.unwrap())); auto fmt = std::move(std::get<1>(val_fmt_reg.unwrap()));
auto reg = std::move(std::get<2>(val_fmt_reg.unwrap())); auto reg = std::move(std::get<2>(val_fmt_reg.unwrap()));
return ok(basic_value<TC>(std::move(val), std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(std::move(val), std::move(fmt), {}, {}, std::move(reg)));
} }
// all the offset_datetime, local_datetime, local_time parses date part. // all the offset_datetime, local_datetime, local_time parses date part.
@@ -954,7 +954,7 @@ parse_local_time(location& loc, const context<TC>& ctx)
auto fmt = std::move(std::get<1>(val_fmt_reg.unwrap())); auto fmt = std::move(std::get<1>(val_fmt_reg.unwrap()));
auto reg = std::move(std::get<2>(val_fmt_reg.unwrap())); auto reg = std::move(std::get<2>(val_fmt_reg.unwrap()));
return ok(basic_value<TC>(std::move(val), std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(std::move(val), std::move(fmt), {}, {}, std::move(reg)));
} }
template<typename TC> template<typename TC>
@@ -1013,7 +1013,7 @@ parse_local_datetime(location& loc, const context<TC>& ctx)
local_datetime val(std::get<0>(date_fmt_reg.unwrap()), local_datetime val(std::get<0>(date_fmt_reg.unwrap()),
std::get<0>(time_fmt_reg.unwrap())); std::get<0>(time_fmt_reg.unwrap()));
return ok(basic_value<TC>(val, std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(val, std::move(fmt), {}, {}, std::move(reg)));
} }
template<typename TC> template<typename TC>
@@ -1140,7 +1140,7 @@ parse_offset_datetime(location& loc, const context<TC>& ctx)
std::get<0>(time_fmt_reg.unwrap())), std::get<0>(time_fmt_reg.unwrap())),
offset); offset);
return ok(basic_value<TC>(val, std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(val, std::move(fmt), {}, {}, std::move(reg)));
} }
/* ============================================================================ /* ============================================================================
@@ -1401,7 +1401,7 @@ parse_ml_basic_string(location& loc, const context<TC>& ctx)
} }
return ok(basic_value<TC>( return ok(basic_value<TC>(
std::move(val), std::move(fmt), {}, std::move(reg) std::move(val), std::move(fmt), {}, {}, std::move(reg)
)); ));
} }
@@ -1481,7 +1481,7 @@ parse_basic_string(location& loc, const context<TC>& ctx)
auto val = std::move(val_res.unwrap().first ); auto val = std::move(val_res.unwrap().first );
auto reg = std::move(val_res.unwrap().second); auto reg = std::move(val_res.unwrap().second);
return ok(basic_value<TC>(std::move(val), std::move(fmt), {}, std::move(reg))); return ok(basic_value<TC>(std::move(val), std::move(fmt), {}, {}, std::move(reg)));
} }
template<typename TC> template<typename TC>
@@ -1528,7 +1528,7 @@ parse_ml_literal_string(location& loc, const context<TC>& ctx)
string_type val(str.begin(), str.end()); string_type val(str.begin(), str.end());
return ok(basic_value<TC>( return ok(basic_value<TC>(
std::move(val), std::move(fmt), {}, std::move(reg) std::move(val), std::move(fmt), {}, {}, std::move(reg)
)); ));
} }
@@ -1581,7 +1581,7 @@ parse_literal_string(location& loc, const context<TC>& ctx)
auto reg = std::move(val_res.unwrap().second); auto reg = std::move(val_res.unwrap().second);
return ok(basic_value<TC>( return ok(basic_value<TC>(
std::move(val), std::move(fmt), {}, std::move(reg) std::move(val), std::move(fmt), {}, {}, std::move(reg)
)); ));
} }
@@ -1793,6 +1793,9 @@ parse_key_value_pair(location& loc, context<TC>& ctx)
// loc = first; // loc = first;
return err(v_res.unwrap_err()); return err(v_res.unwrap_err());
} }
// set key reg/fmt
return ok(std::make_pair(std::move(key_res.unwrap()), std::move(v_res.unwrap()))); return ok(std::make_pair(std::move(key_res.unwrap()), std::move(v_res.unwrap())));
} }
@@ -2049,7 +2052,7 @@ parse_array(location& loc, context<TC>& ctx)
} }
return ok(basic_value<TC>( return ok(basic_value<TC>(
std::move(val), std::move(fmt), {}, region(first, loc) std::move(val), std::move(fmt), {}, {}, region(first, loc)
)); ));
} }
@@ -2206,7 +2209,7 @@ insert_value(const inserting_value_kind kind,
fmt.fmt = table_format::implicit; fmt.fmt = table_format::implicit;
} }
current_table.emplace(key, value_type( current_table.emplace(key, value_type(
table_type{}, fmt, std::vector<std::string>{}, key_reg)); table_type{}, fmt, std::vector<std::string>{}, {}, key_reg));
assert(current_table.at(key).is_table()); assert(current_table.at(key).is_table());
current_table_ptr = std::addressof(current_table.at(key).as_table()); current_table_ptr = std::addressof(current_table.at(key).as_table());
@@ -2353,7 +2356,8 @@ insert_value(const inserting_value_kind kind,
current_table.emplace(key, value_type( current_table.emplace(key, value_type(
array_type{ std::move(val) }, std::move(fmt), array_type{ std::move(val) }, std::move(fmt),
std::vector<std::string>{}, std::move(key_reg) std::vector<std::string>{}, key_format_info{},
key_reg, key_reg
)); ));
assert( ! current_table.at(key).as_array().empty()); assert( ! current_table.at(key).as_array().empty());
@@ -2604,7 +2608,7 @@ parse_inline_table(location& loc, context<TC>& ctx)
} }
basic_value<TC> retval( basic_value<TC> retval(
std::move(table), std::move(fmt), {}, region(first, loc)); std::move(table), std::move(fmt), {}, {}, region(first, loc));
return ok(std::move(retval)); return ok(std::move(retval));
} }
@@ -3171,10 +3175,10 @@ parse_file(location& loc, context<TC>& ctx)
if(loc.eof()) if(loc.eof())
{ {
return ok(value_type(table_type(), table_format_info{}, {}, region(loc))); return ok(value_type(table_type(), table_format_info{}, {}, {}, region(loc)));
} }
value_type root(table_type(), table_format_info{}, {}, region(loc)); value_type root(table_type(), table_format_info{}, {}, {}, region(loc));
root.as_table_fmt().fmt = table_format::multiline; root.as_table_fmt().fmt = table_format::multiline;
root.as_table_fmt().indent_type = indent_char::none; root.as_table_fmt().indent_type = indent_char::none;
@@ -3279,7 +3283,7 @@ parse_file(location& loc, context<TC>& ctx)
table_format_info fmt; table_format_info fmt;
fmt.fmt = table_format::multiline; fmt.fmt = table_format::multiline;
fmt.indent_type = indent_char::none; fmt.indent_type = indent_char::none;
auto tab = value_type(table_type{}, std::move(fmt), std::move(com), reg); auto tab = value_type(table_type{}, std::move(fmt), std::move(com), {}, reg);
auto inserted = insert_value(inserting_value_kind::array_table, auto inserted = insert_value(inserting_value_kind::array_table,
std::addressof(root.as_table()), std::addressof(root.as_table()),
@@ -3366,7 +3370,7 @@ parse_file(location& loc, context<TC>& ctx)
table_format_info fmt; table_format_info fmt;
fmt.fmt = table_format::multiline; fmt.fmt = table_format::multiline;
fmt.indent_type = indent_char::none; fmt.indent_type = indent_char::none;
auto tab = value_type(table_type{}, std::move(fmt), std::move(com), reg); auto tab = value_type(table_type{}, std::move(fmt), std::move(com), {}, reg);
auto inserted = insert_value(inserting_value_kind::std_table, auto inserted = insert_value(inserting_value_kind::std_table,
std::addressof(root.as_table()), std::addressof(root.as_table()),
@@ -3441,7 +3445,7 @@ parse_impl(std::vector<location::char_type> cs, std::string fname, const spec& s
{ {
auto src = std::make_shared<std::vector<location::char_type>>(std::move(cs)); auto src = std::make_shared<std::vector<location::char_type>>(std::move(cs));
location loc(std::move(src), std::move(fname)); location loc(std::move(src), std::move(fname));
return ok(value_type(table_type(), table_format_info{}, std::vector<std::string>{}, region(loc))); return ok(value_type(table_type(), table_format_info{}, std::vector<std::string>{}, {}, region(loc)));
} }
// to simplify parser, add newline at the end if there is no LF. // to simplify parser, add newline at the end if there is no LF.

View File

@@ -557,16 +557,11 @@ class serializer
} }
} }
} }
if(this->force_inline_ && f == array_format::array_of_tables) if(this->force_inline_ && f == array_format::array_of_tables)
{ {
f = array_format::multiline; f = array_format::multiline;
} }
if(a.empty() && f == array_format::array_of_tables)
{
f = array_format::oneline;
}
// --------------------------------------------------------------------
if(f == array_format::array_of_tables) if(f == array_format::array_of_tables)
{ {

View File

@@ -53,6 +53,9 @@ error_info make_not_found_error(const basic_value<TC>&, const std::string&, cons
template<typename TC> template<typename TC>
void change_region_of_value(basic_value<TC>&, const basic_value<TC>&); void change_region_of_value(basic_value<TC>&, const basic_value<TC>&);
template<typename TC>
void change_region_of_key(basic_value<TC>&, region);
template<typename TC, value_t V> template<typename TC, value_t V>
struct getter; struct getter;
} // detail } // detail
@@ -85,14 +88,14 @@ class basic_value
public: public:
basic_value() noexcept basic_value() noexcept
: type_(value_t::empty), empty_('\0'), region_{}, comments_{} : type_(value_t::empty), empty_('\0'), region_{}, comments_{}, key_region_{}, key_fmt_{}
{} {}
~basic_value() noexcept {this->cleanup();} ~basic_value() noexcept {this->cleanup();}
// copy/move constructor/assigner ===================================== {{{ // copy/move constructor/assigner ===================================== {{{
basic_value(const basic_value& v) basic_value(const basic_value& v)
: type_(v.type_), region_(v.region_), comments_(v.comments_) : type_(v.type_), region_(v.region_), comments_(v.comments_), key_region_(v.key_region_), key_fmt_(v.key_fmt_)
{ {
switch(this->type_) switch(this->type_)
{ {
@@ -111,7 +114,8 @@ class basic_value
} }
basic_value(basic_value&& v) basic_value(basic_value&& v)
: type_(v.type()), region_(std::move(v.region_)), : type_(v.type()), region_(std::move(v.region_)),
comments_(std::move(v.comments_)) comments_(std::move(v.comments_)),
key_region_(v.key_region_), key_fmt_(v.key_fmt_)
{ {
switch(this->type_) switch(this->type_)
{ {
@@ -137,6 +141,8 @@ class basic_value
this->type_ = v.type_; this->type_ = v.type_;
this->region_ = v.region_; this->region_ = v.region_;
this->comments_ = v.comments_; this->comments_ = v.comments_;
this->key_region_ = v.key_region_;
this->key_fmt_ = v.key_fmt_;
switch(this->type_) switch(this->type_)
{ {
case value_t::boolean : assigner(boolean_ , v.boolean_ ); break; case value_t::boolean : assigner(boolean_ , v.boolean_ ); break;
@@ -161,6 +167,8 @@ class basic_value
this->type_ = v.type_; this->type_ = v.type_;
this->region_ = std::move(v.region_); this->region_ = std::move(v.region_);
this->comments_ = std::move(v.comments_); this->comments_ = std::move(v.comments_);
this->key_region_ = std::move(v.key_region_);
this->key_fmt_ = std::move(v.key_fmt_);
switch(this->type_) switch(this->type_)
{ {
case value_t::boolean : assigner(boolean_ , std::move(v.boolean_ )); break; case value_t::boolean : assigner(boolean_ , std::move(v.boolean_ )); break;
@@ -183,7 +191,8 @@ class basic_value
basic_value(basic_value v, std::vector<std::string> com) basic_value(basic_value v, std::vector<std::string> com)
: type_(v.type()), region_(std::move(v.region_)), : type_(v.type()), region_(std::move(v.region_)),
comments_(std::move(com)) comments_(std::move(com)),
key_region_(v.key_region_), key_fmt_(v.key_fmt_)
{ {
switch(this->type_) switch(this->type_)
{ {
@@ -208,7 +217,9 @@ class basic_value
basic_value(basic_value<TI> other) basic_value(basic_value<TI> other)
: type_(other.type_), : type_(other.type_),
region_(std::move(other.region_)), region_(std::move(other.region_)),
comments_(std::move(other.comments_)) comments_(std::move(other.comments_)),
key_region_(std::move(other.key_region_)),
key_fmt_(std::move(other.key_fmt_))
{ {
switch(other.type_) switch(other.type_)
{ {
@@ -253,7 +264,9 @@ class basic_value
basic_value(basic_value<TI> other, std::vector<std::string> com) basic_value(basic_value<TI> other, std::vector<std::string> com)
: type_(other.type_), : type_(other.type_),
region_(std::move(other.region_)), region_(std::move(other.region_)),
comments_(std::move(com)) comments_(std::move(com)),
key_region_(std::move(other.key_region_)),
key_fmt_(std::move(other.key_fmt_))
{ {
switch(other.type_) switch(other.type_)
{ {
@@ -299,6 +312,8 @@ class basic_value
this->cleanup(); this->cleanup();
this->region_ = other.region_; this->region_ = other.region_;
this->comments_ = comment_type(other.comments_); this->comments_ = comment_type(other.comments_);
this->key_region_ = other.key_region_;
this->key_fmt_ = other.key_fmt_;
this->type_ = other.type_; this->type_ = other.type_;
switch(other.type_) switch(other.type_)
{ {
@@ -343,22 +358,18 @@ class basic_value
// constructor (boolean) ============================================== {{{ // constructor (boolean) ============================================== {{{
basic_value(boolean_type x)
: basic_value(x, boolean_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(boolean_type x, boolean_format_info fmt)
: basic_value(x, fmt, std::vector<std::string>{}, region_type{})
{}
basic_value(boolean_type x, std::vector<std::string> com) basic_value(boolean_type x, std::vector<std::string> com)
: basic_value(x, boolean_format_info{}, std::move(com), region_type{}) : basic_value(x, boolean_format_info{}, std::move(com))
{} {}
basic_value(boolean_type x, boolean_format_info fmt, std::vector<std::string> com) basic_value(boolean_type x,
: basic_value(x, fmt, std::move(com), region_type{}) boolean_format_info fmt = boolean_format_info{},
{} std::vector<std::string> com = {},
basic_value(boolean_type x, boolean_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
region_type key_reg = region_type{})
: type_(value_t::boolean), boolean_(boolean_storage(x, fmt)), : type_(value_t::boolean), boolean_(boolean_storage(x, fmt)),
region_(std::move(reg)), comments_(std::move(com)) region_(std::move(reg)), comments_(std::move(com)),
key_region_(key_reg), key_fmt_(key_fmt)
{} {}
basic_value& operator=(boolean_type x) basic_value& operator=(boolean_type x)
{ {
@@ -370,6 +381,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::boolean; this->type_ = value_t::boolean;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->boolean_, boolean_storage(x, fmt)); assigner(this->boolean_, boolean_storage(x, fmt));
return *this; return *this;
} }
@@ -378,21 +390,19 @@ class basic_value
// constructor (integer) ============================================== {{{ // constructor (integer) ============================================== {{{
basic_value(integer_type x)
: basic_value(std::move(x), integer_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(integer_type x, integer_format_info fmt)
: basic_value(std::move(x), std::move(fmt), std::vector<std::string>{}, region_type{})
{}
basic_value(integer_type x, std::vector<std::string> com) basic_value(integer_type x, std::vector<std::string> com)
: basic_value(std::move(x), integer_format_info{}, std::move(com), region_type{}) : basic_value(std::move(x), integer_format_info{}, std::move(com))
{} {}
basic_value(integer_type x, integer_format_info fmt, std::vector<std::string> com) basic_value(integer_type x,
: basic_value(std::move(x), std::move(fmt), std::move(com), region_type{}) integer_format_info fmt = integer_format_info{},
{} std::vector<std::string> com = {},
basic_value(integer_type x, integer_format_info fmt, std::vector<std::string> com, region_type reg) key_format_info key_fmt = key_format_info{},
: type_(value_t::integer), integer_(integer_storage(std::move(x), std::move(fmt))), region_type reg = region_type{},
region_(std::move(reg)), comments_(std::move(com)) region_type key_reg = region_type{})
: type_(value_t::integer),
integer_(integer_storage(std::move(x), std::move(fmt))),
region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(integer_type x) basic_value& operator=(integer_type x)
{ {
@@ -404,6 +414,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::integer; this->type_ = value_t::integer;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->integer_, integer_storage(std::move(x), std::move(fmt))); assigner(this->integer_, integer_storage(std::move(x), std::move(fmt)));
return *this; return *this;
} }
@@ -419,26 +430,21 @@ class basic_value
public: public:
template<typename T, enable_if_integer_like_t<T> = nullptr>
basic_value(T x)
: basic_value(std::move(x), integer_format_info{}, std::vector<std::string>{}, region_type{})
{}
template<typename T, enable_if_integer_like_t<T> = nullptr>
basic_value(T x, integer_format_info fmt)
: basic_value(std::move(x), std::move(fmt), std::vector<std::string>{}, region_type{})
{}
template<typename T, enable_if_integer_like_t<T> = nullptr> template<typename T, enable_if_integer_like_t<T> = nullptr>
basic_value(T x, std::vector<std::string> com) basic_value(T x, std::vector<std::string> com)
: basic_value(std::move(x), integer_format_info{}, std::move(com), region_type{}) : basic_value(std::move(x), integer_format_info{}, std::move(com))
{} {}
template<typename T, enable_if_integer_like_t<T> = nullptr> template<typename T, enable_if_integer_like_t<T> = nullptr>
basic_value(T x, integer_format_info fmt, std::vector<std::string> com) basic_value(T x,
: basic_value(std::move(x), std::move(fmt), std::move(com), region_type{}) integer_format_info fmt = integer_format_info{},
{} std::vector<std::string> com = {},
template<typename T, enable_if_integer_like_t<T> = nullptr> key_format_info key_fmt = key_format_info{},
basic_value(T x, integer_format_info fmt, std::vector<std::string> com, region_type reg) region_type reg = region_type{},
: type_(value_t::integer), integer_(integer_storage(std::move(x), std::move(fmt))), region_type key_reg = region_type{})
region_(std::move(reg)), comments_(std::move(com)) : type_(value_t::integer),
integer_(integer_storage(std::move(x), std::move(fmt))),
region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
template<typename T, enable_if_integer_like_t<T> = nullptr> template<typename T, enable_if_integer_like_t<T> = nullptr>
basic_value& operator=(T x) basic_value& operator=(T x)
@@ -451,6 +457,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::integer; this->type_ = value_t::integer;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->integer_, integer_storage(x, std::move(fmt))); assigner(this->integer_, integer_storage(x, std::move(fmt)));
return *this; return *this;
} }
@@ -459,21 +466,19 @@ class basic_value
// constructor (floating) ============================================= {{{ // constructor (floating) ============================================= {{{
basic_value(floating_type x)
: basic_value(std::move(x), floating_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(floating_type x, floating_format_info fmt)
: basic_value(std::move(x), std::move(fmt), std::vector<std::string>{}, region_type{})
{}
basic_value(floating_type x, std::vector<std::string> com) basic_value(floating_type x, std::vector<std::string> com)
: basic_value(std::move(x), floating_format_info{}, std::move(com), region_type{}) : basic_value(std::move(x), floating_format_info{}, std::move(com))
{} {}
basic_value(floating_type x, floating_format_info fmt, std::vector<std::string> com) basic_value(floating_type x,
: basic_value(std::move(x), std::move(fmt), std::move(com), region_type{}) floating_format_info fmt = floating_format_info{},
{} std::vector<std::string> com = {},
basic_value(floating_type x, floating_format_info fmt, std::vector<std::string> com, region_type reg) key_format_info key_fmt = key_format_info{},
: type_(value_t::floating), floating_(floating_storage(std::move(x), std::move(fmt))), region_type reg = region_type{},
region_(std::move(reg)), comments_(std::move(com)) region_type key_reg = region_type{})
: type_(value_t::floating),
floating_(floating_storage(std::move(x), std::move(fmt))),
region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(floating_type x) basic_value& operator=(floating_type x)
{ {
@@ -485,6 +490,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::floating; this->type_ = value_t::floating;
this->region_ = region_type{}; this->region_ = region_type{};
// key_region/fmt is kept
assigner(this->floating_, floating_storage(std::move(x), std::move(fmt))); assigner(this->floating_, floating_storage(std::move(x), std::move(fmt)));
return *this; return *this;
} }
@@ -499,32 +505,22 @@ class basic_value
public: public:
template<typename T, enable_if_floating_like_t<T> = nullptr>
basic_value(T x)
: basic_value(x, floating_format_info{}, std::vector<std::string>{}, region_type{})
{}
template<typename T, enable_if_floating_like_t<T> = nullptr>
basic_value(T x, floating_format_info fmt)
: basic_value(x, std::move(fmt), std::vector<std::string>{}, region_type{})
{}
template<typename T, enable_if_floating_like_t<T> = nullptr> template<typename T, enable_if_floating_like_t<T> = nullptr>
basic_value(T x, std::vector<std::string> com) basic_value(T x, std::vector<std::string> com)
: basic_value(x, floating_format_info{}, std::move(com), region_type{}) : basic_value(x, floating_format_info{}, std::move(com))
{} {}
template<typename T, enable_if_floating_like_t<T> = nullptr> template<typename T, enable_if_floating_like_t<T> = nullptr>
basic_value(T x, floating_format_info fmt, std::vector<std::string> com) basic_value(T x,
: basic_value(x, std::move(fmt), std::move(com), region_type{}) floating_format_info fmt = floating_format_info{},
std::vector<std::string> com = {},
key_format_info key_fmt = key_format_info{},
region_type reg = region_type{},
region_type key_reg = region_type{})
: type_(value_t::floating),
floating_(floating_storage(x, std::move(fmt))),
region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
template<typename T, enable_if_floating_like_t<T> = nullptr>
basic_value(T x, floating_format_info fmt, std::vector<std::string> com, region_type reg)
: type_(value_t::floating), floating_(floating_storage(x, std::move(fmt))),
region_(std::move(reg)), comments_(std::move(com))
{}
template<typename T, enable_if_floating_like_t<T> = nullptr> template<typename T, enable_if_floating_like_t<T> = nullptr>
basic_value& operator=(T x) basic_value& operator=(T x)
{ {
@@ -536,6 +532,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::floating; this->type_ = value_t::floating;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->floating_, floating_storage(x, std::move(fmt))); assigner(this->floating_, floating_storage(x, std::move(fmt)));
return *this; return *this;
} }
@@ -544,22 +541,19 @@ class basic_value
// constructor (string) =============================================== {{{ // constructor (string) =============================================== {{{
basic_value(string_type x)
: basic_value(std::move(x), string_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(string_type x, string_format_info fmt)
: basic_value(std::move(x), std::move(fmt), std::vector<std::string>{}, region_type{})
{}
basic_value(string_type x, std::vector<std::string> com) basic_value(string_type x, std::vector<std::string> com)
: basic_value(std::move(x), string_format_info{}, std::move(com), region_type{}) : basic_value(std::move(x), string_format_info{}, std::move(com))
{} {}
basic_value(string_type x, string_format_info fmt, std::vector<std::string> com) basic_value(string_type x,
: basic_value(std::move(x), std::move(fmt), std::move(com), region_type{}) string_format_info fmt = string_format_info{},
{} std::vector<std::string> com = {},
basic_value(string_type x, string_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
: type_(value_t::string), string_(string_storage(std::move(x), std::move(fmt))), region_type key_reg = region_type{})
region_(std::move(reg)), comments_(std::move(com)) : type_(value_t::string),
string_(string_storage(std::move(x), std::move(fmt))),
region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(string_type x) basic_value& operator=(string_type x)
{ {
@@ -571,28 +565,26 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::string; this->type_ = value_t::string;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->string_, string_storage(x, std::move(fmt))); assigner(this->string_, string_storage(x, std::move(fmt)));
return *this; return *this;
} }
// "string literal" // "string literal"
basic_value(const typename string_type::value_type* x)
: basic_value(x, string_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(const typename string_type::value_type* x, string_format_info fmt)
: basic_value(x, std::move(fmt), std::vector<std::string>{}, region_type{})
{}
basic_value(const typename string_type::value_type* x, std::vector<std::string> com) basic_value(const typename string_type::value_type* x, std::vector<std::string> com)
: basic_value(x, string_format_info{}, std::move(com), region_type{}) : basic_value(x, string_format_info{}, std::move(com))
{} {}
basic_value(const typename string_type::value_type* x, string_format_info fmt, std::vector<std::string> com) basic_value(const typename string_type::value_type* x,
: basic_value(x, std::move(fmt), std::move(com), region_type{}) string_format_info fmt = string_format_info{},
{} std::vector<std::string> com = {},
basic_value(const typename string_type::value_type* x, string_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
: type_(value_t::string), string_(string_storage(string_type(x), std::move(fmt))), region_type key_reg = region_type{})
region_(std::move(reg)), comments_(std::move(com)) : type_(value_t::string),
string_(string_storage(string_type(x), std::move(fmt))),
region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(const typename string_type::value_type* x) basic_value& operator=(const typename string_type::value_type* x)
{ {
@@ -604,6 +596,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::string; this->type_ = value_t::string;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->string_, string_storage(string_type(x), std::move(fmt))); assigner(this->string_, string_storage(string_type(x), std::move(fmt)));
return *this; return *this;
} }
@@ -612,22 +605,18 @@ class basic_value
using string_view_type = std::basic_string_view< using string_view_type = std::basic_string_view<
typename string_type::value_type, typename string_type::traits_type>; typename string_type::value_type, typename string_type::traits_type>;
basic_value(string_view_type x)
: basic_value(x, string_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(string_view_type x, string_format_info fmt)
: basic_value(x, std::move(fmt), std::vector<std::string>{}, region_type{})
{}
basic_value(string_view_type x, std::vector<std::string> com) basic_value(string_view_type x, std::vector<std::string> com)
: basic_value(x, string_format_info{}, std::move(com), region_type{}) : basic_value(x, string_format_info{}, std::move(com))
{} {}
basic_value(string_view_type x, string_format_info fmt, std::vector<std::string> com) basic_value(string_view_type x,
: basic_value(x, std::move(fmt), std::move(com), region_type{}) string_format_info fmt = string_format_info{},
{} std::vector<std::string> com = {},
basic_value(string_view_type x, string_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
region_type key_reg = region_type{})
: type_(value_t::string), string_(string_storage(string_type(x), std::move(fmt))), : type_(value_t::string), string_(string_storage(string_type(x), std::move(fmt))),
region_(std::move(reg)), comments_(std::move(com)) region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(string_view_type x) basic_value& operator=(string_view_type x)
{ {
@@ -639,49 +628,34 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::string; this->type_ = value_t::string;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->string_, string_storage(string_type(x), std::move(fmt))); assigner(this->string_, string_storage(string_type(x), std::move(fmt)));
return *this; return *this;
} }
#endif // TOML11_HAS_STRING_VIEW #endif // TOML11_HAS_STRING_VIEW
template<typename T, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
detail::is_1byte_std_basic_string<T>
>::value, std::nullptr_t> = nullptr>
basic_value(const T& x)
: basic_value(x, string_format_info{}, std::vector<std::string>{}, region_type{})
{}
template<typename T, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
detail::is_1byte_std_basic_string<T>
>::value, std::nullptr_t> = nullptr>
basic_value(const T& x, string_format_info fmt)
: basic_value(x, std::move(fmt), std::vector<std::string>{}, region_type{})
{}
template<typename T, cxx::enable_if_t<cxx::conjunction< template<typename T, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>, cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
detail::is_1byte_std_basic_string<T> detail::is_1byte_std_basic_string<T>
>::value, std::nullptr_t> = nullptr> >::value, std::nullptr_t> = nullptr>
basic_value(const T& x, std::vector<std::string> com) basic_value(const T& x, std::vector<std::string> com)
: basic_value(x, string_format_info{}, std::move(com), region_type{}) : basic_value(x, string_format_info{}, std::move(com))
{} {}
template<typename T, cxx::enable_if_t<cxx::conjunction< template<typename T, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>, cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
detail::is_1byte_std_basic_string<T> detail::is_1byte_std_basic_string<T>
>::value, std::nullptr_t> = nullptr> >::value, std::nullptr_t> = nullptr>
basic_value(const T& x, string_format_info fmt, std::vector<std::string> com) basic_value(const T& x,
: basic_value(x, std::move(fmt), std::move(com), region_type{}) string_format_info fmt = string_format_info{},
{} std::vector<std::string> com = {},
template<typename T, cxx::enable_if_t<cxx::conjunction< key_format_info key_fmt = key_format_info{},
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>, region_type reg = region_type{},
detail::is_1byte_std_basic_string<T> region_type key_reg = region_type{})
>::value, std::nullptr_t> = nullptr>
basic_value(const T& x, string_format_info fmt,
std::vector<std::string> com, region_type reg)
: type_(value_t::string), : type_(value_t::string),
string_(string_storage(detail::string_conv<string_type>(x), std::move(fmt))), string_(string_storage(detail::string_conv<string_type>(x), std::move(fmt))),
region_(std::move(reg)), comments_(std::move(com)) region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
template<typename T, cxx::enable_if_t<cxx::conjunction< template<typename T, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>, cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
@@ -697,6 +671,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::string; this->type_ = value_t::string;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->string_, string_storage(detail::string_conv<string_type>(x), std::move(fmt))); assigner(this->string_, string_storage(detail::string_conv<string_type>(x), std::move(fmt)));
return *this; return *this;
} }
@@ -705,22 +680,19 @@ class basic_value
// constructor (local_date) =========================================== {{{ // constructor (local_date) =========================================== {{{
basic_value(local_date_type x)
: basic_value(x, local_date_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(local_date_type x, local_date_format_info fmt)
: basic_value(x, fmt, std::vector<std::string>{}, region_type{})
{}
basic_value(local_date_type x, std::vector<std::string> com) basic_value(local_date_type x, std::vector<std::string> com)
: basic_value(x, local_date_format_info{}, std::move(com), region_type{}) : basic_value(x, local_date_format_info{}, std::move(com))
{} {}
basic_value(local_date_type x, local_date_format_info fmt, std::vector<std::string> com) basic_value(local_date_type x,
: basic_value(x, fmt, std::move(com), region_type{}) local_date_format_info fmt = local_date_format_info{},
{} std::vector<std::string> com = {},
basic_value(local_date_type x, local_date_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
: type_(value_t::local_date), local_date_(local_date_storage(x, fmt)), region_type key_reg = region_type{})
region_(std::move(reg)), comments_(std::move(com)) : type_(value_t::local_date),
local_date_(local_date_storage(x, fmt)),
region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(local_date_type x) basic_value& operator=(local_date_type x)
{ {
@@ -732,6 +704,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::local_date; this->type_ = value_t::local_date;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->local_date_, local_date_storage(x, fmt)); assigner(this->local_date_, local_date_storage(x, fmt));
return *this; return *this;
} }
@@ -740,22 +713,18 @@ class basic_value
// constructor (local_time) =========================================== {{{ // constructor (local_time) =========================================== {{{
basic_value(local_time_type x)
: basic_value(x, local_time_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(local_time_type x, local_time_format_info fmt)
: basic_value(x, fmt, std::vector<std::string>{}, region_type{})
{}
basic_value(local_time_type x, std::vector<std::string> com) basic_value(local_time_type x, std::vector<std::string> com)
: basic_value(x, local_time_format_info{}, std::move(com), region_type{}) : basic_value(x, local_time_format_info{}, std::move(com))
{} {}
basic_value(local_time_type x, local_time_format_info fmt, std::vector<std::string> com) basic_value(local_time_type x,
: basic_value(x, fmt, std::move(com), region_type{}) local_time_format_info fmt = local_time_format_info{},
{} std::vector<std::string> com = {},
basic_value(local_time_type x, local_time_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
region_type key_reg = region_type{})
: type_(value_t::local_time), local_time_(local_time_storage(x, fmt)), : type_(value_t::local_time), local_time_(local_time_storage(x, fmt)),
region_(std::move(reg)), comments_(std::move(com)) region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(local_time_type x) basic_value& operator=(local_time_type x)
{ {
@@ -767,31 +736,24 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::local_time; this->type_ = value_t::local_time;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->local_time_, local_time_storage(x, fmt)); assigner(this->local_time_, local_time_storage(x, fmt));
return *this; return *this;
} }
template<typename Rep, typename Period>
basic_value(const std::chrono::duration<Rep, Period>& x)
: basic_value(local_time_type(x), local_time_format_info{}, std::vector<std::string>{}, region_type{})
{}
template<typename Rep, typename Period>
basic_value(const std::chrono::duration<Rep, Period>& x, local_time_format_info fmt)
: basic_value(local_time_type(x), std::move(fmt), std::vector<std::string>{}, region_type{})
{}
template<typename Rep, typename Period> template<typename Rep, typename Period>
basic_value(const std::chrono::duration<Rep, Period>& x, std::vector<std::string> com) basic_value(const std::chrono::duration<Rep, Period>& x, std::vector<std::string> com)
: basic_value(local_time_type(x), local_time_format_info{}, std::move(com), region_type{}) : basic_value(local_time_type(x), local_time_format_info{}, std::move(com))
{}
template<typename Rep, typename Period>
basic_value(const std::chrono::duration<Rep, Period>& x, local_time_format_info fmt, std::vector<std::string> com)
: basic_value(local_time_type(x), std::move(fmt), std::move(com), region_type{})
{} {}
template<typename Rep, typename Period> template<typename Rep, typename Period>
basic_value(const std::chrono::duration<Rep, Period>& x, basic_value(const std::chrono::duration<Rep, Period>& x,
local_time_format_info fmt, local_time_format_info fmt = local_time_format_info{},
std::vector<std::string> com, region_type reg) std::vector<std::string> com = {},
: basic_value(local_time_type(x), std::move(fmt), std::move(com), std::move(reg)) key_format_info key_fmt = key_format_info{},
region_type reg = region_type{},
region_type key_reg = region_type{})
: basic_value(local_time_type(x), std::move(fmt), std::move(com), std::move(key_fmt),
std::move(reg), std::move(key_reg))
{} {}
template<typename Rep, typename Period> template<typename Rep, typename Period>
basic_value& operator=(const std::chrono::duration<Rep, Period>& x) basic_value& operator=(const std::chrono::duration<Rep, Period>& x)
@@ -804,6 +766,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::local_time; this->type_ = value_t::local_time;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->local_time_, local_time_storage(local_time_type(x), std::move(fmt))); assigner(this->local_time_, local_time_storage(local_time_type(x), std::move(fmt)));
return *this; return *this;
} }
@@ -812,22 +775,19 @@ class basic_value
// constructor (local_datetime) =========================================== {{{ // constructor (local_datetime) =========================================== {{{
basic_value(local_datetime_type x)
: basic_value(x, local_datetime_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(local_datetime_type x, local_datetime_format_info fmt)
: basic_value(x, fmt, std::vector<std::string>{}, region_type{})
{}
basic_value(local_datetime_type x, std::vector<std::string> com) basic_value(local_datetime_type x, std::vector<std::string> com)
: basic_value(x, local_datetime_format_info{}, std::move(com), region_type{}) : basic_value(x, local_datetime_format_info{}, std::move(com))
{} {}
basic_value(local_datetime_type x, local_datetime_format_info fmt, std::vector<std::string> com) basic_value(local_datetime_type x,
: basic_value(x, fmt, std::move(com), region_type{}) local_datetime_format_info fmt = local_datetime_format_info{},
{} std::vector<std::string> com = {},
basic_value(local_datetime_type x, local_datetime_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
: type_(value_t::local_datetime), local_datetime_(local_datetime_storage(x, fmt)), region_type key_reg = region_type{})
region_(std::move(reg)), comments_(std::move(com)) : type_(value_t::local_datetime),
local_datetime_(local_datetime_storage(x, fmt)),
region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(local_datetime_type x) basic_value& operator=(local_datetime_type x)
{ {
@@ -839,6 +799,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::local_datetime; this->type_ = value_t::local_datetime;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->local_datetime_, local_datetime_storage(x, fmt)); assigner(this->local_datetime_, local_datetime_storage(x, fmt));
return *this; return *this;
} }
@@ -847,22 +808,19 @@ class basic_value
// constructor (offset_datetime) =========================================== {{{ // constructor (offset_datetime) =========================================== {{{
basic_value(offset_datetime_type x)
: basic_value(x, offset_datetime_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(offset_datetime_type x, offset_datetime_format_info fmt)
: basic_value(x, fmt, std::vector<std::string>{}, region_type{})
{}
basic_value(offset_datetime_type x, std::vector<std::string> com) basic_value(offset_datetime_type x, std::vector<std::string> com)
: basic_value(x, offset_datetime_format_info{}, std::move(com), region_type{}) : basic_value(x, offset_datetime_format_info{}, std::move(com))
{} {}
basic_value(offset_datetime_type x, offset_datetime_format_info fmt, std::vector<std::string> com) basic_value(offset_datetime_type x,
: basic_value(x, fmt, std::move(com), region_type{}) offset_datetime_format_info fmt = offset_datetime_format_info{},
{} std::vector<std::string> com = {},
basic_value(offset_datetime_type x, offset_datetime_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
: type_(value_t::offset_datetime), offset_datetime_(offset_datetime_storage(x, fmt)), region_type key_reg = region_type{})
region_(std::move(reg)), comments_(std::move(com)) : type_(value_t::offset_datetime),
offset_datetime_(offset_datetime_storage(x, fmt)),
region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(offset_datetime_type x) basic_value& operator=(offset_datetime_type x)
{ {
@@ -874,27 +832,24 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::offset_datetime; this->type_ = value_t::offset_datetime;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->offset_datetime_, offset_datetime_storage(x, fmt)); assigner(this->offset_datetime_, offset_datetime_storage(x, fmt));
return *this; return *this;
} }
// system_clock::time_point // system_clock::time_point
basic_value(std::chrono::system_clock::time_point x)
: basic_value(offset_datetime_type(x), offset_datetime_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(std::chrono::system_clock::time_point x, offset_datetime_format_info fmt)
: basic_value(offset_datetime_type(x), fmt, std::vector<std::string>{}, region_type{})
{}
basic_value(std::chrono::system_clock::time_point x, std::vector<std::string> com) basic_value(std::chrono::system_clock::time_point x, std::vector<std::string> com)
: basic_value(offset_datetime_type(x), offset_datetime_format_info{}, std::move(com), region_type{}) : basic_value(offset_datetime_type(x), offset_datetime_format_info{}, std::move(com))
{} {}
basic_value(std::chrono::system_clock::time_point x, offset_datetime_format_info fmt, std::vector<std::string> com) basic_value(std::chrono::system_clock::time_point x,
: basic_value(offset_datetime_type(x), fmt, std::move(com), region_type{}) offset_datetime_format_info fmt = offset_datetime_format_info{},
{} std::vector<std::string> com = {},
basic_value(std::chrono::system_clock::time_point x, offset_datetime_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
: basic_value(offset_datetime_type(x), std::move(fmt), std::move(com), std::move(reg)) region_type key_reg = region_type{})
: basic_value(offset_datetime_type(x), std::move(fmt), std::move(com),
std::move(key_fmt), std::move(reg), std::move(key_reg))
{} {}
basic_value& operator=(std::chrono::system_clock::time_point x) basic_value& operator=(std::chrono::system_clock::time_point x)
{ {
@@ -906,6 +861,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::offset_datetime; this->type_ = value_t::offset_datetime;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->offset_datetime_, offset_datetime_storage(offset_datetime_type(x), fmt)); assigner(this->offset_datetime_, offset_datetime_storage(offset_datetime_type(x), fmt));
return *this; return *this;
} }
@@ -914,23 +870,19 @@ class basic_value
// constructor (array) ================================================ {{{ // constructor (array) ================================================ {{{
basic_value(array_type x)
: basic_value(std::move(x), array_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(array_type x, array_format_info fmt)
: basic_value(std::move(x), std::move(fmt), std::vector<std::string>{}, region_type{})
{}
basic_value(array_type x, std::vector<std::string> com) basic_value(array_type x, std::vector<std::string> com)
: basic_value(std::move(x), array_format_info{}, std::move(com), region_type{}) : basic_value(std::move(x), array_format_info{}, std::move(com))
{} {}
basic_value(array_type x, array_format_info fmt, std::vector<std::string> com) basic_value(array_type x,
: basic_value(std::move(x), fmt, std::move(com), region_type{}) array_format_info fmt = array_format_info{},
{} std::vector<std::string> com = {},
basic_value(array_type x, array_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
region_type key_reg = region_type{})
: type_(value_t::array), array_(array_storage( : type_(value_t::array), array_(array_storage(
detail::storage<array_type>(std::move(x)), std::move(fmt) detail::storage<array_type>(std::move(x)), std::move(fmt)
)), region_(std::move(reg)), comments_(std::move(com)) )), region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(array_type x) basic_value& operator=(array_type x)
{ {
@@ -942,6 +894,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::array; this->type_ = value_t::array;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->array_, array_storage( assigner(this->array_, array_storage(
detail::storage<array_type>(std::move(x)), std::move(fmt))); detail::storage<array_type>(std::move(x)), std::move(fmt)));
return *this; return *this;
@@ -963,31 +916,24 @@ class basic_value
public: public:
template<typename T, enable_if_array_like_t<T> = nullptr>
basic_value(T x)
: basic_value(std::move(x), array_format_info{}, std::vector<std::string>{}, region_type{})
{}
template<typename T, enable_if_array_like_t<T> = nullptr>
basic_value(T x, array_format_info fmt)
: basic_value(std::move(x), std::move(fmt), std::vector<std::string>{}, region_type{})
{}
template<typename T, enable_if_array_like_t<T> = nullptr> template<typename T, enable_if_array_like_t<T> = nullptr>
basic_value(T x, std::vector<std::string> com) basic_value(T x, std::vector<std::string> com)
: basic_value(std::move(x), array_format_info{}, std::move(com), region_type{}) : basic_value(std::move(x), array_format_info{}, std::move(com))
{} {}
template<typename T, enable_if_array_like_t<T> = nullptr> template<typename T, enable_if_array_like_t<T> = nullptr>
basic_value(T x, array_format_info fmt, std::vector<std::string> com) basic_value(T x,
: basic_value(std::move(x), fmt, std::move(com), region_type{}) array_format_info fmt = array_format_info{},
{} std::vector<std::string> com = {},
template<typename T, enable_if_array_like_t<T> = nullptr> key_format_info key_fmt = key_format_info{},
basic_value(T x, array_format_info fmt, region_type reg = region_type{},
std::vector<std::string> com, region_type reg) region_type key_reg = region_type{})
: type_(value_t::array), array_(array_storage( : type_(value_t::array), array_(array_storage(
detail::storage<array_type>(array_type( detail::storage<array_type>(array_type(
std::make_move_iterator(x.begin()), std::make_move_iterator(x.begin()),
std::make_move_iterator(x.end())) std::make_move_iterator(x.end()))
), std::move(fmt) ), std::move(fmt)
)), region_(std::move(reg)), comments_(std::move(com)) )), region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
template<typename T, enable_if_array_like_t<T> = nullptr> template<typename T, enable_if_array_like_t<T> = nullptr>
basic_value& operator=(T x) basic_value& operator=(T x)
@@ -1000,6 +946,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::array; this->type_ = value_t::array;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
array_type a(std::make_move_iterator(x.begin()), array_type a(std::make_move_iterator(x.begin()),
std::make_move_iterator(x.end())); std::make_move_iterator(x.end()));
@@ -1012,23 +959,19 @@ class basic_value
// constructor (table) ================================================ {{{ // constructor (table) ================================================ {{{
basic_value(table_type x)
: basic_value(std::move(x), table_format_info{}, std::vector<std::string>{}, region_type{})
{}
basic_value(table_type x, table_format_info fmt)
: basic_value(std::move(x), std::move(fmt), std::vector<std::string>{}, region_type{})
{}
basic_value(table_type x, std::vector<std::string> com) basic_value(table_type x, std::vector<std::string> com)
: basic_value(std::move(x), table_format_info{}, std::move(com), region_type{}) : basic_value(std::move(x), table_format_info{}, std::move(com))
{} {}
basic_value(table_type x, table_format_info fmt, std::vector<std::string> com) basic_value(table_type x,
: basic_value(std::move(x), fmt, std::move(com), region_type{}) table_format_info fmt = table_format_info{},
{} std::vector<std::string> com = {},
basic_value(table_type x, table_format_info fmt, key_format_info key_fmt = key_format_info{},
std::vector<std::string> com, region_type reg) region_type reg = region_type{},
region_type key_reg = region_type{})
: type_(value_t::table), table_(table_storage( : type_(value_t::table), table_(table_storage(
detail::storage<table_type>(std::move(x)), std::move(fmt) detail::storage<table_type>(std::move(x)), std::move(fmt)
)), region_(std::move(reg)), comments_(std::move(com)) )), region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
basic_value& operator=(table_type x) basic_value& operator=(table_type x)
{ {
@@ -1040,6 +983,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::table; this->type_ = value_t::table;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
assigner(this->table_, table_storage( assigner(this->table_, table_storage(
detail::storage<table_type>(std::move(x)), std::move(fmt))); detail::storage<table_type>(std::move(x)), std::move(fmt)));
return *this; return *this;
@@ -1059,31 +1003,24 @@ class basic_value
public: public:
template<typename T, enable_if_table_like_t<T> = nullptr>
basic_value(T x)
: basic_value(std::move(x), table_format_info{}, std::vector<std::string>{}, region_type{})
{}
template<typename T, enable_if_table_like_t<T> = nullptr>
basic_value(T x, table_format_info fmt)
: basic_value(std::move(x), std::move(fmt), std::vector<std::string>{}, region_type{})
{}
template<typename T, enable_if_table_like_t<T> = nullptr> template<typename T, enable_if_table_like_t<T> = nullptr>
basic_value(T x, std::vector<std::string> com) basic_value(T x, std::vector<std::string> com)
: basic_value(std::move(x), table_format_info{}, std::move(com), region_type{}) : basic_value(std::move(x), table_format_info{}, std::move(com))
{} {}
template<typename T, enable_if_table_like_t<T> = nullptr> template<typename T, enable_if_table_like_t<T> = nullptr>
basic_value(T x, table_format_info fmt, std::vector<std::string> com) basic_value(T x,
: basic_value(std::move(x), fmt, std::move(com), region_type{}) table_format_info fmt = table_format_info{},
{} std::vector<std::string> com = {},
template<typename T, enable_if_table_like_t<T> = nullptr> key_format_info key_fmt = key_format_info{},
basic_value(T x, table_format_info fmt, region_type reg = region_type{},
std::vector<std::string> com, region_type reg) region_type key_reg = region_type{})
: type_(value_t::table), table_(table_storage( : type_(value_t::table), table_(table_storage(
detail::storage<table_type>(table_type( detail::storage<table_type>(table_type(
std::make_move_iterator(x.begin()), std::make_move_iterator(x.begin()),
std::make_move_iterator(x.end()) std::make_move_iterator(x.end())
)), std::move(fmt) )), std::move(fmt)
)), region_(std::move(reg)), comments_(std::move(com)) )), region_(std::move(reg)), comments_(std::move(com)),
key_region_(std::move(key_reg)), key_fmt_(std::move(key_fmt))
{} {}
template<typename T, enable_if_table_like_t<T> = nullptr> template<typename T, enable_if_table_like_t<T> = nullptr>
basic_value& operator=(T x) basic_value& operator=(T x)
@@ -1096,6 +1033,7 @@ class basic_value
this->cleanup(); this->cleanup();
this->type_ = value_t::table; this->type_ = value_t::table;
this->region_ = region_type{}; this->region_ = region_type{};
// key region/fmt is kept
table_type t(std::make_move_iterator(x.begin()), table_type t(std::make_move_iterator(x.begin()),
std::make_move_iterator(x.end())); std::make_move_iterator(x.end()));
@@ -1180,7 +1118,8 @@ class basic_value
// mainly for `null` extension // mainly for `null` extension
basic_value(detail::none_t, region_type reg) noexcept basic_value(detail::none_t, region_type reg) noexcept
: type_(value_t::empty), empty_('\0'), region_(std::move(reg)), comments_{} : type_(value_t::empty), empty_('\0'), region_(std::move(reg)), comments_{},
key_region_{}, key_fmt_{}
{} {}
// }}} // }}}
@@ -1856,6 +1795,13 @@ class basic_value
comment_type const& comments() const noexcept {return this->comments_;} comment_type const& comments() const noexcept {return this->comments_;}
comment_type& comments() noexcept {return this->comments_;} comment_type& comments() noexcept {return this->comments_;}
source_location key_location() const
{
return source_location(this->key_region_);
}
key_format_info& key_fmt() noexcept {return this->key_fmt_;}
key_format_info const& key_fmt() const noexcept {return this->key_fmt_;}
private: private:
// private helper functions =========================================== {{{ // private helper functions =========================================== {{{
@@ -1905,6 +1851,9 @@ class basic_value
template<typename TC> template<typename TC>
friend void detail::change_region_of_value(basic_value<TC>&, const basic_value<TC>&); friend void detail::change_region_of_value(basic_value<TC>&, const basic_value<TC>&);
template<typename TC>
friend void change_region_of_key(basic_value<TC>&, detail::region);
template<typename TC> template<typename TC>
friend class basic_value; friend class basic_value;
@@ -1942,6 +1891,8 @@ class basic_value
}; };
region_type region_; region_type region_;
comment_type comments_; comment_type comments_;
region_type key_region_;
key_format_info key_fmt_;
}; };
template<typename TC> template<typename TC>
@@ -2249,6 +2200,13 @@ template<typename TC>
void change_region_of_value(basic_value<TC>& dst, const basic_value<TC>& src) void change_region_of_value(basic_value<TC>& dst, const basic_value<TC>& src)
{ {
dst.region_ = std::move(src.region_); dst.region_ = std::move(src.region_);
dst.key_region_ = std::move(src.key_region_);
return;
}
template<typename TC>
void change_region_of_key(basic_value<TC>& dst, region src)
{
dst.key_region_ = std::move(src);
return; return;
} }

View File

@@ -2,7 +2,7 @@
#define TOML11_VERSION_HPP #define TOML11_VERSION_HPP
#define TOML11_VERSION_MAJOR 4 #define TOML11_VERSION_MAJOR 4
#define TOML11_VERSION_MINOR 2 #define TOML11_VERSION_MINOR 1
#define TOML11_VERSION_PATCH 0 #define TOML11_VERSION_PATCH 0
#ifndef __cplusplus #ifndef __cplusplus
@@ -77,12 +77,6 @@
# endif # endif
#endif #endif
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= TOML11_CXX17_VALUE
# if __has_include(<optional>)
# define TOML11_HAS_OPTIONAL 1
# endif
#endif
#if defined(TOML11_COMPILE_SOURCES) #if defined(TOML11_COMPILE_SOURCES)
# define TOML11_INLINE # define TOML11_INLINE
#else #else

View File

@@ -40,6 +40,7 @@ enum class string_format : std::uint8_t;
enum class datetime_delimiter_kind : std::uint8_t; enum class datetime_delimiter_kind : std::uint8_t;
enum class array_format : std::uint8_t; enum class array_format : std::uint8_t;
enum class table_format : std::uint8_t; enum class table_format : std::uint8_t;
enum class key_format : std::uint8_t;
struct boolean_format_info; struct boolean_format_info;
struct integer_format_info; struct integer_format_info;
@@ -51,6 +52,7 @@ struct local_date_format_info;
struct local_time_format_info; struct local_time_format_info;
struct array_format_info; struct array_format_info;
struct table_format_info; struct table_format_info;
struct key_format_info;
template<typename Key, typename Val, typename Cmp, typename Allocator> template<typename Key, typename Val, typename Cmp, typename Allocator>
class ordered_map; class ordered_map;

View File

@@ -2,7 +2,7 @@
#define TOML11_VERSION_HPP #define TOML11_VERSION_HPP
#define TOML11_VERSION_MAJOR 4 #define TOML11_VERSION_MAJOR 4
#define TOML11_VERSION_MINOR 2 #define TOML11_VERSION_MINOR 1
#define TOML11_VERSION_PATCH 0 #define TOML11_VERSION_PATCH 0
#ifndef __cplusplus #ifndef __cplusplus
@@ -77,12 +77,6 @@
# endif # endif
#endif #endif
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= TOML11_CXX17_VALUE
# if __has_include(<optional>)
# define TOML11_HAS_OPTIONAL 1
# endif
#endif
#if defined(TOML11_COMPILE_SOURCES) #if defined(TOML11_COMPILE_SOURCES)
# define TOML11_INLINE # define TOML11_INLINE
#else #else
@@ -641,7 +635,7 @@ TOML11_INLINE std::ostream& operator<<(std::ostream& os, const table_format f)
case table_format::implicit : {os << "implicit" ; break;} case table_format::implicit : {os << "implicit" ; break;}
default: default:
{ {
os << "unknown table_format: " << static_cast<std::uint8_t>(f); os << "unknown array_format: " << static_cast<std::uint8_t>(f);
break; break;
} }
} }
@@ -2425,7 +2419,6 @@ struct storage
// to use __has_builtin // to use __has_builtin
#include <exception>
#include <initializer_list> #include <initializer_list>
#include <iterator> #include <iterator>
#include <stdexcept> #include <stdexcept>
@@ -2934,12 +2927,6 @@ TOML11_INLINE std::ostream& operator<<(std::ostream& os, const preserve_comments
#define TOML11_ERROR_MESSAGE_COLORIZED false #define TOML11_ERROR_MESSAGE_COLORIZED false
#endif #endif
#ifdef TOML11_USE_THREAD_LOCAL_COLORIZATION
#define TOML11_THREAD_LOCAL_COLORIZATION thread_local
#else
#define TOML11_THREAD_LOCAL_COLORIZATION
#endif
namespace toml namespace toml
{ {
namespace color namespace color
@@ -2975,7 +2962,7 @@ class color_mode
inline color_mode& color_status() noexcept inline color_mode& color_status() noexcept
{ {
static TOML11_THREAD_LOCAL_COLORIZATION color_mode status; static thread_local color_mode status;
return status; return status;
} }
@@ -3747,6 +3734,128 @@ using is_basic_value = is_basic_value_impl<cxx::remove_cvref_t<T>>;
}// detail }// detail
}//toml }//toml
#endif // TOML11_TRAITS_HPP #endif // TOML11_TRAITS_HPP
#ifndef TOML11_CONVERSION_HPP
#define TOML11_CONVERSION_HPP
// use it in the following way.
// ```cpp
// namespace foo
// {
// struct Foo
// {
// std::string s;
// double d;
// int i;
// };
// } // foo
//
// TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(foo::Foo, s, d, i)
// ```
//
// And then you can use `toml::get<foo::Foo>(v)` and `toml::find<foo::Foo>(file, "foo");`
//
#define TOML11_STRINGIZE_AUX(x) #x
#define TOML11_STRINGIZE(x) TOML11_STRINGIZE_AUX(x)
#define TOML11_CONCATENATE_AUX(x, y) x##y
#define TOML11_CONCATENATE(x, y) TOML11_CONCATENATE_AUX(x, y)
// ============================================================================
// TOML11_DEFINE_CONVERSION_NON_INTRUSIVE
#ifndef TOML11_WITHOUT_DEFINE_NON_INTRUSIVE
// ----------------------------------------------------------------------------
// TOML11_ARGS_SIZE
#define TOML11_INDEX_RSEQ() \
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, \
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
#define TOML11_ARGS_SIZE_IMPL(\
ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8, ARG9, ARG10, \
ARG11, ARG12, ARG13, ARG14, ARG15, ARG16, ARG17, ARG18, ARG19, ARG20, \
ARG21, ARG22, ARG23, ARG24, ARG25, ARG26, ARG27, ARG28, ARG29, ARG30, \
ARG31, ARG32, N, ...) N
#define TOML11_ARGS_SIZE_AUX(...) TOML11_ARGS_SIZE_IMPL(__VA_ARGS__)
#define TOML11_ARGS_SIZE(...) TOML11_ARGS_SIZE_AUX(__VA_ARGS__, TOML11_INDEX_RSEQ())
// ----------------------------------------------------------------------------
// TOML11_FOR_EACH_VA_ARGS
#define TOML11_FOR_EACH_VA_ARGS_AUX_1( FUNCTOR, ARG1 ) FUNCTOR(ARG1)
#define TOML11_FOR_EACH_VA_ARGS_AUX_2( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_1( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_3( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_2( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_4( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_3( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_5( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_4( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_6( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_5( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_7( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_6( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_8( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_7( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_9( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_8( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_10(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_9( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_11(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_10(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_12(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_11(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_13(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_12(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_14(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_13(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_15(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_14(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_16(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_15(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_17(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_16(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_18(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_17(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_19(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_18(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_20(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_19(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_21(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_20(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_22(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_21(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_23(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_22(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_24(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_23(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_25(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_24(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_26(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_25(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_27(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_26(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_28(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_27(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_29(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_28(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_30(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_29(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_31(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_30(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_32(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_31(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS(FUNCTOR, ...)\
TOML11_CONCATENATE(TOML11_FOR_EACH_VA_ARGS_AUX_, TOML11_ARGS_SIZE(__VA_ARGS__))(FUNCTOR, __VA_ARGS__)
#define TOML11_FIND_MEMBER_VARIABLE_FROM_VALUE(VAR_NAME)\
obj.VAR_NAME = toml::find<decltype(obj.VAR_NAME)>(v, TOML11_STRINGIZE(VAR_NAME));
#define TOML11_ASSIGN_MEMBER_VARIABLE_TO_VALUE(VAR_NAME)\
v[TOML11_STRINGIZE(VAR_NAME)] = obj.VAR_NAME;
#define TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...)\
namespace toml { \
template<> \
struct from<NAME> \
{ \
template<typename TC> \
static NAME from_toml(const basic_value<TC>& v) \
{ \
NAME obj; \
TOML11_FOR_EACH_VA_ARGS(TOML11_FIND_MEMBER_VARIABLE_FROM_VALUE, __VA_ARGS__) \
return obj; \
} \
}; \
template<> \
struct into<NAME> \
{ \
template<typename TC> \
static basic_value<TC> into_toml(const NAME& obj) \
{ \
::toml::basic_value<TC> v = typename ::toml::basic_value<TC>::table_type{}; \
TOML11_FOR_EACH_VA_ARGS(TOML11_ASSIGN_MEMBER_VARIABLE_TO_VALUE, __VA_ARGS__) \
return v; \
} \
}; \
} /* toml */
#endif// TOML11_WITHOUT_DEFINE_NON_INTRUSIVE
#endif // TOML11_CONVERSION_HPP
#ifndef TOML11_EXCEPTION_HPP #ifndef TOML11_EXCEPTION_HPP
#define TOML11_EXCEPTION_HPP #define TOML11_EXCEPTION_HPP
@@ -9258,14 +9367,16 @@ find_or(const basic_value<TC>& v, const K& ky, T opt)
namespace detail namespace detail
{ {
template<typename T>
template<typename ...Ts> T& last_one(T& arg)
auto last_one(Ts&&... args)
-> decltype(std::get<sizeof...(Ts)-1>(std::forward_as_tuple(std::forward<Ts>(args)...)))
{ {
return std::get<sizeof...(Ts)-1>(std::forward_as_tuple(std::forward<Ts>(args)...)); return arg;
}
template<typename T1, typename T2, typename ...Ts>
auto last_one(T1&, T2& arg, Ts& ... args) -> decltype(last_one(arg, args...))
{
return last_one(arg, args...);
} }
} // detail } // detail
template<typename Value, typename K1, typename K2, typename K3, typename ... Ks> template<typename Value, typename K1, typename K2, typename K3, typename ... Ks>
@@ -9300,206 +9411,6 @@ T find_or(const basic_value<TC>& v, const K1& k1, const K2& k2, const K3& k3, co
} // toml } // toml
#endif // TOML11_FIND_HPP #endif // TOML11_FIND_HPP
#ifndef TOML11_CONVERSION_HPP
#define TOML11_CONVERSION_HPP
#if defined(TOML11_HAS_OPTIONAL)
#include <optional>
namespace toml
{
namespace detail
{
template<typename T>
inline constexpr bool is_optional_v = false;
template<typename T>
inline constexpr bool is_optional_v<std::optional<T>> = true;
template<typename T, typename TC>
void find_member_variable_from_value(T& obj, const basic_value<TC>& v, const char* var_name)
{
if constexpr(is_optional_v<T>)
{
if(v.contains(var_name))
{
obj = toml::find<typename T::value_type>(v, var_name);
}
else
{
obj = std::nullopt;
}
}
else
{
obj = toml::find<T>(v, var_name);
}
}
template<typename T, typename TC>
void assign_member_variable_to_value(const T& obj, basic_value<TC>& v, const char* var_name)
{
if constexpr(is_optional_v<T>)
{
if(obj.has_value())
{
v[var_name] = obj.value();
}
}
else
{
v[var_name] = obj;
}
}
} // detail
} // toml
#else
namespace toml
{
namespace detail
{
template<typename T, typename TC>
void find_member_variable_from_value(T& obj, const basic_value<TC>& v, const char* var_name)
{
obj = toml::find<T>(v, var_name);
}
template<typename T, typename TC>
void assign_member_variable_to_value(const T& obj, basic_value<TC>& v, const char* var_name)
{
v[var_name] = obj;
}
} // detail
} // toml
#endif // optional
// use it in the following way.
// ```cpp
// namespace foo
// {
// struct Foo
// {
// std::string s;
// double d;
// int i;
// };
// } // foo
//
// TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(foo::Foo, s, d, i)
// ```
//
// And then you can use `toml::get<foo::Foo>(v)` and `toml::find<foo::Foo>(file, "foo");`
//
#define TOML11_STRINGIZE_AUX(x) #x
#define TOML11_STRINGIZE(x) TOML11_STRINGIZE_AUX(x)
#define TOML11_CONCATENATE_AUX(x, y) x##y
#define TOML11_CONCATENATE(x, y) TOML11_CONCATENATE_AUX(x, y)
// ============================================================================
// TOML11_DEFINE_CONVERSION_NON_INTRUSIVE
#ifndef TOML11_WITHOUT_DEFINE_NON_INTRUSIVE
// ----------------------------------------------------------------------------
// TOML11_ARGS_SIZE
#define TOML11_INDEX_RSEQ() \
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, \
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
#define TOML11_ARGS_SIZE_IMPL(\
ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8, ARG9, ARG10, \
ARG11, ARG12, ARG13, ARG14, ARG15, ARG16, ARG17, ARG18, ARG19, ARG20, \
ARG21, ARG22, ARG23, ARG24, ARG25, ARG26, ARG27, ARG28, ARG29, ARG30, \
ARG31, ARG32, N, ...) N
#define TOML11_ARGS_SIZE_AUX(...) TOML11_ARGS_SIZE_IMPL(__VA_ARGS__)
#define TOML11_ARGS_SIZE(...) TOML11_ARGS_SIZE_AUX(__VA_ARGS__, TOML11_INDEX_RSEQ())
// ----------------------------------------------------------------------------
// TOML11_FOR_EACH_VA_ARGS
#define TOML11_FOR_EACH_VA_ARGS_AUX_1( FUNCTOR, ARG1 ) FUNCTOR(ARG1)
#define TOML11_FOR_EACH_VA_ARGS_AUX_2( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_1( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_3( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_2( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_4( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_3( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_5( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_4( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_6( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_5( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_7( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_6( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_8( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_7( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_9( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_8( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_10(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_9( FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_11(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_10(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_12(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_11(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_13(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_12(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_14(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_13(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_15(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_14(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_16(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_15(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_17(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_16(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_18(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_17(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_19(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_18(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_20(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_19(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_21(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_20(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_22(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_21(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_23(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_22(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_24(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_23(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_25(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_24(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_26(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_25(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_27(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_26(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_28(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_27(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_29(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_28(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_30(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_29(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_31(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_30(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS_AUX_32(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_31(FUNCTOR, __VA_ARGS__)
#define TOML11_FOR_EACH_VA_ARGS(FUNCTOR, ...)\
TOML11_CONCATENATE(TOML11_FOR_EACH_VA_ARGS_AUX_, TOML11_ARGS_SIZE(__VA_ARGS__))(FUNCTOR, __VA_ARGS__)
#define TOML11_FIND_MEMBER_VARIABLE_FROM_VALUE(VAR_NAME)\
toml::detail::find_member_variable_from_value(obj.VAR_NAME, v, TOML11_STRINGIZE(VAR_NAME));
#define TOML11_ASSIGN_MEMBER_VARIABLE_TO_VALUE(VAR_NAME)\
toml::detail::assign_member_variable_to_value(obj.VAR_NAME, v, TOML11_STRINGIZE(VAR_NAME));
#define TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...)\
namespace toml { \
template<> \
struct from<NAME> \
{ \
template<typename TC> \
static NAME from_toml(const basic_value<TC>& v) \
{ \
NAME obj; \
TOML11_FOR_EACH_VA_ARGS(TOML11_FIND_MEMBER_VARIABLE_FROM_VALUE, __VA_ARGS__) \
return obj; \
} \
}; \
template<> \
struct into<NAME> \
{ \
template<typename TC> \
static basic_value<TC> into_toml(const NAME& obj) \
{ \
::toml::basic_value<TC> v = typename ::toml::basic_value<TC>::table_type{}; \
TOML11_FOR_EACH_VA_ARGS(TOML11_ASSIGN_MEMBER_VARIABLE_TO_VALUE, __VA_ARGS__) \
return v; \
} \
}; \
} /* toml */
#endif// TOML11_WITHOUT_DEFINE_NON_INTRUSIVE
#endif // TOML11_CONVERSION_HPP
#ifndef TOML11_CONTEXT_HPP #ifndef TOML11_CONTEXT_HPP
#define TOML11_CONTEXT_HPP #define TOML11_CONTEXT_HPP
@@ -16493,16 +16404,11 @@ class serializer
} }
} }
} }
if(this->force_inline_ && f == array_format::array_of_tables) if(this->force_inline_ && f == array_format::array_of_tables)
{ {
f = array_format::multiline; f = array_format::multiline;
} }
if(a.empty() && f == array_format::array_of_tables)
{
f = array_format::oneline;
}
// --------------------------------------------------------------------
if(f == array_format::array_of_tables) if(f == array_format::array_of_tables)
{ {

View File

@@ -505,39 +505,6 @@ TEST_CASE("testing find_or(val, keys..., opt)")
CHECK_EQ(v1, "qux"); CHECK_EQ(v1, "qux");
CHECK_EQ(v2, "hoge"); CHECK_EQ(v2, "hoge");
// v1 and v2 are mutable
v1 = "hoge";
v2 = "fuga";
CHECK_EQ(v1, "hoge");
CHECK_EQ(v2, "fuga");
}
// the same with deeper table
{
toml::value v(
toml::table{ {"A",
toml::table{ {"B",
toml::table{ {"C",
toml::table{ {"D",
toml::table{ {"E",
toml::table{ {"F",
"foo"
} }
} }
} }
} }
} }
} }
);
std::string opt("bar");
auto& v1 = toml::find_or(v, "A", "B", "C", "D", "E", "F", opt);
auto& v2 = toml::find_or(v, "A", "B", "C", "D", "E", "G", opt);
CHECK_EQ(v1, "foo");
CHECK_EQ(v2, "bar");
// v1 and v2 are mutable
v1 = "hoge"; v1 = "hoge";
v2 = "fuga"; v2 = "fuga";
@@ -564,30 +531,6 @@ TEST_CASE("testing find_or(val, keys..., opt)")
CHECK_EQ(v1, "qux"); CHECK_EQ(v1, "qux");
CHECK_EQ(v2, "hoge"); CHECK_EQ(v2, "hoge");
} }
{
toml::value v(
toml::table{ {"A",
toml::table{ {"B",
toml::table{ {"C",
toml::table{ {"D",
toml::table{ {"E",
toml::table{ {"F",
"foo"
} }
} }
} }
} }
} }
} }
);
std::string opt("bar");
const auto& v1 = toml::find_or(v, "A", "B", "C", "D", "E", "F", opt);
const auto& v2 = toml::find_or(v, "A", "B", "C", "D", "E", "G", opt);
CHECK_EQ(v1, "foo");
CHECK_EQ(v2, "bar");
}
// explicitly specify type, doing type conversion // explicitly specify type, doing type conversion
{ {
@@ -608,32 +551,7 @@ TEST_CASE("testing find_or(val, keys..., opt)")
CHECK_EQ(v1, 42); CHECK_EQ(v1, 42);
CHECK_EQ(v2, 6*9); CHECK_EQ(v2, 6*9);
} }
{
toml::value v(
toml::table{ {"A",
toml::table{ {"B",
toml::table{ {"C",
toml::table{ {"D",
toml::table{ {"E",
toml::table{ {"F",
42
} }
} }
} }
} }
} }
} }
);
int opt = 6 * 9;
auto v1 = toml::find_or<int>(v, "A", "B", "C", "D", "E", "F", opt);
auto v2 = toml::find_or<int>(v, "A", "B", "C", "D", "E", "G", opt);
CHECK_EQ(v1, 42);
CHECK_EQ(v2, 6*9);
}
// the value exists, but type is different from the expected.
{ {
const toml::value v( const toml::value v(
toml::table{ {"foo", toml::table{ {"foo",
@@ -645,31 +563,7 @@ TEST_CASE("testing find_or(val, keys..., opt)")
} } } }
); );
auto v1 = toml::find_or<std::string>(v, "foo", "bar", "baz", "hoge"); auto v1 = toml::find_or<std::string>(v, "foo", "bar", "baz", "hoge");
auto v2 = toml::find_or<double >(v, "foo", "bar", "baz", 3.14);
CHECK_EQ(v1, "hoge"); CHECK_EQ(v1, "hoge");
CHECK_EQ(v2, 3.14);
}
{
const toml::value v(
toml::table{ {"A",
toml::table{ {"B",
toml::table{ {"C",
toml::table{ {"D",
toml::table{ {"E",
toml::table{ {"F",
42
} }
} }
} }
} }
} }
} }
);
auto v1 = toml::find_or<std::string>(v, "A", "B", "C", "D", "E", "F", "bar");
auto v2 = toml::find_or<double >(v, "A", "B", "C", "D", "E", "F", 3.14);
CHECK_EQ(v1, "bar");
CHECK_EQ(v2, 3.14);
} }
} }

View File

@@ -4,10 +4,6 @@
#include <toml.hpp> #include <toml.hpp>
#include "utility.hpp" #include "utility.hpp"
#if defined(TOML11_HAS_OPTIONAL)
#include <optional>
#endif
namespace extlib namespace extlib
{ {
struct foo struct foo
@@ -656,84 +652,4 @@ TEST_CASE("test_conversion_via_macro")
CHECK(v2 == v); CHECK(v2 == v);
} }
} }
#if defined(TOML11_HAS_OPTIONAL)
namespace extlib4
{
struct foo
{
std::optional<int> a;
std::optional<std::string> b;
};
struct bar
{
std::optional<int> a;
std::optional<std::string> b;
std::optional<foo> f;
};
} // extlib4
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(extlib4::foo, a, b)
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(extlib4::bar, a, b, f)
TEST_CASE("test_optional_conversion_via_macro")
{
{
const toml::value v(toml::table{{"a", 42}});
const auto foo = toml::get<extlib4::foo>(v);
CHECK(foo.a.value() == 42);
CHECK(foo.b == std::nullopt);
const toml::value v2(foo);
CHECK(v2 == v);
}
{
const toml::ordered_value v(toml::ordered_table{
{"b", "baz"}
});
const auto foo = toml::get<extlib4::foo>(v);
CHECK(foo.a == std::nullopt);
CHECK(foo.b.value() == "baz");
const toml::ordered_value v2(foo);
CHECK(v2 == v);
}
// -----------------------------------------------------------------------
{
const toml::value v(toml::table{
{"b", "bar.b"},
{"f", toml::table{{"a", 42}}}
});
const auto bar = toml::get<extlib4::bar>(v);
CHECK(bar.a == std::nullopt);
CHECK(bar.b.value() == "bar.b");
CHECK(bar.f.value().a.value() == 42);
CHECK(bar.f.value().b == std::nullopt);
const toml::value v2(bar);
CHECK(v2 == v);
}
{
const toml::ordered_value v(toml::ordered_table{
{"a", 42},
{"f", toml::ordered_table{{"b", "foo.b"}}}
});
const auto bar = toml::get<extlib4::bar>(v);
CHECK(bar.a.value() == 42);
CHECK(bar.b == std::nullopt);
CHECK(bar.f.value().a == std::nullopt);
CHECK(bar.f.value().b.value() == "foo.b");
const toml::ordered_value v2(bar);
CHECK(v2 == v);
}
}
#endif // TOML11_HAS_OPTIONAL
#endif // TOML11_WITHOUT_DEFINE_NON_INTRUSIVE #endif // TOML11_WITHOUT_DEFINE_NON_INTRUSIVE