Skip to content

Commit fb4931d

Browse files
authored
Merge pull request #193 from build-cpp/toml11-upgrade
Support TOML 1.1.0
2 parents e96cd30 + 438fecc commit fb4931d

28 files changed

+1666
-457
lines changed

docs/examples/templates.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ description = "Target templates"
2020
type = "executable"
2121
sources = ["src/templates.cpp"]
2222
compile-definitions = ["IS_APP"]
23-
2423
# Unlike interface targets you can also inherit properties
25-
[template.app.properties]
26-
CXX_STANDARD = "11"
27-
CXX_STANDARD_REQUIRED = true
24+
properties = {
25+
CXX_STANDARD = "11",
26+
CXX_STANDARD_REQUIRED = true,
27+
}
2828

2929
[target.app-a]
3030
type = "app"

tests/templates/cmake.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ description = "Target templates"
88
type = "executable"
99
sources = ["src/templates.cpp"]
1010
compile-definitions = ["IS_APP"]
11-
1211
# Unlike interface targets you can also inherit properties
13-
[template.app.properties]
14-
CXX_STANDARD = "11"
15-
CXX_STANDARD_REQUIRED = true
12+
properties = {
13+
CXX_STANDARD = "11",
14+
CXX_STANDARD_REQUIRED = true,
15+
}
1616

1717
[target.app-a]
1818
type = "app"

third_party/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,14 @@
2525
#ifndef TOML_FOR_MODERN_CPP
2626
#define TOML_FOR_MODERN_CPP
2727

28-
#ifndef __cplusplus
29-
# error "__cplusplus is not defined"
30-
#endif
31-
32-
#if __cplusplus < 201103L && _MSC_VER < 1900
33-
# error "toml11 requires C++11 or later."
34-
#endif
35-
3628
#define TOML11_VERSION_MAJOR 3
37-
#define TOML11_VERSION_MINOR 5
38-
#define TOML11_VERSION_PATCH 0
29+
#define TOML11_VERSION_MINOR 8
30+
#define TOML11_VERSION_PATCH 1
3931

4032
#include "toml/parser.hpp"
4133
#include "toml/literal.hpp"
4234
#include "toml/serializer.hpp"
4335
#include "toml/get.hpp"
36+
#include "toml/macros.hpp"
4437

4538
#endif// TOML_FOR_MODERN_CPP
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,41 @@ namespace color_ansi
1717
{
1818
namespace detail
1919
{
20+
2021
inline int colorize_index()
2122
{
2223
static const int index = std::ios_base::xalloc();
2324
return index;
2425
}
26+
27+
// Control color mode globally
28+
class color_mode
29+
{
30+
public:
31+
inline void enable()
32+
{
33+
should_color_ = true;
34+
}
35+
inline void disable()
36+
{
37+
should_color_ = false;
38+
}
39+
40+
inline bool should_color() const
41+
{
42+
return should_color_;
43+
}
44+
45+
static color_mode& status()
46+
{
47+
static color_mode status_;
48+
return status_;
49+
}
50+
51+
private:
52+
bool should_color_ = false;
53+
};
54+
2555
} // detail
2656

2757
inline std::ostream& colorize(std::ostream& os)
@@ -55,6 +85,21 @@ inline std::ostream& cyan (std::ostream& os)
5585
{if(os.iword(detail::colorize_index()) == 1) {os << "\033[36m";} return os;}
5686
inline std::ostream& white (std::ostream& os)
5787
{if(os.iword(detail::colorize_index()) == 1) {os << "\033[37m";} return os;}
88+
89+
inline void enable()
90+
{
91+
return detail::color_mode::status().enable();
92+
}
93+
inline void disable()
94+
{
95+
return detail::color_mode::status().disable();
96+
}
97+
98+
inline bool should_color()
99+
{
100+
return detail::color_mode::status().should_color();
101+
}
102+
58103
} // color_ansi
59104

60105
// ANSI escape sequence is the only and default colorization method currently

third_party/toml11-3.6.0/toml/combinator.hpp renamed to third_party/toml11-3.8.1/toml/combinator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace detail
2929
// to output character as an error message.
3030
inline std::string show_char(const char c)
3131
{
32-
// It supress an error that occurs only in Debug mode of MSVC++ on Windows.
32+
// It suppresses an error that occurs only in Debug mode of MSVC++ on Windows.
3333
// I'm not completely sure but they check the value of char to be in the
3434
// range [0, 256) and some of the COMPLETELY VALID utf-8 character sometimes
3535
// has negative value (if char has sign). So here it re-interprets c as
@@ -154,7 +154,7 @@ struct sequence<Head, Tail...>
154154
invoke(location& loc)
155155
{
156156
const auto first = loc.iter();
157-
const auto rslt = Head::invoke(loc);
157+
auto rslt = Head::invoke(loc);
158158
if(rslt.is_err())
159159
{
160160
loc.reset(first);

third_party/toml11-3.6.0/toml/comments.hpp renamed to third_party/toml11-3.8.1/toml/comments.hpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
#define TOML11_COMMENTS_HPP
55
#include <initializer_list>
66
#include <iterator>
7+
#include <stdexcept>
78
#include <string>
89
#include <type_traits>
910
#include <utility>
1011
#include <vector>
1112

13+
#ifdef TOML11_PRESERVE_COMMENTS_BY_DEFAULT
14+
# define TOML11_DEFAULT_COMMENT_STRATEGY ::toml::preserve_comments
15+
#else
16+
# define TOML11_DEFAULT_COMMENT_STRATEGY ::toml::discard_comments
17+
#endif
18+
1219
// This file provides mainly two classes, `preserve_comments` and `discard_comments`.
1320
// Those two are a container that have the same interface as `std::vector<std::string>`
1421
// but bahaves in the opposite way. `preserve_comments` is just the same as
@@ -339,7 +346,7 @@ operator+(const empty_iterator<T, C>& lhs, typename empty_iterator<T, C>::differ
339346
//
340347
// Why this is chose as the default type is because the last version (2.x.y)
341348
// does not contain any comments in a value. To minimize the impact on the
342-
// efficiency, this is choosed as a default.
349+
// efficiency, this is chosen as a default.
343350
//
344351
// To reduce the memory footprint, later we can try empty base optimization (EBO).
345352
struct discard_comments
@@ -418,14 +425,14 @@ struct discard_comments
418425
// empty, so accessing through operator[], front/back, data causes address
419426
// error.
420427

421-
reference operator[](const size_type) noexcept {return *data();}
422-
const_reference operator[](const size_type) const noexcept {return *data();}
428+
reference operator[](const size_type) noexcept {never_call("toml::discard_comment::operator[]");}
429+
const_reference operator[](const size_type) const noexcept {never_call("toml::discard_comment::operator[]");}
423430
reference at(const size_type) {throw std::out_of_range("toml::discard_comment is always empty.");}
424431
const_reference at(const size_type) const {throw std::out_of_range("toml::discard_comment is always empty.");}
425-
reference front() noexcept {return *data();}
426-
const_reference front() const noexcept {return *data();}
427-
reference back() noexcept {return *data();}
428-
const_reference back() const noexcept {return *data();}
432+
reference front() noexcept {never_call("toml::discard_comment::front");}
433+
const_reference front() const noexcept {never_call("toml::discard_comment::front");}
434+
reference back() noexcept {never_call("toml::discard_comment::back");}
435+
const_reference back() const noexcept {never_call("toml::discard_comment::back");}
429436

430437
pointer data() noexcept {return nullptr;}
431438
const_pointer data() const noexcept {return nullptr;}
@@ -443,6 +450,18 @@ struct discard_comments
443450
const_reverse_iterator rend() const noexcept {return const_iterator{};}
444451
const_reverse_iterator crbegin() const noexcept {return const_iterator{};}
445452
const_reverse_iterator crend() const noexcept {return const_iterator{};}
453+
454+
private:
455+
456+
[[noreturn]] static void never_call(const char *const this_function)
457+
{
458+
#ifdef __has_builtin
459+
# if __has_builtin(__builtin_unreachable)
460+
__builtin_unreachable();
461+
# endif
462+
#endif
463+
throw std::logic_error{this_function};
464+
}
446465
};
447466

448467
inline bool operator==(const discard_comments&, const discard_comments&) noexcept {return true;}

third_party/toml11-3.6.0/toml/datetime.hpp renamed to third_party/toml11-3.8.1/toml/datetime.hpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,34 @@ namespace toml
2121
namespace detail
2222
{
2323
// TODO: find more sophisticated way to handle this
24-
#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_POSIX_SOURCE)
24+
#if defined(_MSC_VER)
2525
inline std::tm localtime_s(const std::time_t* src)
2626
{
2727
std::tm dst;
28-
const auto result = ::localtime_r(src, &dst);
29-
if (!result) { throw std::runtime_error("localtime_r failed."); }
28+
const auto result = ::localtime_s(&dst, src);
29+
if (result) { throw std::runtime_error("localtime_s failed."); }
3030
return dst;
3131
}
3232
inline std::tm gmtime_s(const std::time_t* src)
3333
{
3434
std::tm dst;
35-
const auto result = ::gmtime_r(src, &dst);
36-
if (!result) { throw std::runtime_error("gmtime_r failed."); }
35+
const auto result = ::gmtime_s(&dst, src);
36+
if (result) { throw std::runtime_error("gmtime_s failed."); }
3737
return dst;
3838
}
39-
#elif defined(_MSC_VER)
39+
#elif (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_POSIX_SOURCE)
4040
inline std::tm localtime_s(const std::time_t* src)
4141
{
4242
std::tm dst;
43-
const auto result = ::localtime_s(&dst, src);
44-
if (result) { throw std::runtime_error("localtime_s failed."); }
43+
const auto result = ::localtime_r(src, &dst);
44+
if (!result) { throw std::runtime_error("localtime_r failed."); }
4545
return dst;
4646
}
4747
inline std::tm gmtime_s(const std::time_t* src)
4848
{
4949
std::tm dst;
50-
const auto result = ::gmtime_s(&dst, src);
51-
if (result) { throw std::runtime_error("gmtime_s failed."); }
50+
const auto result = ::gmtime_r(src, &dst);
51+
if (!result) { throw std::runtime_error("gmtime_r failed."); }
5252
return dst;
5353
}
5454
#else // fallback. not threadsafe
@@ -85,9 +85,9 @@ enum class month_t : std::uint8_t
8585

8686
struct local_date
8787
{
88-
std::int16_t year; // A.D. (like, 2018)
89-
std::uint8_t month; // [0, 11]
90-
std::uint8_t day; // [1, 31]
88+
std::int16_t year{}; // A.D. (like, 2018)
89+
std::uint8_t month{}; // [0, 11]
90+
std::uint8_t day{}; // [1, 31]
9191

9292
local_date(int y, month_t m, int d)
9393
: year (static_cast<std::int16_t>(y)),
@@ -181,12 +181,12 @@ operator<<(std::basic_ostream<charT, traits>& os, const local_date& date)
181181

182182
struct local_time
183183
{
184-
std::uint8_t hour; // [0, 23]
185-
std::uint8_t minute; // [0, 59]
186-
std::uint8_t second; // [0, 60]
187-
std::uint16_t millisecond; // [0, 999]
188-
std::uint16_t microsecond; // [0, 999]
189-
std::uint16_t nanosecond; // [0, 999]
184+
std::uint8_t hour{}; // [0, 23]
185+
std::uint8_t minute{}; // [0, 59]
186+
std::uint8_t second{}; // [0, 60]
187+
std::uint16_t millisecond{}; // [0, 999]
188+
std::uint16_t microsecond{}; // [0, 999]
189+
std::uint16_t nanosecond{}; // [0, 999]
190190

191191
local_time(int h, int m, int s,
192192
int ms = 0, int us = 0, int ns = 0)
@@ -297,8 +297,8 @@ operator<<(std::basic_ostream<charT, traits>& os, const local_time& time)
297297

298298
struct time_offset
299299
{
300-
std::int8_t hour; // [-12, 12]
301-
std::int8_t minute; // [-59, 59]
300+
std::int8_t hour{}; // [-12, 12]
301+
std::int8_t minute{}; // [-59, 59]
302302

303303
time_offset(int h, int m)
304304
: hour (static_cast<std::int8_t>(h)),
@@ -364,8 +364,8 @@ operator<<(std::basic_ostream<charT, traits>& os, const time_offset& offset)
364364

365365
struct local_datetime
366366
{
367-
local_date date;
368-
local_time time;
367+
local_date date{};
368+
local_time time{};
369369

370370
local_datetime(local_date d, local_time t): date(d), time(t) {}
371371

@@ -478,9 +478,9 @@ operator<<(std::basic_ostream<charT, traits>& os, const local_datetime& dt)
478478

479479
struct offset_datetime
480480
{
481-
local_date date;
482-
local_time time;
483-
time_offset offset;
481+
local_date date{};
482+
local_time time{};
483+
time_offset offset{};
484484

485485
offset_datetime(local_date d, local_time t, time_offset o)
486486
: date(d), time(t), offset(o)

third_party/toml11-3.6.0/toml/exception.hpp renamed to third_party/toml11-3.8.1/toml/exception.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@
22
// Distributed under the MIT License.
33
#ifndef TOML11_EXCEPTION_HPP
44
#define TOML11_EXCEPTION_HPP
5-
#include <stdexcept>
5+
6+
#include <array>
67
#include <string>
8+
#include <stdexcept>
9+
10+
#include <cstring>
711

812
#include "source_location.hpp"
913

1014
namespace toml
1115
{
1216

17+
struct file_io_error : public std::runtime_error
18+
{
19+
public:
20+
file_io_error(int errnum, const std::string& msg, const std::string& fname)
21+
: std::runtime_error(msg + " \"" + fname + "\": errno = " + std::to_string(errnum)),
22+
errno_(errnum)
23+
{}
24+
25+
int get_errno() const noexcept {return errno_;}
26+
27+
private:
28+
int errno_;
29+
};
30+
1331
struct exception : public std::exception
1432
{
1533
public:

0 commit comments

Comments
 (0)