25#ifndef LSST_AFW_IMAGE_DETAIL_STORABLEMAP_H
26#define LSST_AFW_IMAGE_DETAIL_STORABLEMAP_H
33#include <unordered_map>
121 template <typename T>
124 "Can only retrieve pointers to subclasses of Storable.");
126 "Due to implementation constraints, pointers to non-const are not supported.");
139 if (typedPointer.use_count() > 0) {
143 message <<
"Key " << key <<
" not found, but a key labeled " << key.getId() <<
" is present.";
148 "No key labeled " + key.getId() +
" found."));
156 bool empty() const noexcept;
200 template <typename T>
203 "Can only retrieve pointers to subclasses of Storable.");
205 "Due to implementation constraints, pointers to non-const are not supported.");
206 if (_contents.count(key) > 0) {
208 mapped_type const& pointer = _contents.at(key);
211 if (pointer == nullptr) {
218 return typedPointer.use_count() > 0;
232 bool operator==(StorableMap
const& other)
const noexcept;
243 void clear() noexcept;
262 template <typename T>
265 "Can only store shared pointers to subclasses of Storable.");
267 "Due to implementation constraints, pointers to non-const are not supported.");
270 return _contents.emplace(key, value).second;
292 template <
typename T>
298 result.second =
insert(strongKey, value);
310 template <
typename T>
314 return _contents.erase(key) > 0;
328 iterator begin() noexcept;
329 const_iterator begin() const noexcept;
342 iterator end() noexcept;
343 const_iterator end() const noexcept;
#define LSST_EXCEPT(type,...)
std::reverse_iterator< iterator > reverse_iterator
StorableMap & operator=(StorableMap &&other)
bool empty() const noexcept
Return true if this map contains no key-value pairs.
std::shared_ptr< T > at(Key< std::shared_ptr< T > > const &key) const
Return a the mapped value of the element with key equal to key.
bool contains(std::string const &key) const
Return true if this map contains a mapping whose key has the specified label.
value_type const * const_pointer
lsst::afw::typehandling::Key< std::string, V > Key
bool operator!=(StorableMap const &other) const noexcept
Test for map equality.
size_type size() const noexcept
Return the number of key-value pairs in the map.
typehandling::Key< std::string, mapped_type > key_type
StorableMap(StorableMap &&other)
bool erase(Key< T > const &key) noexcept
Remove the mapping for a key from this map, if it exists.
const_iterator cend() const noexcept
Return an iterator to the element past the end of the map.
const_iterator cbegin() const noexcept
Return an iterator to the first element of the map.
std::ptrdiff_t difference_type
iterator begin() noexcept
Return an iterator to the first element of the map.
bool insert(Key< std::shared_ptr< T > > const &key, std::shared_ptr< T > const &value)
Insert an element into the map, if the map doesn't already contain a mapping with the same or a confl...
StorableMap(StorableMap const &other)
_Impl::const_iterator const_iterator
iterator end() noexcept
Return an iterator to the element past the end of the map.
StorableMap & operator=(StorableMap const &other)
std::shared_ptr< typehandling::Storable const > mapped_type
lsst::afw::typehandling::Storable Storable
std::pair< Key< T >, bool > insert(std::string const &key, T const &value)
Insert an element into the map, if the map doesn't already contain a mapping with a conflicting key.
value_type const & const_reference
std::pair< key_type const, mapped_type > value_type
size_type max_size() const noexcept
Return the maximum number of elements the container is able to hold due to system or library implemen...
std::reverse_iterator< const_iterator > const_reverse_iterator
Key for type-safe lookup in a GenericMap.
Interface supporting iteration over heterogenous containers.
constexpr Key< K, V > makeKey(K const &id)
Factory function for Key, to enable type parameter inference.
T dynamic_pointer_cast(T... args)
T throw_with_nested(T... args)