Skip to content

Commit

Permalink
added array::at() and table::at()
Browse files Browse the repository at this point in the history
  • Loading branch information
marzer committed Nov 7, 2021
1 parent 5e2ddc1 commit 76e681d
Show file tree
Hide file tree
Showing 9 changed files with 510 additions and 383 deletions.
55 changes: 29 additions & 26 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,56 @@ template:
## Unreleased

This release will be a major version bump, so it's ABI breaks all around. Any API changes that might necessitate
code changes at callsites or in build systems are indicated with '️'.
code changes at callsites or in build systems are indicated with ⚠️.

#### Fixes:
- fixed `json_formatter` not formatting inf and nan incorrectly
- fixed `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 incorrect source position in redefinition error messages
- fixed documentation issues
- fixed some interfaces missing `TOML_API`
- fixed `toml::table` init-list constructor requiring double-brackets
- fixed incorrect `noexcept` specifications on many functions ⚠️
- fixed incorrect source position in redefinition error messages
- fixed missing `#include <initializer_list>`
- fixed missing `#include <utility>`
- fixed incorrect `noexcept` specifications on many functions ⚠&#xFE0F;
- fixed `TOML_API` + extern templates causing linker errors in some circumstances
- fixed inf and nan being formatted incorrectly by the `json_formatter`
- fixed missing `TOML_API` on interfaces
- fixed parser not correctly round-tripping the format of binary and octal integers in some cases

#### Additions:
- added support for Unicode 14.0
- added formatter indentation flags (#120) (@W4RH4WK)
- added value flags to array + table insert methods (#44) (@levicki)
- added magic `value_flags` constant `preserve_source_value_flags`
- added clang's enum annotation attributes to all enums
- added `formatter_flags::quote_infinities_and_nans`
- added `TOML_ENABLE_FORMATTERS` option
- added `array::at()` and `table::at()`
- added `array::replace()` (#109) (#LebJe)
- added `default_init_flags` param to `array::resize()`
- added `toml::yaml_formatter`
- added `operator->` to `toml::value` for class types
- added `formatter_flags::quote_infinities_and_nans`
- added `operator->` to `value` for class types
- added `parse_benchmark` example
- added `array::replace()` (#109) (#LebJe)
- 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 support for Unicode 14.0
- added value flags to array + table insert methods (#44) (@levicki)

#### Changes:
- moved all implementation headers to `/impl`
- `format_flags` is now backed by `uint64_t` (was previously `uint8_t`) ⚠&#xFE0F;
- `source_index` is now an alias for `uint32_t` unconditionally (was previously dependent on `TOML_LARGE_FILES`) ⚠&#xFE0F;
- `value_flags` is now backed by `uint16_t` (was previously `uint8_t`) ⚠&#xFE0F;
- applied clang-format to all the things 🎉&#xFE0F;
- improved performance of parser's internal UTF-8 stream decoder
- made all overloaded operators 'hidden friends' where possible ⚠&#xFE0F;
- made date/time constructors accept any integral types
- made all overloaded operators 'hidden friends' where possible
- renamed all implementation headers to `.h` and 'source' headers to `.inl`
- moved all implementation headers to `/impl`
- renamed `default_formatter` to `toml_formatter` (`default_formatter` is now an alias)
- applied clang-format to all the things 🎉&#xFE0F;
- renamed all implementation headers to `.h` and 'source' headers to `.inl`
- updated conformance tests


#### Removals and Deprecations:
- removed `TOML_LARGE_FILES` (it is now default - explicitly setting `TOML_PARSER` to `0` will invoke an `#error`) ⚠&#xFE0F;
- renamed `TOML_PARSER` option to `TOML_ENABLE_PARSER` (`TOML_PARSER` will continue to work but is deprecated) ⚠&#xFE0F;
- renamed `TOML_WINDOWS_COMPAT` to `TOML_ENABLE_WINDOWS_COMPAT` (`TOML_WINDOWS_COMPAT` will continue to work but is deprecated) ⚠&#xFE0F;
- renamed `TOML_UNRELEASED_FEATURES` to `TOML_ENABLE_UNRELEASED_FEATURES` (`TOML_UNRELEASED_FEATURES` will continue to work but is deprecated) ⚠&#xFE0F;
- removed `TOML_LARGE_FILES` (it is now default - explicitly setting `TOML_LARGE_FILES` to `0` will invoke an `#error`) ⚠&#xFE0F;
- removed unnecessary template machinery (esp. where ostreams were involved)
- removed unnecessary uses of `final`
- renamed `TOML_PARSER` option to `TOML_ENABLE_PARSER` (`TOML_PARSER` will continue to work but is deprecated) ⚠&#xFE0F;
- renamed `TOML_UNRELEASED_FEATURES` to `TOML_ENABLE_UNRELEASED_FEATURES` (`TOML_UNRELEASED_FEATURES` will continue to work but is deprecated) ⚠&#xFE0F;
- renamed `TOML_WINDOWS_COMPAT` to `TOML_ENABLE_WINDOWS_COMPAT` (`TOML_WINDOWS_COMPAT` will continue to work but is deprecated) ⚠&#xFE0F;

#### Build system:
- disabled 'install' path when being used as a meson subproject (#114) (@Tachi107)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ won't need to mess with these at all, but if you do, set them before including t
| `TOML_CONFIG_HEADER` | string literal | Includes the given header file before the rest of the library. | undefined |
| `TOML_ENABLE_FORMATTERS` | boolean | Enables the formatters. Set to `0` if you don't need them to improve compile times and binary size. | `1` |
| `TOML_ENABLE_PARSER` | boolean | Enables the parser. Set to `0` if you don't need it to improve compile times and binary size. | `1` |
| `TOML_ENABLE_UNRELEASED_FEATURES` | boolean | Enables support for [unreleased TOML language features. | `0` |
| `TOML_ENABLE_UNRELEASED_FEATURES` | boolean | Enables support for [unreleased TOML language features]. | `0` |
| `TOML_ENABLE_WINDOWS_COMPAT` | boolean | Enables support for transparent conversion between wide and narrow strings. | `1` on Windows |
| `TOML_EXCEPTIONS` | boolean | Sets whether the library uses exceptions. | per compiler settings |
| `TOML_HEADER_ONLY` | boolean | Disable this to explicitly control where toml++'s implementation is compiled (e.g. as part of a library).| `1` |
Expand All @@ -167,7 +167,7 @@ support for a number of unreleased features from the [TOML master] and some sane
The library advertises the most recent numbered language version it fully supports via the preprocessor
defines `TOML_LANG_MAJOR`, `TOML_LANG_MINOR` and `TOML_LANG_PATCH`.
### 🔸&#xFE0F; **Unreleased language features:**
### **Unreleased language features:**
- [#516]: Allow newlines and trailing commas in inline tables
- [#562]: Allow hex floating-point values
- [#644]: Support `+` in key names
Expand Down Expand Up @@ -238,7 +238,7 @@ though you're welcome to reach out via other means. In order of likely response
[API documentation]: https://marzer.github.io/tomlplusplus/
[homepage]: https://marzer.github.io/tomlplusplus/
[unreleased TOML language features]: #-unreleased-language-features
[unreleased TOML language features]: #unreleased-language-features
[most recently-released version]: https://github.com/toml-lang/toml/releases
[numbered version]: https://github.com/toml-lang/toml/releases
[char8_t]: https://en.cppreference.com/w/cpp/keyword/char8_t
Expand Down
22 changes: 22 additions & 0 deletions include/toml++/impl/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,28 @@ TOML_NAMESPACE_START
return *elems_[index];
}

#if TOML_COMPILER_EXCEPTIONS

/// \brief Gets a reference to the element at a specific index, throwing `std::out_of_range` if none existed.
///
/// \availability This function is only available if you compile with exceptions enabled.
TOML_NODISCARD
node& at(size_t index)
{
return *elems_.at(index);
}

/// \brief Gets a reference to the element at a specific index, throwing `std::out_of_range` if none existed.
///
/// \availability This function is only available if you compile with exceptions enabled.
TOML_NODISCARD
const node& at(size_t index) const
{
return *elems_.at(index);
}

#endif // TOML_COMPILER_EXCEPTIONS

/// \brief Returns a reference to the first element in the array.
TOML_NODISCARD
node& front() noexcept
Expand Down
14 changes: 5 additions & 9 deletions include/toml++/impl/source_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ TOML_NAMESPACE_START
/// std::cout << "The node 'description' was defined at "sv
/// << table.get("description")->source().begin()
/// << "\n";
///
/// \ecpp
///
/// \out
/// The value 'description' was defined at line 7, column 15
/// \eout
///
/// \remarks toml++'s parser is unicode-aware insofar as it knows how to handle
/// various non-conventional whitespace and newline characters, but it doesn't give
/// much thought to combining marks, grapheme clusters vs. characters, et cetera.
/// non-ASCII whitespace and newline characters, but it doesn't give much thought
/// to combining marks, grapheme clusters vs. characters, et cetera.
/// If a TOML document contains lots of codepoints outside of the ASCII range
/// you may find that your source_positions don't match those given by a text editor
/// (typically the line numbers will be accurate but column numbers will be too high).
Expand Down Expand Up @@ -93,7 +92,6 @@ TOML_NAMESPACE_START
/// std::cout << "The value for 'bar' was found on "sv
/// << tbl.get("bar")->source().begin()
/// << "\n";
///
/// \ecpp
///
/// \out
Expand Down Expand Up @@ -121,7 +119,6 @@ TOML_NAMESPACE_START
/// std::cout << "end: "sv << server->source().end << "\n";
/// std::cout << "path: "sv << *server->source().path << "\n";
/// }
///
/// \ecpp
///
/// \out
Expand All @@ -131,8 +128,8 @@ TOML_NAMESPACE_START
/// \eout
///
/// \remarks toml++'s parser is unicode-aware insofar as it knows how to handle
/// various non-conventional whitespace and newline characters, but it doesn't give
/// much thought to combining marks, grapheme clusters vs. characters, et cetera.
/// non-ASCII whitespace and newline characters, but it doesn't give much thought
/// to combining marks, grapheme clusters vs. characters, et cetera.
/// If a TOML document contains lots of codepoints outside of the ASCII range
/// you may find that your source_positions don't match those given by a text editor
/// (typically the line numbers will be accurate but column numbers will be too high).
Expand All @@ -159,7 +156,7 @@ TOML_NAMESPACE_START
///
/// \remarks This will return an empty optional if no path was provided to toml::parse().
TOML_NODISCARD
optional<std::wstring> wide_path() const noexcept
optional<std::wstring> wide_path() const
{
if (!path || path->empty())
return {};
Expand All @@ -176,7 +173,6 @@ TOML_NAMESPACE_START
/// std::cout << "The value for 'bar' was found on "sv
/// << tbl.get("bar")->source()
/// << "\n";
///
/// \ecpp
///
/// \out
Expand Down
Loading

0 comments on commit 76e681d

Please sign in to comment.