]> mj.ucw.cz Git - leo.git/blob - fixed.c
Support for fixed objects
[leo.git] / fixed.c
1 /*
2  *      Hic Est Leo -- Fixed Objects
3  *
4  *      (c) 2014 Martin Mares <mj@ucw.cz>
5  */
6
7 #include <ucw/lib.h>
8 #include <ucw/conf.h>
9
10 #include <stdio.h>
11
12 #include "leo.h"
13 #include "osm.h"
14 #include "fixed.h"
15
16 struct fixed_tag {
17   cnode n;
18   char *key, *val;
19 };
20
21 struct fixed_object {
22   cnode n;
23   double x, y;
24   clist tags;
25 };
26
27 static clist fixed_objects;
28
29 static struct cf_section fixed_tag_cf = {
30 #define P(_x) PTR_TO(struct fixed_tag, _x)
31   CF_TYPE(struct fixed_object),
32   CF_ITEMS {
33     CF_STRING("Key", P(key)),
34     CF_STRING("Value", P(val)),
35     CF_END
36   }
37 #undef P
38 };
39
40 static struct cf_section fixed_object_cf = {
41 #define P(_x) PTR_TO(struct fixed_object, _x)
42   CF_TYPE(struct fixed_object),
43   CF_ITEMS {
44     CF_DOUBLE("X", P(x)),
45     CF_DOUBLE("Y", P(y)),
46     CF_LIST("Tag", P(tags), &fixed_tag_cf),
47     CF_END
48   }
49 #undef P
50 };
51
52 static struct cf_section fixed_cf = {
53   CF_ITEMS {
54     CF_LIST("Object", &fixed_objects, &fixed_object_cf),
55     CF_END
56   }
57 };
58
59 static void CONSTRUCTOR fixed_preinit(void)
60 {
61   cf_declare_section("FixedObjects", &fixed_cf, 0);
62 }
63
64 void fixed_add(void)
65 {
66   u64 id = 1;
67   CLIST_FOR_EACH(struct fixed_object *, fo, fixed_objects)
68     {
69       struct osm_node *n = osm_node_new(id++);
70       n->x = fo->x;
71       n->y = fo->y;
72       CLIST_FOR_EACH(struct fixed_tag *, ft, fo->tags)
73         osm_obj_add_tag(&n->o, ft->key, ft->val);
74     }
75 }