Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/ways.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1784 - (show annotations) (download) (as text)
Sat Aug 15 13:08:37 2015 UTC (9 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 3457 byte(s)
Merge libroutino branch back into the trunk.

1 /***************************************
2 Way data type functions.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2015 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #include <stdlib.h>
24
25 #include "ways.h"
26
27 #include "files.h"
28
29
30 /*++++++++++++++++++++++++++++++++++++++
31 Load in a way list from a file.
32
33 Ways *LoadWayList Returns the way list.
34
35 const char *filename The name of the file to load.
36 ++++++++++++++++++++++++++++++++++++++*/
37
38 Ways *LoadWayList(const char *filename)
39 {
40 Ways *ways;
41
42 ways=(Ways*)malloc(sizeof(Ways));
43
44 #if !SLIM
45
46 ways->data=MapFile(filename);
47
48 /* Copy the WaysFile structure from the loaded data */
49
50 ways->file=*((WaysFile*)ways->data);
51
52 /* Set the pointers in the Ways structure. */
53
54 ways->ways =(Way *)(ways->data+sizeof(WaysFile));
55 ways->names=(char*)(ways->data+sizeof(WaysFile)+ways->file.number*sizeof(Way));
56
57 #else
58
59 ways->fd=SlimMapFile(filename);
60
61 /* Copy the WaysFile header structure from the loaded data */
62
63 SlimFetch(ways->fd,&ways->file,sizeof(WaysFile),0);
64
65 ways->namesoffset=sizeof(WaysFile)+ways->file.number*sizeof(Way);
66
67 memset(ways->ncached,0,sizeof(ways->ncached));
68
69 ways->cache=NewWayCache();
70 #ifndef LIBROUTINO
71 log_malloc(ways->cache,sizeof(*ways->cache));
72 #endif
73
74 #endif
75
76 return(ways);
77 }
78
79
80 /*++++++++++++++++++++++++++++++++++++++
81 Destroy the way list.
82
83 Ways *ways The way list to destroy.
84 ++++++++++++++++++++++++++++++++++++++*/
85
86 void DestroyWayList(Ways *ways)
87 {
88 #if !SLIM
89
90 ways->data=UnmapFile(ways->data);
91
92 #else
93
94 ways->fd=SlimUnmapFile(ways->fd);
95
96 #ifndef LIBROUTINO
97 log_free(ways->cache);
98 #endif
99 DeleteWayCache(ways->cache);
100
101 #endif
102
103 free(ways);
104 }
105
106
107 /*++++++++++++++++++++++++++++++++++++++
108 Return 0 if the two ways are the same (in respect of their types and limits),
109 otherwise return positive or negative to allow sorting.
110
111 int WaysCompare Returns a comparison.
112
113 Way *way1p The first way.
114
115 Way *way2p The second way.
116 ++++++++++++++++++++++++++++++++++++++*/
117
118 int WaysCompare(Way *way1p,Way *way2p)
119 {
120 if(way1p==way2p)
121 return(0);
122
123 if(way1p->type!=way2p->type)
124 return((int)way1p->type - (int)way2p->type);
125
126 if(way1p->allow!=way2p->allow)
127 return((int)way1p->allow - (int)way2p->allow);
128
129 if(way1p->props!=way2p->props)
130 return((int)way1p->props - (int)way2p->props);
131
132 if(way1p->speed!=way2p->speed)
133 return((int)way1p->speed - (int)way2p->speed);
134
135 if(way1p->weight!=way2p->weight)
136 return((int)way1p->weight - (int)way2p->weight);
137
138 if(way1p->height!=way2p->height)
139 return((int)way1p->height - (int)way2p->height);
140
141 if(way1p->width!=way2p->width)
142 return((int)way1p->width - (int)way2p->width);
143
144 if(way1p->length!=way2p->length)
145 return((int)way1p->length - (int)way2p->length);
146
147 return(0);
148 }

Properties

Name Value
cvs:description Functions for ways.