Fix:Core:Corretly set moved flag
[navit-package] / navit / vehicleprofile.c
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 <glib.h>
21 #include <string.h>
22 #include <stdlib.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         default:
55                 break;
56         }
57 }
58
59 struct vehicleprofile *
60 vehicleprofile_new(struct attr *parent, struct attr **attrs)
61 {
62         struct vehicleprofile *this_;
63         struct attr **attr, *type_attr;
64         if (! (type_attr=attr_search(attrs, NULL, attr_name))) {
65                 return NULL;
66         }
67         this_=g_new0(struct vehicleprofile, 1);
68         this_->attrs=attr_list_dup(attrs);
69         this_->roadprofile_hash=g_hash_table_new(NULL, NULL);
70         for (attr=attrs;*attr; attr++)
71                 vehicleprofile_set_attr_do(this_, *attr);
72         return this_;
73 }
74
75 int
76 vehicleprofile_get_attr(struct vehicleprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
77 {
78         return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
79 }
80
81 int
82 vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr)
83 {
84         vehicleprofile_set_attr_do(this_, attr);
85         this_->attrs=attr_generic_set_attr(this_->attrs, attr);
86         return 1;
87 }
88
89 int
90 vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr)
91 {
92         this_->attrs=attr_generic_add_attr(this_->attrs, attr);
93         struct attr item_types_attr;
94         switch (attr->type) {
95         case attr_roadprofile:
96                 if (roadprofile_get_attr(attr->u.roadprofile, attr_item_types, &item_types_attr, NULL)) {
97                         enum item_type *types=item_types_attr.u.item_types;
98                         while (*types != type_none) {
99                                 g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), attr->u.roadprofile);
100                                 types++;
101                         }
102                 }
103                 break;
104         default:
105                 break;
106         }
107         return 1;
108 }
109
110 int
111 vehicleprofile_remove_attr(struct vehicleprofile *this_, struct attr *attr)
112 {
113         this_->attrs=attr_generic_remove_attr(this_->attrs, attr);
114         return 1;
115 }
116
117 struct roadprofile *
118 vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type)
119 {
120         return g_hash_table_lookup(this_->roadprofile_hash, (void *)(long)type);
121 }
122
123 char *
124 vehicleprofile_get_name(struct vehicleprofile *this_)
125 {
126     return this_->name;
127 }