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

Contents of /navit/navit/vehicleprofile.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 4136 byte(s)
import files
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 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 #include <stdlib.h>
21 #include <glib.h>
22 #include <string.h>
23 #include "debug.h"
24 #include "item.h"
25 #include "roadprofile.h"
26 #include "vehicleprofile.h"
27
28 static void
29 vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr)
30 {
31 dbg(1,"%s:%d\n", attr_to_name(attr->type), attr->u.num);
32 switch (attr->type) {
33 case attr_flags:
34 this_->flags=attr->u.num;
35 break;
36 case attr_flags_forward_mask:
37 this_->flags_forward_mask=attr->u.num;
38 break;
39 case attr_flags_reverse_mask:
40 this_->flags_reverse_mask=attr->u.num;
41 break;
42 case attr_maxspeed_handling:
43 this_->maxspeed_handling=attr->u.num;
44 break;
45 case attr_route_mode:
46 this_->mode=attr->u.num;
47 break;
48 case attr_name:
49 if(this_->name)
50 g_free(this_->name);
51 /* previously used strdupn not available on win32 */
52 this_->name = g_strdup(attr->u.str);
53 break;
54 case attr_vehicle_axle_weight:
55 this_->axle_weight=attr->u.num;
56 break;
57 case attr_vehicle_height:
58 this_->height=attr->u.num;
59 break;
60 case attr_vehicle_length:
61 this_->length=attr->u.num;
62 break;
63 case attr_vehicle_weight:
64 this_->weight=attr->u.num;
65 break;
66 case attr_vehicle_width:
67 this_->width=attr->u.num;
68 break;
69 case attr_static_speed:
70 this_->static_speed=attr->u.num;
71 break;
72 case attr_static_distance:
73 this_->static_distance=attr->u.num;
74 break;
75 case attr_through_traffic_penalty:
76 this_->through_traffic_penalty=attr->u.num;
77 break;
78 default:
79 break;
80 }
81 }
82
83 struct vehicleprofile *
84 vehicleprofile_new(struct attr *parent, struct attr **attrs)
85 {
86 struct vehicleprofile *this_;
87 struct attr **attr, *type_attr;
88 if (! (type_attr=attr_search(attrs, NULL, attr_name))) {
89 return NULL;
90 }
91 this_=g_new0(struct vehicleprofile, 1);
92 this_->attrs=attr_list_dup(attrs);
93 this_->roadprofile_hash=g_hash_table_new(NULL, NULL);
94 this_->length=-1;
95 this_->width=-1;
96 this_->height=-1;
97 this_->weight=-1;
98 this_->axle_weight=-1;
99 this_->through_traffic_penalty=9000;
100 for (attr=attrs;*attr; attr++)
101 vehicleprofile_set_attr_do(this_, *attr);
102 return this_;
103 }
104
105 int
106 vehicleprofile_get_attr(struct vehicleprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
107 {
108 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
109 }
110
111 int
112 vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr)
113 {
114 vehicleprofile_set_attr_do(this_, attr);
115 this_->attrs=attr_generic_set_attr(this_->attrs, attr);
116 return 1;
117 }
118
119 int
120 vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr)
121 {
122 struct attr item_types_attr;
123 this_->attrs=attr_generic_add_attr(this_->attrs, attr);
124 switch (attr->type) {
125 case attr_roadprofile:
126 if (roadprofile_get_attr(attr->u.roadprofile, attr_item_types, &item_types_attr, NULL)) {
127 enum item_type *types=item_types_attr.u.item_types;
128 while (*types != type_none) {
129 g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), attr->u.roadprofile);
130 types++;
131 }
132 }
133 break;
134 default:
135 break;
136 }
137 return 1;
138 }
139
140 int
141 vehicleprofile_remove_attr(struct vehicleprofile *this_, struct attr *attr)
142 {
143 this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
144 return 1;
145 }
146
147 struct roadprofile *
148 vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type)
149 {
150 return g_hash_table_lookup(this_->roadprofile_hash, (void *)(long)type);
151 }
152
153 char *
154 vehicleprofile_get_name(struct vehicleprofile *this_)
155 {
156 return this_->name;
157 }

   
Visit the ZANavi Wiki