objcbase.pp 11 KB

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