OpenMS
Loading...
Searching...
No Matches
CVTermList.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: Mathias Walzer $
6// $Authors: Andreas Bertsch, Mathias Walzer $
7// --------------------------------------------------------------------------
8
9#pragma once
10
14#include <map>
15
16namespace OpenMS
17{
27 class OPENMS_DLLAPI CVTermList :
29 {
30public:
31
33 CVTermList() = default;
34
36 CVTermList(const CVTermList&) = default;
37
38 // note: we implement the move constructor ourselves due to a bug in MSVS
39 // 2015/2017 which cannot produce a default move constructor for classes
40 // that contain STL containers (other than vector).
41
44
46 virtual ~CVTermList();
47
49 CVTermList& operator=(const CVTermList& rhs) & = default;
50
52 CVTermList& operator=(CVTermList&&) & = default;
53
58 void setCVTerms(const std::vector<CVTerm>& terms);
59
61 void replaceCVTerm(const CVTerm& cv_term);
62
64 void replaceCVTerms(const std::vector<CVTerm>& cv_terms, const std::string& accession);
65
67 void replaceCVTerms(const std::map<std::string, std::vector<CVTerm> >& cv_term_map);
68
70 void consumeCVTerms(const std::map<std::string, std::vector<CVTerm> >& cv_term_map);
71
73 const std::map<std::string, std::vector<CVTerm> >& getCVTerms() const;
74
76 void addCVTerm(const CVTerm& term);
77
79 //bool checkCVTerms(const ControlledVocabulary& cv) const;
80
82 //void correctCVTermNames();
84
89 bool operator==(const CVTermList& cv_term_list) const;
90
92 bool operator!=(const CVTermList& cv_term_list) const;
93
95 bool hasCVTerm(const std::string& accession) const;
96
99 //bool checkCVTerms(const CVMappingRule & rule, const ControlledVocabulary & cv) const;
100
102 bool empty() const;
103 //}
104
105protected:
106
107 std::map<std::string, std::vector<CVTerm> > cv_terms_;
108
109 };
110
112 template<typename T>
113 inline std::size_t hashCVTerms(const T& obj) noexcept
114 {
115 std::size_t seed = 0;
116 const auto& cv_terms = obj.getCVTerms();
117 for (const auto& [accession, terms] : cv_terms)
118 {
119 hash_combine(seed, fnv1a_hash_string(accession));
120 for (const auto& term : terms)
121 {
122 hash_combine(seed, fnv1a_hash_string(term.getAccession()));
123 hash_combine(seed, fnv1a_hash_string(term.getName()));
124 hash_combine(seed, fnv1a_hash_string(term.getCVIdentifierRef()));
125 if (term.hasValue())
126 {
127 hash_combine(seed, fnv1a_hash_string(term.getValue().toString()));
128 }
129 if (term.hasUnit())
130 {
131 hash_combine(seed, fnv1a_hash_string(term.getUnit().accession));
132 }
133 }
134 }
135 return seed;
136 }
137
138 // Convenience wrappers for backward compatibility
139 inline std::size_t hashCVTermList(const CVTermList& cvtl) noexcept { return hashCVTerms(cvtl); }
140
141} // namespace OpenMS
142
143// Hash function specialization for CVTermList
144namespace std
145{
156 template<>
157 struct hash<OpenMS::CVTermList>
158 {
159 std::size_t operator()(const OpenMS::CVTermList& list) const noexcept
160 {
161 // Start with MetaInfoInterface base class hash
162 std::size_t seed = std::hash<OpenMS::MetaInfoInterface>{}(list);
163
164 // Hash all CV terms
165 for (const auto& entry : list.getCVTerms())
166 {
167 // Hash the accession string
169 // Hash each CV term in the vector
170 for (const auto& term : entry.second)
171 {
172 OpenMS::hash_combine(seed, std::hash<OpenMS::CVTerm>{}(term));
173 }
174 }
175 return seed;
176 }
177 };
178} // namespace std
179
Representation of controlled vocabulary term list.
Definition CVTermList.h:29
CVTermList()=default
Defaults constructor.
CVTermList(const CVTermList &)=default
Copy constructor.
CVTermList(CVTermList &&) noexcept
Move constructor.
Representation of controlled vocabulary term.
Definition CVTerm.h:28
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:35
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::size_t hashCVTermList(const CVTermList &cvtl) noexcept
Definition CVTermList.h:139
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
std::size_t hashCVTerms(const T &obj) noexcept
Helper template to hash any type with getCVTerms() method (CVTermList, CVTermListInterface)
Definition CVTermList.h:113
STL namespace.
std::size_t operator()(const OpenMS::CVTermList &list) const noexcept
Definition CVTermList.h:159