00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00042
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
00074
00075
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