Oolite 1.91.0.7604-240417-a536cbe
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#ifndef OO_EXCLUDE_DEBUG_SUPPORT
10
12#import "OOCocoa.h"
13
14
15// 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.
17{
18 static NSMutableDictionary *sStrings = nil;
19 NSValue *key = nil;
20 NSString *value = nil;
21
22 if (sStrings == nil)
23 {
24 sStrings = [[NSMutableDictionary alloc] init];
25 }
26
27 key = [NSValue valueWithPointer:string];
28 value = [sStrings objectForKey:key];
29 if (value == nil)
30 {
31 // Note: non-ASCII strings are not permitted, but we don't bother to detect them.
32 value = [NSString stringWithUTF8String:string];
33 if (value != nil) [sStrings setObject:value forKey:key];
34 }
35
36 return value;
37}
38
39
41{
42 [object release];
43}
44
45
47{
48 return [[object class] description];
49}
50
51
53{
54 return [object isKindOfClass:[NSString class]];
55}
56
57
59{
60 return [[NSString alloc] initWithFormat:format arguments:args];
61}
62
63
65{
66 return [object isKindOfClass:[NSDictionary class]];
67}
68
69
71{
72 return [dictionary objectForKey:key];
73}
74
75
77{
78 return [object isKindOfClass:[NSData class]];
79}
80
81
83{
84 return [[NSMutableData alloc] initWithCapacity:capacity];
85}
86
87
88void OOALMutableDataAppendBytes(OOALMutableDataRef data, const void *bytes, size_t length)
89{
90 [data appendBytes:bytes length:length];
91}
92
93
95{
96 return [data bytes];
97}
98
99
101{
102 return [data length];
103}
104
105
107{
108 return [[NSAutoreleasePool alloc] init];
109}
110
111
113{
114 id result = [NSPropertyListSerialization propertyListFromData:data
115 mutabilityOption:NSPropertyListImmutable
116 format:NULL
117 errorDescription:errStr];
118 [result retain];
119
120#if !OOLITE_RELEASE_PLIST_ERROR_STRINGS
121 [*errStr retain];
122#endif
123
124 return result;
125}
126
127#endif /* OO_EXCLUDE_DEBUG_SUPPORT */
return nil
const struct NSAutoreleasePool * OOALAutoreleasePoolRef
const struct NSString * OOALStringRef
const void * OOALObjectRef
const struct NSDictionary * OOALDictionaryRef
struct NSData * OOALMutableDataRef
const struct NSData * OOALDataRef
OOALStringRef OOTypeDescription(OOALObjectRef object)
bool OOALIsDictionary(OOALObjectRef object)
OOALStringRef OOALStringCreateWithFormatAndArguments(OOALStringRef format, va_list args)
void OOALMutableDataAppendBytes(OOALMutableDataRef data, const void *bytes, size_t length)
const void * OOALDataGetBytePtr(OOALDataRef data)
size_t OOALDataGetLength(OOALDataRef data)
OOALObjectRef OOALDictionaryGetValue(OOALDictionaryRef dictionary, OOALObjectRef key)
bool OOALIsData(OOALObjectRef object)
OOALStringRef OOALGetConstantString(const char *string)
bool OOALIsString(OOALObjectRef object)
OOALAutoreleasePoolRef OOALCreateAutoreleasePool(void)
OOALMutableDataRef OOALDataCreateMutable(size_t capacity)
void OOALRelease(OOALObjectRef object)
OOALObjectRef OOALPropertyListFromData(OOALMutableDataRef data, OOALStringRef *errStr)