Oolite
Loading...
Searching...
No Matches
OOTCPStreamDecoderAbstractionLayer.m
Go to the documentation of this file.
1/* OOTCPStreamDecoderAbstractionLayer.h
2
3 Abstraction layer to allow OOTCPStreamDecoder to work with CoreFoundation/
4 CF-Lite, Cocoa Foundation or GNUstep Foundation.
5
6 Foundation implementation.
7*/
8
9#ifdef OO_DEBUG_MONITOR_ENABLED
10
12#import "OOFoundation.h"
13
14// Simulate literal CF/NS strings. Each literal string that is used becomes a single object. Since it uses pointers as keys, it should only be used with literals.
15OOALStringRef OOALGetConstantString(const char* string)
16{
17 static NSMutableDictionary* sStrings = nil;
18 NSValue* key = nil;
19 NSString* value = nil;
20
21 if (sStrings == nil) {
22 sStrings = [[NSMutableDictionary alloc] init];
23 }
24
25 key = [NSValue valueWithPointer:string];
26 value = [sStrings objectForKey:key];
27 if (value == nil) {
28 // Note: non-ASCII strings are not permitted, but we don't bother to detect them.
29 value = [NSString stringWithUTF8String:string];
30 if (value != nil)
31 [sStrings setObject:value forKey:key];
32 }
33
34 return value;
35}
36
37void OOALRelease(OOALObjectRef object)
38{
39 [object release];
40}
41
43{
44 return [[object class] description];
45}
46
47bool OOALIsString(OOALObjectRef object)
48{
49 return [object isKindOfClass:[NSString class]];
50}
51
53{
54 return [[NSString alloc] initWithFormat:format arguments:args];
55}
56
58{
59 return [object isKindOfClass:[NSDictionary class]];
60}
61
63{
64 return [dictionary objectForKey:key];
65}
66
67bool OOALIsData(OOALObjectRef object)
68{
69 return [object isKindOfClass:[NSData class]];
70}
71
73{
74 return [[NSMutableData alloc] initWithCapacity:capacity];
75}
76
77void OOALMutableDataAppendBytes(OOALMutableDataRef data, const void* bytes, size_t length)
78{
79 [data appendBytes:bytes length:length];
80}
81
82const void* OOALDataGetBytePtr(OOALDataRef data)
83{
84 return [data bytes];
85}
86
88{
89 return [data length];
90}
91
93{
94 return [[NSAutoreleasePool alloc] init];
95}
96
98{
99 id result = [NSPropertyListSerialization propertyListFromData:data
100 mutabilityOption:NSPropertyListImmutable
101 format:NULL
102 errorDescription:errStr];
103 [result retain];
104
105#if !OOLITE_RELEASE_PLIST_ERROR_STRINGS
106 [*errStr retain];
107#endif
108
109 return result;
110}
111
112#endif /* OO_DEBUG_MONITOR_ENABLED */
return nil
OOALStringRef OOTypeDescription(OOALObjectRef object)
bool OOALIsDictionary(OOALObjectRef object)
OOALStringRef OOALStringCreateWithFormatAndArguments(OOALStringRef format, va_list args)
const struct NSAutoreleasePool * OOALAutoreleasePoolRef
void OOALMutableDataAppendBytes(OOALMutableDataRef data, const void *bytes, size_t length)
const void * OOALDataGetBytePtr(OOALDataRef data)
const struct NSString * OOALStringRef
size_t OOALDataGetLength(OOALDataRef data)
const void * OOALObjectRef
OOALObjectRef OOALDictionaryGetValue(OOALDictionaryRef dictionary, OOALObjectRef key)
bool OOALIsData(OOALObjectRef object)
OOALStringRef OOALGetConstantString(const char *string)
const struct NSDictionary * OOALDictionaryRef
bool OOALIsString(OOALObjectRef object)
OOALAutoreleasePoolRef OOALCreateAutoreleasePool(void)
struct NSData * OOALMutableDataRef
OOALMutableDataRef OOALDataCreateMutable(size_t capacity)
void OOALRelease(OOALObjectRef object)
OOALObjectRef OOALPropertyListFromData(OOALMutableDataRef data, OOALStringRef *errStr)
const struct NSData * OOALDataRef