| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 5 | <title>Objects in C</title> |
| 6 | <meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> |
| 7 | <link rel="home" href="index.html" title="Redland RDF Library Manual"> |
| 8 | <link rel="up" href="reference-manual.html" title="Part II. Reference Manual"> |
| 9 | <link rel="prev" href="reference-manual.html" title="Part II. Reference Manual"> |
| 10 | <link rel="next" href="redland-world.html" title="World"> |
| 11 | <meta name="generator" content="GTK-Doc V1.18 (XML mode)"> |
| 12 | <link rel="stylesheet" href="style.css" type="text/css"> |
| 13 | </head> |
| 14 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| 15 | <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"> |
| 16 | <td><a accesskey="p" href="reference-manual.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td> |
| 17 | <td><a accesskey="u" href="reference-manual.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td> |
| 18 | <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td> |
| 19 | <th width="100%" align="center">Redland RDF Library Manual</th> |
| 20 | <td><a accesskey="n" href="redland-world.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td> |
| 21 | </tr></table> |
| 22 | <div class="chapter"> |
| 23 | <div class="titlepage"><div><div><h2 class="title"> |
| 24 | <a name="objects"></a>Objects in C</h2></div></div></div> |
| 25 | <p> |
| 26 | Redland uses objects and is written in C, which has no built in support for |
| 27 | object construction, destruction, copying etc. This library thus uses |
| 28 | conventions for the names of the routines providing the |
| 29 | constructor, destructor and copy constructor functionality for a class as |
| 30 | well as conventions for the general methods. |
| 31 | </p> |
| 32 | <p> |
| 33 | A class FOO is defined as a C typedef <code class="literal">librdf_foo</code>, |
| 34 | and its a public interface defined in <code class="filename">rdf_foo.h</code> |
| 35 | along with any public or private types, enumerations or constants. |
| 36 | The private definitions are not exposed to library users, only |
| 37 | internally when the library is built. The implementation of the |
| 38 | class is defined in file <code class="filename">rdf_foo.c</code> and may |
| 39 | include private (static) functions either for internal |
| 40 | implementations or to satisfy part of a factory API. |
| 41 | </p> |
| 42 | <p>Each class may have a class initialiser / termination pair |
| 43 | of functions which must be called before any object in the class is created, |
| 44 | and after the last object has been freed. These are defined with signatures |
| 45 | like: |
| 46 | </p> |
| 47 | <pre class="programlisting"> |
| 48 | void init_librdf_foo (...) |
| 49 | void terminate_librdf_foo (void) |
| 50 | </pre> |
| 51 | <p> |
| 52 | The arguments to the initialisation vary since there are sometimes |
| 53 | some class wide options that can be set at initialisation time. |
| 54 | </p> |
| 55 | <p> |
| 56 | The object constructor(s) are defined with signatures like: |
| 57 | </p> |
| 58 | <pre class="programlisting"> |
| 59 | librdf_foo* librdf_new_foo(void) |
| 60 | </pre> |
| 61 | <p> |
| 62 | which takes no parameters. Additional constructors can be defined |
| 63 | with parameters, and are named in a similar way with an extra part |
| 64 | appropriate for the name for example: |
| 65 | </p> |
| 66 | <pre class="programlisting"> |
| 67 | librdf_foo* librdf_new_foo_with_options(char *options) |
| 68 | </pre> |
| 69 | <p> |
| 70 | </p> |
| 71 | <p>A copy constructor may be defined which will have the signature: |
| 72 | </p> |
| 73 | <pre class="programlisting"> |
| 74 | librdf_foo* librdf_new_foo_from_foo(librdf_foo* old_foo) |
| 75 | </pre> |
| 76 | <p> |
| 77 | </p> |
| 78 | <p>A destructor must be defined and has the signature: |
| 79 | </p> |
| 80 | <pre class="programlisting"> |
| 81 | void librdf_free_foo(librdf_foo* foo) |
| 82 | </pre> |
| 83 | <p> |
| 84 | </p> |
| 85 | <p>Methods of the class have names starting with <code class="literal">librdf_foo_</code> and |
| 86 | examples could be: |
| 87 | </p> |
| 88 | <pre class="programlisting"> |
| 89 | /* accessor functions to object part 'thing' */ |
| 90 | int librdf_foo_set_thing(librdf_foo* foo, char *thing) |
| 91 | char *librdf_foo_get_thing(librdf_foo* foo) |
| 92 | </pre> |
| 93 | <p> |
| 94 | </p> |
| 95 | <p>It is often convenient to get a string representation of an |
| 96 | object for further processing, debugging or serialisation. There are |
| 97 | two conventions for methods that provide this functionality - the |
| 98 | first is when a pointer is returned to a <span class="emphasis"><em>shared</em></span> |
| 99 | copy of the string and in that case the method ends |
| 100 | <code class="literal">_as_string</code>. The second is when a pointer is |
| 101 | returned to a <span class="emphasis"><em>newly allocated</em></span> string in which |
| 102 | case the method ends <code class="literal">_to_string</code>.</p> |
| 103 | </div> |
| 104 | <div class="footer"> |
| 105 | <hr> |
| 106 | Generated by GTK-Doc V1.18</div> |
| 107 | </body> |
| 108 | </html> |