3 .\" The Sod runtime library
5 .\" (c) 2015 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the Sensble Object Design, an object system for C.
12 .\" SOD is free software; you can redistribute it and/or modify
13 .\" it under the terms of the GNU General Public License as published by
14 .\" the Free Software Foundation; either version 2 of the License, or
15 .\" (at your option) any later version.
17 .\" SOD is distributed in the hope that it will be useful,
18 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
19 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 .\" GNU General Public License for more details.
22 .\" You should have received a copy of the GNU General Public License
23 .\" along with SOD; if not, write to the Free Software Foundation,
24 .\" Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 .\" Highlight using terminal escapes, rather than overstriking.
29 .\" String definitions and font selection.
38 .\" .hP TEXT -- start an indented paragraph with TEXT hanging off to the left
41 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
44 .\"--------------------------------------------------------------------------
45 .TH sod 3 "8 September 2015" "Straylight/Edgeware" "Sensible Object Design"
48 sod \- Sensible Object Design runtime library
50 .\"--------------------------------------------------------------------------
52 .B #include <sod/sod.h>
57 .BI "const " cls " *" obj );
65 .IB cls "__ilayout *" \c
69 .BI "const void *" obj );
77 .BI "const " cls " *" obj );
81 .BI "const " cls " *" obj );
86 .BI "const void *" obj );
94 .BI "const SodClass *" sub ,
95 .BI "const SodClass *" super );
99 .BI "const SodClass *" cls ,
100 .BI "const void *" obj );
102 .\"--------------------------------------------------------------------------
105 The functions and macros defined here generally expect that
106 instances and classes inherit from the standard
109 While the translator can (at some effort) support alternative roots,
110 they will require different run-time support machinery.
112 .SS Infrastructure macros
113 These macros are mostly intended for use in code
114 generated by the Sod translator.
115 Others may find them useful for special effects,
116 but they can be tricky to understand and use correctly
117 and can't really be recommended for general use.
121 macro performs a `cross-chain upcast'.
125 to an instance of a class of type
129 of the least specific class in one of
131 superclass chains which does not contain
137 returns the address of that chain's storage
138 within the instance layout as a raw
143 is not mentioned explicitly.)
144 This macro is used by the generated
145 .IB CLASS __CONV_ CLS
147 which you are encouraged to use instead where possible.
151 macro returns the signed offset between
152 two members of a structure or union type.
153 Given a structure or union type
164 gives the difference, in bytes,
173 This macro is used internally when generating vtables
174 and is not expected to be very useful elsewhere.
178 macro recovers the instance layout base address
179 from a pointer to one of its instance chains.
180 Specifically, given a class name
184 of the least specific class in one of
189 to the instance storage for the chain containing
191 within an exact instance of
193 (i.e., not an instance of any proper subclass),
198 returns the a pointer to the layout structure containing
200 This macro is used internally in effective method bodies
201 and is not expected to be very useful elsewhere
202 since it's unusual to have such specific knowledge
203 about the dynamic type of an instance.
206 macro (described below) is more suited to general use.
210 macro accepts one or more arguments
211 and expands to just its first argument,
212 discarding the others.
213 It is only defined if the C implementation
214 advertises support for C99.
215 It is used in the definitions of message convenience macros
216 for messages which accept a variable number of arguments
217 but no required arguments,
218 and is exported because the author has found such a thing useful in
222 The following macros are expected to be useful
223 in Sod method definitions and client code.
227 macro returns the class object describing an instance's dynamic class.
229 .BI "const " cls " *" obj
231 .BI SOD_CLASSOF( obj )
238 is typed correctly in the first place)
239 will be a subclass of
241 (If you wanted the class object for
245 .IB cls __class \fR.)
249 macro finds the base address of an instance's layout.
251 .BI "const " cls " *" obj
253 .BI SOD_INSTBASE( obj )
254 returns the base address of the storage allocated to
256 This is useful if you want to free a dynamically allocated instance,
258 This macro needs to look up an offset in
260 vtable to do its work.
264 which is faster but requires
265 precise knowledge of the instance's dynamic class.
269 macro performs general conversions
270 (up-, down-, and cross-casts) on instance pointers.
274 .BI "const void *" obj
279 returns an appropriately converted pointer to
283 is indeed an instance of (some subclass of)
285 otherwise it returns a null pointer.
286 This macro is a simple wrapper around the
288 function described below,
289 which is useful in the common case that
290 the target class is known statically.
294 macro declares and initializes an instance
295 with automatic storage duration.
305 to be a pointer to an instance of
307 The instance is initialized in the sense that
308 its vtable and class pointers have been set up,
309 and slots for which initializers are defined
310 are set to the appropriate initial values.
311 The instance has automatic storage duration:
312 pointers to it will become invalid when control
313 exits the scope of the declaration.
316 The following functions are provided.
320 function answers whether one class
322 is actually a subclass of another class
327 returns nonzero if and only if
331 This involves a run-time trawl through the class structures:
332 while some effort has been made to make it perform well
333 it's still not very fast.
337 function performs general conversions
338 (up-, down-, and cross-casts) on instance pointers.
339 Given a class pointer
341 and an instance pointer
346 returns an appropriately converted pointer to
350 is an instance of (some subclass of)
352 otherwise it returns null.
353 This involves a run-time trawl through the class structures:
354 while some effort has been made to make it perform well
355 it's still not very fast.
358 is a superclass of the static type of
360 the automatically defined conversion macros should be used instead,
361 because they're much faster and can't fail.
362 When the target class is known statically,
363 it's slightly more convenient to use the
367 .\"--------------------------------------------------------------------------
372 .\"--------------------------------------------------------------------------
374 Mark Wooding, <mdw@distorted.org.uk>
376 .\"----- That's all, folks --------------------------------------------------