OpenMS
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 
13 #include <OpenMS/CONCEPT/Types.h>
16 
17 #include <boost/container/flat_map.hpp>
18 
19 namespace OpenMS
20 {
21  class String;
22 
42  class OPENMS_DLLAPI MetaInfo
43  {
44 public:
46  MetaInfo() = default;
47 
49  MetaInfo(const MetaInfo&) = default;
50 
52  MetaInfo(MetaInfo&&) = default;
53 
56 
58  MetaInfo& operator=(const MetaInfo&) = default;
60  MetaInfo& operator=(MetaInfo&&) & = default;
61 
63  bool operator==(const MetaInfo& rhs) const;
65  bool operator!=(const MetaInfo& rhs) const;
66 
68  const DataValue& getValue(const String& name, const DataValue& default_value = DataValue::EMPTY) const;
70  const DataValue& getValue(UInt index, const DataValue& default_value = DataValue::EMPTY) const;
71 
73  bool exists(const String& name) const;
75  bool exists(UInt index) const;
76 
78  void setValue(const String& name, const DataValue& value);
80  void setValue(UInt index, const DataValue& value);
81 
83  void removeValue(const String& name);
85  void removeValue(UInt index);
86 
89 
91  void getKeys(std::vector<String>& keys) const;
92 
94  void getKeys(std::vector<UInt>& keys) const;
95 
97  bool empty() const;
98 
100  void clear();
101 
102 private:
103  using MapType = boost::container::flat_map<UInt, DataValue>;
104 
107 
110  };
111 
112 } // namespace OpenMS
113 
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:33
static const DataValue EMPTY
Empty data value for comparisons.
Definition: DataValue.h:38
Registry which assigns unique integer indices to strings.
Definition: MetaInfoRegistry.h:50
A Type-Name-Value tuple class.
Definition: MetaInfo.h:43
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 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...
MetaInfo(const MetaInfo &)=default
Copy constructor.
bool operator!=(const MetaInfo &rhs) const
Equality operator.
~MetaInfo()
Destructor.
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.
MapType index_to_value_
The actual mapping of indexes to values.
Definition: MetaInfo.h:109
void getKeys(std::vector< String > &keys) const
Fills the given vector with a list of all keys for which a value is set.
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
Definition: MetaInfo.h:103
MetaInfo()=default
Constructor.
void setValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
static MetaInfoRegistry & registry()
Returns a reference to the MetaInfoRegistry.
MetaInfo(MetaInfo &&)=default
Move constructor.
static MetaInfoRegistry registry_
Static MetaInfoRegistry.
Definition: MetaInfo.h:106
void clear()
Removes all meta values.
MetaInfo & operator=(const MetaInfo &)=default
Assignment operator.
MetaInfo & operator=(MetaInfo &&) &=default
Move assignment operator.
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...
bool exists(UInt index) const
Returns whether an entry with the given index exists.
A more convenient string class.
Definition: String.h:34
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19