bioformats
5.1.0
|
Metadata key-value map using a restricted set of value types. More...
#include <ome/bioformats/MetadataMap.h>
Classes | |
struct | getkey |
Functor to get a map key. More... | |
struct | make_vector |
Convert T into a std::vector<T>. More... | |
Public Types | |
typedef std::string | key_type |
Key type. | |
typedef boost::make_variant_over< discriminated_types >::type | value_type |
Value type, allowing assignment of all storable types. | |
typedef std::map< key_type, value_type > | map_type |
std::string to discriminated type mapping. | |
typedef map_type::size_type | size_type |
Size type. | |
typedef map_type::iterator | iterator |
Iterator. | |
typedef map_type::const_iterator | const_iterator |
Constant iterator. | |
typedef map_type::reverse_iterator | reverse_iterator |
Reverse iterator. | |
typedef map_type::const_reverse_iterator | const_reverse_iterator |
Constant reverse iterator. | |
Public Member Functions | |
MetadataMap () | |
Constructor. | |
~MetadataMap () | |
Destructor. | |
void | set (const key_type &key, const value_type &value) |
Add a key-value pair to the map. More... | |
template<typename T > | |
void | set (const key_type &key, const T &value) |
Add a key-value pair to the map. More... | |
template<typename T > | |
void | append (const key_type &key, const T &value) |
Append a value to a vector. More... | |
bool | get (const key_type &key, value_type &value) const |
Get the value of a particular key from the map. More... | |
template<typename T > | |
bool | get (const key_type &key, T &value) const |
Get the value of a particular key from the map. More... | |
template<typename T > | |
T & | get (const key_type &key) |
Get a reference to the value of a particular key from the map. More... | |
template<typename T > | |
const T & | get (const key_type &key) const |
Get a reference to the value of a particular key from the map. More... | |
iterator | find (const key_type &key) |
Find a key in the map. More... | |
const_iterator | find (const key_type &key) const |
Find a key in the map. More... | |
std::pair< iterator, bool > | insert (map_type::value_type &value) |
Insert a value into the map. More... | |
void | erase (const key_type &key) |
Erase a key from the map by name. More... | |
void | erase (iterator pos) |
Erase a key from the map by an iterator position. More... | |
std::vector< key_type > | keys () const |
Get a list of keys in the map. More... | |
void | merge (const MetadataMap &map, const std::string &prefix) |
Merge a separate map into this map. More... | |
MetadataMap | flatten () const |
Create a flattened map. More... | |
map_type & | map () |
Get the underlying map. More... | |
const map_type & | map () const |
Get the underlying map. More... | |
iterator | begin () |
Get an iterator to the beginning of the map. More... | |
const_iterator | begin () const |
Get a constant iterator to the beginning of the map. More... | |
iterator | end () |
Get an iterator to the end of the map. More... | |
const_iterator | end () const |
Get a constant iterator to the end of the map. More... | |
reverse_iterator | rbegin () |
Get a reverse iterator to the end of the map. More... | |
const_reverse_iterator | rbegin () const |
Get a constant reverse iterator to the end of the map. More... | |
reverse_iterator | rend () |
Get a reverse iterator to the beginning of the map. More... | |
const_reverse_iterator | rend () const |
Get a constant reverse iterator to the beginning of the map. More... | |
value_type & | operator[] (const key_type &key) |
Get or set a value by key index. More... | |
bool | operator== (const MetadataMap &rhs) const |
Compare maps for equality. More... | |
bool | operator!= (const MetadataMap &rhs) const |
Compare maps for non-equality. More... | |
bool | operator< (const MetadataMap &rhs) const |
Check if map is less than another map. More... | |
bool | operator<= (const MetadataMap &rhs) const |
Check if map is less than or equal to another map. More... | |
bool | operator> (const MetadataMap &rhs) const |
Check if map is greater than another map. More... | |
bool | operator>= (const MetadataMap &rhs) const |
Check if map is greater than or equal to another map. More... | |
size_type | size () const |
Get the size of the map. More... | |
bool | empty () const |
Check if the map is empty. More... | |
void | clear () |
Clear the map. More... | |
Private Types | |
typedef boost::mpl::vector< std::string, bool > | non_numeric_types |
Storable non-numeric types. | |
typedef boost::mpl::vector< uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t > | integer_types |
Storable integer types. | |
typedef boost::mpl::vector< float, double, long double > | float_types |
Storable floating-point types. | |
typedef boost::mpl::joint_view< integer_types, float_types >::type | numeric_types_view |
Aggregate view of all numeric types. | |
typedef boost::mpl::joint_view< non_numeric_types, numeric_types_view >::type | basic_types_view |
Aggregate view of all storable simple types. | |
typedef boost::mpl::transform_view< basic_types_view, make_vector< boost::mpl::_1 > >::type | list_types_view |
Aggregate view of all storable list types. | |
typedef boost::mpl::joint_view< basic_types_view, list_types_view > | all_types_view |
Aggregate view of all storable types. | |
typedef boost::mpl::vector | empty_types |
Empty vector placeholder. | |
typedef boost::mpl::insert_range< empty_types, boost::mpl::end< empty_types >::type, all_types_view >::type | discriminated_types |
List of discriminated types used by boost::variant. | |
Private Attributes | |
map_type | discriminating_map |
Key-value mapping. | |
Metadata key-value map using a restricted set of value types.
Permitted types include std::string
, bool
, integer types (uint8_t
, uint16_t
, uint32_t
, uint64_t
, int8_t
, int16_t
, int32_t
, int64_t
) and floating point types (float
, double
, long
double
). Additionally a std::vector
specialised for each of the aforementioned types may also be stored. However, types may not be mixed within a single std::vector
.
The set() method permits setting of values, which includes both simple values and vectors of any supported type. The convenience method append() allows appending of a single value to a list.
The get() methods permit retrieval of values. There are various forms, which offer different tradeoffs, for example copying the value and returning an error, versus returning a direct reference but throwing an exception on error.
|
inline |
Append a value to a vector.
key | the key name. |
value | the value to append. |
References set().
|
inline |
Get an iterator to the beginning of the map.
Referenced by keys(), merge(), and ome::bioformats::detail::FormatReader::setId().
|
inline |
Get a constant iterator to the beginning of the map.
|
inline |
Clear the map.
All keys are cleared from the map.
Referenced by ome::bioformats::detail::FormatReader::initFile().
|
inline |
Check if the map is empty.
true
if empty, false
otherwise. Referenced by ome::bioformats::fillOriginalMetadata().
|
inline |
Get an iterator to the end of the map.
Referenced by get(), keys(), merge(), set(), and ome::bioformats::detail::FormatReader::setId().
|
inline |
Get a constant iterator to the end of the map.
|
inline |
Erase a key from the map by name.
key | the key to erase. |
Referenced by set().
|
inline |
Erase a key from the map by an iterator position.
pos | the iterator position to erase. |
|
inline |
Find a key in the map.
key | the key to find. |
|
inline |
Create a flattened map.
All vectors in the map will be flattened, which is the replacement of each vector by a key per element with with a #n
key suffix.
References discriminating_map.
Referenced by ome::bioformats::fillOriginalMetadata().
|
inline |
Get the value of a particular key from the map.
If the key was not found, value
will remain unmodified.
key | the key to find. |
value | a reference to store a copy of the value. |
true
if the key was found, false
otherwise. Referenced by ome::bioformats::detail::FormatReader::getMetadataValue(), and ome::bioformats::detail::FormatReader::getSeriesMetadataValue().
|
inline |
Get the value of a particular key from the map.
If the key was not found, or the type of value
does not match the stored value type, value
will remain unmodified.
key | the key to find. |
value | a reference to store a copy of the value. |
true
if the key was found and the value was of the correct type, false
otherwise.
|
inline |
Get a reference to the value of a particular key from the map.
If the key was not found, or the type of value
does not match the stored value type, value
will remain unmodified.
key | the key to find. |
boost::bad_get | on failure if the key was not found or if the type did not match the stored value type. |
|
inline |
Get a reference to the value of a particular key from the map.
If the key was not found, or the type of value
does not match the stored value type, value
will remain unmodified.
key | the key to find. |
boost::bad_get | on failure if the key was not found or if the type did not match the stored value type. |
|
inline |
Insert a value into the map.
Note that this method is an alternative to set(), which retains the insert semantics of std::map::insert(), i.e. it will not replace keys which already exist in the map, and so will be a no-op if the key is already present.
value | the value to insert. |
true
if the value was inserted, false
otherwise. Referenced by merge(), and set().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Compare maps for non-equality.
rhs | the map to compare. |
true
if not equal to rhs
, false
otherwise. References discriminating_map.
|
inline |
Check if map is less than another map.
rhs | the map to compare. |
true
if less than rhs
, false
otherwise. References discriminating_map.
|
inline |
Check if map is less than or equal to another map.
rhs | the map to compare. |
true
if less than or equal to rhs
, false
otherwise. References discriminating_map.
|
inline |
Compare maps for equality.
rhs | the map to compare. |
true
if equal to rhs
, false
otherwise. References discriminating_map.
|
inline |
Check if map is greater than another map.
rhs | the map to compare. |
true
if greater than rhs
, false
otherwise. References discriminating_map.
|
inline |
Check if map is greater than or equal to another map.
rhs | the map to compare. |
true
if greater than or equal to rhs
, false
otherwise. References discriminating_map.
|
inline |
Get or set a value by key index.
Access the metadata map as an associative array. This may be used to get or set a value, with the value being created if the key was not already present in the map.
key | the key to retrieve. |
key
.
|
inline |
Get a reverse iterator to the end of the map.
|
inline |
Get a constant reverse iterator to the end of the map.
|
inline |
Get a reverse iterator to the beginning of the map.
|
inline |
Get a constant reverse iterator to the beginning of the map.
|
inline |
Add a key-value pair to the map.
key | the key name. |
value | the abstract value. |
References end(), erase(), find(), and insert().
Referenced by append(), ome::bioformats::getOriginalMetadata(), ome::bioformats::detail::MetadataMapFlattenVisitor::operator()(), set(), and ome::bioformats::detail::FormatReader::setId().
|
inline |
Add a key-value pair to the map.
key | the key name. |
value | the value. |
References set().
|
inline |
Get the size of the map.
Note that vectors are counted as a single item; child elements are not included.