MCPcopy Create free account
hub / github.com/KTH-RPL/dufomap / value

Method value

src/toml.hpp:5392–5506  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5390
5391 template <typename T>
5392 TOML_NODISCARD
5393 inline optional<T> node::value() const noexcept(impl::value_retrieval_is_nothrow<T>)
5394 {
5395 using namespace impl;
5396
5397 static_assert(!is_wide_string<T> || TOML_ENABLE_WINDOWS_COMPAT,
5398 "Retrieving values as wide-character strings with node::value() is only "
5399 "supported on Windows with TOML_ENABLE_WINDOWS_COMPAT enabled.");
5400 static_assert((is_native<T> || can_represent_native<T> || can_partially_represent_native<T>)&&!is_cvref<T>,
5401 TOML_SA_VALUE_FUNC_MESSAGE("return type of node::value()"));
5402
5403 // when asking for strings, dates, times and date_times there's no 'fuzzy' conversion
5404 // semantics to be mindful of so the exact retrieval is enough.
5405 if constexpr (is_natively_one_of<T, std::string, time, date, date_time>)
5406 {
5407 if (type() == node_type_of<T>)
5408 return { this->get_value_exact<T>() };
5409 else
5410 return {};
5411 }
5412
5413 // everything else requires a bit of logicking.
5414 else
5415 {
5416 switch (type())
5417 {
5418 // int -> *
5419 case node_type::integer:
5420 {
5421 // int -> int
5422 if constexpr (is_natively_one_of<T, int64_t>)
5423 {
5424 if constexpr (is_native<T> || can_represent_native<T>)
5425 return static_cast<T>(*ref_cast<int64_t>());
5426 else
5427 return node_integer_cast<T>(*ref_cast<int64_t>());
5428 }
5429
5430 // int -> float
5431 else if constexpr (is_natively_one_of<T, double>)
5432 {
5433 const int64_t val = *ref_cast<int64_t>();
5434 if constexpr (std::numeric_limits<T>::digits < 64)
5435 {
5436 constexpr auto largest_whole_float = (int64_t{ 1 } << std::numeric_limits<T>::digits);
5437 if (val < -largest_whole_float || val > largest_whole_float)
5438 return {};
5439 }
5440 return static_cast<T>(val);
5441 }
5442
5443 // int -> bool
5444 else if constexpr (is_natively_one_of<T, bool>)
5445 return static_cast<bool>(*ref_cast<int64_t>());
5446
5447 // int -> anything else
5448 else
5449 return {};

Callers

nothing calls this directly

Calls 2

typeFunction · 0.85
fpclassifyFunction · 0.85

Tested by

no test coverage detected