"Fossies" - the Fresh Open Source Software Archive

Member "netxms-3.8.166/include/uuid.h" (23 Feb 2021, 2482 Bytes) of package /linux/misc/netxms-3.8.166.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "uuid.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Public include file for the UUID library
    3  * 
    4  * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
    5  *
    6  * %Begin-Header%
    7  * This file may be redistributed under the terms of the GNU 
    8  * Library General Public License.
    9  * %End-Header%
   10  */
   11 
   12 #ifndef _UUID_H_
   13 #define _UUID_H_
   14 
   15 #define UUID_LENGTH     16
   16 
   17 #if !HAVE_UUID_T
   18 #undef uuid_t
   19 typedef unsigned char uuid_t[UUID_LENGTH];
   20 #endif
   21 
   22 /* UUID Variant definitions */
   23 #define UUID_VARIANT_NCS         0
   24 #define UUID_VARIANT_DCE         1
   25 #define UUID_VARIANT_MICROSOFT   2
   26 #define UUID_VARIANT_OTHER       3
   27 
   28 void LIBNETXMS_EXPORTABLE _uuid_clear(uuid_t uu);
   29 int LIBNETXMS_EXPORTABLE _uuid_compare(const uuid_t uu1, const uuid_t uu2);
   30 void LIBNETXMS_EXPORTABLE _uuid_generate(uuid_t out);
   31 bool LIBNETXMS_EXPORTABLE _uuid_is_null(const uuid_t uu);
   32 int LIBNETXMS_EXPORTABLE _uuid_parse(const TCHAR *in, uuid_t uu);
   33 TCHAR LIBNETXMS_EXPORTABLE *_uuid_to_string(const uuid_t uu, TCHAR *out);
   34 #ifdef UNICODE
   35 char LIBNETXMS_EXPORTABLE *_uuid_to_stringA(const uuid_t uu, char *out);
   36 #else
   37 #define _uuid_to_stringA _uuid_to_string
   38 #endif
   39 
   40 #ifdef __cplusplus
   41 
   42 /**
   43  * Wrapper class for UUID
   44  * Lower case used to avoid conflict with UUID struct defined in Windows headers
   45  */
   46 class LIBNETXMS_EXPORTABLE uuid
   47 {
   48 private:
   49    uuid_t m_value;
   50 
   51 public:
   52    uuid() { _uuid_clear(m_value); }
   53    uuid(const uuid_t v) { memcpy(m_value, v, UUID_LENGTH); }
   54 
   55    int compare(const uuid& u) const { return _uuid_compare(m_value, u.m_value); }
   56    bool equals(const uuid& u) const { return _uuid_compare(m_value, u.m_value) == 0; }
   57    const uuid_t& getValue() const { return m_value; }
   58    bool isNull() const { return _uuid_is_null(m_value); }
   59    TCHAR *toString(TCHAR *buffer) const { return _uuid_to_string(m_value, buffer); }
   60    String toString() const { TCHAR buffer[64]; return String(_uuid_to_string(m_value, buffer)); }
   61    char *toStringA(char *buffer) const { return _uuid_to_stringA(m_value, buffer); }
   62    json_t *toJson() const { char buffer[64]; return json_string(toStringA(buffer)); }
   63 
   64    operator const uuid_t&() const { return m_value; }
   65 
   66    /**
   67     * Generate new UUID
   68     */
   69    static uuid generate() 
   70    { 
   71       uuid_t u;
   72       _uuid_generate(u);
   73       return uuid(u);
   74    }
   75 
   76    /**
   77     * Parse string into UUID. Returns NULL UUID on error.
   78     */
   79    static uuid parse(const TCHAR *s)
   80    {
   81       uuid_t u;
   82       if (_uuid_parse(s, u) != 0)
   83          return NULL_UUID;
   84       return uuid(u);
   85    }
   86 
   87    static const uuid NULL_UUID;
   88 };
   89 
   90 #endif
   91 
   92 #endif