objcbase.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2009 by the Free Pascal development team
  4. This unit provides the definition of the NSObject root class
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit objcbase;
  12. {$ifdef FPC_HAS_FEATURE_OBJECTIVEC1}
  13. {$modeswitch objectivec1}
  14. interface
  15. uses
  16. ctypes;
  17. type
  18. NSString = objcclass external;
  19. NSInvocation = objcclass external;
  20. NSMethodSignature = objcclass external;
  21. NSCoder = objcclass external;
  22. { needed by NSZone.h below }
  23. {$if defined(cpu64) or defined(cpuarm) or defined(win32)}
  24. NSInteger = clong;
  25. NSUInteger = culong;
  26. {$else}
  27. NSInteger = cint;
  28. NSUInteger = cuint;
  29. {$endif}
  30. { NSZone.h, has to be here because NSObject.h imports NSZone.inc }
  31. { Types }
  32. type
  33. NSZone = record
  34. end;
  35. PNSZone = ^NSZone;
  36. NSZonePtr = PNSZone;
  37. { Constants }
  38. const
  39. NSScannedOption = 1 shl 0;
  40. NSCollectorDisabledOption = 1 shl 1;
  41. { Functions }
  42. function NSDefaultMallocZone: NSZonePtr; cdecl; external;
  43. function NSCreateZone(startSize: NSUInteger; granularity: NSUInteger; canFree: Boolean): NSZonePtr; cdecl; external;
  44. procedure NSRecycleZone(zone_: NSZonePtr); cdecl; external;
  45. procedure NSSetZoneName(zone_: NSZonePtr; name: NSString); cdecl; external;
  46. function NSZoneName(zone_: NSZonePtr): NSString; cdecl; external;
  47. function NSZoneFromPointer(ptr: Pointer): NSZonePtr; cdecl; external;
  48. function NSZoneMalloc(zone_: NSZonePtr; size: NSUInteger): Pointer; cdecl; external;
  49. function NSZoneCalloc(zone_: NSZonePtr; numElems: NSUInteger; byteSize: NSUInteger): Pointer; cdecl; external;
  50. function NSZoneRealloc(zone_: NSZonePtr; ptr: Pointer; size: NSUInteger): Pointer; cdecl; external;
  51. procedure NSZoneFree(zone_: NSZonePtr; ptr: Pointer); cdecl; external;
  52. function NSAllocateCollectable(size: NSUInteger; options: NSUInteger): Pointer; cdecl; external;
  53. function NSReallocateCollectable(ptr: Pointer; size: NSUInteger; options: NSUInteger): Pointer; cdecl; external;
  54. function NSPageSize: NSUInteger; cdecl; external;
  55. function NSLogPageSize: NSUInteger; cdecl; external;
  56. function NSRoundUpToMultipleOfPageSize(bytes: NSUInteger): NSUInteger; cdecl; external;
  57. function NSRoundDownToMultipleOfPageSize(bytes: NSUInteger): NSUInteger; cdecl; external;
  58. function NSAllocateMemoryPages(bytes: NSUInteger): Pointer; cdecl; external;
  59. procedure NSDeallocateMemoryPages(ptr: Pointer; bytes: NSUInteger); cdecl; external;
  60. procedure NSCopyMemoryPages(source: Pointer; dest: Pointer; bytes: NSUInteger); cdecl; external;
  61. function NSRealMemoryAvailable: NSUInteger; cdecl; external;
  62. type
  63. Protocol = objcclass external
  64. end;
  65. NSObjectProtocol = objcprotocol external name 'NSObject'
  66. function isEqual(obj: id): boolean; message 'isEqual:';
  67. function hash: NSUInteger; message 'hash';
  68. function superclass: pobjc_class; message 'superclass';
  69. function _class: pobjc_class; message 'class';
  70. { "self" is both a hidden parameter to each method, and a method of
  71. NSObject and thereby of each subclass as well
  72. }
  73. function self: id; message 'self';
  74. function zone: PNSZone; message 'zone';
  75. function performSelector(aSelector: SEL): id; message 'performSelector:';
  76. function performSelector_withObject(aSelector: SEL; obj: id): id; message 'performSelector:withObject:';
  77. function performSelector_withObject_withObject(aSelector: SEL; obj1, obj2: id): id; message 'performSelector:withObject:withObject:';
  78. function isProxy: boolean; message 'isProxy';
  79. function isKindOfClass(aClass: pobjc_class): boolean; message 'isKindOfClass:';
  80. function isMemberOfClass(aClass: pobjc_class): boolean; message 'isMemberOfClass:';
  81. function conformsToProtocol(aProtocol: Protocol): boolean; message 'conformsToProtocol:';
  82. function respondsToSelector(aSelector: SEL): boolean; message 'respondsToSelector:';
  83. function retain: id; message 'retain';
  84. procedure release; message 'release'; { oneway }
  85. function autorelease: id; message 'autorelease';
  86. function retainCount: NSUInteger; message 'retainCount';
  87. function description: NSString; message 'description';
  88. end;
  89. NSObject = objcclass external (NSObjectProtocol)
  90. strict protected
  91. isa: pobjc_class;
  92. public
  93. { NSObjectProtocol -- the message names are copied from the protocol
  94. definition by the compiler, but you can still repeat them if you want }
  95. function isEqual(obj: id): boolean;
  96. function isEqual_(obj: id): boolean; message 'isEqual:';
  97. function hash: NSUInteger;
  98. function superclass: pobjc_class;
  99. function _class: pobjc_class;
  100. { "self" is both a hidden parameter to each method, and a method of
  101. NSObject and thereby of each subclass as well
  102. }
  103. function self: id;
  104. function zone: PNSZone;
  105. function performSelector(aSelector: SEL): id;
  106. function performSelector_(aSelector: SEL): id; message 'performSelector:';
  107. function performSelector_withObject(aSelector: SEL; obj: id): id;
  108. function performSelector_withObject_(aSelector: SEL; obj: id): id; message 'performSelector:withObject:';
  109. function performSelector_withObject_withObject(aSelector: SEL; obj1, obj2: id): id;
  110. function performSelector_withObject_withObject_(aSelector: SEL; obj1, obj2: id): id; message 'performSelector:withObject:withObject:';
  111. function isProxy: boolean;
  112. function isKindOfClass(aClass: pobjc_class): boolean;
  113. function isKindOfClass_(aClass: pobjc_class): boolean; message 'isKindOfClass:';
  114. function isMemberOfClass(aClass: pobjc_class): boolean;
  115. function isMemberOfClass_(aClass: pobjc_class): boolean; message 'isMemberOfClass:';
  116. function conformsToProtocol(aProtocol: Protocol): boolean;
  117. function conformsToProtocol_(aProtocol: Protocol): boolean; message 'conformsToProtocol:';
  118. function respondsToSelector(aSelector: SEL): boolean;
  119. function respondsToSelector_(aSelector: SEL): boolean; message 'respondsToSelector:';
  120. function retain: id;
  121. procedure release; { oneway }
  122. function autorelease: id;
  123. function retainCount: NSUInteger;
  124. function description: NSString;
  125. { NSObject class }
  126. { "class" prefix to method name to avoid name collision with NSObjectProtocol }
  127. class function classIsEqual(obj: id): boolean; message 'isEqual:';
  128. class function classIsEqual_(obj: id): boolean; message 'isEqual:';
  129. { "class" prefix to method name to avoid name collision with NSObjectProtocol }
  130. class function classHash: cuint; message 'hash';
  131. { NSObject methods }
  132. class procedure load; message 'load';
  133. class procedure initialize; message 'initialize';
  134. function init: id; message 'init';
  135. class function new: id; message 'new';
  136. class function allocWithZone(_zone: PNSZone): id; message 'allocWithZone:';
  137. class function allocWithZone_(_zone: PNSZone): id; message 'allocWithZone:';
  138. class function alloc: id; message 'alloc';
  139. procedure dealloc; message 'dealloc';
  140. { if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 }
  141. procedure finalize; message 'finalize';
  142. { endif }
  143. function copy: id; message 'copy';
  144. function mutableCopy: id; message 'mutableCopy';
  145. class function classCopyWithZone(_zone: NSZonePtr): id; message 'copyWithZone:';
  146. class function classCopyWithZone_(_zone: NSZonePtr): id; message 'copyWithZone:';
  147. class function classMutableCopyWithZone(_zone: NSZonePtr): id; message 'mutableCopyWithZone:';
  148. class function classMutableCopyWithZone_(_zone: NSZonePtr): id; message 'mutableCopyWithZone:';
  149. { "class" prefix to method name to avoid name collision with NSObjectProtocol }
  150. class function classSuperclass: pobjc_class; message 'superclass';
  151. { "class" prefix to method name to avoid name collision with NSObjectProtocol }
  152. class function classClass: pobjc_class; message 'class';
  153. class procedure poseAsClass(aClass: pobjc_class); message 'poseAsClass:';
  154. class procedure poseAsClass_(aClass: pobjc_class); message 'poseAsClass:';
  155. class function instancesRespondToSelector(aSelector: SEL): boolean; message 'instancesRespondToSelector:';
  156. class function instancesRespondToSelector_(aSelector: SEL): boolean; message 'instancesRespondToSelector:';
  157. { "class" prefix to method name to avoid name collision with NSObjectProtocol }
  158. class function classConformsToProtocol(aProtocol: Protocol): boolean; message 'conformsToProtocol:';
  159. class function classConformsToProtocol_(aProtocol: Protocol): boolean; message 'conformsToProtocol:';
  160. function methodForSelector(aSelector: SEL): IMP; message 'methodForSelector:';
  161. function methodForSelector_(aSelector: SEL): IMP; message 'methodForSelector:';
  162. class function instanceMethodForSelector(aSelector: SEL): IMP; message 'instanceMethodForSelector:';
  163. class function instanceMethodForSelector_(aSelector: SEL): IMP; message 'instanceMethodForSelector:';
  164. procedure doesNotRecognizeSelector(aSelector: SEL); message 'doesNotRecognizeSelector:';
  165. procedure doesNotRecognizeSelector_(aSelector: SEL); message 'doesNotRecognizeSelector:';
  166. procedure forwardInvocation(anInvocation: NSInvocation); message 'forwardInvocation:';
  167. procedure forwardInvocation_(anInvocation: NSInvocation); message 'forwardInvocation:';
  168. function methodSignatureForSelector(aSelector: SEL): NSMethodSignature; message 'methodSignatureForSelector:';
  169. function methodSignatureForSelector_(aSelector: SEL): NSMethodSignature; message 'methodSignatureForSelector:';
  170. // can't be classDescription, becaue there's a method in another
  171. // class that's also called classDescription
  172. class function _classDescription: NSString; message 'description';
  173. end;
  174. NSCoderMethods = objccategory external (NSObject)
  175. class function version: cint; message 'version';
  176. class procedure setVersion(aVersion: cint); message 'setVersion:';
  177. function classForCoder: pobjc_class; message 'classForCoder';
  178. function replacementObjectForCoder(aCoder: NSCoder): id; message 'replacementObjectForCoder:';
  179. function awakeAfterUsingCoder(aDecoder: NSCoder): id; message 'awakeAfterUsingCoder:';
  180. end;
  181. NSCopyingProtocol = objcprotocol external name 'NSCopying'
  182. function copyWithZone(zone_: NSZonePtr): id; message 'copyWithZone:';
  183. end;
  184. { NSMutableCopying Protocol }
  185. NSMutableCopyingProtocol = objcprotocol external name 'NSMutableCopying'
  186. function mutableCopyWithZone(zone_: NSZonePtr): id; message 'mutableCopyWithZone:';
  187. end;
  188. { NSCoding Protocol }
  189. NSCodingProtocol = objcprotocol external name 'NSCoding'
  190. procedure encodeWithCoder(aCoder: NSCoder); message 'encodeWithCoder:';
  191. function initWithCoder(aDecoder: NSCoder): id; message 'initWithCoder:';
  192. end;
  193. { NSDiscardableContent Protocol }
  194. NSDiscardableContentProtocol = objcprotocol external name 'NSDiscardableContent'
  195. function beginContentAccess: Boolean; message 'beginContentAccess';
  196. procedure endContentAccess; message 'endContentAccess';
  197. procedure discardContentIfPossible; message 'discardContentIfPossible';
  198. function isContentDiscarded: Boolean; message 'isContentDiscarded';
  199. end;
  200. implementation
  201. {$else }
  202. interface
  203. implementation
  204. {$endif}
  205. end.