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
13#include <string>
14#include <utility>
15
16namespace OpenMS
17{
18
27 class OPENMS_DLLAPI UniqueIdInterface
28 {
29public:
30
35 enum
36 {
37 INVALID = 0
38 };
39
44 inline static bool
45 isValid(UInt64 unique_id)
46 {
47 return unique_id != INVALID;
48 }
49
52 unique_id_(UInt64(INVALID))
53 {
54 //do not use clearUniqueId(), as it will be slower and creates a warranted valgrind warning;
55 }
56
58 UniqueIdInterface(const UniqueIdInterface & rhs) = default;
59
62
65
68
70 virtual ~UniqueIdInterface() = default;
71
73 bool
74 operator==(UniqueIdInterface const & rhs) const
75 {
76 return unique_id_ == rhs.unique_id_;
77 }
78
80 UInt64
82 {
83 return unique_id_;
84 }
85
87 Size
89 {
90 if (hasValidUniqueId())
91 {
92 unique_id_ = 0;
93 return 1;
94 }
95 else
96 return 0;
97 }
98
99 void
101 {
102 std::swap(unique_id_, from.unique_id_);
103 return;
104 }
105
107 Size
109 {
110 return isValid(unique_id_);
111 }
112
114 Size
116 {
117 return !isValid(unique_id_);
118 }
119
121 Size
123
125 Size
127
129 void
131 {
132 unique_id_ = rhs;
133 }
134
142 void
143 setUniqueId(const std::string & rhs);
144
145protected:
148
149 };
150
151} //namespace OpenMS
152
A base class defining a common interface for all classes having a unique id.
Definition UniqueIdInterface.h:28
UniqueIdInterface()
Default constructor - the unique id will be invalid
Definition UniqueIdInterface.h:51
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:147
void setUniqueId(UInt64 rhs)
Assigns the given unique id.
Definition UniqueIdInterface.h:130
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:108
UInt64 getUniqueId() const
Non-mutable access to unique id - returns the unique id.
Definition UniqueIdInterface.h:81
Size hasInvalidUniqueId() const
Returns whether the unique id is invalid. Returns 1 if the unique id is invalid, 0 otherwise.
Definition UniqueIdInterface.h:115
void setUniqueId(const std::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:45
UniqueIdInterface(const UniqueIdInterface &rhs)=default
Copy constructor - copies the unique id.
void swap(UniqueIdInterface &from)
Definition UniqueIdInterface.h:100
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:88
bool operator==(UniqueIdInterface const &rhs) const
Equality comparison operator - the unique ids must be equal (!)
Definition UniqueIdInterface.h:74
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