Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_CONCEPT_UNIQUEIDINTERFACE_H
00036 #define OPENMS_CONCEPT_UNIQUEIDINTERFACE_H
00037
00038 #include <OpenMS/CONCEPT/UniqueIdGenerator.h>
00039
00040 namespace OpenMS
00041 {
00042
00051 class OPENMS_DLLAPI UniqueIdInterface
00052 {
00053 public:
00054
00059 enum
00060 {
00061 INVALID = 0
00062 };
00063
00068 inline static bool
00069 isValid(UInt64 unique_id)
00070 {
00071 return unique_id != INVALID;
00072 }
00073
00075 UniqueIdInterface() :
00076 unique_id_(UInt64(INVALID))
00077 {
00078
00079 }
00080
00082 UniqueIdInterface(const UniqueIdInterface & rhs) :
00083 unique_id_(rhs.unique_id_)
00084 {
00085 }
00086
00088 UniqueIdInterface &
00089 operator=(UniqueIdInterface const & rhs)
00090 {
00091 unique_id_ = rhs.unique_id_;
00092 return *this;
00093 }
00094
00096 ~UniqueIdInterface()
00097 {
00098 }
00099
00101 bool
00102 operator==(UniqueIdInterface const & rhs) const
00103 {
00104 return unique_id_ == rhs.unique_id_;
00105 }
00106
00108 UInt64
00109 getUniqueId() const
00110 {
00111 return unique_id_;
00112 }
00113
00115 Size
00116 clearUniqueId()
00117 {
00118 if (hasValidUniqueId())
00119 {
00120 unique_id_ = 0;
00121 return 1;
00122 }
00123 else
00124 return 0;
00125 }
00126
00127 void
00128 swap(UniqueIdInterface & from)
00129 {
00130 std::swap(unique_id_, from.unique_id_);
00131 return;
00132 }
00133
00135 Size
00136 hasValidUniqueId() const
00137 {
00138 return isValid(unique_id_);
00139 }
00140
00142 Size
00143 hasInvalidUniqueId() const
00144 {
00145 return !isValid(unique_id_);
00146 }
00147
00149 Size
00150 setUniqueId()
00151 {
00152 unique_id_ = UniqueIdGenerator::getUniqueId();
00153 return 1;
00154 }
00155
00157 Size
00158 ensureUniqueId()
00159 {
00160 if (!hasValidUniqueId())
00161 {
00162 unique_id_ = UniqueIdGenerator::getUniqueId();
00163 return 1;
00164 }
00165 else
00166 return 0;
00167 }
00168
00170 void
00171 setUniqueId(UInt64 rhs)
00172 {
00173 unique_id_ = rhs;
00174 }
00175
00183 void
00184 setUniqueId(const String & rhs);
00185
00186 protected:
00188 UInt64 unique_id_;
00189
00190 };
00191
00192 }
00193
00194 #endif // OPENMS_CONCEPT_UNIQUEIDINTERFACE_H