Skip to content

Commit

Permalink
updated toml++ to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
marzer committed Jan 11, 2022
1 parent ba6ea91 commit 19538a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
3 changes: 1 addition & 2 deletions include/pytomlpp/pytomlpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#endif

// toml++ config
#define TOML_WINDOWS_COMPAT 0
#define TOML_LARGE_FILES 1
#define TOML_ENABLE_WINDOWS_COMPAT 0
#define TOML_HEADER_ONLY 0
#ifdef __APPLE__
#define TOML_INT_CHARCONV 0
Expand Down
22 changes: 12 additions & 10 deletions src/encoding_decoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ py::list toml_array_to_py_list(toml::array &&a) {
py::dict toml_table_to_py_dict(toml::table &&t) {
py::dict result;
for (auto &&[key_, val_] : std::move(t)) {
std::move(val_).visit([&, key = key_.c_str()](auto &&val) {
std::move(val_).visit([&, key = key_.str().data()](auto &&val) {
if constexpr (toml::is_table<decltype(val)>)
result[key] = toml_table_to_py_dict(std::move(val));
else if constexpr (toml::is_array<decltype(val)>)
Expand Down Expand Up @@ -108,43 +108,45 @@ toml::table py_dict_to_toml_table(const py::dict &object) {
bool insert_ok = true;
if (py::isinstance<py::bool_>(value)) {
bool bool_value = value.cast<py::bool_>();
auto insert = t.insert_or_assign(key_string, bool_value);
auto insert = t.insert_or_assign(std::move(key_string), bool_value);
insert_ok = insert.second;
} else if (py::isinstance<py::int_>(value)) {
int64_t int_value = value.cast<py::int_>();
auto insert = t.insert_or_assign(key_string, int_value);
auto insert = t.insert_or_assign(std::move(key_string), int_value);
insert_ok = insert.second;
} else if (py::isinstance<py::float_>(value)) {
double float_value = value.cast<py::float_>();
auto insert = t.insert_or_assign(key_string, float_value);
auto insert = t.insert_or_assign(std::move(key_string), float_value);
insert_ok = insert.second;
} else if (py::isinstance<py::str>(value)) {
std::string string_value = value.cast<py::str>();
auto insert = t.insert_or_assign(key_string, string_value);
auto insert = t.insert_or_assign(std::move(key_string), string_value);
insert_ok = insert.second;
} else if (py::isinstance<py::dict>(value)) {
toml::table table_value = py_dict_to_toml_table(value.cast<py::dict>());
auto insert = t.insert_or_assign(key_string, std::move(table_value));
auto insert =
t.insert_or_assign(std::move(key_string), std::move(table_value));
insert_ok = insert.second;
} else if (py::isinstance<py::list>(value)) {
toml::array array_value = py_list_to_toml_array(value.cast<py::list>());
auto insert = t.insert_or_assign(key_string, std::move(array_value));
auto insert =
t.insert_or_assign(std::move(key_string), std::move(array_value));
insert_ok = insert.second;
} else if (py::isinstance(value, datetime_class)) {
// Order matters here.
// isinstance(datetime_obj, datetime) --> true
// isinstance(datetime_obj, date) --> true as well
// so we need to test datetime first then date.
toml::date_time date_time_value = value.cast<toml::date_time>();
auto insert = t.insert_or_assign(key_string, date_time_value);
auto insert = t.insert_or_assign(std::move(key_string), date_time_value);
insert_ok = insert.second;
} else if (py::isinstance(value, date_class)) {
toml::date date_value = value.cast<toml::date>();
auto insert = t.insert_or_assign(key_string, date_value);
auto insert = t.insert_or_assign(std::move(key_string), date_value);
insert_ok = insert.second;
} else if (py::isinstance(value, time_class)) {
toml::time time_value = value.cast<toml::time>();
auto insert = t.insert_or_assign(key_string, time_value);
auto insert = t.insert_or_assign(std::move(key_string), time_value);
insert_ok = insert.second;
} else {
std::stringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion third_party/tomlplusplus
Submodule tomlplusplus updated 194 files

0 comments on commit 19538a4

Please sign in to comment.