Moka kernel
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Moka kernel
Todo List
Namespaces
Classes
Files
File List
lib-gmapkernel
g-map
g-map-generic
g-map-vertex
tools
geometry
streams
streams.cc
streams.hh
streams.icc
alt-stdint.hh
attributes-id.hh
chrono.hh
inline-macro.hh
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
streams.icc
Go to the documentation of this file.
1
/*
2
* lib-gmapkernel : Un noyau de 3-G-cartes et des opérations.
3
* Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4
* http://www.sic.sp2mi.univ-poitiers.fr/
5
* Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6
* guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7
*
8
* This file is part of lib-gmapkernel
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU Lesser General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
19
*
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*/
23
24
//******************************************************************************
25
static
bool
bin =
true
;
26
//******************************************************************************
27
INLINE
28
uint8_t
bool2char
(
bool
ABoolArray[])
29
{
30
uint8_t
AChar = 0;
31
32
for
(
int
i=7; i>=0; --i)
33
{
34
AChar+=AChar;
35
36
if
(ABoolArray[i])
37
++AChar;
38
}
39
40
return
AChar;
41
}
42
//******************************************************************************
43
INLINE
44
void
char2bool
(
uint8_t
AChar,
bool
ABoolArray[])
45
{
46
uint8_t
mask = 1;
47
48
for
(
int
i=0; i<8; ++i)
49
{
50
ABoolArray[i]= (AChar & mask)!=0;
51
mask+=mask;
52
}
53
}
54
//******************************************************************************
55
INLINE
56
void
setBinaryMode
()
57
{
58
bin=
true
;
59
}
60
//******************************************************************************
61
INLINE
62
void
setAsciiMode
()
63
{
64
bin=
false
;
65
}
66
//******************************************************************************
67
INLINE
68
void
writeBool
(std::ostream& AStream,
bool
b)
69
{
70
if
(bin)
71
writeChar
(AStream, b);
72
else
73
writeInt
(AStream, b);
74
}
75
//******************************************************************************
76
INLINE
77
void
writeChar
(std::ostream& AStream,
uint8_t
AChar)
78
{
79
if
(bin)
80
AStream.write((
char
*) & AChar,
sizeof
(
uint8_t
));
81
else
82
AStream << (int) AChar;
83
}
84
//******************************************************************************
85
INLINE
86
void
writeInt
(std::ostream& AStream,
unsigned
long
int
AInt)
87
{
88
if
(bin)
89
AStream.write((
char
*) & AInt,
sizeof
(
unsigned
long
int
));
90
else
91
AStream << AInt;
92
}
93
//******************************************************************************
94
INLINE
95
void
writeCoord
(std::ostream& AStream,
const
TCoordinate
& ACoord)
96
{
97
if
(bin)
98
AStream.write((
char
*) & ACoord,
sizeof
(
TCoordinate
));
99
else
100
AStream << ACoord;
101
}
102
//******************************************************************************
103
INLINE
104
bool
readBool
(std::istream& AStream)
105
{
106
if
(bin)
107
return
readChar
(AStream)!=0;
108
else
109
return
readInt
(AStream)!=0;
110
}
111
//******************************************************************************
112
INLINE
113
uint8_t
readChar
(std::istream& AStream)
114
{
115
uint8_t
c;
116
117
if
(bin)
118
AStream.read((
char
*) & c,
sizeof
(
uint8_t
));
119
else
120
{
int
i; AStream >> i; c=i; }
121
122
return
c;
123
}
124
//******************************************************************************
125
INLINE
126
unsigned
long
int
readInt
(std::istream& AStream)
127
{
128
unsigned
long
int
i;
129
130
if
(bin)
131
AStream.read((
char
*) & i,
sizeof
(
unsigned
long
int
));
132
else
133
AStream >> i;
134
135
return
i;
136
}
137
//******************************************************************************
138
INLINE
139
TCoordinate
readCoord
(std::istream& AStream)
140
{
141
TCoordinate
c;
142
143
if
(bin)
144
AStream.read((
char
*) & c,
sizeof
(
TCoordinate
));
145
else
146
AStream >> c;
147
148
return
c;
149
}
150
//******************************************************************************
151
INLINE
152
void
writeTab
(std::ostream& AStream)
153
{
154
if
(!bin)
155
AStream <<
'\t'
;
156
}
157
//******************************************************************************
158
INLINE
159
void
writeSpc
(std::ostream& AStream)
160
{
161
if
(!bin)
162
AStream <<
' '
;
163
}
164
//******************************************************************************
165
INLINE
166
void
writeRet
(std::ostream& AStream)
167
{
168
if
(!bin)
169
AStream << std::endl;
170
}
171
//******************************************************************************
lib-gmapkernel
tools
streams
streams.icc
Generated on Tue Apr 9 2013 09:51:36 for Moka kernel by
1.8.2