2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
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.
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.
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.
25 #include "roadprofile.h"
26 #include "vehicleprofile.h"
27 #include "xmlconfig.h"
30 vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr)
32 dbg(1,"%s:%d\n", attr_to_name(attr->type), attr->u.num);
35 this_->flags=attr->u.num;
37 case attr_flags_forward_mask:
38 this_->flags_forward_mask=attr->u.num;
40 case attr_flags_reverse_mask:
41 this_->flags_reverse_mask=attr->u.num;
43 case attr_maxspeed_handling:
44 this_->maxspeed_handling=attr->u.num;
47 this_->mode=attr->u.num;
52 /* previously used strdupn not available on win32 */
53 this_->name = g_strdup(attr->u.str);
55 case attr_vehicle_axle_weight:
56 this_->axle_weight=attr->u.num;
58 case attr_vehicle_height:
59 this_->height=attr->u.num;
61 case attr_vehicle_length:
62 this_->length=attr->u.num;
64 case attr_vehicle_weight:
65 this_->weight=attr->u.num;
67 case attr_vehicle_width:
68 this_->width=attr->u.num;
70 case attr_static_speed:
71 this_->static_speed=attr->u.num;
73 case attr_static_distance:
74 this_->static_distance=attr->u.num;
76 case attr_through_traffic_penalty:
77 this_->through_traffic_penalty=attr->u.num;
84 struct vehicleprofile *
85 vehicleprofile_new(struct attr *parent, struct attr **attrs)
87 struct vehicleprofile *this_;
88 struct attr **attr, *type_attr;
89 if (! (type_attr=attr_search(attrs, NULL, attr_name))) {
92 this_=g_new0(struct vehicleprofile, 1);
93 this_->attrs=attr_list_dup(attrs);
94 this_->roadprofile_hash=g_hash_table_new(NULL, NULL);
99 this_->axle_weight=-1;
100 this_->through_traffic_penalty=9000;
101 for (attr=attrs;*attr; attr++)
102 vehicleprofile_set_attr_do(this_, *attr);
107 vehicleprofile_attr_iter_new(void)
109 return g_new0(void *,1);
113 vehicleprofile_attr_iter_destroy(struct attr_iter *iter)
120 vehicleprofile_get_attr(struct vehicleprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
122 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
126 vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr)
128 vehicleprofile_set_attr_do(this_, attr);
129 this_->attrs=attr_generic_set_attr(this_->attrs, attr);
134 vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr)
136 struct attr item_types_attr;
137 this_->attrs=attr_generic_add_attr(this_->attrs, attr);
138 switch (attr->type) {
139 case attr_roadprofile:
140 if (roadprofile_get_attr(attr->u.roadprofile, attr_item_types, &item_types_attr, NULL)) {
141 enum item_type *types=item_types_attr.u.item_types;
142 while (*types != type_none) {
143 g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), attr->u.roadprofile);
155 vehicleprofile_remove_attr(struct vehicleprofile *this_, struct attr *attr)
157 this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
162 vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type)
164 return g_hash_table_lookup(this_->roadprofile_hash, (void *)(long)type);
168 vehicleprofile_get_name(struct vehicleprofile *this_)
173 struct object_func vehicleprofile_func = {
175 (object_func_new)vehicleprofile_new,
176 (object_func_get_attr)vehicleprofile_get_attr,
177 (object_func_iter_new)vehicleprofile_attr_iter_new,
178 (object_func_iter_destroy)vehicleprofile_attr_iter_destroy,
179 (object_func_set_attr)vehicleprofile_set_attr,
180 (object_func_add_attr)vehicleprofile_add_attr,
181 (object_func_remove_attr)vehicleprofile_remove_attr,
182 (object_func_init)NULL,
183 (object_func_destroy)NULL,
184 (object_func_dup)NULL,
185 (object_func_ref)NULL,
186 (object_func_unref)NULL,