2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* ForFoundationOnly.h
26 Copyright (c) 1998-2003, Apple, Inc. All rights reserved.
29 #if !CF_BUILDING_CF && !NSBUILDINGFOUNDATION
30 #error The header file ForFoundationOnly.h is for the exclusive use of the
31 #error CoreFoundation and Foundation projects. No other project should include it.
34 #if !defined(__COREFOUNDATION_FORFOUNDATIONONLY__)
35 #define __COREFOUNDATION_FORFOUNDATIONONLY__ 1
37 #include <CoreFoundation/CFBase.h>
38 #include <CoreFoundation/CFString.h>
39 #include <CoreFoundation/CFArray.h>
40 #include <CoreFoundation/CFDictionary.h>
41 #include <CoreFoundation/CFPriv.h>
43 // NOTE: miscellaneous declarations are at the end
46 // ---- CFBundle material ----------------------------------------
48 #include "CFBundlePriv.h"
50 #if defined(__cplusplus)
54 CF_EXPORT
const CFStringRef _kCFBundleExecutablePathKey
;
55 CF_EXPORT
const CFStringRef _kCFBundleInfoPlistURLKey
;
56 CF_EXPORT
const CFStringRef _kCFBundleNumericVersionKey
;
57 CF_EXPORT
const CFStringRef _kCFBundleResourcesFileMappedKey
;
58 CF_EXPORT
const CFStringRef _kCFBundleCFMLoadAsBundleKey
;
59 CF_EXPORT
const CFStringRef _kCFBundleAllowMixedLocalizationsKey
;
62 CF_EXPORT CFArrayRef
_CFBundleCopyLanguageSearchListInDirectory(CFAllocatorRef alloc
, CFURLRef url
, UInt8
*version
);
63 CF_EXPORT CFArrayRef
_CFBundleGetLanguageSearchList(CFBundleRef bundle
);
65 #if defined(__cplusplus)
70 // ---- CFString material ----------------------------------------
72 #if defined(__cplusplus)
76 /* Create a byte stream from a CFString backing. Can convert a string piece at a
77 time into a fixed size buffer. Returns number of characters converted.
78 Characters that cannot be converted to the specified encoding are represented
79 with the char specified by lossByte; if 0, then lossy conversion is not allowed
80 and conversion stops, returning partial results.
81 generatingExternalFile indicates that any extra stuff to allow this data to be
82 persistent (for instance, BOM) should be included.
83 Pass buffer==NULL if you don't care about the converted string (but just the
84 convertability, or number of bytes required, indicated by usedBufLen).
85 Does not zero-terminate. If you want to create Pascal or C string, allow one
86 extra byte at start or end.
88 CF_EXPORT CFIndex
__CFStringEncodeByteStream(CFStringRef string
, CFIndex rangeLoc
, CFIndex rangeLen
, Boolean generatingExternalFile
, CFStringEncoding encoding
, char lossByte
, UInt8
*buffer
, CFIndex max
, CFIndex
*usedBufLen
);
90 CF_INLINE Boolean
__CFStringEncodingIsSupersetOfASCII(CFStringEncoding encoding
) {
91 switch (encoding
& 0x0000FF00) {
92 case 0x0: // MacOS Script range
95 case 0x100: // Unicode range
96 if (encoding
== kCFStringEncodingUnicode
) return false;
99 case 0x200: // ISO range
102 case 0x600: // National standards range
103 if (encoding
!= kCFStringEncodingASCII
) return false;
106 case 0x800: // ISO 2022 range
107 return false; // It's modal encoding
109 case 0xA00: // Misc standard range
113 if (encoding
== kCFStringEncodingNonLossyASCII
) return false;
116 case 0xC00: // EBCDIC
120 return ((encoding
& 0x0000FF00) > 0x0C00 ? false : true);
124 /* Desperately using extern here */
125 CF_EXPORT CFStringEncoding __CFDefaultEightBitStringEncoding
;
126 CF_EXPORT CFStringEncoding
__CFStringComputeEightBitStringEncoding(void);
128 CF_INLINE CFStringEncoding
__CFStringGetEightBitStringEncoding(void) {
129 if (__CFDefaultEightBitStringEncoding
== kCFStringEncodingInvalidId
) __CFStringComputeEightBitStringEncoding();
130 return __CFDefaultEightBitStringEncoding
;
134 __kCFVarWidthLocalBufferSize
= 1008
137 typedef struct { /* A simple struct to maintain ASCII/Unicode versions of the same buffer. */
142 Boolean isASCII
; /* This really does mean 7-bit ASCII, not _NSDefaultCStringEncoding() */
143 Boolean shouldFreeChars
; /* If the number of bytes exceeds __kCFVarWidthLocalBufferSize, bytes are allocated */
146 CFAllocatorRef allocator
; /* Use this allocator to allocate, reallocate, and deallocate the bytes */
147 UInt32 numChars
; /* This is in terms of ascii or unicode; that is, if isASCII, it is number of 7-bit chars; otherwise it is number of UniChars; note that the actual allocated space might be larger */
148 UInt8 localBuffer
[__kCFVarWidthLocalBufferSize
]; /* private; 168 ISO2022JP chars, 504 Unicode chars, 1008 ASCII chars */
149 } CFVarWidthCharBuffer
;
152 /* Convert a byte stream to ASCII (7-bit!) or Unicode, with a CFVarWidthCharBuffer struct on the stack. false return indicates an error occured during the conversion. Depending on .isASCII, follow .chars.ascii or .chars.unicode. If .shouldFreeChars is returned as true, free the returned buffer when done with it. If useClientsMemoryPtr is provided as non-NULL, and the provided memory can be used as is, this is set to true, and the .ascii or .unicode buffer in CFVarWidthCharBuffer is set to bytes.
153 !!! If the stream is Unicode and has no BOM, the data is assumed to be big endian! Could be trouble on Intel if someone didn't follow that assumption.
154 !!! __CFStringDecodeByteStream2() needs to be deprecated and removed post-Jaguar.
156 CF_EXPORT Boolean
__CFStringDecodeByteStream2(const UInt8
*bytes
, UInt32 len
, CFStringEncoding encoding
, Boolean alwaysUnicode
, CFVarWidthCharBuffer
*buffer
, Boolean
*useClientsMemoryPtr
);
157 CF_EXPORT Boolean
__CFStringDecodeByteStream3(const UInt8
*bytes
, UInt32 len
, CFStringEncoding encoding
, Boolean alwaysUnicode
, CFVarWidthCharBuffer
*buffer
, Boolean
*useClientsMemoryPtr
, UInt32 converterFlags
);
160 /* Convert single byte to Unicode; assumes one-to-one correspondence (that is, can only be used with 1-byte encodings). You can use the function if it's not NULL. The table is always safe to use; calling __CFSetCharToUniCharFunc() updates it.
162 CF_EXPORT
Boolean (*__CFCharToUniCharFunc
)(UInt32 flags
, UInt8 ch
, UniChar
*unicodeChar
);
163 CF_EXPORT
void __CFSetCharToUniCharFunc(Boolean (*func
)(UInt32 flags
, UInt8 ch
, UniChar
*unicodeChar
));
164 CF_EXPORT UniChar __CFCharToUniCharTable
[256];
166 /* Character class functions UnicodeData-2_1_5.txt
168 CF_INLINE Boolean
__CFIsWhitespace(UniChar theChar
) {
169 return ((theChar
< 0x21) || (theChar
> 0x7E && theChar
< 0xA1) || (theChar
>= 0x2000 && theChar
<= 0x200B) || (theChar
== 0x3000)) ? true : false;
172 /* Same as CFStringGetCharacterFromInlineBuffer() but returns 0xFFFF on out of bounds access
174 CF_INLINE UniChar
__CFStringGetCharacterFromInlineBufferAux(CFStringInlineBuffer
*buf
, CFIndex idx
) {
175 if (buf
->directBuffer
) {
176 if (idx
< 0 || idx
>= buf
->rangeToBuffer
.length
) return 0xFFFF;
177 return buf
->directBuffer
[idx
+ buf
->rangeToBuffer
.location
];
179 if (idx
>= buf
->bufferedRangeEnd
|| idx
< buf
->bufferedRangeStart
) {
180 if (idx
< 0 || idx
>= buf
->rangeToBuffer
.length
) return 0xFFFF;
181 if ((buf
->bufferedRangeStart
= idx
- 4) < 0) buf
->bufferedRangeStart
= 0;
182 buf
->bufferedRangeEnd
= buf
->bufferedRangeStart
+ __kCFStringInlineBufferLength
;
183 if (buf
->bufferedRangeEnd
> buf
->rangeToBuffer
.length
) buf
->bufferedRangeEnd
= buf
->rangeToBuffer
.length
;
184 CFStringGetCharacters(buf
->theString
, CFRangeMake(buf
->rangeToBuffer
.location
+ buf
->bufferedRangeStart
, buf
->bufferedRangeEnd
- buf
->bufferedRangeStart
), buf
->buffer
);
186 return buf
->buffer
[idx
- buf
->bufferedRangeStart
];
189 /* Same as CFStringGetCharacterFromInlineBuffer(), but without the bounds checking (will return garbage or crash)
191 CF_INLINE UniChar
__CFStringGetCharacterFromInlineBufferQuick(CFStringInlineBuffer
*buf
, CFIndex idx
) {
192 if (buf
->directBuffer
) return buf
->directBuffer
[idx
+ buf
->rangeToBuffer
.location
];
193 if (idx
>= buf
->bufferedRangeEnd
|| idx
< buf
->bufferedRangeStart
) {
194 if ((buf
->bufferedRangeStart
= idx
- 4) < 0) buf
->bufferedRangeStart
= 0;
195 buf
->bufferedRangeEnd
= buf
->bufferedRangeStart
+ __kCFStringInlineBufferLength
;
196 if (buf
->bufferedRangeEnd
> buf
->rangeToBuffer
.length
) buf
->bufferedRangeEnd
= buf
->rangeToBuffer
.length
;
197 CFStringGetCharacters(buf
->theString
, CFRangeMake(buf
->rangeToBuffer
.location
+ buf
->bufferedRangeStart
, buf
->bufferedRangeEnd
- buf
->bufferedRangeStart
), buf
->buffer
);
199 return buf
->buffer
[idx
- buf
->bufferedRangeStart
];
203 /* These two allow specifying an alternate description function (instead of CFCopyDescription); used by NSString
205 CF_EXPORT
void _CFStringAppendFormatAndArgumentsAux(CFMutableStringRef outputString
, CFStringRef (*copyDescFunc
)(void *, CFDictionaryRef
), CFDictionaryRef formatOptions
, CFStringRef formatString
, va_list args
);
206 CF_EXPORT CFStringRef
_CFStringCreateWithFormatAndArgumentsAux(CFAllocatorRef alloc
, CFStringRef (*copyDescFunc
)(void *, CFDictionaryRef
), CFDictionaryRef formatOptions
, CFStringRef format
, va_list arguments
);
208 enum {_CFStringErrNone
= 0, _CFStringErrNotMutable
= 1, _CFStringErrNilArg
= 2, _CFStringErrBounds
= 3};
210 CF_EXPORT Boolean
__CFStringNoteErrors(void); // Should string errors raise?
212 #if defined(__cplusplus)
217 // ---- Binary plist material ----------------------------------------
219 typedef const struct __CFKeyedArchiverUID
* CFKeyedArchiverUIDRef
;
220 extern CFTypeID
_CFKeyedArchiverUIDGetTypeID(void);
221 extern CFKeyedArchiverUIDRef
_CFKeyedArchiverUIDCreate(CFAllocatorRef allocator
, uint32_t value
);
222 extern uint32_t _CFKeyedArchiverUIDGetValue(CFKeyedArchiverUIDRef uid
);
226 kCFBinaryPlistMarkerNull
= 0x00,
227 kCFBinaryPlistMarkerFalse
= 0x08,
228 kCFBinaryPlistMarkerTrue
= 0x09,
229 kCFBinaryPlistMarkerFill
= 0x0F,
230 kCFBinaryPlistMarkerInt
= 0x10,
231 kCFBinaryPlistMarkerReal
= 0x20,
232 kCFBinaryPlistMarkerDate
= 0x33,
233 kCFBinaryPlistMarkerData
= 0x40,
234 kCFBinaryPlistMarkerASCIIString
= 0x50,
235 kCFBinaryPlistMarkerUnicode16String
= 0x60,
236 kCFBinaryPlistMarkerUID
= 0x80,
237 kCFBinaryPlistMarkerArray
= 0xA0,
238 kCFBinaryPlistMarkerDict
= 0xD0
244 } CFBinaryPlistHeader
;
248 uint8_t _offsetIntSize
;
249 uint8_t _objectRefSize
;
250 uint64_t _numObjects
;
252 uint64_t _offsetTableOffset
;
253 } CFBinaryPlistTrailer
;
256 // ---- Miscellaneous material ----------------------------------------
258 #include <CoreFoundation/CFBag.h>
259 #include <CoreFoundation/CFSet.h>
262 #if defined(__cplusplus)
266 CF_EXPORT CFTypeID
CFTypeGetTypeID(void);
268 CF_EXPORT
void _CFArraySetCapacity(CFMutableArrayRef array
, CFIndex cap
);
269 CF_EXPORT
void _CFBagSetCapacity(CFMutableBagRef bag
, CFIndex cap
);
270 CF_EXPORT
void _CFDictionarySetCapacity(CFMutableDictionaryRef dict
, CFIndex cap
);
271 CF_EXPORT
void _CFSetSetCapacity(CFMutableSetRef set
, CFIndex cap
);
273 CF_EXPORT
void _CFArrayReplaceValues(CFMutableArrayRef array
, CFRange range
, const void **newValues
, CFIndex newCount
);
276 /* For use by NSNumber and CFNumber.
277 Hashing algorithm for CFNumber:
278 M = Max CFHashCode (assumed to be unsigned)
279 For positive integral values: N mod M
280 For negative integral values: (-N) mod M
281 For floating point numbers that are not integral: hash(integral part) + hash(float part * M)
283 CF_INLINE CFHashCode
_CFHashInt(int i
) {
284 return (i
> 0) ? (CFHashCode
)(i
) : (CFHashCode
)(-i
);
287 CF_INLINE CFHashCode
_CFHashDouble(double d
) {
291 return (CFHashCode
)(fmod(dInt
, (double)0xFFFFFFFF) + ((d
- dInt
) * 0xFFFFFFFF));
295 typedef void (*CFRunLoopPerformCallBack
)(void *info
);
298 #if defined(__MACH__)
299 #include <mach/mach_time.h>
300 CF_INLINE UInt64
__CFReadTSR(void) {
301 return mach_absolute_time();
304 CF_INLINE UInt64
__CFReadTSR(void) {
309 #if defined(__i386__)
310 /* Read from Pentium and Pentium Pro 64-bit timestamp counter. */
311 /* The counter is set to 0 at processor reset and increments on */
312 /* every clock cycle. */
313 __asm__
volatile("rdtsc" : : : "eax", "edx");
314 __asm__
volatile("movl %%eax,%0" : "=m" (now
.word
[0]) : : "eax");
315 __asm__
volatile("movl %%edx,%0" : "=m" (now
.word
[1]) : : "edx");
316 #elif defined(__ppc__)
317 /* Read from PowerPC 64-bit time base register. The increment */
318 /* rate of the time base is implementation-dependent, but is */
319 /* 1/4th the bus clock cycle on 603/604/750 processors. */
322 __asm__
volatile("mftbu %0" : "=r" (now
.word
[0]));
323 __asm__
volatile("mftb %0" : "=r" (now
.word
[1]));
324 __asm__
volatile("mftbu %0" : "=r" (t3
));
325 } while (now
.word
[0] != t3
);
327 // ??? Do not know how to read a time stamp register on this architecture
328 now
.time64
= (uint64_t)0;
334 #if defined(__cplusplus)
338 #endif /* ! __COREFOUNDATION_FORFOUNDATIONONLY__ */