Differences From Artifact [6180a99265]:
- File
src/OFObject.h
— part of check-in
[5903c87d36]
at
2009-08-17 21:13:21
on branch trunk
— Ensure in the headers that we got the required definitions.
This prevents compiling stuff using libobjfw without objfw-config,
which could generate strange bugs. (user: js, size: 7354) [annotate] [blame] [check-ins using]
To Artifact [5cc0fd9342]:
- File src/OFObject.h — part of check-in [146db53e4a] at 2009-08-26 19:40:11 on branch trunk — Improve documentation. (user: js, size: 7844) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
23 24 25 26 27 28 29 | #endif /** * The OFObject class is the base class for all other classes inside ObjFW. */ @interface OFObject { | > | > | > | | > | > < > | | | < | | < < < | > | | | | | | | | > | | | | > > > < < < < < | > > > > > > > > > | < > > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | #endif /** * The OFObject class is the base class for all other classes inside ObjFW. */ @interface OFObject { /// The class of the object Class isa; } /** * This code is executed once when a method of the class is called for the first * time. * * Derived classes can override this to execute their own code on * initialization. */ + (void)initialize; /** * Allocates memory for an instance of the class and sets up the memory pool for * the object. * * alloc will never return nil, instead, it will throw an * OFAllocFailedException. * * \return The allocated object. */ + alloc; /** * \return The class */ + (Class)class; /** * \return The name of the class as a C string */ + (const char*)className; /** * Checks whether instances of the class respond to a given selector. * * \param selector The selector which should be checked for respondance * \return A boolean whether instances of the class respond to the specified * selector */ + (BOOL)instancesRespondToSelector: (SEL)selector; /** * Checks whether the class conforms to a given protocol. * * \param protocol The protocol which should be checked for conformance * \return A boolean whether the class conforms to the specified protocol */ + (BOOL)conformsToProtocol: (Protocol*)protocol; /** * \param selector The selector for which the method should be returned * \return The implementation of the instance method for the specified selector * or nil if it isn't implemented */ + (IMP)instanceMethodForSelector: (SEL)selector; /** * Replaces a method implementation with another implementation. * * \param selector The selector of the method to replace * \param imp The new implementation for the method * \return The old implementation */ + (IMP)setImplementation: (IMP)newimp forMethod: (SEL)selector; /** * Replaces a method with a method from another class. * * \param selector The selector of the method to replace * \param class The class from which the new method should be taken * \return The old implementation */ + (IMP)replaceMethod: (SEL)selector withMethodFromClass: (Class)class; /** * Initializes an already allocated object. * * Derived classes may override this, but need to do self = [super init] before * they do any initialization themselves. init may never return nil, instead * an exception (for example OFInitializationFailed) should be thrown. * * \return An initialized object */ - init; /** * \return The class of the object */ - (Class)class; /** * \return The name of the object's class as a C string */ - (const char*)className; /** * \param class The class whose kind is checked * \return A boolean whether the object is of the specified kind */ - (BOOL)isKindOfClass: (Class)class; /** * \param selector The selector which should be checked for respondance * \return A boolean whether the objects responds to the specified selector */ - (BOOL)respondsToSelector: (SEL)selector; /** * \param protocol The protocol which should be checked for conformance * \return A boolean whether the objects conforms to the specified protocol */ - (BOOL)conformsToProtocol: (Protocol*)protocol; /** * \param selector The selector for which the method should be returned * * \return The implementation for the specified selector */ - (IMP)methodForSelector: (SEL)selector; /** * Checks two objects for equality. * * Classes containing data (like strings, arrays, lists etc.) should reimplement * this! * * \param obj The object which should be tested for equality * \return A boolean whether the object is equal to the specified object */ - (BOOL)isEqual: (id)obj; /** * Calculates a hash for the object. * * Classes containing data (like strings, arrays, lists etc.) should reimplement * this! * * \return A 32 bit hash for the object */ - (uint32_t)hash; /** * Adds a pointer to the object's memory pool. * * This is useful to add memory allocated by functions such as asprintf to the * pool so it gets free'd automatically when the object is deallocated. * * \param ptr A pointer to add to the memory pool */ - addMemoryToPool: (void*)ptr; /** * Allocates memory and stores it in the object's memory pool so it can be * free'd automatically when the object is deallocated. * * \param size The size of the memory to allocate * \return A pointer to the allocated memory */ - (void*)allocMemoryWithSize: (size_t)size; /** * Allocates memory for the specified number of items and stores it in the * object's memory pool so it can be free'd automatically when the object is * deallocated. * * \param nitems The number of items to allocate * \param size The size of each item to allocate * \return A pointer to the allocated memory */ - (void*)allocMemoryForNItems: (size_t)nitems withSize: (size_t)size; /** * Resizes memory in the object's memory pool to the specified size. * * \param ptr A pointer to the already allocated memory * \param size The new size for the memory chunk * \return A pointer to the resized memory chunk */ - (void*)resizeMemory: (void*)ptr toSize: (size_t)size; /** * Resizes memory in the object's memory pool to the specific number of items of * the specified size. * * \param ptr A pointer to the already allocated memory * \param nitems The number of items to resize to * \param size The size of each item to resize to * \return A pointer to the resized memory chunk */ - (void*)resizeMemory: (void*)ptr toNItems: (size_t)nitems withSize: (size_t)size; /** * Frees allocated memory and removes it from the object's memory pool. * * \param ptr A pointer to the allocated memory */ - freeMemory: (void*)ptr; /** * Increases the retain count. * * Each time an object is released, the retain count gets decreased and the * object deallocated if it reaches 0. */ - retain; /** * \return The retain count */ - (size_t)retainCount; /** * Decreases the retain count. * * Each time an object is released, the retain count gets decreased and the * object deallocated if it reaches 0. */ - (void)release; /** * Adds the object to the topmost OFAutoreleasePool of the thread's release pool * stack. */ - autorelease; /** * Deallocates the object and also frees all memory in its memory pool. * * It is also called when the retain count reaches zero. */ - (void)dealloc; /* * Those are needed as the root class is the superclass of the root class's * metaclass and thus instance methods can be sent to class objects as well. */ |
︙ | ︙ |