bioformats  5.1.6
Classes | Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
ome::bioformats::MetadataMap Class Reference

Metadata key-value map using a restricted set of value types. More...

#include <ome/bioformats/MetadataMap.h>

+ Collaboration diagram for ome::bioformats::MetadataMap:

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_typemap_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_typekeys () 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_typemap ()
 Get the underlying map. More...
 
const map_typemap () 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_typeoperator[] (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_viewall_types_view
 Aggregate view of all storable types.
 
typedef boost::mpl::insert_range< boost::mpl::vector0<>, boost::mpl::end< boost::mpl::vector0<> >::type, all_types_view >::type discriminated_types
 List of discriminated types used by boost::variant.
 

Private Attributes

map_type discriminating_map
 Key-value mapping.
 

Detailed Description

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.

Member Function Documentation

template<typename T >
void ome::bioformats::MetadataMap::append ( const key_type key,
const T &  value 
)
inline

Append a value to a vector.

Note
If a key by the same already exists in the map and is of the wrong type or is not a vector, it will be removed and replaced.
Parameters
keythe key name.
valuethe value to append.

References set().

iterator ome::bioformats::MetadataMap::begin ( )
inline

Get an iterator to the beginning of the map.

Returns
an iterator.

Referenced by keys(), merge(), and ome::bioformats::detail::FormatReader::setId().

+ Here is the caller graph for this function:

const_iterator ome::bioformats::MetadataMap::begin ( ) const
inline

Get a constant iterator to the beginning of the map.

Returns
a constant iterator.
void ome::bioformats::MetadataMap::clear ( )
inline

Clear the map.

All keys are cleared from the map.

Referenced by ome::bioformats::detail::FormatReader::initFile().

+ Here is the caller graph for this function:

bool ome::bioformats::MetadataMap::empty ( ) const
inline

Check if the map is empty.

Returns
true if empty, false otherwise.

Referenced by ome::bioformats::fillOriginalMetadata().

+ Here is the caller graph for this function:

iterator ome::bioformats::MetadataMap::end ( )
inline

Get an iterator to the end of the map.

Returns
an iterator.

Referenced by get(), keys(), merge(), set(), and ome::bioformats::detail::FormatReader::setId().

+ Here is the caller graph for this function:

const_iterator ome::bioformats::MetadataMap::end ( ) const
inline

Get a constant iterator to the end of the map.

Returns
a constant iterator.
void ome::bioformats::MetadataMap::erase ( const key_type key)
inline

Erase a key from the map by name.

Parameters
keythe key to erase.

Referenced by set().

+ Here is the caller graph for this function:

void ome::bioformats::MetadataMap::erase ( iterator  pos)
inline

Erase a key from the map by an iterator position.

Parameters
posthe iterator position to erase.
iterator ome::bioformats::MetadataMap::find ( const key_type key)
inline

Find a key in the map.

Parameters
keythe key to find.
Returns
an iterator to the key-value pair.

Referenced by get(), and set().

+ Here is the caller graph for this function:

const_iterator ome::bioformats::MetadataMap::find ( const key_type key) const
inline

Find a key in the map.

Parameters
keythe key to find.
Returns
an iterator to the key-value pair.
MetadataMap ome::bioformats::MetadataMap::flatten ( ) const
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.

Returns
the flattened map.

References discriminating_map.

Referenced by ome::bioformats::fillOriginalMetadata().

+ Here is the caller graph for this function:

bool ome::bioformats::MetadataMap::get ( const key_type key,
value_type value 
) const
inline

Get the value of a particular key from the map.

If the key was not found, value will remain unmodified.

Parameters
keythe key to find.
valuea reference to store a copy of the value.
Returns
true if the key was found, false otherwise.

References end(), and find().

Referenced by ome::bioformats::detail::FormatReader::getMetadataValue(), and ome::bioformats::detail::FormatReader::getSeriesMetadataValue().

+ Here is the caller graph for this function:

template<typename T >
bool ome::bioformats::MetadataMap::get ( const key_type key,
T &  value 
) const
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.

Parameters
keythe key to find.
valuea reference to store a copy of the value.
Returns
true if the key was found and the value was of the correct type, false otherwise.
template<typename T >
T& ome::bioformats::MetadataMap::get ( const key_type key)
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.

Parameters
keythe key to find.
Returns
a reference to the stored value.
Exceptions
boost::bad_geton failure if the key was not found or if the type did not match the stored value type.
template<typename T >
const T& ome::bioformats::MetadataMap::get ( const key_type key) const
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.

Parameters
keythe key to find.
Returns
a reference to the stored value.
Exceptions
boost::bad_geton failure if the key was not found or if the type did not match the stored value type.
std::pair<iterator, bool> ome::bioformats::MetadataMap::insert ( map_type::value_type &  value)
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.

Parameters
valuethe value to insert.
Returns
an iterator to the inserted key, or prexisting key if present, and true if the value was inserted, false otherwise.

Referenced by merge(), and set().

+ Here is the caller graph for this function:

std::vector<key_type> ome::bioformats::MetadataMap::keys ( ) const
inline

Get a list of keys in the map.

Note
This is inefficient, and exists solely for compatibility with the Java implementation. Using the iterator interface directly should be preferred.
Returns
a sorted list of keys.

References begin(), and end().

map_type& ome::bioformats::MetadataMap::map ( )
inline

Get the underlying map.

Returns
a reference to the map.

References discriminating_map.

const map_type& ome::bioformats::MetadataMap::map ( ) const
inline

Get the underlying map.

Returns
a reference to the map.

References discriminating_map.

void ome::bioformats::MetadataMap::merge ( const MetadataMap map,
const std::string &  prefix 
)
inline

Merge a separate map into this map.

Parameters
mapthe map to merge.
prefixa prefix to append to the keys of the map being merged.

References begin(), end(), and insert().

bool ome::bioformats::MetadataMap::operator!= ( const MetadataMap rhs) const
inline

Compare maps for non-equality.

Parameters
rhsthe map to compare.
Returns
true if not equal to rhs, false otherwise.

References discriminating_map.

bool ome::bioformats::MetadataMap::operator< ( const MetadataMap rhs) const
inline

Check if map is less than another map.

Parameters
rhsthe map to compare.
Returns
true if less than rhs, false otherwise.

References discriminating_map.

bool ome::bioformats::MetadataMap::operator<= ( const MetadataMap rhs) const
inline

Check if map is less than or equal to another map.

Parameters
rhsthe map to compare.
Returns
true if less than or equal to rhs, false otherwise.

References discriminating_map.

bool ome::bioformats::MetadataMap::operator== ( const MetadataMap rhs) const
inline

Compare maps for equality.

Parameters
rhsthe map to compare.
Returns
true if equal to rhs, false otherwise.

References discriminating_map.

bool ome::bioformats::MetadataMap::operator> ( const MetadataMap rhs) const
inline

Check if map is greater than another map.

Parameters
rhsthe map to compare.
Returns
true if greater than rhs, false otherwise.

References discriminating_map.

bool ome::bioformats::MetadataMap::operator>= ( const MetadataMap rhs) const
inline

Check if map is greater than or equal to another map.

Parameters
rhsthe map to compare.
Returns
true if greater than or equal to rhs, false otherwise.

References discriminating_map.

value_type& ome::bioformats::MetadataMap::operator[] ( const key_type key)
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.

Parameters
keythe key to retrieve.
Returns
a reference to the value associated with the key.
reverse_iterator ome::bioformats::MetadataMap::rbegin ( )
inline

Get a reverse iterator to the end of the map.

Returns
an iterator.
const_reverse_iterator ome::bioformats::MetadataMap::rbegin ( ) const
inline

Get a constant reverse iterator to the end of the map.

Returns
an iterator.
reverse_iterator ome::bioformats::MetadataMap::rend ( )
inline

Get a reverse iterator to the beginning of the map.

Returns
an iterator.
const_reverse_iterator ome::bioformats::MetadataMap::rend ( ) const
inline

Get a constant reverse iterator to the beginning of the map.

Returns
an iterator.
void ome::bioformats::MetadataMap::set ( const key_type key,
const value_type value 
)
inline

Add a key-value pair to the map.

Note
If a key by the same already exists in the map, it will be removed and replaced.
Parameters
keythe key name.
valuethe abstract value.

References end(), erase(), find(), and insert().

Referenced by append(), ome::bioformats::tiff::getCoreMetadata(), ome::bioformats::getOriginalMetadata(), ome::bioformats::detail::MetadataMapFlattenVisitor::operator()(), set(), and ome::bioformats::detail::FormatReader::setId().

+ Here is the caller graph for this function:

template<typename T >
void ome::bioformats::MetadataMap::set ( const key_type key,
const T &  value 
)
inline

Add a key-value pair to the map.

Note
If a key by the same already exists in the map, it will be removed and replaced.
Parameters
keythe key name.
valuethe value.

References set().

size_type ome::bioformats::MetadataMap::size ( ) const
inline

Get the size of the map.

Note that vectors are counted as a single item; child elements are not included.

Returns
the number of elements.

The documentation for this class was generated from the following file: