19c5662748eaf84309ea0f8e1f012abfecff85c3
[navit-package] / navit / attr.h
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19
20 #ifndef NAVIT_ATTR_H
21 #define NAVIT_ATTR_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #include "projection.h"
28 #include "config.h"
29
30 enum item_type;
31
32 enum attr_type {
33 #define ATTR2(x,y) attr_##y=x,
34 #define ATTR(x) attr_##x,
35 #include "attr_def.h"
36 #undef ATTR2
37 #undef ATTR
38 };
39
40 #define AF_ONEWAY               (1<<0)
41 #define AF_ONEWAYREV            (1<<1)
42 #define AF_NOPASS               (AF_ONEWAY|AF_ONEWAYREV)
43 #define AF_ONEWAYMASK           (AF_ONEWAY|AF_ONEWAYREV)
44 #define AF_SEGMENTED            (1<<2)
45 #define AF_ROUNDABOUT           (1<<3)
46 #define AF_ROUNDABOUT_VALID     (1<<4)
47 #define AF_ONEWAY_EXCEPTION     (1<<5)
48 #define AF_SPEED_LIMIT          (1<<6)
49 #define AF_TRUCK_SPEED_LIMIT    (1<<7)
50 #define AF_SIZE_OR_WEIGHT_LIMIT (1<<8)
51 #define AF_THROUGH_TRAFFIC      (1<<9)
52 #define AF_TOLL                 (1<<10)
53 #define AF_SEASONAL             (1<<11)
54 #define AF_UNPAVED              (1<<12)
55 #define AF_DANGEROUS_GOODS      (1<<19)
56 #define AF_EMERGENCY_VEHICLES   (1<<20)
57 #define AF_TRANSPORT_TRUCK      (1<<21)
58 #define AF_DELIVERY_TRUCK       (1<<22)
59 #define AF_PUBLIC_BUS           (1<<23)
60 #define AF_TAXI                 (1<<24) 
61 #define AF_HIGH_OCCUPANCY_CAR   (1<<25) 
62 #define AF_CAR                  (1<<26) 
63 #define AF_MOTORCYCLE           (1<<27) 
64 #define AF_MOPED                (1<<28) 
65 #define AF_HORSE                (1<<29) 
66 #define AF_BIKE                 (1<<30) 
67 #define AF_PEDESTRIAN           (1<<31) 
68
69 /* Values for attributes that could carry relative values */
70 #define ATTR_REL_MAXABS                 0x40000000
71 #define ATTR_REL_RELSHIFT               0x60000000
72
73 enum attr_position_valid {
74         attr_position_valid_invalid,
75         attr_position_valid_static,
76         attr_position_valid_extrapolated_time,
77         attr_position_valid_extrapolated_spatial,
78         attr_position_valid_valid,
79 };
80
81 #define ATTR_IS_INT(x) ((x) >= attr_type_int_begin && (x) <= attr_type_int_end)
82 #define ATTR_IS_DOUBLE(x) ((x) >= attr_type_double_begin && (x) <= attr_type_double_end)
83 #define ATTR_IS_STRING(x) ((x) >= attr_type_string_begin && (x) <= attr_type_string_end)
84 #define ATTR_IS_OBJECT(x) ((x) >= attr_type_object_begin && (x) <= attr_type_object_end)
85 #define ATTR_IS_COORD_GEO(x) ((x) >= attr_type_coord_geo_begin && (x) <= attr_type_coord_geo_end)
86 #define ATTR_IS_NUMERIC(x) (ATTR_IS_INT(x) || ATTR_IS_DOUBLE(x))
87
88 struct attr {
89         enum attr_type type;
90         union {
91                 char *str;
92                 void *data;
93                 int num;
94                 struct item *item;
95                 enum item_type item_type;
96                 enum projection projection;
97                 double * numd;
98                 struct color *color;
99                 struct coord_geo *coord_geo;
100                 struct navit *navit;
101                 struct callback *callback;
102                 struct callback_list *callback_list;
103                 struct vehicle *vehicle;
104                 struct layout *layout;
105                 struct layer *layer;
106                 struct map *map;
107                 struct mapset *mapset;
108                 struct log *log;
109                 struct route *route;
110                 struct navigation *navigation;
111                 struct coord *coord;
112                 struct pcoord *pcoord;
113                 struct gui *gui;
114                 struct graphics *graphics;
115                 struct tracking *tracking;
116                 struct itemgra *itemgra;
117                 struct plugin *plugin;
118                 struct plugins *plugins;
119                 struct polygon *polygon;
120                 struct polyline *polyline;
121                 struct circle *circle;
122                 struct text *text;
123                 struct icon *icon;
124                 struct image *image;
125                 struct arrows *arrows;
126                 struct element *element;
127                 struct speech *speech;
128                 struct cursor *cursor;
129                 struct displaylist *displaylist;
130                 struct transformation *transformation;
131                 struct vehicleprofile *vehicleprofile;
132                 struct roadprofile *roadprofile;
133                 struct range {
134                         short min, max;
135                 } range;
136                 int *dash;
137                 enum item_type *item_types;
138                 enum attr_type *attr_types;
139                 long long *num64;
140         } u;
141 };
142
143 struct attr_iter;
144 /* prototypes */
145 enum attr_type attr_from_name(const char *name);
146 char *attr_to_name(enum attr_type attr);
147 struct attr *attr_new_from_text(const char *name, const char *value);
148 char *attr_to_text(struct attr *attr, struct map *map, int pretty);
149 struct attr *attr_search(struct attr **attrs, struct attr *last, enum attr_type attr);
150 int attr_generic_get_attr(struct attr **attrs, struct attr **def_attrs, enum attr_type type, struct attr *attr, struct attr_iter *iter);
151 struct attr **attr_generic_set_attr(struct attr **attrs, struct attr *attr);
152 struct attr **attr_generic_add_attr(struct attr **attrs, struct attr *attr);
153 struct attr **attr_generic_remove_attr(struct attr **attrs, struct attr *attr);
154 enum attr_type attr_type_begin(enum attr_type type);
155 int attr_data_size(struct attr *attr);
156 void *attr_data_get(struct attr *attr);
157 void attr_data_set(struct attr *attr, void *data);
158 void attr_data_set_le(struct attr *attr, void *data);
159 void attr_free(struct attr *attr);
160 void attr_dup_content(struct attr *src, struct attr *dst);
161 struct attr *attr_dup(struct attr *attr);
162 void attr_list_free(struct attr **attrs);
163 struct attr **attr_list_dup(struct attr **attrs);
164 int attr_from_line(char *line, char *name, int *pos, char *val_ret, char *name_ret);
165 int attr_types_contains(enum attr_type *types, enum attr_type type);
166 int attr_types_contains_default(enum attr_type *types, enum attr_type type, int deflt);
167 /* end of prototypes */
168 #ifdef __cplusplus
169 }
170 #endif
171
172 #endif