All Data Structures Files Functions Variables Typedefs Macros Pages
ReadOSM basic architecture

ReadOSM implements a very simple and straightforward interface; there are only three methods:

- readosm_open(): this function is intended to establish a connection to some OSM input file.
- readosm_close(): this function is intended to terminate a previously established connection.
- readosm_parse(): a single function dispatching the whole parsing process (mainly based on callback functions).

Accordingly to the above premises, implementing a complete OSM parser is incredibly simple:

    #include <readosm.h>

    static int
    parse_node (const void *user_data, const readosm_node * node)
    {
    /* callback function consuming Node objects */
      struct some_user_defined_struct *my_struct =
        (struct some_user_defined_struct *) user_data;

      ... some smart code ...

      return READOSM_OK;
    }

    static int
    parse_way (const void *user_data, const readosm_way * way)
    {
    /* callback function consuming Way objects */
      struct some_user_defined_struct *my_struct =
        (struct some_user_defined_struct *) user_data;

      ... some smart code ...

      return READOSM_OK;
    }

    static int
    parse_relation (const void *user_data, const readosm_relation * relation)
    {
    /* callback function consuming Relation objects */
      struct some_user_defined_struct *my_struct =
        (struct some_user_defined_struct *) user_data;

      ... some smart code ...

      return READOSM_OK;
    }

    int main ()
    {
    /* the basic OSM parser implementation */
      int ret;
      const void *handle;
      struct some_user_defined_struct my_struct;

      ret = readosm_open ("path-to-some-OSM-file", &handle);

      ... error handling intentionally suppressed ...

      ret = readosm_parse (handle, &my_struct, parse_node, parse_way, parse_relation);

      ... error handling intentionally suppressed ...

      ret = readosm_close (handle);

      ... error handling intentionally suppressed ...

      return 0;
    }

So the real programming work is simply the one required in order to implement the callback-functions own code.
You can usefully read and study the Examples code-samples in order to get any other relevant information about this topic.