PseudoUuid.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/common/PseudoUuid.h#14 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #ifndef Fennel_PseudoUuid_Included
00025 #define Fennel_PseudoUuid_Included
00026 
00027 #include "fennel/common/FennelExcn.h"
00028 
00029 #if defined(HAVE_LIBUUID) || defined(HAVE_LIBUUID_NEW)
00030 
00031 #ifdef HAVE_UUID_UUID_H
00032 #include <uuid/uuid.h>
00033 #define FENNEL_UUID_REAL
00034 #endif
00035 
00036 #ifdef HAVE_UUID_H
00037 #include <uuid.h>
00038 #define FENNEL_UUID_REAL_NEW
00039 #endif
00040 
00041 // REVIEW: SWZ: 9/23/2006: It's possible to HAVE_LIBUUID but not either version
00042 // of uuid.h.  Should probably detect and use a #error (or something) here.
00043 
00044 #else
00045 
00046 #define FENNEL_UUID_FAKE
00047 
00048 #endif
00049 
00050 FENNEL_BEGIN_NAMESPACE
00051 
00058 class FENNEL_COMMON_EXPORT PseudoUuid
00059 {
00060 public:
00061 #ifdef FENNEL_UUID_REAL_NEW
00062     static const int UUID_LENGTH = UUID_LEN_BIN;
00063 #else
00064     static const int UUID_LENGTH = 16;
00065 #endif
00066 
00067 protected:
00068 #ifdef FENNEL_UUID_REAL
00069     uuid_t data;
00070 
00071 #else
00072     /*
00073      * For FENNEL_UUID_REAL_NEW, uuid_t is not longer a concrete type.
00074      * To keep PseudoUuid simple, we use the new API to copy UUIDs into
00075      * our own array.
00076      */
00077     uint8_t data[UUID_LENGTH];
00078 #endif
00079 
00080 public:
00081     explicit PseudoUuid();
00082     PseudoUuid(std::string uuid);
00083 
00084     virtual ~PseudoUuid();
00085 
00089     void generate();
00090 
00094     void generateInvalid();
00095 
00100     std::string toString() const;
00101 
00105     int hashCode() const;
00106 
00107     bool operator == (PseudoUuid const &) const;
00108 
00109     bool operator != (PseudoUuid const &other) const
00110     {
00111         return !(*this == other);
00112     }
00113 
00114     uint8_t getByte(int) const;
00115 
00116     const uint8_t *getBytes() const;
00117 
00125     void parse(std::string uuid) throw(FennelExcn);
00126 };
00127 
00134 class FENNEL_COMMON_EXPORT PseudoUuidGenerator
00135 {
00136 public:
00137     virtual ~PseudoUuidGenerator();
00138 
00144     virtual void generateUuid(PseudoUuid &pseudoUuid);
00145 };
00146 
00147 inline std::ostream &operator<<(std::ostream &str, PseudoUuid const &uuid)
00148 {
00149     str << uuid.toString();
00150     return str;
00151 }
00152 
00153 FENNEL_END_NAMESPACE
00154 
00155 #endif
00156 
00157 // End PseudoUuid.h

Generated on Mon Jun 22 04:00:18 2009 for Fennel by  doxygen 1.5.1