Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
UniqueIdInterface.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_CONCEPT_UNIQUEIDINTERFACE_H
36 #define OPENMS_CONCEPT_UNIQUEIDINTERFACE_H
37 
40 
41 namespace OpenMS
42 {
43 
52  class OPENMS_DLLAPI UniqueIdInterface
53  {
54 public:
55 
60  enum
61  {
62  INVALID = 0
63  };
64 
69  inline static bool
70  isValid(UInt64 unique_id)
71  {
72  return unique_id != INVALID;
73  }
74 
77  unique_id_(UInt64(INVALID))
78  {
79  //do not use clearUniqueId(), as it will be slower and creates a warranted valgrind warning;
80  }
81 
84  unique_id_(rhs.unique_id_)
85  {
86  }
87 
91  {
92  unique_id_ = rhs.unique_id_;
93  return *this;
94  }
95 
98  {
99  }
100 
102  bool
103  operator==(UniqueIdInterface const & rhs) const
104  {
105  return unique_id_ == rhs.unique_id_;
106  }
107 
109  UInt64
110  getUniqueId() const
111  {
112  return unique_id_;
113  }
114 
116  Size
118  {
119  if (hasValidUniqueId())
120  {
121  unique_id_ = 0;
122  return 1;
123  }
124  else
125  return 0;
126  }
127 
128  void
130  {
131  std::swap(unique_id_, from.unique_id_);
132  return;
133  }
134 
136  Size
138  {
139  return isValid(unique_id_);
140  }
141 
143  Size
145  {
146  return !isValid(unique_id_);
147  }
148 
150  Size
152  {
153  unique_id_ = UniqueIdGenerator::getUniqueId();
154  return 1;
155  }
156 
158  Size
160  {
161  if (!hasValidUniqueId())
162  {
163  unique_id_ = UniqueIdGenerator::getUniqueId();
164  return 1;
165  }
166  else
167  return 0;
168  }
169 
171  void
173  {
174  unique_id_ = rhs;
175  }
176 
184  void
185  setUniqueId(const String & rhs);
186 
187 protected:
190 
191  };
192 
193 } //namespace OpenMS
194 
195 #endif // OPENMS_CONCEPT_UNIQUEIDINTERFACE_H
A more convenient string class.
Definition: String.h:57
Size setUniqueId()
Assigns a new, valid unique id. Always returns 1.
Definition: UniqueIdInterface.h:151
UniqueIdInterface()
Default constructor - the unique id will be invalid
Definition: UniqueIdInterface.h:76
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Size clearUniqueId()
Clear the unique id. The new unique id will be invalid. Returns 1 if the unique id was changed...
Definition: UniqueIdInterface.h:117
Size hasInvalidUniqueId() const
Returns whether the unique id is invalid. Returns 1 if the unique id is invalid, 0 otherwise...
Definition: UniqueIdInterface.h:144
static bool isValid(UInt64 unique_id)
Returns true if the unique_id is valid, false otherwise.
Definition: UniqueIdInterface.h:70
void setUniqueId(UInt64 rhs)
Assigns the given unique id.
Definition: UniqueIdInterface.h:172
static UInt64 getUniqueId()
Returns a new unique id.
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:78
UniqueIdInterface(const UniqueIdInterface &rhs)
Copy constructor - copies the unique id.
Definition: UniqueIdInterface.h:83
A base class defining a common interface for all classes having a unique id.
Definition: UniqueIdInterface.h:52
bool operator==(UniqueIdInterface const &rhs) const
Equality comparison operator - the unique ids must be equal (!)
Definition: UniqueIdInterface.h:103
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
UInt64 unique_id_
the unique id
Definition: UniqueIdInterface.h:189
virtual ~UniqueIdInterface()
Destructor.
Definition: UniqueIdInterface.h:97
void swap(UniqueIdInterface &from)
Definition: UniqueIdInterface.h:129
UniqueIdInterface & operator=(UniqueIdInterface const &rhs)
Assignment operator - copies the unique id.
Definition: UniqueIdInterface.h:90
Size hasValidUniqueId() const
Returns whether the unique id is valid. Returns 1 if the unique id is valid, 0 otherwise.
Definition: UniqueIdInterface.h:137
UInt64 getUniqueId() const
Non-mutable access to unique id - returns the unique id.
Definition: UniqueIdInterface.h:110
Size ensureUniqueId()
Assigns a valid unique id, but only if the present one is invalid. Returns 1 if the unique id was cha...
Definition: UniqueIdInterface.h:159

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:04 using doxygen 1.8.13