<li><a href="#Main_functions">Main functions</a></li>
<li><a href="#Object_model_structure">Object model structure</a></li>
+ <ul>
+ <li><a href="#Object_lists">Object lists</a><br>
+ </li>
+ </ul>
+
- <li><a href="#User_data">User data</a><br>
+
+ <ul>
+ <li><a href="#User_data">User data</a></li>
+ </ul>
+ <li><a href="#Other_functions">Modifying the object model</a></li>
+ <ul>
+ <li><a href="#Manipulating_strings">Manipulating strings</a></li>
+ </ul><li><a href="#Writing_the_object_model_to_file">Writing the object model to file</a><br>
<br>
</li>
+
+
<li><a href="gomxref.html">C object model details</a><br>
</h2>
There are two ways to start with a GEDCOM object model (after having called <code>gedcom_init</code>): either by starting from scratch, or by starting from a given GEDCOM file. This is done via the following two functions:<br>
-<blockquote><code>int <b>gom_parse_file</b> (const char* file_name)<br>
+<blockquote><code>int <b>gom_parse_file</b> (const char* file_name);<br>
</code>
<blockquote>This initializes the object model by parsing the GEDCOM file given by <code>file_name</code>. It returns 0 on success and 1 on failure.<br>
</blockquote>
</blockquote>
-<blockquote><code>int <b>gom_new_model</b> ()<br>
+<blockquote><code>int <b>gom_new_model</b> ();<br>
</code>
<blockquote>This starts an empty model. Actually, this is done by processing the file "<code>new.ged</code>" in the gedcom-parse data directory.<br>
</blockquote>
</blockquote>
</li>
</ul>
-<blockquote>The <b>XXX</b> stands for one of the following: <code>family, </code><code>individual, multimedia, note, repository, source, submitter, user_rec</code>.<br>
+<blockquote>The <code><b>XXX</b></code> stands for one of the following: <code><b>family</b>, </code><code><b>individual</b>, <b>multimedia</b>, <b>note</b>, <b>repository</b>, <b>source</b>, <b>submitter</b>, <b>user_rec</b></code>.<br>
</blockquote>
+<hr width="100%" size="2">
<h2><a name="Object_model_structure"></a>Object model structure<br>
</h2>
-
+<h3><a name="Object_lists"></a>Object lists<br>
+</h3>
All records of a certain type are linked together in a linked list. The
above functions only give access to the first record of each linked list.
The others can be accessed by traversing the linked list via the <code>next</code> member of the structs. This means that e.g. the following piece of code will traverse the linked list of family records:<br>
Actually, the linked list is a doubly-linked list: each record also has a <code>previous</code> member. But for implementation reasons the behaviour of this <code>previous</code> member on the edges of the linked list will not be guaranteed, i.e. it can be circular or terminated with <code>NULL</code>, no assumptions can be made in the application code.<br>
<br>
This linked-list model applies also to all sub-structures of the main record structs, i.e. each struct that has a <code>next </code>and <code>previous</code>
-member following the above conventions. This means that the following
+member follows the above conventions. This means that the following
piece of code traverses all children of a family (see the details of the
different structs <a href="gomxref.html">here</a>):<br>
<blockquote><code>struct family* fam = ...;<br>
...<br>
}</code> <br>
</blockquote>
-Note that all character strings in the object model are encoded in UTF-8 (<a href="file:///home/verthezp/src/external/gedcom-parse/doc/encoding.html">Why UTF-8?</a>).<br>
-<h2><a name="User_data"></a>User data</h2>
+Note that all character strings in the object model are encoded in UTF-8 (<a href="file:///home/verthezp/src/external/gedcom-parse/doc/encoding.html">Why UTF-8?</a>), but see <a href="#Manipulating_strings">below</a> for how to convert these automatically.<br>
+<h3><a name="User_data"></a>User data</h3>
+
Each of the structs has an extra member called <code>extra</code> (of type <code>struct user_data*</code>).
This gathers all non-standard GEDCOM tags within the scope of the struct
</li>
</ul>
This way, none of the information in the GEDCOM file is lost, even the non-standard information.<br>
-<hr width="100%" size="2">
-
+<br>
+<hr width="100%" size="2">
+<h2><a name="Other_functions"></a>Modifying the object model</h2>Currently, there are only functions available to modify strings in the model (and the date manipulation functions described <a href="interface.html#date_value">here</a>).
+ In principle it is possible to add new records, notes, ... yourself,
+but you have to know what you are doing, because you should keep the model
+consistent. In the next release, functions will be available to add,
+remove and modify anything in the model.<br>
+
+<h3><a name="Manipulating_strings"></a>Manipulating strings<br>
+</h3>
+There are some functions available to retrieve and change strings in the
+Gedcom object model, depending whether you use UTF-8 strings in your application
+or locale-defined strings.<br>
+<br>
+The following functions retrieve and set the string in UTF-8 encoding:<br>
+<blockquote><code>char* <b>gom_get_string</b> (char* data);<br>
+char* <b>gom_set_string</b> (char** data, const char* str_in_utf8);</code><br>
+</blockquote>
+The first function is in fact superfluous, because it just returns the <code>data</code>, but it is there for symmetry with the functions given below for the locale-defined input and output. <br>
+<br>
+The second function returns the new value if successful, or <code>NULL</code>
+if an error occurred (e.g. failure to allocate memory or the given string is not a valid UTF-8 string). It makes a
+copy of the input string to store it in the object model. It also takes
+care of deallocating the old value of the data if needed. Note that
+the set function needs the address of the data variable, to be able to modify
+it. In the case of an error, the target data variable is not modified.<br>
+<br>
+Examples of use of these strings would be, e.g. for retrieving and setting the system ID in the header:<br>
+<blockquote><code>struct header* head = gom_get_header();</code><code></code><br>
+ <code>char* oldvalue = gom_get_string(head->source.id);<br>
+char* newvalue = "My_Gedcom_Tool";<br>
+ </code><br>
+ <code>if (gom_set_string(&head->source.id, newvalue)) {<br>
+ printf("Modified system id from %s to %s\n", oldvalue, newvalue);<br>
+}</code><br>
+</blockquote>
+<br>
+A second couple of functions retrieve and set the string in the format defined by the current locale:<br>
+<blockquote><code>char* <b>gom_get_string_for_locale</b> (char* data, int* conversion_failures);<br>
+char* <b>gom_set_string_for_locale</b> (char** data, const char* str_in_locale)</code>;<br>
+</blockquote>
+The use of these functions is the same as the previous ones, but e.g. in
+the "en_US" locale the string will be returned by the first function in the
+ISO-8859-1 encoding and the second function expects the <code>str_in_locale</code> to be in this encoding. Conversion to and from UTF-8 for the object model is done on the fly.<br>
+<br>
+Since the conversion from UTF-8 to the locale encoding is not always possible,
+the get function has a second parameter that can return the number of conversion
+failures for the result string. Pass a pointer to an integer if you
+want to know this. You can pass <code>NULL</code> if you're not interested. The function returns <code>NULL</code>
+if an error occurred (e.g. if the given string is not a valid string for
+the current locale); in that case the target data variable is not modified.<br>
+<hr width="100%" size="2">
+<h2><a name="Writing_the_object_model_to_file"></a>Writing the object model to file<br>
+</h2>
+Writing the current object model to a file is simply done using the following function:<br>
+<blockquote><code>int <b>gom_write_file</b> (const char* filename, int* total_conv_fails);<br></code></blockquote>
+This writes the model to the file <code>filename</code>. The second parameter can return the total number of conversion failures (pass <code>NULL</code><code></code> if you're not interested). The functions in <a href="usage.html#Controlling_some_settings">this section</a> can be used before <code>gom_write_file</code> to control some settings.<br>
+<br>
+Before you write the file, you can update the timestamp in the header using the following function:<br>
+<blockquote><code>int <b>gom_header_update_timestamp</b> (time_t tval);<br></code></blockquote>
+This sets the <code>date</code> and <code>time</code> fields of the header to the time indicated by <code>tval</code>.
+ The function returns 0 on success, non-zero if an error occurred. Typically,
+the function would be used as follows, to set the current time in the timestamp:<br>
+<blockquote><code>int result;<br>
+result = gom_header_update_timestamp(time(NULL));</code><br>
+</blockquote>
+<hr width="100%" size="2"><br>
+
<pre><font size="-1">$Id$<br>$Name$</font><br></pre>
+
<pre> </pre>
+<br>
+<br>
+<br>
+<br>
+<br>
+<br>
<br>
<br>
<br>