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