Skip to content

Commit

Permalink
deprecated parse_result::get() in favour of parse_result::table()
Browse files Browse the repository at this point in the history
also:
- fixed static assert messages being badly formatted on clang
- minor documentation fixes
- updated version numbers
  • Loading branch information
marzer committed Jul 20, 2020
1 parent d84bd8b commit 7314fbf
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 398 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ welcome a pull request with a smile and open arms!
### Conan
`toml++` is available through the [Conan-Center-Index](https://github.com/conan-io/conan-center-index). You simply need
to add `tomlplusplus/1.3.3` to your _conanfile_ to include this in your project. The default options are set for the
to add `tomlplusplus/2.0.0` to your _conanfile_ to include this in your project. The default options are set for the
single-header flavour, however specifying the option `"multiple_headers": True` is available.
<br>
Expand Down
62 changes: 31 additions & 31 deletions docs/main_page.dox
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,14 @@
///
/// \out
/// [library]
/// authors = ["Mark Gillard <[email protected]>"]
/// authors = [ 'Mark Gillard <[email protected]>' ]
/// cpp = 17
/// name = "toml++"
/// name = 'toml++'
///
/// ... twice
/// [library]
/// authors = [ 'Mark Gillard <[email protected]>' ]
/// cpp = 17
/// name = 'toml++'
/// \eout
///
/// \see
Expand Down Expand Up @@ -155,7 +158,7 @@
/// return 1;
/// }
///
/// do_stuff_with_your_config(result); //toml::parse_result is convertible to toml::table
/// do_stuff_with_your_config(std::move(result).table()); // 'steal' the table from the result
/// return 0;
/// }
/// \ecpp
Expand Down Expand Up @@ -201,7 +204,7 @@
/// and toml::table, respectively. All three inherit from toml::node, and can be easily accessed via
/// the toml::node_view:
///
/// \godbolt{ieG52U}
/// \godbolt{7z6GGW}
///
/// \cpp
/// #include <iostream>
Expand All @@ -228,15 +231,13 @@
/// // different ways of directly querying data
/// std::optional<std::string_view> str1 = tbl["str"].value<std::string_view>();
/// std::optional<std::string> str2 = tbl["str"].value<std::string>();
/// std::string_view str3 = tbl["str"].value_or("");
/// std::string str4 = tbl["str"].value_or(std::string{});
/// std::string& str5 = tbl["str"].ref<std::string>(); // ~~dangerous~~, but fast
/// std::string_view str3 = tbl["str"].value_or(""sv);
/// std::string& str4 = tbl["str"].ref<std::string>(); // ~~dangerous~~
///
/// std::cout << *str1 << "\n";
/// std::cout << *str2 << "\n";
/// std::cout << str3 << "\n";
/// std::cout << str4 << "\n";
/// std::cout << str5 << "\n";
///
/// // get a toml::node_view of the element 'numbers' using operator[]
/// auto numbers = tbl["numbers"];
Expand Down Expand Up @@ -281,14 +282,13 @@
/// hello world
/// hello world
/// hello world
/// hello world
/// table has 'numbers': true
/// table has 'numbers': 1
/// numbers is an: array
/// numbers: [1, 2, 3, "four", 5.0]
/// numbers: [2, 3, 4, "five", 6.0, 7, [8, 9]]
/// cats: ["tiger", "lion", "puma"]
/// fish[1]: "trout"
/// dinosaurs:
/// numbers: [ 1, 2, 3, 'four', 5.0 ]
/// numbers: [ 2, 3, 4, 'five', 6.0, 7, [ 8, 9 ] ]
/// cats: [ 'tiger', 'lion', 'puma' ]
/// fish[1]: 'trout'
/// dinosaurs:
/// \eout
///
/// \see
Expand Down Expand Up @@ -340,31 +340,31 @@
/// \out
/// ###### TOML ######
///
/// cpp = [17, 20, "and beyond"]
/// lib = "toml++"
/// repo = "https://github.com/marzer/tomlplusplus/"
/// toml = ["1.0.0-rc.1", "and beyond"]
/// cpp = [ 17, 20, 'and beyond' ]
/// lib = 'toml++'
/// repo = 'https://github.com/marzer/tomlplusplus/'
/// toml = [ '1.0.0-rc.1', 'and beyond' ]
///
/// [author]
/// github = "https://github.com/marzer"
/// name = "Mark Gillard"
/// twitter = "https://twitter.com/marzer8789"
/// github = 'https://github.com/marzer'
/// name = 'Mark Gillard'
/// twitter = 'https://twitter.com/marzer8789'
///
/// ###### JSON ######
///
/// {
/// "author" : {
/// "github" : "https://github.com/marzer",
/// "name" : "Mark Gillard",
/// "github" : "https://github.com/marzer",
/// "name" : "Mark Gillard",
/// "twitter" : "https://twitter.com/marzer8789"
/// },
/// },
/// "cpp" : [
/// 17,
/// 20,
/// "and beyond"
/// ],
/// "lib" : "toml++",
/// "repo" : "https://github.com/marzer/tomlplusplus/",
/// ],
/// "lib" : "toml++",
/// "repo" : "https://github.com/marzer/tomlplusplus/",
/// "toml" : [
/// "1.0.0-rc.1",
/// "and beyond"
Expand Down Expand Up @@ -442,7 +442,7 @@
//////////////////////////////////
///
/// \subsection mainpage-adding-lib-conan Conan
/// Add `tomlplusplus/1.3.3` to your conanfile. This adds the single-header version by default, but you can specify the
/// Add `tomlplusplus/2.0.0` to your conanfile. This adds the single-header version by default, but you can specify the
/// regular version using `"multiple_headers": True`.
///
//////////////////////////////////
Expand Down Expand Up @@ -474,7 +474,7 @@
///
/// \section mainpage-configuration Library configuration options
/// The library exposes a number of configuration options in the form of compiler `#defines`. Things like
/// changing the `optional<T>` type, using `char8_t` strings, disabling header-only mode, et cetera. The full list of
/// changing the `optional<T>` type, disabling header-only mode, et cetera. The full list of
/// configurables can be found on the \ref configuration page.
///
/// \see \ref configuration
Expand Down
14 changes: 11 additions & 3 deletions include/toml++/toml.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,19 @@
#undef TOML_EVAL_BOOL_1
#undef TOML_EVAL_BOOL_0
#undef TOML_HAS_CUSTOM_OPTIONAL_TYPE
#undef TOML_UNWRAPPED_NODE_TYPE_LIST
#undef TOML_NATIVE_VALUE_TYPE_LIST
#undef TOML_NODE_TYPE_LIST
#undef TOML_IMPL_NAMESPACE_START
#undef TOML_IMPL_NAMESPACE_END
#undef TOML_SIMPLE_STATIC_ASSERT_MESSAGES
#undef TOML_SA_NEWLINE
#undef TOML_SA_LIST_SEP
#undef TOML_SA_LIST_BEG
#undef TOML_SA_LIST_END
#undef TOML_SA_LIST_NEW
#undef TOML_SA_LIST_NXT
#undef TOML_SA_LIST_CAP
#undef TOML_SA_NATIVE_VALUE_TYPE_LIST
#undef TOML_SA_NODE_TYPE_LIST
#undef TOML_SA_UNWRAPPED_NODE_TYPE_LIST
#endif

//# {{
Expand Down
12 changes: 6 additions & 6 deletions include/toml++/toml_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ namespace toml
static_assert(
std::is_void_v<type>
|| ((impl::is_native<type> || impl::is_one_of<type, table, array>) && !impl::is_cvref<type>),
"The template type argument of array::is_homogeneous() must be void or one of the following:"
TOML_UNWRAPPED_NODE_TYPE_LIST
"The template type argument of array::is_homogeneous() must be void or one of:"
TOML_SA_UNWRAPPED_NODE_TYPE_LIST
);

if constexpr (std::is_void_v<type>)
Expand Down Expand Up @@ -651,8 +651,8 @@ namespace toml
using type = impl::unwrap_node<U>;
static_assert(
(impl::is_native<type> || impl::is_one_of<type, table, array>) && !impl::is_cvref<type>,
"Emplacement type parameter must be one of the following:"
TOML_UNWRAPPED_NODE_TYPE_LIST
"Emplacement type parameter must be one of:"
TOML_SA_UNWRAPPED_NODE_TYPE_LIST
);

return { values.emplace(pos.raw_, new impl::wrap_node<type>{ std::forward<V>(args)...} ) };
Expand Down Expand Up @@ -813,8 +813,8 @@ namespace toml
using type = impl::unwrap_node<U>;
static_assert(
(impl::is_native<type> || impl::is_one_of<type, table, array>) && !impl::is_cvref<type>,
"Emplacement type parameter must be one of the following:"
TOML_UNWRAPPED_NODE_TYPE_LIST
"Emplacement type parameter must be one of:"
TOML_SA_UNWRAPPED_NODE_TYPE_LIST
);

auto nde = new impl::wrap_node<type>{ std::forward<V>(args)... };
Expand Down
97 changes: 60 additions & 37 deletions include/toml++/toml_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,56 @@
TOML_PUSH_WARNINGS
TOML_DISABLE_MISC_WARNINGS

#define TOML_NATIVE_VALUE_TYPE_LIST \
"\n| - std::string" \
"\n| - int64_t" \
"\n| - double" \
"\n| - bool" \
"\n| - toml::date" \
"\n| - toml::time" \
"\n| - toml::date_time"


#define TOML_NODE_TYPE_LIST \
"\n| - toml::table" \
"\n| - toml::array" \
"\n| - toml::value<std::string>" \
"\n| - toml::value<int64_t>" \
"\n| - toml::value<double>" \
"\n| - toml::value<bool>" \
"\n| - toml::value<toml::date>" \
"\n| - toml::value<toml::time>" \
"\n| - toml::value<toml::date_time>"

#define TOML_UNWRAPPED_NODE_TYPE_LIST \
"\n|" \
"\n| A native TOML value type" \
TOML_NATIVE_VALUE_TYPE_LIST \
"\n|" \
"\n| A TOML node type" \
TOML_NODE_TYPE_LIST
#if TOML_SIMPLE_STATIC_ASSERT_MESSAGES

#define TOML_SA_NEWLINE " "
#define TOML_SA_LIST_SEP ", "
#define TOML_SA_LIST_BEG " ("
#define TOML_SA_LIST_END ")"
#define TOML_SA_LIST_NEW " "
#define TOML_SA_LIST_NXT ", "
#define TOML_SA_LIST_CAP(...)

#else

#define TOML_SA_NEWLINE "\n| "
#define TOML_SA_LIST_SEP TOML_SA_NEWLINE " - "
#define TOML_SA_LIST_BEG TOML_SA_LIST_SEP
#define TOML_SA_LIST_END
#define TOML_SA_LIST_NEW TOML_SA_NEWLINE TOML_SA_NEWLINE
#define TOML_SA_LIST_NXT TOML_SA_LIST_NEW
#define TOML_SA_LIST_CAP(val) val

#endif

#define TOML_SA_NATIVE_VALUE_TYPE_LIST \
TOML_SA_LIST_BEG "std::string" \
TOML_SA_LIST_SEP "int64_t" \
TOML_SA_LIST_SEP "double" \
TOML_SA_LIST_SEP "bool" \
TOML_SA_LIST_SEP "toml::date" \
TOML_SA_LIST_SEP "toml::time" \
TOML_SA_LIST_SEP "toml::date_time" \
TOML_SA_LIST_END

#define TOML_SA_NODE_TYPE_LIST \
TOML_SA_LIST_BEG "toml::table" \
TOML_SA_LIST_SEP "toml::array" \
TOML_SA_LIST_SEP "toml::value<std::string>" \
TOML_SA_LIST_SEP "toml::value<int64_t>" \
TOML_SA_LIST_SEP "toml::value<double>" \
TOML_SA_LIST_SEP "toml::value<bool>" \
TOML_SA_LIST_SEP "toml::value<toml::date>" \
TOML_SA_LIST_SEP "toml::value<toml::time>" \
TOML_SA_LIST_SEP "toml::value<toml::date_time>" \
TOML_SA_LIST_END

#define TOML_SA_UNWRAPPED_NODE_TYPE_LIST \
TOML_SA_LIST_NEW "A native TOML value type" \
TOML_SA_NATIVE_VALUE_TYPE_LIST \
\
TOML_SA_LIST_NXT "A TOML node type" \
TOML_SA_NODE_TYPE_LIST

namespace toml
{
Expand Down Expand Up @@ -133,8 +155,8 @@ namespace toml
using type = impl::unwrap_node<T>;
static_assert(
(impl::is_native<type> || impl::is_one_of<type, table, array>) && !impl::is_cvref<type>,
"The template type argument of node::is() must be one of the following:"
TOML_UNWRAPPED_NODE_TYPE_LIST
"The template type argument of node::is() must be one of:"
TOML_SA_UNWRAPPED_NODE_TYPE_LIST
);

if constexpr (std::is_same_v<type, table>) return is_table();
Expand Down Expand Up @@ -382,8 +404,8 @@ namespace toml
using type = impl::unwrap_node<T>;
static_assert(
(impl::is_native<type> || impl::is_one_of<type, table, array>) && !impl::is_cvref<type>,
"The template type argument of node::as() must be one of the following:"
TOML_UNWRAPPED_NODE_TYPE_LIST
"The template type argument of node::as() must be one of:"
TOML_SA_UNWRAPPED_NODE_TYPE_LIST
);

if constexpr (std::is_same_v<type, table>) return as_table();
Expand All @@ -405,8 +427,8 @@ namespace toml
using type = impl::unwrap_node<T>;
static_assert(
(impl::is_native<type> || impl::is_one_of<type, table, array>) && !impl::is_cvref<type>,
"The template type argument of node::as() must be one of the following:"
TOML_UNWRAPPED_NODE_TYPE_LIST
"The template type argument of node::as() must be one of:"
TOML_SA_UNWRAPPED_NODE_TYPE_LIST
);

if constexpr (std::is_same_v<type, table>) return as_table();
Expand Down Expand Up @@ -493,7 +515,8 @@ namespace toml
{
static_assert(
can_visit_any<Func&&, N&&>,
"Visitors must be invocable for at least one of the toml::node specializations"
"TOML node visitors must be invocable for at least one of the toml::node specializations:"
TOML_SA_NODE_TYPE_LIST
);

switch (n.type())
Expand Down Expand Up @@ -582,8 +605,8 @@ namespace toml
using type = impl::unwrap_node<T>;
static_assert(
(impl::is_native<type> || impl::is_one_of<type, table, array>) && !impl::is_cvref<type>,
"The template type argument of node::ref() must be one of the following:"
TOML_UNWRAPPED_NODE_TYPE_LIST
"The template type argument of node::ref() must be one of:"
TOML_SA_UNWRAPPED_NODE_TYPE_LIST
);
TOML_ASSERT(
n.template is<T>()
Expand Down
19 changes: 3 additions & 16 deletions include/toml++/toml_node_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace toml
/// \brief Returns the node that's being referenced by the view.
[[nodiscard]] viewed_type* node() const noexcept { return node_; }

[[nodiscard, deprecated("use node_view::node() instead (the name is better)")]]
[[nodiscard, deprecated("use node_view::node() instead")]]
viewed_type* get() const noexcept { return node_; }

/// \brief Returns the type identifier for the viewed node.
Expand Down Expand Up @@ -149,14 +149,7 @@ namespace toml
[[nodiscard]]
auto as() const noexcept
{
using type = impl::unwrap_node<T>;
static_assert(
impl::is_native<type> || impl::is_one_of<type, table, array>,
"Template type parameter must be one of the following:"
TOML_UNWRAPPED_NODE_TYPE_LIST
);

return node_ ? node_->template as<type>() : nullptr;
return node_ ? node_->template as<T>() : nullptr;
}

/// \brief Returns a pointer to the viewed node as a toml::table, if it is one.
Expand Down Expand Up @@ -332,17 +325,11 @@ namespace toml
[[nodiscard]]
decltype(auto) ref() const noexcept
{
using type = impl::unwrap_node<T>;
static_assert(
impl::is_native<type> || impl::is_one_of<type, table, array>,
"Template type parameter must be one of the following:"
TOML_UNWRAPPED_NODE_TYPE_LIST
);
TOML_ASSERT(
node_
&& "toml::node_view::ref() called on a node_view that did not reference a node"
);
return node_->template ref<type>();
return node_->template ref<impl::unwrap_node<T>>();
}

/// \brief Returns true if the viewed node is a table with the same contents as RHS.
Expand Down
Loading

0 comments on commit 7314fbf

Please sign in to comment.