All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
70  {
71  // index_to_value_.insert(rhs.index_to_value_.begin(), rhs.index_to_value_.end()); // does not overwrite existing data
72  for (const auto& kv : rhs.index_to_value_)
73  {
74  index_to_value_[kv.first] = kv.second;
75  }
76  return *this;
77  }
78 
80  const DataValue& getValue(const String& name, const DataValue& default_value = DataValue::EMPTY) const;
82  const DataValue& getValue(UInt index, const DataValue& default_value = DataValue::EMPTY) const;
83 
85  bool exists(const String& name) const;
87  bool exists(UInt index) const;
88 
90  void setValue(const String& name, const DataValue& value);
92  void setValue(UInt index, const DataValue& value);
93 
95  void removeValue(const String& name);
97  void removeValue(UInt index);
98 
101 
103  void getKeys(std::vector<String>& keys) const;
104 
106  void getKeys(std::vector<UInt>& keys) const;
107 
109  bool empty() const;
110 
112  void clear();
113 
114 private:
115  using MapType = boost::container::flat_map<UInt, DataValue>;
116 
119 
122  };
123 
124 } // namespace OpenMS
125 
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:121
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:115
MetaInfo & operator+=(const MetaInfo &rhs)
Definition: MetaInfo.h:69
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:118
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