Skip to content

Commit

Permalink
added toml::key (closes #82)
Browse files Browse the repository at this point in the history
also:
- added `table::lower_bound()`
- added `table::emplace_hint()`
- changed `table` key type to `toml::key`
- clarified value initializer static assert messages
- lots of misc refactoring
  • Loading branch information
marzer committed Nov 10, 2021
1 parent 6808825 commit 209e9b6
Show file tree
Hide file tree
Showing 22 changed files with 1,545 additions and 796 deletions.
45 changes: 25 additions & 20 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ code changes at callsites or in build systems are indicated with ⚠️.

#### Fixes:
-️ fixed incorrect `noexcept` specifications on many functions
- fixed `json_formatter` not formatting inf and nan incorrectly
- fixed `table` init-list constructor requiring double-brackets
- fixed `toml::json_formatter` not formatting inf and nan incorrectly
- fixed `toml::table` init-list constructor requiring double-brackets
- fixed `TOML_API` + extern templates causing linker errors in some circumstances
- fixed an illegal table redefinition edge case (#112) (@python36)
- fixed documentation issues
Expand All @@ -34,32 +34,37 @@ code changes at callsites or in build systems are indicated with ⚠️.
- fixed parser not correctly round-tripping the format of binary and octal integers in some cases

#### Additions:
- added `array::at()` and `table::at()`
- added `array::replace()` (#109) (@LebJe)
- added `array::resize()` param `default_init_flags`
- added `format_flags::allow_binary_integers`
- added `format_flags::allow_hexadecimal_integers`
- added `format_flags::allow_octal_integers`
- added `format_flags::allow_real_tabs_in_strings`
- added `format_flags::indent_array_elements`
- added `format_flags::indent_sub_tables`
- added `format_flags::quote_infinities_and_nans`
- added `operator->` to `value` for class types
- added `operator->` to `toml::value` for class types
- added `parse_benchmark` example
- added `toml::array::at()` (same semantics as `std::vector::at()`)
- added `toml::array::replace()` (#109) (@LebJe)
- added `toml::array::resize()` param `default_init_flags`
- added `toml::format_flags::allow_binary_integers`
- added `toml::format_flags::allow_hexadecimal_integers`
- added `toml::format_flags::allow_octal_integers`
- added `toml::format_flags::allow_real_tabs_in_strings`
- added `toml::format_flags::indent_array_elements`
- added `toml::format_flags::indent_sub_tables`
- added `toml::format_flags::quote_infinities_and_nans`
- added `toml::key` - provides a facility to access the source_regions of parsed keys (#82) (@vaartis)
- added `toml::table::at()` (same semantics as `std::map::at()`)
- added `toml::table::emplace_hint()` (same semantics as `std::map::emplace_hint()`)
- added `toml::table::lower_bound()` (same semantics as `std::map::lower_bound()`)
- added `toml::yaml_formatter`
- added `TOML_ENABLE_FORMATTERS` option
- added `yaml_formatter`
- added clang's enum annotation attributes to all enums
- added formatter indentation flags (#120) (@W4RH4WK)
- added magic `value_flags` constant `preserve_source_value_flags`
- added magic `toml::value_flags` constant `toml::preserve_source_value_flags`
- added support for Unicode 14.0
- added value flags to array + table insert methods (#44) (@levicki)

#### Changes:
-️ `format_flags` is now backed by `uint64_t` (was previously `uint8_t`)
-️ `source_index` is now an alias for `uint32_t` unconditionally (was previously dependent on `TOML_LARGE_FILES`)
-️ `value_flags` is now backed by `uint16_t` (was previously `uint8_t`)
-️ `toml::format_flags` is now backed by `uint64_t` (was previously `uint8_t`)
-️ `toml::source_index` is now an alias for `uint32_t` unconditionally (was previously dependent on `TOML_LARGE_FILES`)
-️ `toml::table` now uses `toml::key` as the key type (was previously `std::string`)
-️ `toml::value_flags` is now backed by `uint16_t` (was previously `uint8_t`)
-️ made all overloaded operators 'hidden friends' where possible
-️ renamed `default_formatter` to `toml_formatter` (`default_formatter` is now an alias)
-️ renamed `toml::default_formatter` to `toml::toml_formatter` (`toml::default_formatter` is now an alias)
-️ renamed `TOML_PARSER` option to `TOML_ENABLE_PARSER` (`TOML_PARSER` will continue to work but is deprecated)
-️ renamed `TOML_UNRELEASED_FEATURES` to `TOML_ENABLE_UNRELEASED_FEATURES` (`TOML_UNRELEASED_FEATURES` will continue to work but is deprecated)
-️ renamed `TOML_WINDOWS_COMPAT` to `TOML_ENABLE_WINDOWS_COMPAT` (`TOML_WINDOWS_COMPAT` will continue to work but is deprecated)
Expand All @@ -71,7 +76,7 @@ code changes at callsites or in build systems are indicated with ⚠️.
- updated conformance tests

#### Removals:
-️ removed `format_flags::allow_value_format_flags`
-️ removed `toml::format_flags::allow_value_format_flags`
-️ removed `TOML_LARGE_FILES` (it is now default - explicitly setting `TOML_LARGE_FILES` to `0` will invoke an `#error`)
- removed unnecessary template machinery (esp. where ostreams were involved)
- removed unnecessary uses of `final`
Expand Down
19 changes: 10 additions & 9 deletions docs/poxy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,18 @@ string_literals = [ '_toml' ]


[autolinks]
'(?:toml::)?parse[_ ]results?' = 'classtoml_1_1parse__result.html'
'(?:toml::)?parse[_ ]errors?' = 'classtoml_1_1parse__error.html'
'(?:toml::)?node[_ ]views?' = 'classtoml_1_1node__view.html'
'(?:toml::)?json[_ ]formatters?' = 'classtoml_1_1json__formatter.html'
'(?:toml::)?date[_-]times?' = 'structtoml_1_1date__time.html'
'(?:toml::)?default[_ ]formatters?' = 'classtoml_1_1default__formatter.html'
'(?:toml::)?json[_ ]formatters?' = 'classtoml_1_1json__formatter.html'
'(?:toml::)?node[_ ]views?' = 'classtoml_1_1node__view.html'
'(?:toml::)?parse[_ ]errors?' = 'classtoml_1_1parse__error.html'
'(?:toml::)?parse[_ ]results?' = 'classtoml_1_1parse__result.html'
'(?:toml::)?source[_ ]positions?' = 'structtoml_1_1source__position.html'
'(?:toml::)?source[_ ]regions?' = 'structtoml_1_1source__region.html'
'toml::values?' = 'classtoml_1_1value.html'
'(?:toml::)?time[_ ]offsets?' = 'structtoml_1_1time__offset.html'
'(?:toml::)?toml[_ ]formatters?' = 'classtoml_1_1toml__formatter.html'
'(?:toml::)?yaml[_ ]formatters?' = 'classtoml_1_1yaml__formatter.html'
'toml::dates?' = 'structtoml_1_1date.html'
'toml::keys?' = 'classtoml_1_1key.html'
'toml::times?' = 'structtoml_1_1time.html'
'(?:toml::)?time[_ ]offsets?' = 'structtoml_1_1time__offset.html'
'(?:toml::)?date_times?' = 'structtoml_1_1date__time.html'
'(?:toml::)?toml_formatters?' = 'classtoml_1_1toml__formatter.html'
'(?:toml::)?json_formatters?' = 'classtoml_1_1json__formatter.html'
'toml::values?' = 'classtoml_1_1value.html'
20 changes: 10 additions & 10 deletions include/toml++/impl/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ TOML_IMPL_NAMESPACE_START
friend class array_iterator;
friend class TOML_NAMESPACE::array;

using raw_mutable_iterator = std::vector<std::unique_ptr<node>>::iterator;
using raw_const_iterator = std::vector<std::unique_ptr<node>>::const_iterator;
using raw_mutable_iterator = std::vector<node_ptr>::iterator;
using raw_const_iterator = std::vector<node_ptr>::const_iterator;
using raw_iterator = std::conditional_t<IsConst, raw_const_iterator, raw_mutable_iterator>;

mutable raw_iterator raw_;
Expand Down Expand Up @@ -250,7 +250,7 @@ TOML_NAMESPACE_START
/// \cond

friend class TOML_PARSER_TYPENAME;
std::vector<std::unique_ptr<node>> elems_;
std::vector<impl::node_ptr> elems_;

TOML_API
void preinsertion_resize(size_t idx, size_t count);
Expand Down Expand Up @@ -949,10 +949,10 @@ TOML_NAMESPACE_START
preinsertion_resize(start_idx, count);
size_t i = start_idx;
for (size_t e = start_idx + count - 1u; i < e; i++)
elems_[i].reset(impl::make_node(val, flags));
elems_[i] = impl::make_node(val, flags);

//# potentially move the initial value into the last element
elems_[i].reset(impl::make_node(static_cast<ElemType&&>(val), flags));
elems_[i] = impl::make_node(static_cast<ElemType&&>(val), flags);
return { elems_.begin() + static_cast<ptrdiff_t>(start_idx) };
}
}
Expand Down Expand Up @@ -1001,9 +1001,9 @@ TOML_NAMESPACE_START
continue;
}
if constexpr (std::is_rvalue_reference_v<deref_type>)
elems_[i++].reset(impl::make_node(std::move(*it), flags));
elems_[i++] = impl::make_node(std::move(*it), flags);
else
elems_[i++].reset(impl::make_node(*it, flags));
elems_[i++] = impl::make_node(*it, flags);
}
return { elems_.begin() + static_cast<ptrdiff_t>(start_idx) };
}
Expand Down Expand Up @@ -1104,7 +1104,7 @@ TOML_NAMESPACE_START
}

const auto it = elems_.begin() + (pos.raw_ - elems_.cbegin());
it->reset(impl::make_node(static_cast<ElemType&&>(val), flags));
*it = impl::make_node(static_cast<ElemType&&>(val), flags);
return iterator{ it };
}

Expand Down Expand Up @@ -1342,8 +1342,8 @@ TOML_NAMESPACE_START
static bool equal_to_container(const array& lhs, const T& rhs) noexcept
{
using element_type = std::remove_const_t<typename T::value_type>;
static_assert(impl::is_native<element_type> || impl::is_losslessly_convertible_to_native<element_type>,
"Container element type must be (or be promotable to) one of the TOML value types");
static_assert(impl::is_losslessly_convertible_to_native<element_type>,
"Container element type must be losslessly convertible one of the native TOML value types");

if (lhs.size() != rhs.size())
return false;
Expand Down
4 changes: 2 additions & 2 deletions include/toml++/impl/array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ TOML_NAMESPACE_START
continue;
}

std::unique_ptr<node> arr_storage = std::move(elems_[i]);
const auto leaf_count = arr->total_leaf_count();
impl::node_ptr arr_storage = std::move(elems_[i]);
const auto leaf_count = arr->total_leaf_count();
if (leaf_count > 1u)
preinsertion_resize(i + 1u, leaf_count - 1u);
flatten_child(std::move(*arr), i); // increments i
Expand Down
Loading

0 comments on commit 209e9b6

Please sign in to comment.