/[zanavi_public1]/navit/navit/vehicleprofile.c
ZANavi

Contents of /navit/navit/vehicleprofile.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (6 years, 11 months ago) by zoff99
File MIME type: text/plain
File size: 5069 byte(s)
new map version, lots of fixes and experimental new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU 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 General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * 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 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 #include <stdlib.h>
40 #include <glib.h>
41 #include <string.h>
42 #include "debug.h"
43 #include "item.h"
44 #include "roadprofile.h"
45 #include "vehicleprofile.h"
46
47 static void vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr)
48 {
49 dbg(1, "%s:%d\n", attr_to_name(attr->type), attr->u.num);
50 switch (attr->type)
51 {
52 case attr_flags:
53 this_->flags = attr->u.num;
54 break;
55 case attr_flags_forward_mask:
56 this_->flags_forward_mask = attr->u.num;
57 break;
58 case attr_flags_reverse_mask:
59 this_->flags_reverse_mask = attr->u.num;
60 break;
61 case attr_maxspeed_handling:
62 this_->maxspeed_handling = attr->u.num;
63 break;
64 case attr_route_mode:
65 this_->mode = attr->u.num;
66 break;
67 case attr_name:
68 if (this_->name)
69 g_free(this_->name);
70 /* previously used strdupn not available on win32 */
71 this_->name = g_strdup(attr->u.str);
72 break;
73 case attr_vehicle_axle_weight:
74 this_->axle_weight = attr->u.num;
75 break;
76 case attr_vehicle_height:
77 this_->height = attr->u.num;
78 break;
79 case attr_vehicle_length:
80 this_->length = attr->u.num;
81 break;
82 case attr_vehicle_weight:
83 this_->weight = attr->u.num;
84 break;
85 case attr_vehicle_width:
86 this_->width = attr->u.num;
87 break;
88 case attr_static_speed:
89 this_->static_speed = attr->u.num;
90 break;
91 case attr_static_distance:
92 this_->static_distance = attr->u.num;
93 break;
94 case attr_through_traffic_penalty:
95 this_->through_traffic_penalty = attr->u.num;
96 break;
97 default:
98 break;
99 }
100 }
101
102 struct vehicleprofile *
103 vehicleprofile_new(struct attr *parent, struct attr **attrs)
104 {
105 dbg(0, "EEnter\n");
106
107 struct vehicleprofile *this_;
108 struct attr **attr, *type_attr;
109 if (!(type_attr = attr_search(attrs, NULL, attr_name)))
110 {
111 return NULL;
112 } this_=g_new0(struct vehicleprofile, 1);
113 this_->attrs = attr_list_dup(attrs);
114 this_->roadprofile_hash = g_hash_table_new(NULL, NULL);
115 this_->length = -1;
116 this_->width = -1;
117 this_->height = -1;
118 this_->weight = -1;
119 this_->axle_weight = -1;
120 this_->through_traffic_penalty = 9000;
121 for (attr = attrs; *attr; attr++)
122 {
123 vehicleprofile_set_attr_do(this_, *attr);
124 }
125
126 dbg(0, "return\n");
127 return this_;
128 }
129
130 int vehicleprofile_get_attr(struct vehicleprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
131 {
132 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
133 }
134
135 int vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr)
136 {
137 vehicleprofile_set_attr_do(this_, attr);
138 this_->attrs = attr_generic_set_attr(this_->attrs, attr);
139 return 1;
140 }
141
142 int vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr)
143 {
144 struct attr item_types_attr;
145 this_->attrs = attr_generic_add_attr(this_->attrs, attr);
146 switch (attr->type)
147 {
148 case attr_roadprofile:
149 if (roadprofile_get_attr(attr->u.roadprofile, attr_item_types, &item_types_attr, NULL))
150 {
151 enum item_type *types = item_types_attr.u.item_types;
152 while (*types != type_none)
153 {
154 g_hash_table_insert(this_->roadprofile_hash, (void *) (long) (*types), attr->u.roadprofile);
155 types++;
156 }
157 }
158 break;
159 default:
160 break;
161 }
162 return 1;
163 }
164
165 int vehicleprofile_remove_attr(struct vehicleprofile *this_, struct attr *attr)
166 {
167 this_->attrs = attr_generic_remove_attr(this_->attrs, attr);
168 return 1;
169 }
170
171 struct roadprofile *
172 vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type)
173 {
174 return g_hash_table_lookup(this_->roadprofile_hash, (void *) (long) type);
175 }
176
177 char *
178 vehicleprofile_get_name(struct vehicleprofile *this_)
179 {
180 return this_->name;
181 }

   
Visit the ZANavi Wiki