src/Base.cpp
author Jens Alfke <jens@mooseyard.com>
Sun Sep 20 15:14:12 2009 -0700 (2009-09-20)
changeset 0 31a43d94cc26
child 8 21a6c17f4e3e
permissions -rw-r--r--
First official checkin.
     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 #include <CoreFoundation/CFUUID.h>
    15 
    16 namespace Mooseyard {
    17     
    18 #pragma mark -
    19 #pragma mark BLOB:
    20     
    21     Blob::Blob (const char *str)
    22         :bytes(str),
    23          length(str ?strlen(str) :0)
    24     { }
    25     
    26     /*
    27      struct MutableBlob :public Blob {
    28          MutableBlob(void *b, size_t len)                        :Blob(b,len) { }
    29          void* mutableBytes()                                    {return (void*)bytes;}
    30          void freeBytes()                                        {::free(mutableBytes()); bytes=NULL; length=0;}
    31      };
    32      MutableBlob Blob::copyBytes() const {
    33         MutableBlob copy( malloc(length), length);
    34         memcpy(copy.mutableBytes(), bytes, length);
    35         return copy;
    36     }
    37     */
    38         
    39 #pragma mark -
    40 #pragma mark UUID:
    41   
    42 #if 0
    43     /** Typical 128-bit universally-unique identifier. */
    44     class UUID {
    45     public:
    46         UUID();
    47         const void *bytes() const                           {return _bytes;}
    48         bool operator== (const UUID&) const;
    49     private:
    50         uint8_t _bytes[16];
    51     };
    52     
    53     
    54     UUID::UUID() {
    55         CFUUIDRef u = CFUUIDCreate(NULL);
    56         CFUUIDBytes bytes = CFUUIDGetUUIDBytes(u);
    57         memcpy(&_bytes, &bytes, sizeof(_bytes));
    58         CFRelease(u);
    59     }
    60 
    61     bool UUID::operator== (const UUID& u) const {
    62         return memcmp(_bytes, u._bytes, sizeof(_bytes)) == 0;
    63     }
    64 #endif
    65     
    66 }