OpenMS
Loading...
Searching...
No Matches
UniqueIdInterface.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: $
7// --------------------------------------------------------------------------
8
9#pragma once
10
12
13namespace OpenMS
14{
15
24 class OPENMS_DLLAPI UniqueIdInterface
25 {
26public:
27
32 enum
33 {
34 INVALID = 0
35 };
36
41 inline static bool
42 isValid(UInt64 unique_id)
43 {
44 return unique_id != INVALID;
45 }
46
49 unique_id_(UInt64(INVALID))
50 {
51 //do not use clearUniqueId(), as it will be slower and creates a warranted valgrind warning;
52 }
53
55 UniqueIdInterface(const UniqueIdInterface & rhs) = default;
56
59
62
65
67 virtual ~UniqueIdInterface() = default;
68
70 bool
71 operator==(UniqueIdInterface const & rhs) const
72 {
73 return unique_id_ == rhs.unique_id_;
74 }
75
77 UInt64
79 {
80 return unique_id_;
81 }
82
84 Size
86 {
87 if (hasValidUniqueId())
88 {
89 unique_id_ = 0;
90 return 1;
91 }
92 else
93 return 0;
94 }
95
96 void
98 {
99 std::swap(unique_id_, from.unique_id_);
100 return;
101 }
102
104 Size
106 {
107 return isValid(unique_id_);
108 }
109
111 Size
113 {
114 return !isValid(unique_id_);
115 }
116
118 Size
120
122 Size
124
126 void
128 {
129 unique_id_ = rhs;
130 }
131
139 void
140 setUniqueId(const String & rhs);
141
142protected:
145
146 };
147
148} //namespace OpenMS
149
A more convenient string class.
Definition String.h:34
A base class defining a common interface for all classes having a unique id.
Definition UniqueIdInterface.h:25
UniqueIdInterface()
Default constructor - the unique id will be invalid
Definition UniqueIdInterface.h:48
Size ensureUniqueId()
Assigns a valid unique id, but only if the present one is invalid. Returns 1 if the unique id was cha...
UInt64 unique_id_
the unique id
Definition UniqueIdInterface.h:144
void setUniqueId(UInt64 rhs)
Assigns the given unique id.
Definition UniqueIdInterface.h:127
UniqueIdInterface(UniqueIdInterface &&rhs)=default
Move constructor.
Size hasValidUniqueId() const
Returns whether the unique id is valid. Returns 1 if the unique id is valid, 0 otherwise.
Definition UniqueIdInterface.h:105
UInt64 getUniqueId() const
Non-mutable access to unique id - returns the unique id.
Definition UniqueIdInterface.h:78
Size hasInvalidUniqueId() const
Returns whether the unique id is invalid. Returns 1 if the unique id is invalid, 0 otherwise.
Definition UniqueIdInterface.h:112
void setUniqueId(const String &rhs)
Mutable access to unique id.
virtual ~UniqueIdInterface()=default
Destructor.
UniqueIdInterface & operator=(UniqueIdInterface const &rhs)=default
Assignment operator - copies the unique id.
static bool isValid(UInt64 unique_id)
Returns true if the unique_id is valid, false otherwise.
Definition UniqueIdInterface.h:42
UniqueIdInterface(const UniqueIdInterface &rhs)=default
Copy constructor - copies the unique id.
void swap(UniqueIdInterface &from)
Definition UniqueIdInterface.h:97
Size setUniqueId()
Assigns a new, valid unique id. Always returns 1.
Size clearUniqueId()
Clear the unique id. The new unique id will be invalid. Returns 1 if the unique id was changed,...
Definition UniqueIdInterface.h:85
bool operator==(UniqueIdInterface const &rhs) const
Equality comparison operator - the unique ids must be equal (!)
Definition UniqueIdInterface.h:71
UniqueIdInterface & operator=(UniqueIdInterface &&) &=default
Move Assignment operator - copies the unique id.
uint64_t UInt64
Unsigned integer type (64bit)
Definition Types.h:47
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