CFBase.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. { CFBase.h
  2. Copyright (c) 1998-2005, Apple, Inc. All rights reserved.
  3. }
  4. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, September 2005 }
  5. {
  6. Modified for use with Free Pascal
  7. Version 200
  8. Please report any bugs to <[email protected]>
  9. }
  10. {$mode macpas}
  11. {$packenum 1}
  12. {$macro on}
  13. {$inline on}
  14. {$CALLING MWPASCAL}
  15. unit CFBase;
  16. interface
  17. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  18. {$setc GAP_INTERFACES_VERSION := $0200}
  19. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  20. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  21. {$endc}
  22. {$ifc defined CPUPOWERPC and defined CPUI386}
  23. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  24. {$endc}
  25. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  26. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  27. {$endc}
  28. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  29. {$setc __ppc__ := 1}
  30. {$elsec}
  31. {$setc __ppc__ := 0}
  32. {$endc}
  33. {$ifc not defined __i386__ and defined CPUI386}
  34. {$setc __i386__ := 1}
  35. {$elsec}
  36. {$setc __i386__ := 0}
  37. {$endc}
  38. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  39. {$error Conflicting definitions for __ppc__ and __i386__}
  40. {$endc}
  41. {$ifc defined __ppc__ and __ppc__}
  42. {$setc TARGET_CPU_PPC := TRUE}
  43. {$setc TARGET_CPU_X86 := FALSE}
  44. {$elifc defined __i386__ and __i386__}
  45. {$setc TARGET_CPU_PPC := FALSE}
  46. {$setc TARGET_CPU_X86 := TRUE}
  47. {$elsec}
  48. {$error Neither __ppc__ nor __i386__ is defined.}
  49. {$endc}
  50. {$setc TARGET_CPU_PPC_64 := FALSE}
  51. {$ifc defined FPC_BIG_ENDIAN}
  52. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  53. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  54. {$elifc defined FPC_LITTLE_ENDIAN}
  55. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  56. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  57. {$elsec}
  58. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  59. {$endc}
  60. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  61. {$setc CALL_NOT_IN_CARBON := FALSE}
  62. {$setc OLDROUTINENAMES := FALSE}
  63. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  64. {$setc OPAQUE_UPP_TYPES := TRUE}
  65. {$setc OTCARBONAPPLICATION := TRUE}
  66. {$setc OTKERNEL := FALSE}
  67. {$setc PM_USE_SESSION_APIS := TRUE}
  68. {$setc TARGET_API_MAC_CARBON := TRUE}
  69. {$setc TARGET_API_MAC_OS8 := FALSE}
  70. {$setc TARGET_API_MAC_OSX := TRUE}
  71. {$setc TARGET_CARBON := TRUE}
  72. {$setc TARGET_CPU_68K := FALSE}
  73. {$setc TARGET_CPU_MIPS := FALSE}
  74. {$setc TARGET_CPU_SPARC := FALSE}
  75. {$setc TARGET_OS_MAC := TRUE}
  76. {$setc TARGET_OS_UNIX := FALSE}
  77. {$setc TARGET_OS_WIN32 := FALSE}
  78. {$setc TARGET_RT_MAC_68881 := FALSE}
  79. {$setc TARGET_RT_MAC_CFM := FALSE}
  80. {$setc TARGET_RT_MAC_MACHO := TRUE}
  81. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  82. {$setc TYPE_BOOL := FALSE}
  83. {$setc TYPE_EXTENDED := FALSE}
  84. {$setc TYPE_LONGLONG := TRUE}
  85. uses MacTypes;
  86. {$ALIGN POWER}
  87. var kCFCoreFoundationVersionNumber: Float64; external name '_kCFCoreFoundationVersionNumber'; (* attribute const *)
  88. const
  89. kCFCoreFoundationVersionNumber10_0 = 196.4;
  90. const
  91. kCFCoreFoundationVersionNumber10_0_3 = 196.5;
  92. const
  93. kCFCoreFoundationVersionNumber10_1 = 226.0;
  94. { Note the next two do not follow the usual numbering policy from the base release }
  95. const
  96. kCFCoreFoundationVersionNumber10_1_2 = 227.2;
  97. const
  98. kCFCoreFoundationVersionNumber10_1_4 = 227.3;
  99. const
  100. kCFCoreFoundationVersionNumber10_2 = 263.0;
  101. const
  102. kCFCoreFoundationVersionNumber10_3 = 299.0;
  103. const
  104. kCFCoreFoundationVersionNumber10_3_3 = 299.3;
  105. const
  106. kCFCoreFoundationVersionNumber10_3_4 = 299.31;
  107. {$ifc TARGET_CPU_PPC_64}
  108. type
  109. CFTypeID = UInt32;
  110. CFOptionFlags = UInt64;
  111. CFHashCode = UInt32;
  112. CFIndex = SInt64;
  113. CFIndexPtr = ^CFIndex;
  114. {$elsec}
  115. type
  116. CFTypeID = UInt32;
  117. CFOptionFlags = UInt32;
  118. CFHashCode = UInt32;
  119. CFIndex = SInt32;
  120. CFIndexPtr = ^CFIndex;
  121. {$endc}
  122. { Base "type" of all "CF objects", and polymorphic functions on them }
  123. type
  124. CFTypeRef = ^SInt32; { an opaque 32-bit type }
  125. type
  126. CFStringRef = ^SInt32; { an opaque 32-bit type }
  127. CFStringRefPtr = ^CFStringRef;
  128. CFMutableStringRef = ^SInt32; { an opaque 32-bit type }
  129. CFMutableStringRefPtr = ^CFMutableStringRef;
  130. {
  131. Type to mean any instance of a property list type;
  132. currently, CFString, CFData, CFNumber, CFBoolean, CFDate,
  133. CFArray, and CFDictionary.
  134. }
  135. type
  136. CFPropertyListRef = CFTypeRef;
  137. { Values returned from comparison functions }
  138. CFComparisonResult = SInt32;
  139. const
  140. kCFCompareLessThan = -1;
  141. kCFCompareEqualTo = 0;
  142. kCFCompareGreaterThan = 1;
  143. { A standard comparison function }
  144. type
  145. CFComparatorFunction = function( val1: {const} UnivPtr; val2: {const} UnivPtr; context: UnivPtr ): CFComparisonResult;
  146. { Constant used by some functions to indicate failed searches. }
  147. { This is of type CFIndex. }
  148. const
  149. kCFNotFound = -1;
  150. { Range type }
  151. type
  152. CFRangePtr = ^CFRange;
  153. CFRange = record
  154. location: CFIndex;
  155. length: CFIndex;
  156. end;
  157. function CFRangeMake( loc: CFIndex; len: CFIndex ): CFRange; external name '___CFRangeMake';
  158. { Private; do not use }
  159. function __CFRangeMake( loc: CFIndex; len: CFIndex ): CFRange; external name '___CFRangeMake';
  160. {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  161. { Null representant }
  162. type
  163. CFNullRef = ^SInt32; { an opaque 32-bit type }
  164. function CFNullGetTypeID: CFTypeID; external name '_CFNullGetTypeID';
  165. var kCFNull: CFNullRef; external name '_kCFNull'; (* attribute const *) // the singleton null instance
  166. {#endif}
  167. { Allocator API
  168. Most of the time when specifying an allocator to Create functions, the NULL
  169. argument indicates "use the default"; this is the same as using kCFAllocatorDefault
  170. or the return value from CFAllocatorGetDefault(). This assures that you will use
  171. the allocator in effect at that time.
  172. You should rarely use kCFAllocatorSystemDefault, the default default allocator.
  173. }
  174. type
  175. CFAllocatorRef = ^SInt32; { an opaque 32-bit type }
  176. CFAllocatorRefPtr = ^CFAllocatorRef;
  177. { This is a synonym for NULL, if you'd rather use a named constant. }
  178. var kCFAllocatorDefault: CFAllocatorRef; external name '_kCFAllocatorDefault'; (* attribute const *)
  179. { Default system allocator; you rarely need to use this. }
  180. var kCFAllocatorSystemDefault: CFAllocatorRef; external name '_kCFAllocatorSystemDefault'; (* attribute const *)
  181. { This allocator uses malloc(), realloc(), and free(). This should not be
  182. generally used; stick to kCFAllocatorDefault whenever possible. This
  183. allocator is useful as the "bytesDeallocator" in CFData or
  184. "contentsDeallocator" in CFString where the memory was obtained as a
  185. result of malloc() type functions.
  186. }
  187. var kCFAllocatorMalloc: CFAllocatorRef; external name '_kCFAllocatorMalloc'; (* attribute const *)
  188. { This allocator explicitly uses the default malloc zone, returned by
  189. malloc_default_zone(). It should only be used when an object is
  190. safe to be allocated in non-scanned memory.
  191. }
  192. var kCFAllocatorMallocZone: CFAllocatorRef; external name '_kCFAllocatorMallocZone'; (* attribute const *)
  193. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  194. { Null allocator which does nothing and allocates no memory. This allocator
  195. is useful as the "bytesDeallocator" in CFData or "contentsDeallocator"
  196. in CFString where the memory should not be freed.
  197. }
  198. var kCFAllocatorNull: CFAllocatorRef; external name '_kCFAllocatorNull'; (* attribute const *)
  199. { Special allocator argument to CFAllocatorCreate() which means
  200. "use the functions given in the context to allocate the allocator
  201. itself as well".
  202. }
  203. var kCFAllocatorUseContext: CFAllocatorRef; external name '_kCFAllocatorUseContext'; (* attribute const *)
  204. type
  205. CFAllocatorRetainCallBack = function( info: {const} UnivPtr ): UnivPtr;
  206. CFAllocatorReleaseCallBack = procedure( info: {const} UnivPtr );
  207. CFAllocatorCopyDescriptionCallBack = function( info: {const} UnivPtr ): CFStringRef;
  208. CFAllocatorAllocateCallBack = function( allocSize: CFIndex; hint: CFOptionFlags; info: UnivPtr ): UnivPtr;
  209. CFAllocatorReallocateCallBack = function( ptr: UnivPtr; newsize: CFIndex; hint: CFOptionFlags; info: UnivPtr ): UnivPtr;
  210. CFAllocatorDeallocateCallBack = procedure( ptr: UnivPtr; info: UnivPtr );
  211. CFAllocatorPreferredSizeCallBack = function( size: CFIndex; hint: CFOptionFlags; info: UnivPtr ): CFIndex;
  212. CFAllocatorContextPtr = ^CFAllocatorContext;
  213. CFAllocatorContext = record
  214. version: CFIndex;
  215. info: UnivPtr;
  216. retain: CFAllocatorRetainCallBack;
  217. release: CFAllocatorReleaseCallBack;
  218. copyDescription: CFAllocatorCopyDescriptionCallBack;
  219. allocate: CFAllocatorAllocateCallBack;
  220. reallocate: CFAllocatorReallocateCallBack;
  221. deallocate: CFAllocatorDeallocateCallBack;
  222. preferredSize: CFAllocatorPreferredSizeCallBack;
  223. end;
  224. function CFAllocatorGetTypeID: CFTypeID; external name '_CFAllocatorGetTypeID';
  225. {
  226. CFAllocatorSetDefault() sets the allocator that is used in the current
  227. thread whenever NULL is specified as an allocator argument. This means
  228. that most, if not all allocations will go through this allocator. It
  229. also means that any allocator set as the default needs to be ready to
  230. deal with arbitrary memory allocation requests; in addition, the size
  231. and number of requests will change between releases.
  232. An allocator set as the default will never be released, even if later
  233. another allocator replaces it as the default. Not only is it impractical
  234. for it to be released (as there might be caches created under the covers
  235. that refer to the allocator), in general it's also safer and more
  236. efficient to keep it around.
  237. If you wish to use a custom allocator in a context, it's best to provide
  238. it as the argument to the various creation functions rather than setting
  239. it as the default. Setting the default allocator is not encouraged.
  240. If you do set an allocator as the default, either do it for all time in
  241. your app, or do it in a nested fashion (by restoring the previous allocator
  242. when you exit your context). The latter might be appropriate for plug-ins
  243. or libraries that wish to set the default allocator.
  244. }
  245. procedure CFAllocatorSetDefault( allocator: CFAllocatorRef ); external name '_CFAllocatorSetDefault';
  246. function CFAllocatorGetDefault: CFAllocatorRef; external name '_CFAllocatorGetDefault';
  247. function CFAllocatorCreate( allocator: CFAllocatorRef; var context: CFAllocatorContext ): CFAllocatorRef; external name '_CFAllocatorCreate';
  248. function CFAllocatorAllocate( allocator: CFAllocatorRef; size: CFIndex; hint: CFOptionFlags ): UnivPtr; external name '_CFAllocatorAllocate';
  249. function CFAllocatorReallocate( allocator: CFAllocatorRef; ptr: UnivPtr; newsize: CFIndex; hint: CFOptionFlags ): UnivPtr; external name '_CFAllocatorReallocate';
  250. procedure CFAllocatorDeallocate( allocator: CFAllocatorRef; ptr: UnivPtr ); external name '_CFAllocatorDeallocate';
  251. function CFAllocatorGetPreferredSizeForSize( allocator: CFAllocatorRef; size: CFIndex; hint: CFOptionFlags ): CFIndex; external name '_CFAllocatorGetPreferredSizeForSize';
  252. procedure CFAllocatorGetContext( allocator: CFAllocatorRef; var context: CFAllocatorContext ); external name '_CFAllocatorGetContext';
  253. { Polymorphic CF functions }
  254. function CFGetTypeID( cf: CFTypeRef ): CFTypeID; external name '_CFGetTypeID';
  255. function CFCopyTypeIDDescription( type_id: CFTypeID ): CFStringRef; external name '_CFCopyTypeIDDescription';
  256. function CFRetain( cf: CFTypeRef ): CFTypeRef; external name '_CFRetain';
  257. procedure CFRelease( cf: CFTypeRef ); external name '_CFRelease';
  258. function CFGetRetainCount( cf: CFTypeRef ): CFIndex; external name '_CFGetRetainCount';
  259. function CFMakeCollectable( cf: CFTypeRef ): CFTypeRef; external name '_CFMakeCollectable';
  260. (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  261. function CFEqual( cf1: CFTypeRef; cf2: CFTypeRef ): Boolean; external name '_CFEqual';
  262. function CFHash( cf: CFTypeRef ): CFHashCode; external name '_CFHash';
  263. function CFCopyDescription( cf: CFTypeRef ): CFStringRef; external name '_CFCopyDescription';
  264. function CFGetAllocator( cf: CFTypeRef ): CFAllocatorRef; external name '_CFGetAllocator';
  265. end.