Skip to content

Commit 506a68f

Browse files
committed
renamed value::value_arg_t to value_arg for consistency
also: - added major version number to the hidden inline namespace - documentation fixes
1 parent 3d653de commit 506a68f

File tree

6 files changed

+118
-82
lines changed

6 files changed

+118
-82
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
[![GitHub](https://img.shields.io/github/license/marzer/tomlplusplus)](https://github.com/marzer/tomlplusplus/blob/master/LICENSE)
66

77
`toml++` is a header-only toml parser and serializer for C++17, C++20 and whatever comes after.
8-
- Fully [TOML v0.5.0]-compliant
9-
- Modern C++17 (with some C++20 features where supported)
8+
- [TOML v0.5.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md), plus support for some
9+
unreleased TOML features (these are optional)
10+
- C++17 (plus some C++20 features where available, e.g. experimental support for char8_t strings)
1011
- Proper UTF-8 handling (incl. BOM)
1112
- Works with or without exceptions
1213
- Doesn't require RTTI
1314
- First-class support for serializing to JSON
14-
- Supports a number of 'unreleased' TOML features (optional)
1515

1616
<br>
1717

include/toml++/toml.h

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,41 +53,58 @@
5353
#undef TOML_DOXYGEN
5454
#undef TOML_RELOPS_REORDERING
5555
#undef TOML_ASYMMETRICAL_EQUALITY_OPS
56+
#undef TOML_INLINE_NS_EX
5657
#undef TOML_START
58+
#undef TOML_START_2
59+
#undef TOML_START_1
5760
#undef TOML_END
5861
#undef TOML_IMPL_START
5962
#undef TOML_IMPL_END
6063
#endif
6164

6265
/// \mainpage toml++
6366
///
64-
/// This is the home of toml++, a header-only [TOML](https://github.com/toml-lang/toml) parser and serializer for C++17 and later.
67+
/// This is the home of toml++, a header-only [TOML](https://github.com/toml-lang/toml) parser and serializer for C++17
68+
/// and later.
6569
///
6670
/// \tableofcontents
6771
///
6872
///////////////////////////////////////////////////////////////////////
6973
///
7074
/// \section mainpage-features Features
71-
/// - C++17 (plus some C++20 features where supported, e.g. char8_t strings)
75+
/// - [TOML v0.5.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md), plus support for some
76+
/// unreleased TOML features (these are optional)
77+
/// - C++17 (plus some C++20 features where available, e.g. experimental support for char8_t strings)
7278
/// - Proper UTF-8 handling (incl. BOM)
7379
/// - Works with or without exceptions
7480
/// - Doesn't require RTTI
7581
/// - First-class support for serializing to JSON
76-
/// - Fully [TOML v0.5.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md)-compliant
77-
/// - Supports a number of 'unreleased' TOML features (optional; these can be disabled)
7882
///
7983
///////////////////////////////////////////////////////////////////////
8084
///
8185
/// \section mainpage-adding-lib Adding toml++ to your project
82-
/// Clone [the repository](https://github.com/marzer/tomlplusplus/) from GitHub. It's header-only so there's not much you have to do after that,
83-
/// other than some very minor (optional) configuration. See the [README](https://github.com/marzer/tomlplusplus/blob/master/README.md) for more info.
86+
/// It's header-only library so really all you have to do is clone
87+
/// [the repository](https://github.com/marzer/tomlplusplus/) from GitHub and set your include paths.
88+
/// There's some minor configuration you can do to customize some basic library functionality, but that's totally
89+
/// optional. See the [README](https://github.com/marzer/tomlplusplus/blob/master/README.md) for more info.
90+
///
91+
/// <blockquote>
92+
/// <h3>On Linkers and the One-Definition-Rule</h3>
93+
/// <p>Header-only libraries are great for minimal setup, but can cause ODR violations and complex linker errors
94+
/// in situations where multiple modules include them separately, each with different versions, configuration options,
95+
/// exception handling modes, et cetera.</p>
96+
/// <p>`toml++` attempts to combat this problem by nesting everything inside an additional inline namespace that
97+
/// changes according to the library's major version and the compiler's exception-handling mode.</p>
98+
/// </blockquote>
8499
///
85100
///////////////////////////////////////////////////////////////////////
86101
///
87102
/// \section mainpage-api-documentation API Documentation
88-
/// You're looking at it! Browse the docs using the links at the top of the page. You can search from anywhere by pressing the TAB key.
103+
/// You're looking at it! Browse the docs using the links at the top of the page.
104+
/// You can search from anywhere by pressing the TAB key.
89105
///
90-
/// <em>toml++ is still pretty hot off the presses so there's going to be some omissions, typos and general sparseness throughout the docs.
106+
/// <em>toml++ is still pretty hot off the presses so there's going to be some omissions,
107+
/// typos and general sparseness throughout the docs.
91108
/// If you spot something or have a suggestion, please [let me know](https://github.com/marzer/tomlplusplus/issues)!</em>
92109
///
93110
///////////////////////////////////////////////////////////////////////
@@ -99,7 +116,8 @@
99116
/// \subsection mainpage-example-parsing-files Parsing TOML files
100117
/// toml++ works whether you have exceptions enabled or not. For the most part the usage is the same,
101118
/// the main difference being how parsing errors are reported to the caller. When exceptions are enabled
102-
/// a toml::parse_error is thrown directly from the site of the error:
119+
/// a successful call to a parsing function simply returns a toml::table, whereas a failed call sees a toml::parse_error
120+
/// thrown directly from the site of the error:
103121
/// \cpp
104122
/// #include <iostream>
105123
/// #include <fstream> //required for parse_file()
@@ -129,7 +147,7 @@
129147
///
130148
/// \ecpp
131149
///
132-
/// When exceptions are disabled parsing methods return a toml::parse_result and it is up to the caller
150+
/// When exceptions are disabled parsing functions return a toml::parse_result instead and it is up to the caller
133151
/// to check if parsing has been successful by examining the return value:
134152
/// \cpp
135153
/// #include <iostream>
@@ -341,9 +359,13 @@
341359
///
342360
/// \section mainpage-license License
343361
///
344-
/// toml++ is licensed under the terms of the MIT license - see [LICENSE](https://github.com/marzer/tomlplusplus/blob/master/LICENSE).
362+
/// toml++ is licensed under the terms of the MIT license - see
363+
/// [LICENSE](https://github.com/marzer/tomlplusplus/blob/master/LICENSE).
345364
///
346-
/// UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's 'Flexible and Economical UTF - 8 Decoder', which is also subject
347-
/// to the terms of the MIT license - see [LICENSE-utf8-decoder](https://github.com/marzer/tomlplusplus/blob/master/LICENSE-utf8-decoder).
365+
/// UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's
366+
/// 'Flexible and Economical UTF - 8 Decoder', which is also subject to the terms of the MIT license - see
367+
/// [LICENSE-utf8-decoder](https://github.com/marzer/tomlplusplus/blob/master/LICENSE-utf8-decoder).
348368
///
369+
/// \remark Note that if you're using the single-header version of the library you don't need to distribute these files;
370+
/// their contents is included in the preamble at the top of the file.
349371
///

include/toml++/toml_common.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,6 @@
229229
__VA_ARGS__ [[nodiscard]] friend bool operator != (RHS rhs, LHS lhs) noexcept { return !(lhs == rhs); }
230230
#endif
231231

232-
#if !TOML_DOXYGEN
233-
#if TOML_EXCEPTIONS
234-
#define TOML_START namespace toml { inline namespace wex
235-
#else
236-
#define TOML_START namespace toml { inline namespace woex
237-
#endif
238-
#define TOML_END }
239-
#endif
240-
#define TOML_IMPL_START TOML_START { namespace impl
241-
#define TOML_IMPL_END } TOML_END
242-
243232
#include "toml_version.h"
244233

245234
#define TOML_MAKE_VERSION(maj, min, rev) \
@@ -262,6 +251,22 @@
262251
#define TOML_LANG_EXACTLY(maj, min, rev) \
263252
(TOML_LANG_EFFECTIVE_VERSION == TOML_MAKE_VERSION(maj, min, rev))
264253

254+
#if !TOML_DOXYGEN
255+
256+
#if TOML_EXCEPTIONS
257+
#define TOML_INLINE_NS_EX
258+
#else
259+
#define TOML_INLINE_NS_EX _noex
260+
#endif
261+
262+
#define TOML_START_2(VER, ARG1, ARG2) namespace toml { inline namespace v##VER##ARG1##ARG2
263+
#define TOML_START_1(VER, ARG1, ARG2) TOML_START_2(VER, ARG1, ARG2)
264+
#define TOML_START TOML_START_1(TOML_LIB_MAJOR,TOML_INLINE_NS_EX,)
265+
#define TOML_END }
266+
267+
#endif
268+
#define TOML_IMPL_START TOML_START { namespace impl
269+
#define TOML_IMPL_END } TOML_END
265270

266271
////////// INCLUDES
267272

include/toml++/toml_node_view.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@ TOML_START
3535
///
3636
/// tbl["products"][0]["keywords"].as_array()->push_back("heavy");
3737
/// std::cout << tbl["products"][0]["keywords"] << std::endl;
38-
/// std::cout << "has third product: "sv << !!tbl["products"][2] << std::endl;
39-
/// std::cout << tbl["products"][2] << std::endl; // no-op
40-
///
41-
/// \ecpp
38+
/// std::cout << "has product[2]: "sv << !!tbl["products"][2] << std::endl;
39+
/// std::cout << "product[2]: "sv << tbl["products"][2] << std::endl;
40+
/// \ecpp
4241
///
4342
/// \out
4443
/// "my hardware store"
4544
/// "Hammer"
4645
/// [ "hammer", "construction", "build" ]
46+
/// "build"
4747
/// [ "hammer", "construction", "build", "heavy" ]
48-
/// has third product: false
48+
/// has product[2]: false
49+
/// product[2]:
4950
/// \eout
5051
template <typename T>
5152
class node_view final

include/toml++/toml_value.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ TOML_START
4242
/// \brief The value's underlying data type.
4343
using value_type = T;
4444

45+
/// \brief A type alias for 'value arguments'.
46+
/// \details This differs according to the value's type argument:
47+
/// - ints, floats, booleans: `value_type`
48+
/// - strings: `string_view`
49+
/// - everything else: `const value_type&`
50+
using value_arg = std::conditional_t<
51+
std::is_same_v<T, string>,
52+
string_view,
53+
std::conditional_t<impl::is_one_of<T, double, int64_t, bool>, T, const T&>
54+
>;
55+
4556
/// \brief Constructs a toml value.
4657
///
4758
/// \tparam U Constructor argument types.
@@ -167,19 +178,8 @@ TOML_START
167178
return lhs;
168179
}
169180

170-
/// \brief A type alias for 'value arguments'.
171-
/// \details This differs according to the value's type argument:
172-
/// - ints, floats, booleans: `value_type`
173-
/// - strings: `string_view`
174-
/// - everything else: `const value_type&`
175-
using value_arg_t = std::conditional_t<
176-
std::is_same_v<T, string>,
177-
string_view,
178-
std::conditional_t<impl::is_one_of<T, double, int64_t, bool>, T, const T&>
179-
>;
180-
181181
/// \brief Value-assignment operator.
182-
value& operator= (value_arg_t rhs) noexcept
182+
value& operator= (value_arg rhs) noexcept
183183
{
184184
if constexpr (std::is_same_v<T, string>)
185185
val_.assign(rhs);
@@ -196,26 +196,26 @@ TOML_START
196196
}
197197

198198
/// \brief Value equality operator.
199-
[[nodiscard]] friend bool operator == (const value& lhs, value_arg_t rhs) noexcept { return lhs.val_ == rhs; }
200-
TOML_ASYMMETRICAL_EQUALITY_OPS(const value&, value_arg_t, )
199+
[[nodiscard]] friend bool operator == (const value& lhs, value_arg rhs) noexcept { return lhs.val_ == rhs; }
200+
TOML_ASYMMETRICAL_EQUALITY_OPS(const value&, value_arg, )
201201

202202
/// \brief Value less-than operator.
203-
[[nodiscard]] friend bool operator < (const value& lhs, value_arg_t rhs) noexcept { return lhs.val_ < rhs; }
203+
[[nodiscard]] friend bool operator < (const value& lhs, value_arg rhs) noexcept { return lhs.val_ < rhs; }
204204
/// \brief Value less-than operator.
205-
[[nodiscard]] friend bool operator < (value_arg_t lhs, const value& rhs) noexcept { return lhs < rhs.val_; }
205+
[[nodiscard]] friend bool operator < (value_arg lhs, const value& rhs) noexcept { return lhs < rhs.val_; }
206206
/// \brief Value less-than-or-equal-to operator.
207-
[[nodiscard]] friend bool operator <= (const value& lhs, value_arg_t rhs) noexcept { return lhs.val_ <= rhs; }
207+
[[nodiscard]] friend bool operator <= (const value& lhs, value_arg rhs) noexcept { return lhs.val_ <= rhs; }
208208
/// \brief Value less-than-or-equal-to operator.
209-
[[nodiscard]] friend bool operator <= (value_arg_t lhs, const value& rhs) noexcept { return lhs <= rhs.val_; }
209+
[[nodiscard]] friend bool operator <= (value_arg lhs, const value& rhs) noexcept { return lhs <= rhs.val_; }
210210

211211
/// \brief Value greater-than operator.
212-
[[nodiscard]] friend bool operator > (const value& lhs, value_arg_t rhs) noexcept { return lhs.val_ > rhs; }
212+
[[nodiscard]] friend bool operator > (const value& lhs, value_arg rhs) noexcept { return lhs.val_ > rhs; }
213213
/// \brief Value greater-than operator.
214-
[[nodiscard]] friend bool operator > (value_arg_t lhs, const value& rhs) noexcept { return lhs > rhs.val_; }
214+
[[nodiscard]] friend bool operator > (value_arg lhs, const value& rhs) noexcept { return lhs > rhs.val_; }
215215
/// \brief Value greater-than-or-equal-to operator.
216-
[[nodiscard]] friend bool operator >= (const value& lhs, value_arg_t rhs) noexcept { return lhs.val_ >= rhs; }
216+
[[nodiscard]] friend bool operator >= (const value& lhs, value_arg rhs) noexcept { return lhs.val_ >= rhs; }
217217
/// \brief Value greater-than-or-equal-to operator.
218-
[[nodiscard]] friend bool operator >= (value_arg_t lhs, const value& rhs) noexcept { return lhs >= rhs.val_; }
218+
[[nodiscard]] friend bool operator >= (value_arg lhs, const value& rhs) noexcept { return lhs >= rhs.val_; }
219219

220220
/// \brief Equality operator.
221221
///

toml.hpp

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,6 @@
293293
__VA_ARGS__ [[nodiscard]] friend bool operator != (RHS rhs, LHS lhs) noexcept { return !(lhs == rhs); }
294294
#endif
295295

296-
#if !TOML_DOXYGEN
297-
#if TOML_EXCEPTIONS
298-
#define TOML_START namespace toml { inline namespace wex
299-
#else
300-
#define TOML_START namespace toml { inline namespace woex
301-
#endif
302-
#define TOML_END }
303-
#endif
304-
#define TOML_IMPL_START TOML_START { namespace impl
305-
#define TOML_IMPL_END } TOML_END
306-
307296
#define TOML_LIB_MAJOR 0
308297
#define TOML_LIB_MINOR 2
309298
#define TOML_LIB_PATCH 0
@@ -332,6 +321,23 @@
332321
#define TOML_LANG_EXACTLY(maj, min, rev) \
333322
(TOML_LANG_EFFECTIVE_VERSION == TOML_MAKE_VERSION(maj, min, rev))
334323

324+
#if !TOML_DOXYGEN
325+
326+
#if TOML_EXCEPTIONS
327+
#define TOML_INLINE_NS_EX
328+
#else
329+
#define TOML_INLINE_NS_EX _noex
330+
#endif
331+
332+
#define TOML_START_2(VER, ARG1, ARG2) namespace toml { inline namespace v##VER##ARG1##ARG2
333+
#define TOML_START_1(VER, ARG1, ARG2) TOML_START_2(VER, ARG1, ARG2)
334+
#define TOML_START TOML_START_1(TOML_LIB_MAJOR,TOML_INLINE_NS_EX,)
335+
#define TOML_END }
336+
337+
#endif
338+
#define TOML_IMPL_START TOML_START { namespace impl
339+
#define TOML_IMPL_END } TOML_END
340+
335341
TOML_PUSH_WARNINGS
336342
TOML_DISABLE_ALL_WARNINGS
337343

@@ -1680,6 +1686,11 @@ TOML_START
16801686
public:
16811687

16821688
using value_type = T;
1689+
using value_arg = std::conditional_t<
1690+
std::is_same_v<T, string>,
1691+
string_view,
1692+
std::conditional_t<impl::is_one_of<T, double, int64_t, bool>, T, const T&>
1693+
>;
16831694

16841695
template <typename... U>
16851696
TOML_NODISCARD_CTOR
@@ -1757,13 +1768,7 @@ TOML_START
17571768
return lhs;
17581769
}
17591770

1760-
using value_arg_t = std::conditional_t<
1761-
std::is_same_v<T, string>,
1762-
string_view,
1763-
std::conditional_t<impl::is_one_of<T, double, int64_t, bool>, T, const T&>
1764-
>;
1765-
1766-
value& operator= (value_arg_t rhs) noexcept
1771+
value& operator= (value_arg rhs) noexcept
17671772
{
17681773
if constexpr (std::is_same_v<T, string>)
17691774
val_.assign(rhs);
@@ -1779,16 +1784,16 @@ TOML_START
17791784
return *this;
17801785
}
17811786

1782-
[[nodiscard]] friend bool operator == (const value& lhs, value_arg_t rhs) noexcept { return lhs.val_ == rhs; }
1783-
TOML_ASYMMETRICAL_EQUALITY_OPS(const value&, value_arg_t, )
1784-
[[nodiscard]] friend bool operator < (const value& lhs, value_arg_t rhs) noexcept { return lhs.val_ < rhs; }
1785-
[[nodiscard]] friend bool operator < (value_arg_t lhs, const value& rhs) noexcept { return lhs < rhs.val_; }
1786-
[[nodiscard]] friend bool operator <= (const value& lhs, value_arg_t rhs) noexcept { return lhs.val_ <= rhs; }
1787-
[[nodiscard]] friend bool operator <= (value_arg_t lhs, const value& rhs) noexcept { return lhs <= rhs.val_; }
1788-
[[nodiscard]] friend bool operator > (const value& lhs, value_arg_t rhs) noexcept { return lhs.val_ > rhs; }
1789-
[[nodiscard]] friend bool operator > (value_arg_t lhs, const value& rhs) noexcept { return lhs > rhs.val_; }
1790-
[[nodiscard]] friend bool operator >= (const value& lhs, value_arg_t rhs) noexcept { return lhs.val_ >= rhs; }
1791-
[[nodiscard]] friend bool operator >= (value_arg_t lhs, const value& rhs) noexcept { return lhs >= rhs.val_; }
1787+
[[nodiscard]] friend bool operator == (const value& lhs, value_arg rhs) noexcept { return lhs.val_ == rhs; }
1788+
TOML_ASYMMETRICAL_EQUALITY_OPS(const value&, value_arg, )
1789+
[[nodiscard]] friend bool operator < (const value& lhs, value_arg rhs) noexcept { return lhs.val_ < rhs; }
1790+
[[nodiscard]] friend bool operator < (value_arg lhs, const value& rhs) noexcept { return lhs < rhs.val_; }
1791+
[[nodiscard]] friend bool operator <= (const value& lhs, value_arg rhs) noexcept { return lhs.val_ <= rhs; }
1792+
[[nodiscard]] friend bool operator <= (value_arg lhs, const value& rhs) noexcept { return lhs <= rhs.val_; }
1793+
[[nodiscard]] friend bool operator > (const value& lhs, value_arg rhs) noexcept { return lhs.val_ > rhs; }
1794+
[[nodiscard]] friend bool operator > (value_arg lhs, const value& rhs) noexcept { return lhs > rhs.val_; }
1795+
[[nodiscard]] friend bool operator >= (const value& lhs, value_arg rhs) noexcept { return lhs.val_ >= rhs; }
1796+
[[nodiscard]] friend bool operator >= (value_arg lhs, const value& rhs) noexcept { return lhs >= rhs.val_; }
17921797

17931798
template <typename U>
17941799
[[nodiscard]] friend bool operator == (const value& lhs, const value<U>& rhs) noexcept
@@ -8562,7 +8567,10 @@ TOML_END
85628567
#undef TOML_DOXYGEN
85638568
#undef TOML_RELOPS_REORDERING
85648569
#undef TOML_ASYMMETRICAL_EQUALITY_OPS
8570+
#undef TOML_INLINE_NS_EX
85658571
#undef TOML_START
8572+
#undef TOML_START_2
8573+
#undef TOML_START_1
85668574
#undef TOML_END
85678575
#undef TOML_IMPL_START
85688576
#undef TOML_IMPL_END

0 commit comments

Comments
 (0)