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
34 class OPENMS_DLLAPI MetaInfoInterface
35 {
36public:
44
46 MetaInfoInterface() = default;
53
55 MetaInfoInterface& operator=(const MetaInfoInterface& rhs);
57 MetaInfoInterface& operator=(MetaInfoInterface&&) noexcept;
58
60 void swap(MetaInfoInterface& rhs);
61
63 bool operator==(const MetaInfoInterface& rhs) const;
65 bool operator!=(const MetaInfoInterface& rhs) const;
66
68 const DataValue& getMetaValue(const std::string& name) const;
69
71 DataValue getMetaValue(const std::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)
72
74 const DataValue& getMetaValue(UInt index) const;
75
77 DataValue getMetaValue(UInt index, const DataValue& default_value) const; // Note: return needs to be by value to prevent life-time issues at caller site
78
80 bool metaValueExists(const std::string& name) const;
82 bool metaValueExists(UInt index) const;
83
85 void setMetaValue(const std::string& name, const DataValue& value);
87 void setMetaValue(UInt index, const DataValue& value);
88
90 void removeMetaValue(const std::string& name);
92 void removeMetaValue(UInt index);
93
96 void addMetaValues(const MetaInfoInterface& from);
97
99 static MetaInfoRegistry& metaRegistry();
100
102 void getKeys(std::vector<std::string>& keys) const;
103
105 void getKeys(std::vector<UInt>& keys) const;
106
108 bool isMetaEmpty() const;
109
111 void clearMetaInfo();
112
119
128 MetaInfoConstIterator metaBegin() const;
129
135 MetaInfoConstIterator metaEnd() const;
136
142 Size metaSize() const;
144
145protected:
146
148 inline void createIfNotExists_();
149
151 MetaInfo* meta_ = nullptr;
152 };
153
154} // namespace OpenMS
155
156// Hash function specialization for MetaInfoInterface
157namespace std
158{
169 template<>
170 struct hash<OpenMS::MetaInfoInterface>
171 {
172 std::size_t operator()(const OpenMS::MetaInfoInterface& meta) const noexcept
173 {
174 std::size_t hash = 0;
175 // Iterate directly over the underlying flat_map entries
176 for (auto it = meta.metaBegin(); it != meta.metaEnd(); ++it)
177 {
178 std::size_t pair_hash = OpenMS::hash_int(static_cast<int64_t>(it->first));
179 OpenMS::hash_combine(pair_hash, std::hash<OpenMS::DataValue>{}(it->second));
180 hash += pair_hash; // Order-independent accumulation
181 }
182 return hash;
183 }
184 };
185} // namespace std
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition DataValue.h:32
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:35
MetaInfoInterface(MetaInfoInterface &&) noexcept
Move constructor.
MetaInfo::const_iterator MetaInfoConstIterator
Const iterator type for iterating over meta info entries.
Definition MetaInfoInterface.h:43
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:44
MapType::const_iterator const_iterator
Const iterator type.
Definition MetaInfo.h:51
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:172