objcbase.pp 11 KB

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