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

Contents of /navit/navit/vehicleprofile.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations) (download)
Tue Aug 11 18:50:37 2015 UTC (8 years, 7 months ago) by zoff99
File MIME type: text/plain
File size: 5286 byte(s)
many fixes, and 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 {
70 g_free(this_->name);
71 }
72 /* previously used strdupn not available on win32 */
73 this_->name = g_strdup(attr->u.str);
74 break;
75 case attr_vehicle_axle_weight:
76 this_->axle_weight = attr->u.num;
77 break;
78 case attr_vehicle_height:
79 this_->height = attr->u.num;
80 break;
81 case attr_vehicle_length:
82 this_->length = attr->u.num;
83 break;
84 case attr_vehicle_weight:
85 this_->weight = attr->u.num;
86 break;
87 case attr_vehicle_width:
88 this_->width = attr->u.num;
89 break;
90 case attr_static_speed:
91 this_->static_speed = attr->u.num;
92 break;
93 case attr_static_distance:
94 this_->static_distance = attr->u.num;
95 break;
96 case attr_through_traffic_penalty:
97 this_->through_traffic_penalty = attr->u.num;
98 break;
99 default:
100 break;
101 }
102 }
103
104 struct vehicleprofile *
105 vehicleprofile_new(struct attr *parent, struct attr **attrs)
106 {
107 //dbg(0, "EEnter\n");
108
109 struct vehicleprofile *this_;
110 struct attr **attr, *type_attr;
111 if (!(type_attr = attr_search(attrs, NULL, attr_name)))
112 {
113 return NULL;
114 }
115 this_=g_new0(struct vehicleprofile, 1);
116 this_->attrs = attr_list_dup(attrs);
117 this_->roadprofile_hash = g_hash_table_new(NULL, NULL);
118 this_->length = -1;
119 this_->width = -1;
120 this_->height = -1;
121 this_->weight = -1;
122 this_->axle_weight = -1;
123 this_->through_traffic_penalty = 9000;
124 for (attr = attrs; *attr; attr++)
125 {
126 vehicleprofile_set_attr_do(this_, *attr);
127 }
128
129 //dbg(0, "return\n");
130 return this_;
131 }
132
133 int vehicleprofile_get_attr(struct vehicleprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
134 {
135 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
136 }
137
138 int vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr)
139 {
140 vehicleprofile_set_attr_do(this_, attr);
141 this_->attrs = attr_generic_set_attr(this_->attrs, attr);
142 return 1;
143 }
144
145 void vehicleprofile_change_roadprofile_attr(struct vehicleprofile *this_, struct roadprofile *rp, enum item_type type)
146 {
147 g_hash_table_insert(this_->roadprofile_hash, (void *) (long) (type), rp);
148 }
149
150 int vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr)
151 {
152 struct attr item_types_attr;
153 this_->attrs = attr_generic_add_attr(this_->attrs, attr);
154 switch (attr->type)
155 {
156 case attr_roadprofile:
157 if (roadprofile_get_attr(attr->u.roadprofile, attr_item_types, &item_types_attr, NULL))
158 {
159 enum item_type *types = item_types_attr.u.item_types;
160 while (*types != type_none)
161 {
162 g_hash_table_insert(this_->roadprofile_hash, (void *) (long) (*types), attr->u.roadprofile);
163 types++;
164 }
165 }
166 break;
167 default:
168 break;
169 }
170 return 1;
171 }
172
173 int vehicleprofile_remove_attr(struct vehicleprofile *this_, struct attr *attr)
174 {
175 this_->attrs = attr_generic_remove_attr(this_->attrs, attr);
176 return 1;
177 }
178
179 struct roadprofile *
180 vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type)
181 {
182 return g_hash_table_lookup(this_->roadprofile_hash, (void *) (long) type);
183 }
184
185 char *
186 vehicleprofile_get_name(struct vehicleprofile *this_)
187 {
188 return this_->name;
189 }
190

   
Visit the ZANavi Wiki