]> err.no Git - mapper/blob - src/path.h
Move some variables around
[mapper] / src / path.h
1 #ifndef _PATH_H
2 #define _PATH_H
3
4 #include <glib.h>
5 #include <gtk/gtk.h>
6
7 #define MACRO_PATH_INIT(path) { \
8     (path).head = (path).tail = g_new(Point, ARRAY_CHUNK_SIZE); \
9     *((path).tail) = _point_null; \
10     (path).cap = (path).head + ARRAY_CHUNK_SIZE; \
11     (path).whead = g_new(WayPoint, ARRAY_CHUNK_SIZE); \
12     (path).wtail = (path).whead - 1; \
13     (path).wcap = (path).whead + ARRAY_CHUNK_SIZE; \
14 }
15
16 #define MACRO_PATH_FREE(path) if((path).head) { \
17     WayPoint *curr; \
18     g_free((path).head); \
19     (path).head = (path).tail = (path).cap = NULL; \
20     for(curr = (path).whead - 1; curr++ != (path).wtail; ) \
21         g_free(curr->desc); \
22     g_free((path).whead); \
23     (path).whead = (path).wtail = (path).wcap = NULL; \
24 }
25
26 #define MACRO_PATH_INCREMENT_TAIL(route) { \
27     if(++(route).tail == (route).cap) \
28         path_resize(&(route), (route).cap - (route).head + ARRAY_CHUNK_SIZE);\
29 }
30
31 #define MACRO_PATH_INCREMENT_WTAIL(route) { \
32     if(++(route).wtail == (route).wcap) \
33         path_wresize(&(route), \
34                 (route).wcap - (route).whead + ARRAY_CHUNK_SIZE); \
35 }
36
37 /** A lat/lon/alt position */
38 typedef struct _Position Position;
39 struct _Position {
40         gdouble lat;
41         gdouble lon;
42         gfloat altitude;
43         gboolean valid;
44 };
45
46 /** A general definition of a point in the Mapper unit system. */
47 typedef struct _Point Point;
48 struct _Point {
49         guint unitx;
50         guint unity;
51         time_t time;
52         gfloat altitude;
53 };
54
55 /** A WayPoint, which is a Point with a description. */
56 typedef struct _WayPoint WayPoint;
57 struct _WayPoint {
58         Point *point;
59         gchar *desc;
60 };
61
62 /** A Path is a set of PathPoints and WayPoints. */
63 typedef struct _Path Path;
64 struct _Path {
65         Point *head;            /* points to first element in array; NULL if empty. */
66         Point *tail;            /* points to last element in array. */
67         Point *cap;             /* points after last slot in array. */
68         WayPoint *whead;        /* points to first element in array; NULL if empty. */
69         WayPoint *wtail;        /* points to last element in array. */
70         WayPoint *wcap;         /* points after last slot in array. */
71 };
72
73 Point _point_null;
74 Position _home;
75 Position _dest;
76
77 void path_resize(Path *path, guint size);
78 void path_wresize(Path *path, guint wsize);
79
80 GtkListStore *path_generate_store(Path *path);
81
82 #endif