108 template <typename T, typename
std::enable_if_t<!
detail::IS_SMART_PTR<T>,
int> = 0>
111 return const_cast<T&
>(
static_cast<const GenericMap&
>(*this).
at(key));
114 template <
typename T,
typename std::enable_if_t<!detail::IS_SMART_PTR<T>,
int> = 0>
120 template <typename T, typename std::enable_if_t<std::is_base_of<Storable, T>::value,
int> = 0>
132 virtual
bool empty() const noexcept = 0;
156 template <typename T>
193 template <
typename T>
196 return _contains(key);
229 virtual
bool operator==(
GenericMap const& other) const noexcept {
230 auto keys1 = this->
keys();
231 auto keys2 = other.keys();
235 for (K
const& key : keys1) {
229 virtual
bool operator==(
GenericMap const& other) const noexcept {
…}
308 template <
class Visitor>
309 auto apply(Visitor&& visitor)
const {
311 return _apply(visitor);
330 template <
class Visitor>
333 return _apply(visitor);
343 template <
typename... Types>
344 static std::variant<std::reference_wrapper<Types>...> _typeToRef(
345 std::variant<Types...>
const&)
noexcept;
346 template <
typename... Types>
347 static std::variant<std::reference_wrapper<std::add_const_t<Types>>...> _typeToConstRef(
348 std::variant<Types...>
const&)
noexcept;
403 template <
typename T,
404 typename std::enable_if_t<
406 T
const& _at(
Key<K, T> const& key)
const {
408 "Due to implementation constraints, const keys are not supported.");
411 return std::get<std::reference_wrapper<T const>>(foo);
414 message <<
"Key " << key <<
" not found, but a key labeled " << key.
getId() <<
" is present.";
420 template <typename T, typename std::enable_if_t<std::is_base_of<Storable, T>::value,
int> = 0>
421 T
const& _at(Key<K, T>
const& key)
const {
423 "Due to implementation constraints, const keys are not supported.");
426 Storable
const& value = std::get<std::reference_wrapper<PolymorphicValue const>>(foo).get();
427 T
const* typedPointer =
dynamic_cast<T const*
>(&value);
428 if (typedPointer !=
nullptr) {
429 return *typedPointer;
431 std::stringstream message;
432 message <<
"Key " << key <<
" not found, but a key labeled " << key.getId() <<
" is present.";
433 throw LSST_EXCEPT(pex::exceptions::OutOfRangeError, message.
str());
436 std::stringstream message;
437 message <<
"Key " << key <<
" not found, but a key labeled " << key.getId() <<
" is present.";
438 throw LSST_EXCEPT(pex::exceptions::OutOfRangeError, message.
str());
443 template <typename T, typename std::enable_if_t<std::is_base_of<Storable, T>::value,
int> = 0>
444 std::shared_ptr<T> _at(Key<K, std::shared_ptr<T>>
const& key)
const {
445 static_assert(std::is_const<T>::value,
446 "Due to implementation constraints, pointers to non-const are not supported.");
448 if (std::holds_alternative<std::reference_wrapper<std::shared_ptr<Storable const>
const>>(foo)) {
449 auto pointer = std::get<std::reference_wrapper<std::shared_ptr<Storable const>
const>>(foo).get();
450 if (pointer ==
nullptr) {
457 if (typedPointer.use_count() > 0) {
460 std::stringstream message;
461 message <<
"Key " << key <<
" not found, but a key labeled " << key.getId() <<
" is present.";
462 throw LSST_EXCEPT(pex::exceptions::OutOfRangeError, message.
str());
465 std::stringstream message;
466 message <<
"Key " << key <<
" not found, but a key labeled " << key.getId() <<
" is present.";
467 throw LSST_EXCEPT(pex::exceptions::OutOfRangeError, message.
str());
472 template <
typename T,
473 typename std::enable_if_t<
474 std::is_fundamental<T>::value || std::is_base_of<std::string, T>::value,
int> = 0>
475 bool _contains(Key<K, T>
const& key)
const {
482 return std::holds_alternative<std::reference_wrapper<T const>>(foo);
486 template <typename T, typename std::enable_if_t<std::is_base_of<Storable, T>::value,
int> = 0>
487 bool _contains(Key<K, T>
const& key)
const {
494 auto refwrap = std::get_if<std::reference_wrapper<PolymorphicValue const>>(&foo);
496 Storable
const &
value = refwrap->get();
497 auto asT =
dynamic_cast<T const*
>(&
value);
498 return asT !=
nullptr;
505 template <typename T, typename std::enable_if_t<std::is_base_of<Storable, T>::value,
int> = 0>
506 bool _contains(Key<K, std::shared_ptr<T>>
const& key)
const {
507 static_assert(std::is_const<T>::value,
508 "Due to implementation constraints, pointers to non-const are not supported.");
515 if (std::holds_alternative<std::reference_wrapper<std::shared_ptr<Storable const>
const>>(foo)) {
516 auto pointer = std::get<std::reference_wrapper<std::shared_ptr<Storable const>
const>>(foo).get();
517 if (pointer ==
nullptr) {
523 return typedPointer.use_count() > 0;
532 template <
class Visitor>
533 using _VisitorResult = std::invoke_result_t<Visitor, K&&, bool&>;
537 template <
class Visitor,
typename std::enable_if_t<std::is_
void<_VisitorResult<Visitor>>::value,
int> = 0>
538 void _apply(Visitor&& visitor)
const {
540 for (K
const& key :
keys()) {
541 std::variant<K> varKey = key;
547 template <
class Visitor,
548 typename std::enable_if_t<!std::is_void<_VisitorResult<Visitor>>::value,
int> = 0>
549 auto _apply(Visitor&& visitor)
const {
550 std::vector<_VisitorResult<Visitor>>
results;
553 for (K
const& key :
keys()) {
554 std::variant<K> varKey = key;
561 template <
class Visitor,
typename std::enable_if_t<std::is_
void<_VisitorResult<Visitor>>::value,
int> = 0>
562 void _apply(Visitor&& visitor) {
564 for (K
const& key :
keys()) {
565 std::variant<K> varKey = key;
571 template <
class Visitor,
572 typename std::enable_if_t<!std::is_void<_VisitorResult<Visitor>>::value,
int> = 0>
573 auto _apply(Visitor&& visitor) {
574 std::vector<_VisitorResult<Visitor>>
results;
578 for (K
const& key :
keys()) {
579 std::variant<K> varKey = key;