OpenMS
Loading...
Searching...
No Matches
MetaInfo.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Marc Sturm $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <vector>
12
17
18#include <boost/container/flat_map.hpp>
19#include <functional>
20
21namespace OpenMS
22{
23 class String;
24
44 class OPENMS_DLLAPI MetaInfo
45 {
46public:
48 using MapType = boost::container::flat_map<UInt, DataValue>;
53
55 MetaInfo() = default;
56
58 MetaInfo(const MetaInfo&) = default;
59
61 MetaInfo(MetaInfo&&) = default;
62
65
67 MetaInfo& operator=(const MetaInfo&) = default;
69 MetaInfo& operator=(MetaInfo&&) & = default;
70
72 bool operator==(const MetaInfo& rhs) const;
74 bool operator!=(const MetaInfo& rhs) const;
75
89
91 const DataValue& getValue(const String& name, const DataValue& default_value = DataValue::EMPTY) const;
93 const DataValue& getValue(UInt index, const DataValue& default_value = DataValue::EMPTY) const;
94
96 bool exists(const String& name) const;
98 bool exists(UInt index) const;
99
101 void setValue(const String& name, const DataValue& value);
103 void setValue(UInt index, const DataValue& value);
104
106 void removeValue(const String& name);
108 void removeValue(UInt index);
109
112
114 void getKeys(std::vector<String>& keys) const;
115
117 void getKeys(std::vector<UInt>& keys) const;
118
120 bool empty() const;
121
123 void clear();
124
131
136 const_iterator begin() const { return index_to_value_.begin(); }
137
142 const_iterator end() const { return index_to_value_.end(); }
143
148 const_iterator cbegin() const { return index_to_value_.cbegin(); }
149
154 const_iterator cend() const { return index_to_value_.cend(); }
155
161 iterator begin() { return index_to_value_.begin(); }
162
167 iterator end() { return index_to_value_.end(); }
169
174 Size size() const { return index_to_value_.size(); }
175
176private:
177
180
183
184 // Grant access to hash implementation
185 friend struct std::hash<MetaInfo>;
186 };
187
188} // namespace OpenMS
189
190// Hash function specialization for MetaInfo
191namespace std
192{
193 template<>
194 struct hash<OpenMS::MetaInfo>
195 {
196 std::size_t operator()(const OpenMS::MetaInfo& mi) const noexcept
197 {
198 std::size_t seed = 0;
199 // Hash each key-value pair in sorted order (flat_map is already sorted by key)
200 for (const auto& [key, value] : mi.index_to_value_)
201 {
203 OpenMS::hash_combine(seed, std::hash<OpenMS::DataValue>{}(value));
204 }
205 return seed;
206 }
207 };
208} // namespace std
209
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition DataValue.h:34
Base::iterator iterator
Definition MSExperiment.h:97
Base::const_iterator const_iterator
Definition MSExperiment.h:98
Registry which assigns unique integer indices to strings.
Definition MetaInfoRegistry.h:50
A Type-Name-Value tuple class.
Definition MetaInfo.h:45
void setValue(UInt index, const DataValue &value)
Sets the DataValue corresponding to an index.
void removeValue(const String &name)
Removes the DataValue corresponding to name if it exists.
const_iterator begin() const
Returns a const iterator to the beginning of the meta info entries.
Definition MetaInfo.h:136
MetaInfo(const MetaInfo &)=default
Copy constructor.
const_iterator cbegin() const
Returns a const iterator to the beginning of the meta info entries.
Definition MetaInfo.h:148
bool operator!=(const MetaInfo &rhs) const
Equality operator.
MapType::const_iterator const_iterator
Const iterator type.
Definition MetaInfo.h:52
~MetaInfo()
Destructor.
MetaInfo & operator=(MetaInfo &&) &=default
Move assignment operator.
static MetaInfoRegistry & registry()
Returns a reference to the MetaInfoRegistry.
bool empty() const
Returns if the MetaInfo is empty.
void removeValue(UInt index)
Removes the DataValue corresponding to index if it exists.
bool operator==(const MetaInfo &rhs) const
Equality operator.
bool exists(const String &name) const
Returns whether an entry with the given name exists.
MetaInfo & operator=(const MetaInfo &)=default
Assignment operator.
MapType index_to_value_
The actual mapping of indexes to values.
Definition MetaInfo.h:182
const DataValue & getValue(const String &name, const DataValue &default_value=DataValue::EMPTY) const
Returns the value corresponding to a string, or a default value (default: DataValue::EMPTY) if not fo...
const_iterator cend() const
Returns a const iterator to the end of the meta info entries.
Definition MetaInfo.h:154
void getKeys(std::vector< String > &keys) const
Fills the given vector with a list of all keys for which a value is set.
MetaInfo & operator+=(const MetaInfo &rhs)
Merge another MetaInfo into this one.
void getKeys(std::vector< UInt > &keys) const
Fills the given vector with a list of all keys for which a value is set.
boost::container::flat_map< UInt, DataValue > MapType
Internal map type (UInt key to DataValue)
Definition MetaInfo.h:48
MetaInfo()=default
Constructor.
void setValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
MetaInfo(MetaInfo &&)=default
Move constructor.
const DataValue & getValue(UInt index, const DataValue &default_value=DataValue::EMPTY) const
Returns the value corresponding to an index, or a default value (default: DataValue::EMPTY) if not fo...
static MetaInfoRegistry registry_
Static MetaInfoRegistry.
Definition MetaInfo.h:179
void clear()
Removes all meta values.
iterator end()
Returns a mutable iterator to the end of the meta info entries.
Definition MetaInfo.h:167
Size size() const
Returns the number of meta value entries.
Definition MetaInfo.h:174
const_iterator end() const
Returns a const iterator to the end of the meta info entries.
Definition MetaInfo.h:142
iterator begin()
Returns a mutable iterator to the beginning of the meta info entries.
Definition MetaInfo.h:161
bool exists(UInt index) const
Returns whether an entry with the given index exists.
MapType::iterator iterator
Mutable iterator type.
Definition MetaInfo.h:50
A more convenient string class.
Definition String.h:34
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::size_t hash_int(T value) noexcept
Hash for an integer type.
Definition HashUtils.h:107
void hash_combine(std::size_t &seed, std::size_t value) noexcept
Combine a hash value with additional data using golden ratio mixing.
Definition HashUtils.h:87
STL namespace.
std::size_t operator()(const OpenMS::MetaInfo &mi) const noexcept
Definition MetaInfo.h:196