src/Base.cpp
author jbm@humility
Mon Sep 28 23:39:08 2009 -0700 (2009-09-28)
changeset 8 21a6c17f4e3e
parent 0 31a43d94cc26
permissions -rw-r--r--
jbm: it compiles... but bombs in unit tests
     1 /*
     2  *  Base.cpp
     3  *  Ottoman
     4  *
     5  *  Created by Jens Alfke on 8/18/09.
     6  *  Copyright 2009 Jens Alfke. All rights reserved.
     7  *  BSD-Licensed: See the file "LICENSE.txt" for details.
     8  */
     9 
    10 #include "Base.h"
    11 #include "File.h"
    12 #include <assert.h>
    13 #include <errno.h>
    14 
    15 #if USE_REMOVED_UUID
    16 #include <CoreFoundation/CFUUID.h>
    17 #endif
    18 
    19 namespace Mooseyard {
    20     
    21 #pragma mark -
    22 #pragma mark BLOB:
    23     
    24     Blob::Blob (const char *str)
    25         :bytes(str),
    26          length(str ?strlen(str) :0)
    27     { }
    28     
    29     /*
    30      struct MutableBlob :public Blob {
    31          MutableBlob(void *b, size_t len)                        :Blob(b,len) { }
    32          void* mutableBytes()                                    {return (void*)bytes;}
    33          void freeBytes()                                        {::free(mutableBytes()); bytes=NULL; length=0;}
    34      };
    35      MutableBlob Blob::copyBytes() const {
    36         MutableBlob copy( malloc(length), length);
    37         memcpy(copy.mutableBytes(), bytes, length);
    38         return copy;
    39     }
    40     */
    41         
    42 #pragma mark -
    43 #pragma mark UUID:
    44   
    45 #if USE_REMOVED_UUID
    46     /** Typical 128-bit universally-unique identifier. */
    47     class UUID {
    48     public:
    49         UUID();
    50         const void *bytes() const                           {return _bytes;}
    51         bool operator== (const UUID&) const;
    52     private:
    53         uint8_t _bytes[16];
    54     };
    55     
    56     
    57     UUID::UUID() {
    58         CFUUIDRef u = CFUUIDCreate(NULL);
    59         CFUUIDBytes bytes = CFUUIDGetUUIDBytes(u);
    60         memcpy(&_bytes, &bytes, sizeof(_bytes));
    61         CFRelease(u);
    62     }
    63 
    64     bool UUID::operator== (const UUID& u) const {
    65         return memcmp(_bytes, u._bytes, sizeof(_bytes)) == 0;
    66     }
    67 #endif
    68     
    69 }