Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/examples/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ description = "Target templates"
type = "executable"
sources = ["src/templates.cpp"]
compile-definitions = ["IS_APP"]

# Unlike interface targets you can also inherit properties
[template.app.properties]
CXX_STANDARD = "11"
CXX_STANDARD_REQUIRED = true
properties = {
CXX_STANDARD = "11",
CXX_STANDARD_REQUIRED = true,
}

[target.app-a]
type = "app"
Expand Down
8 changes: 4 additions & 4 deletions tests/templates/cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ description = "Target templates"
type = "executable"
sources = ["src/templates.cpp"]
compile-definitions = ["IS_APP"]

# Unlike interface targets you can also inherit properties
[template.app.properties]
CXX_STANDARD = "11"
CXX_STANDARD_REQUIRED = true
properties = {
CXX_STANDARD = "11",
CXX_STANDARD_REQUIRED = true,
}

[target.app-a]
type = "app"
Expand Down
7 changes: 4 additions & 3 deletions third_party/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,14 @@
#ifndef TOML_FOR_MODERN_CPP
#define TOML_FOR_MODERN_CPP

#ifndef __cplusplus
# error "__cplusplus is not defined"
#endif

#if __cplusplus < 201103L && _MSC_VER < 1900
# error "toml11 requires C++11 or later."
#endif

#define TOML11_VERSION_MAJOR 3
#define TOML11_VERSION_MINOR 5
#define TOML11_VERSION_PATCH 0
#define TOML11_VERSION_MINOR 8
#define TOML11_VERSION_PATCH 1

#include "toml/parser.hpp"
#include "toml/literal.hpp"
#include "toml/serializer.hpp"
#include "toml/get.hpp"
#include "toml/macros.hpp"

#endif// TOML_FOR_MODERN_CPP
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,41 @@ namespace color_ansi
{
namespace detail
{

inline int colorize_index()
{
static const int index = std::ios_base::xalloc();
return index;
}

// Control color mode globally
class color_mode
{
public:
inline void enable()
{
should_color_ = true;
}
inline void disable()
{
should_color_ = false;
}

inline bool should_color() const
{
return should_color_;
}

static color_mode& status()
{
static color_mode status_;
return status_;
}

private:
bool should_color_ = false;
};

} // detail

inline std::ostream& colorize(std::ostream& os)
Expand Down Expand Up @@ -55,6 +85,21 @@ inline std::ostream& cyan (std::ostream& os)
{if(os.iword(detail::colorize_index()) == 1) {os << "\033[36m";} return os;}
inline std::ostream& white (std::ostream& os)
{if(os.iword(detail::colorize_index()) == 1) {os << "\033[37m";} return os;}

inline void enable()
{
return detail::color_mode::status().enable();
}
inline void disable()
{
return detail::color_mode::status().disable();
}

inline bool should_color()
{
return detail::color_mode::status().should_color();
}

} // color_ansi

// ANSI escape sequence is the only and default colorization method currently
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace detail
// to output character as an error message.
inline std::string show_char(const char c)
{
// It supress an error that occurs only in Debug mode of MSVC++ on Windows.
// It suppresses an error that occurs only in Debug mode of MSVC++ on Windows.
// I'm not completely sure but they check the value of char to be in the
// range [0, 256) and some of the COMPLETELY VALID utf-8 character sometimes
// has negative value (if char has sign). So here it re-interprets c as
Expand Down Expand Up @@ -154,7 +154,7 @@ struct sequence<Head, Tail...>
invoke(location& loc)
{
const auto first = loc.iter();
const auto rslt = Head::invoke(loc);
auto rslt = Head::invoke(loc);
if(rslt.is_err())
{
loc.reset(first);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
#define TOML11_COMMENTS_HPP
#include <initializer_list>
#include <iterator>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

#ifdef TOML11_PRESERVE_COMMENTS_BY_DEFAULT
# define TOML11_DEFAULT_COMMENT_STRATEGY ::toml::preserve_comments
#else
# define TOML11_DEFAULT_COMMENT_STRATEGY ::toml::discard_comments
#endif

// This file provides mainly two classes, `preserve_comments` and `discard_comments`.
// Those two are a container that have the same interface as `std::vector<std::string>`
// but bahaves in the opposite way. `preserve_comments` is just the same as
Expand Down Expand Up @@ -339,7 +346,7 @@ operator+(const empty_iterator<T, C>& lhs, typename empty_iterator<T, C>::differ
//
// Why this is chose as the default type is because the last version (2.x.y)
// does not contain any comments in a value. To minimize the impact on the
// efficiency, this is choosed as a default.
// efficiency, this is chosen as a default.
//
// To reduce the memory footprint, later we can try empty base optimization (EBO).
struct discard_comments
Expand Down Expand Up @@ -418,14 +425,14 @@ struct discard_comments
// empty, so accessing through operator[], front/back, data causes address
// error.

reference operator[](const size_type) noexcept {return *data();}
const_reference operator[](const size_type) const noexcept {return *data();}
reference operator[](const size_type) noexcept {never_call("toml::discard_comment::operator[]");}
const_reference operator[](const size_type) const noexcept {never_call("toml::discard_comment::operator[]");}
reference at(const size_type) {throw std::out_of_range("toml::discard_comment is always empty.");}
const_reference at(const size_type) const {throw std::out_of_range("toml::discard_comment is always empty.");}
reference front() noexcept {return *data();}
const_reference front() const noexcept {return *data();}
reference back() noexcept {return *data();}
const_reference back() const noexcept {return *data();}
reference front() noexcept {never_call("toml::discard_comment::front");}
const_reference front() const noexcept {never_call("toml::discard_comment::front");}
reference back() noexcept {never_call("toml::discard_comment::back");}
const_reference back() const noexcept {never_call("toml::discard_comment::back");}

pointer data() noexcept {return nullptr;}
const_pointer data() const noexcept {return nullptr;}
Expand All @@ -443,6 +450,18 @@ struct discard_comments
const_reverse_iterator rend() const noexcept {return const_iterator{};}
const_reverse_iterator crbegin() const noexcept {return const_iterator{};}
const_reverse_iterator crend() const noexcept {return const_iterator{};}

private:

[[noreturn]] static void never_call(const char *const this_function)
{
#ifdef __has_builtin
# if __has_builtin(__builtin_unreachable)
__builtin_unreachable();
# endif
#endif
throw std::logic_error{this_function};
}
};

inline bool operator==(const discard_comments&, const discard_comments&) noexcept {return true;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@ namespace toml
namespace detail
{
// TODO: find more sophisticated way to handle this
#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_POSIX_SOURCE)
#if defined(_MSC_VER)
inline std::tm localtime_s(const std::time_t* src)
{
std::tm dst;
const auto result = ::localtime_r(src, &dst);
if (!result) { throw std::runtime_error("localtime_r failed."); }
const auto result = ::localtime_s(&dst, src);
if (result) { throw std::runtime_error("localtime_s failed."); }
return dst;
}
inline std::tm gmtime_s(const std::time_t* src)
{
std::tm dst;
const auto result = ::gmtime_r(src, &dst);
if (!result) { throw std::runtime_error("gmtime_r failed."); }
const auto result = ::gmtime_s(&dst, src);
if (result) { throw std::runtime_error("gmtime_s failed."); }
return dst;
}
#elif defined(_MSC_VER)
#elif (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_POSIX_SOURCE)
inline std::tm localtime_s(const std::time_t* src)
{
std::tm dst;
const auto result = ::localtime_s(&dst, src);
if (result) { throw std::runtime_error("localtime_s failed."); }
const auto result = ::localtime_r(src, &dst);
if (!result) { throw std::runtime_error("localtime_r failed."); }
return dst;
}
inline std::tm gmtime_s(const std::time_t* src)
{
std::tm dst;
const auto result = ::gmtime_s(&dst, src);
if (result) { throw std::runtime_error("gmtime_s failed."); }
const auto result = ::gmtime_r(src, &dst);
if (!result) { throw std::runtime_error("gmtime_r failed."); }
return dst;
}
#else // fallback. not threadsafe
Expand Down Expand Up @@ -85,9 +85,9 @@ enum class month_t : std::uint8_t

struct local_date
{
std::int16_t year; // A.D. (like, 2018)
std::uint8_t month; // [0, 11]
std::uint8_t day; // [1, 31]
std::int16_t year{}; // A.D. (like, 2018)
std::uint8_t month{}; // [0, 11]
std::uint8_t day{}; // [1, 31]

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

struct local_time
{
std::uint8_t hour; // [0, 23]
std::uint8_t minute; // [0, 59]
std::uint8_t second; // [0, 60]
std::uint16_t millisecond; // [0, 999]
std::uint16_t microsecond; // [0, 999]
std::uint16_t nanosecond; // [0, 999]
std::uint8_t hour{}; // [0, 23]
std::uint8_t minute{}; // [0, 59]
std::uint8_t second{}; // [0, 60]
std::uint16_t millisecond{}; // [0, 999]
std::uint16_t microsecond{}; // [0, 999]
std::uint16_t nanosecond{}; // [0, 999]

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

struct time_offset
{
std::int8_t hour; // [-12, 12]
std::int8_t minute; // [-59, 59]
std::int8_t hour{}; // [-12, 12]
std::int8_t minute{}; // [-59, 59]

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

struct local_datetime
{
local_date date;
local_time time;
local_date date{};
local_time time{};

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

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

struct offset_datetime
{
local_date date;
local_time time;
time_offset offset;
local_date date{};
local_time time{};
time_offset offset{};

offset_datetime(local_date d, local_time t, time_offset o)
: date(d), time(t), offset(o)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@
// Distributed under the MIT License.
#ifndef TOML11_EXCEPTION_HPP
#define TOML11_EXCEPTION_HPP
#include <stdexcept>

#include <array>
#include <string>
#include <stdexcept>

#include <cstring>

#include "source_location.hpp"

namespace toml
{

struct file_io_error : public std::runtime_error
{
public:
file_io_error(int errnum, const std::string& msg, const std::string& fname)
: std::runtime_error(msg + " \"" + fname + "\": errno = " + std::to_string(errnum)),
errno_(errnum)
{}

int get_errno() const noexcept {return errno_;}

private:
int errno_;
};

struct exception : public std::exception
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Distributed under the MIT License.
#ifndef TOML11_FROM_HPP
#define TOML11_FROM_HPP
#include "traits.hpp"

namespace toml
{
Expand Down
Loading