OpenMS
Loading...
Searching...
No Matches
CVTerm.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: Andreas Bertsch $
7// --------------------------------------------------------------------------
8
9#pragma once
10
14
15namespace OpenMS
16{
17
27 class OPENMS_DLLAPI CVTerm
28 {
29public:
30
31 struct Unit
32 {
33
35 Unit() = default;
36
37 Unit(const String& p_accession, const String& p_name, const String& p_cv_ref) :
38 accession(p_accession),
39 name(p_name),
40 cv_ref(p_cv_ref)
41 {
42 }
43
45 Unit(const Unit &) = default;
46
48 Unit(Unit&&) = default;
49
51 virtual ~Unit()
52 {
53 }
54
56 Unit& operator=(const Unit&) = default;
57
59 Unit& operator=(Unit&&)& = default;
60
61 bool operator==(const Unit& rhs) const
62 {
63 return accession == rhs.accession &&
64 name == rhs.name &&
65 cv_ref == rhs.cv_ref;
66 }
67
68 bool operator!=(const Unit& rhs) const
69 {
70 return !(*this == rhs);
71 }
72
76 };
77
79 CVTerm() = default;
80
82 CVTerm(const String& accession, const String& name = "", const String& cv_identifier_ref = "", const String& value = "", const Unit& unit = Unit());
83
85 CVTerm(const CVTerm&) = default;
86
88 CVTerm(CVTerm&&) = default;
89
91 virtual ~CVTerm();
92
94 CVTerm& operator=(const CVTerm&) = default;
95
97 CVTerm& operator=(CVTerm&&)& = default;
98
103 void setAccession(const String& accession);
104
106 const String& getAccession() const;
107
109 void setName(const String& name);
110
112 const String& getName() const;
113
115 void setCVIdentifierRef(const String& cv_identifier_ref);
116
119
121 void setValue(const DataValue& value);
122
124 const DataValue& getValue() const;
125
127 void setUnit(const Unit& unit);
128
130 const Unit& getUnit() const;
132
137 bool operator==(const CVTerm& rhs) const;
138
140 bool operator!=(const CVTerm& rhs) const;
141
143 bool hasValue() const;
144
146 bool hasUnit() const;
147 //}
148
149protected:
150
152
154
156
158
160 };
161
162} // namespace OpenMS
163
164// Hash function specializations for CVTerm and CVTerm::Unit
165namespace std
166{
172 template<>
173 struct hash<OpenMS::CVTerm::Unit>
174 {
175 std::size_t operator()(const OpenMS::CVTerm::Unit& unit) const noexcept
176 {
177 std::size_t seed = 0;
178 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(unit.accession));
181 return seed;
182 }
183 };
184
191 template<>
192 struct hash<OpenMS::CVTerm>
193 {
194 std::size_t operator()(const OpenMS::CVTerm& term) const noexcept
195 {
196 std::size_t seed = 0;
197 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(term.getAccession()));
198 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(term.getName()));
199 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(term.getCVIdentifierRef()));
200 OpenMS::hash_combine(seed, std::hash<OpenMS::CVTerm::Unit>{}(term.getUnit()));
201 OpenMS::hash_combine(seed, std::hash<OpenMS::DataValue>{}(term.getValue()));
202 return seed;
203 }
204 };
205} // namespace std
206
Representation of controlled vocabulary term.
Definition CVTerm.h:28
bool operator==(const CVTerm &rhs) const
equality operator
const Unit & getUnit() const
returns the unit
virtual ~CVTerm()
Destructor.
void setUnit(const Unit &unit)
sets the unit of the term
Unit unit_
Definition CVTerm.h:157
String name_
Definition CVTerm.h:153
DataValue value_
Definition CVTerm.h:159
CVTerm(const CVTerm &)=default
Copy constructor.
CVTerm(CVTerm &&)=default
Move constructor.
const DataValue & getValue() const
returns the value of the term
void setCVIdentifierRef(const String &cv_identifier_ref)
sets the cv identifier reference string, e.g. UO for unit obo
void setName(const String &name)
sets the name of the term
void setValue(const DataValue &value)
set the value of the term
CVTerm & operator=(CVTerm &&) &=default
Move assignment operator.
const String & getName() const
returns the name of the term
String accession_
Definition CVTerm.h:151
CVTerm & operator=(const CVTerm &)=default
Assignment operator.
void setAccession(const String &accession)
sets the accession string of the term
bool hasUnit() const
checks whether the term has a unit
const String & getCVIdentifierRef() const
returns the cv identifier reference string
const String & getAccession() const
returns the accession string of the term
bool operator!=(const CVTerm &rhs) const
inequality operator
String cv_identifier_ref_
Definition CVTerm.h:155
bool hasValue() const
checks whether the term has a value
CVTerm()=default
Default constructor.
CVTerm(const String &accession, const String &name="", const String &cv_identifier_ref="", const String &value="", const Unit &unit=Unit())
Detailed constructor.
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition DataValue.h:34
A more convenient string class.
Definition String.h:34
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
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
std::size_t fnv1a_hash_string(const std::string &s) noexcept
FNV-1a hash for a string.
Definition HashUtils.h:70
STL namespace.
Definition CVTerm.h:32
bool operator!=(const Unit &rhs) const
Definition CVTerm.h:68
Unit & operator=(const Unit &)=default
Assignment operator.
Unit()=default
Default constructor.
String cv_ref
Definition CVTerm.h:75
virtual ~Unit()
Destructor.
Definition CVTerm.h:51
String name
Definition CVTerm.h:74
String accession
Definition CVTerm.h:73
Unit(const String &p_accession, const String &p_name, const String &p_cv_ref)
Definition CVTerm.h:37
Unit & operator=(Unit &&) &=default
Move assignment operator.
Unit(Unit &&)=default
Move constructor.
bool operator==(const Unit &rhs) const
Definition CVTerm.h:61
Unit(const Unit &)=default
Copy constructor.
std::size_t operator()(const OpenMS::CVTerm &term) const noexcept
Definition CVTerm.h:194
std::size_t operator()(const OpenMS::CVTerm::Unit &unit) const noexcept
Definition CVTerm.h:175