OpenMS
Loading...
Searching...
No Matches
MetaInfoInterface.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
18
19namespace OpenMS
20{
21 class String;
22
35 class OPENMS_DLLAPI MetaInfoInterface
36 {
37public:
45
47 MetaInfoInterface() = default;
54
56 MetaInfoInterface& operator=(const MetaInfoInterface& rhs);
58 MetaInfoInterface& operator=(MetaInfoInterface&&) noexcept;
59
61 void swap(MetaInfoInterface& rhs);
62
64 bool operator==(const MetaInfoInterface& rhs) const;
66 bool operator!=(const MetaInfoInterface& rhs) const;
67
69 const DataValue& getMetaValue(const String& name) const;
70
72 DataValue getMetaValue(const String& name, const DataValue& default_value) const; // Note: return needs to be by value to prevent life-time issues at caller site (e.g. if he passes a temporary to default-value)
73
75 const DataValue& getMetaValue(UInt index) const;
76
78 DataValue getMetaValue(UInt index, const DataValue& default_value) const; // Note: return needs to be by value to prevent life-time issues at caller site
79
81 bool metaValueExists(const String& name) const;
83 bool metaValueExists(UInt index) const;
84
86 void setMetaValue(const String& name, const DataValue& value);
88 void setMetaValue(UInt index, const DataValue& value);
89
91 void removeMetaValue(const String& name);
93 void removeMetaValue(UInt index);
94
97 void addMetaValues(const MetaInfoInterface& from);
98
100 static MetaInfoRegistry& metaRegistry();
101
103 void getKeys(std::vector<String>& keys) const;
104
106 void getKeys(std::vector<UInt>& keys) const;
107
109 bool isMetaEmpty() const;
110
112 void clearMetaInfo();
113
120
129 MetaInfoConstIterator metaBegin() const;
130
136 MetaInfoConstIterator metaEnd() const;
137
143 Size metaSize() const;
145
146protected:
147
149 inline void createIfNotExists_();
150
152 MetaInfo* meta_ = nullptr;
153 };
154
155} // namespace OpenMS
156
157// Hash function specialization for MetaInfoInterface
158namespace std
159{
170 template<>
171 struct hash<OpenMS::MetaInfoInterface>
172 {
173 std::size_t operator()(const OpenMS::MetaInfoInterface& meta) const noexcept
174 {
175 std::size_t hash = 0;
176 // Iterate directly over the underlying flat_map entries
177 for (auto it = meta.metaBegin(); it != meta.metaEnd(); ++it)
178 {
179 std::size_t pair_hash = OpenMS::hash_int(static_cast<int64_t>(it->first));
180 OpenMS::hash_combine(pair_hash, std::hash<OpenMS::DataValue>{}(it->second));
181 hash += pair_hash; // Order-independent accumulation
182 }
183 return hash;
184 }
185 };
186} // namespace std
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition DataValue.h:34
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:36
MetaInfoInterface(MetaInfoInterface &&) noexcept
Move constructor.
MetaInfo::const_iterator MetaInfoConstIterator
Const iterator type for iterating over meta info entries.
Definition MetaInfoInterface.h:44
MetaInfoInterface()=default
Constructor.
MetaInfoInterface(const MetaInfoInterface &rhs)
Copy constructor.
Registry which assigns unique integer indices to strings.
Definition MetaInfoRegistry.h:50
A Type-Name-Value tuple class.
Definition MetaInfo.h:45
MapType::const_iterator const_iterator
Const iterator type.
Definition MetaInfo.h:52
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::MetaInfoInterface &meta) const noexcept
Definition MetaInfoInterface.h:173