Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

UniqueIdInterface.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Clemens Groepl $
00032 // $Authors: $
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       //do not use clearUniqueId(), as it will be slower and creates a warranted valgrind warning;
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 } //namespace OpenMS
00193 
00194 #endif // OPENMS_CONCEPT_UNIQUEIDINTERFACE_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:46 using doxygen 1.7.1