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