Skip to content

Commit

Permalink
removed <fstream> requirement for parse_file
Browse files Browse the repository at this point in the history
also:
- fixed false-positive char_8 support detection on older compilers
- removed extraneous `TOML_API` declarations
  • Loading branch information
marzer committed May 19, 2021
1 parent ac923d8 commit 1baad21
Show file tree
Hide file tree
Showing 23 changed files with 420 additions and 459 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ cpp = 17
Reading it in C++ is easy with toml++:
```cpp
#include <toml.hpp>
#include <fstream> //required for toml::parse_file()

auto config = toml::parse_file( "configuration.toml" );

Expand Down Expand Up @@ -98,14 +97,13 @@ You'll find some more code examples in the `examples` directory, and plenty more
2. `#include <toml++/toml.h>`
### Conan
Add `tomlplusplus/2.3.0` to your conanfile.<br>
This adds the single-header version by default, but you can specify the regular version using `"multiple_headers": True`.
Add `tomlplusplus/2.4.0` to your conanfile.
### DDS
Add `tomlpp` to your `package.json5`, e.g.:
```
depends: [
'tomlpp^2.3.0',
'tomlpp^2.4.0',
]
```
> ℹ&#xFE0F; _[What is DDS?](https://dds.pizza/)_
Expand All @@ -121,7 +119,7 @@ include(FetchContent)
FetchContent_Declare(
tomlplusplus
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
GIT_TAG 0fcbfbe655917738c39321fcbcbdc7b048a40e33
GIT_TAG v2.4.0
)
FetchContent_MakeAvailable(tomlplusplus)
```
Expand Down
18 changes: 3 additions & 15 deletions docs/pages/main_page.dox
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
///
/// \cpp
/// #include <iostream>
/// #include <fstream> //required for parse_file()
/// #include <toml++/toml.h>
///
/// int main(int argc, char** argv)
Expand All @@ -56,15 +55,6 @@
///
/// \ecpp
///
/// \m_class{m-note m-warning}
///
/// \parblock
/// <h3>Don't forget [code]\#include &lt;fstream&gt;[/code]!</h3>
/// Not everyone who uses the library is going to work directly from files, so not everybody is forced to pay
/// the compilation overhead of including `<fstream>`. You need to explicitly include it if you're going to be calling
/// toml::parse_file().
/// \endparblock
///
/// \see
/// - toml::parse_file()
/// - toml::table
Expand Down Expand Up @@ -144,7 +134,6 @@
///
/// \cpp
/// #include <iostream>
/// #include <fstream>
///
/// #define TOML_EXCEPTIONS 0 // only necessary if you've left them enabled in your compiler
/// #include <toml++/toml.h>
Expand Down Expand Up @@ -437,16 +426,15 @@
//////////////////////////////////
///
/// \subsection mainpage-adding-lib-conan Conan
/// Add `tomlplusplus/2.3.0` to your conanfile. This adds the single-header version by default, but you can specify the
/// regular version using `"multiple_headers": True`.
/// Add `tomlplusplus/2.4.0` to your conanfile.
///
//////////////////////////////////
///
/// \subsection mainpage-adding-lib-dds DDS
/// Add `tomlpp` to your `package.json5`, e.g.:
/// \bash
/// depends: [
/// 'tomlpp^2.3.0',
/// 'tomlpp^2.4.0',
/// ]
/// \ebash
///
Expand All @@ -472,7 +460,7 @@
/// FetchContent_Declare(
/// tomlplusplus
/// GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
/// GIT_TAG 0fcbfbe655917738c39321fcbcbdc7b048a40e33
/// GIT_TAG v2.4.0
/// )
/// FetchContent_MakeAvailable(tomlplusplus)
/// \ebash
Expand Down
1 change: 1 addition & 0 deletions docs/poxy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# https://github.com/marzer/poxy

name = 'toml++'
author = 'Mark Gillard'
description = 'TOML for modern C++'
cpp = 17
github = 'marzer/tomlplusplus'
Expand Down
1 change: 0 additions & 1 deletion examples/simple_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
#include <iostream>
#include <fstream>
#include "utf8_console.h"

#define TOML_UNRELEASED_FEATURES 1
Expand Down
1 change: 0 additions & 1 deletion examples/toml_to_json_transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
#include <iostream>
#include <fstream>
#include "utf8_console.h"

#define TOML_UNRELEASED_FEATURES 1
Expand Down
1 change: 1 addition & 0 deletions include/toml++/toml.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ TOML_POP_WARNINGS; // TOML_DISABLE_SPAM_WARNINGS
#undef TOML_GCC
#undef TOML_HAS_ATTR
#undef TOML_HAS_CUSTOM_OPTIONAL_TYPE
#undef TOML_HAS_CHAR8
#undef TOML_HAS_INCLUDE
#undef TOML_ICC
#undef TOML_ICC_CL
Expand Down
2 changes: 0 additions & 2 deletions include/toml++/toml_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ TOML_NAMESPACE_START
return index < elements.size() ? elements[index].get() : nullptr;
}

TOML_API
TOML_EXTERNAL_LINKAGE
bool operator == (const array& lhs, const array& rhs) noexcept
{
Expand All @@ -264,7 +263,6 @@ TOML_NAMESPACE_START
return true;
}

TOML_API
TOML_EXTERNAL_LINKAGE
bool operator != (const array& lhs, const array& rhs) noexcept
{
Expand Down
19 changes: 11 additions & 8 deletions include/toml++/toml_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@ TOML_DISABLE_WARNINGS;
#include <vector>
#include <map>
#include <iosfwd>
#include <new>
#if !TOML_HAS_CUSTOM_OPTIONAL_TYPE
#include <optional>
#endif
#if TOML_HAS_INCLUDE(<version>)
#include <version>
#endif
TOML_ENABLE_WARNINGS;

#ifdef __cpp_lib_launder
#if defined(__cpp_lib_launder) && __cpp_lib_launder >= 201606
#define TOML_LAUNDER(x) std::launder(x)
#else
#define TOML_LAUNDER(x) x
#endif

#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811 \
&& defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201907
#define TOML_HAS_CHAR8 1
#else
#define TOML_HAS_CHAR8 0
#endif

//#====================================================================================================================
//# ENVIRONMENT GROUND-TRUTHS
//#====================================================================================================================
Expand Down Expand Up @@ -174,7 +179,7 @@ TOML_NAMESPACE_START // abi namespace
#if TOML_WINDOWS_COMPAT
[[nodiscard]] TOML_API std::string narrow(std::wstring_view) noexcept;
[[nodiscard]] TOML_API std::wstring widen(std::string_view) noexcept;
#ifdef __cpp_lib_char8_t
#if TOML_HAS_CHAR8
[[nodiscard]] TOML_API std::wstring widen(std::u8string_view) noexcept;
#endif
#endif // TOML_WINDOWS_COMPAT
Expand Down Expand Up @@ -460,7 +465,7 @@ TOML_IMPL_NAMESPACE_START
template <size_t N> struct value_traits<const char[N]> : string_value_traits<const char[N]> {};
template <> struct value_traits<char*> : string_value_traits<char*> {};
template <size_t N> struct value_traits<char[N]> : string_value_traits<char[N]> {};
#ifdef __cpp_lib_char8_t
#if TOML_HAS_CHAR8
template <> struct value_traits<std::u8string> : string_value_traits<std::u8string> {};
template <> struct value_traits<std::u8string_view> : string_value_traits<std::u8string_view> {};
template <> struct value_traits<const char8_t*> : string_value_traits<const char8_t*> {};
Expand Down Expand Up @@ -795,8 +800,6 @@ TOML_NAMESPACE_START
/// \brief A source document region.
///
/// \detail \cpp
/// #include <fstream>
///
/// auto tbl = toml::parse_file("config.toml"sv);
/// if (auto server = tbl.get("server"))
/// {
Expand Down
10 changes: 2 additions & 8 deletions include/toml++/toml_default_formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ TOML_IMPL_NAMESPACE_START
{
inline constexpr size_t default_formatter_line_wrap = 120_sz;

TOML_API
TOML_EXTERNAL_LINKAGE
std::string default_formatter_make_key_segment(const std::string& str) noexcept
{
Expand Down Expand Up @@ -69,7 +68,6 @@ TOML_IMPL_NAMESPACE_START
}
}

TOML_API
TOML_EXTERNAL_LINKAGE
size_t default_formatter_inline_columns(const node& node) noexcept
{
Expand Down Expand Up @@ -153,7 +151,6 @@ TOML_IMPL_NAMESPACE_START
TOML_UNREACHABLE;
}

TOML_API
TOML_EXTERNAL_LINKAGE
bool default_formatter_forces_multiline(const node& node, size_t starting_column_bias) noexcept
{
Expand Down Expand Up @@ -230,7 +227,6 @@ extern "C"

TOML_IMPL_NAMESPACE_START
{
TOML_API
TOML_EXTERNAL_LINKAGE
std::string narrow(std::wstring_view str) noexcept
{
Expand All @@ -249,7 +245,6 @@ TOML_IMPL_NAMESPACE_START
return s;
}

TOML_API
TOML_EXTERNAL_LINKAGE
std::wstring widen(std::string_view str) noexcept
{
Expand All @@ -266,9 +261,8 @@ TOML_IMPL_NAMESPACE_START
return s;
}

#ifdef __cpp_lib_char8_t
#if TOML_HAS_CHAR8

TOML_API
TOML_EXTERNAL_LINKAGE
std::wstring widen(std::u8string_view str) noexcept
{
Expand All @@ -278,7 +272,7 @@ TOML_IMPL_NAMESPACE_START
return widen(std::string_view{ reinterpret_cast<const char*>(str.data()), str.length() });
}

#endif // __cpp_lib_char8_t
#endif // TOML_HAS_CHAR8
}
TOML_IMPL_NAMESPACE_END;

Expand Down
Loading

0 comments on commit 1baad21

Please sign in to comment.