bytestreamin_istream.hpp
Go to the documentation of this file.
1 /*
2 ===============================================================================
3 
4  FILE: bytestreamin_istream.hpp
5 
6  CONTENTS:
7 
8  PROGRAMMERS:
9 
10  martin.isenburg@gmail.com
11 
12  COPYRIGHT:
13 
14  (c) 2010-2011, Martin Isenburg, LASSO - tools to catch reality
15 
16  This is free software; you can redistribute and/or modify it under the
17  terms of the GNU Lesser General Licence as published by the Free Software
18  Foundation. See the COPYING file for more information.
19 
20  This software is distributed WITHOUT ANY WARRANTY and without even the
21  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 
23  CHANGE HISTORY:
24 
25  1 October 2011 -- added 64 bit file support in MSVC 6.0 at McCafe at Hbf Linz
26  10 January 2011 -- licensing change for LGPL release and liblas integration
27  12 December 2010 -- created from ByteStreamOutFile after Howard got pushy (-;
28 
29 ===============================================================================
30 */
31 #ifndef BYTE_STREAM_IN_ISTREAM_H
32 #define BYTE_STREAM_IN_ISTREAM_H
33 
34 #include "bytestreamin.hpp"
35 
36 #ifdef LZ_WIN32_VC6
37 #include <fstream.h>
38 #else
39 #include <istream>
40 #include <fstream>
41 using namespace std;
42 #endif
43 
45 {
46 public:
47  ByteStreamInIstream(istream& stream);
48 /* read a single byte */
49  U32 getByte();
50 /* read an array of bytes */
51  void getBytes(U8* bytes, const U32 num_bytes);
52 /* is the stream seekable (e.g. standard in is not) */
53  BOOL isSeekable() const;
54 /* get current position of stream */
55  I64 tell() const;
56 /* seek to this position in the stream */
57  BOOL seek(const I64 position);
58 /* seek to the end of the file */
59  BOOL seekEnd(const I64 distance=0);
60 /* destructor */
62 protected:
63  istream& stream;
64 };
65 
67 {
68 public:
69  ByteStreamInIstreamLE(istream& stream);
70 /* read 16 bit low-endian field */
71  void get16bitsLE(U8* bytes);
72 /* read 32 bit low-endian field */
73  void get32bitsLE(U8* bytes);
74 /* read 64 bit low-endian field */
75  void get64bitsLE(U8* bytes);
76 /* read 16 bit big-endian field */
77  void get16bitsBE(U8* bytes);
78 /* read 32 bit big-endian field */
79  void get32bitsBE(U8* bytes);
80 /* read 64 bit big-endian field */
81  void get64bitsBE(U8* bytes);
82 private:
83  U8 swapped[8];
84 };
85 
87 {
88 public:
89  ByteStreamInIstreamBE(istream& stream);
90 /* read 16 bit low-endian field */
91  void get16bitsLE(U8* bytes);
92 /* read 32 bit low-endian field */
93  void get32bitsLE(U8* bytes);
94 /* read 64 bit low-endian field */
95  void get64bitsLE(U8* bytes);
96 /* read 16 bit big-endian field */
97  void get16bitsBE(U8* bytes);
98 /* read 32 bit big-endian field */
99  void get32bitsBE(U8* bytes);
100 /* read 64 bit big-endian field */
101  void get64bitsBE(U8* bytes);
102 private:
103  U8 swapped[8];
104 };
105 
106 inline ByteStreamInIstream::ByteStreamInIstream(istream& stream_param) :
107  stream(stream_param)
108 {
109 }
110 
112 {
113  int byte = stream.get();
114  if (stream.eof())
115  {
116  throw EOF;
117  }
118  return (U32)byte;
119 }
120 
121 inline void ByteStreamInIstream::getBytes(U8* bytes, const U32 num_bytes)
122 {
123  stream.read((char*)bytes, num_bytes);
124  if (!stream.good())
125  {
126  throw EOF;
127  }
128 }
129 
131 {
132  return !!(static_cast<ifstream&>(stream));
133 }
134 
136 {
137  return (I64)stream.tellg();
138 }
139 
140 inline BOOL ByteStreamInIstream::seek(const I64 position)
141 {
142  stream.seekg(static_cast<streamoff>(position));
143  return stream.good();
144 }
145 
146 inline BOOL ByteStreamInIstream::seekEnd(const I64 distance)
147 {
148  stream.seekg(static_cast<streamoff>(-distance), ios::end);
149  return stream.good();
150 }
151 
153 {
154 }
155 
157 {
158  getBytes(bytes, 2);
159 }
160 
162 {
163  getBytes(bytes, 4);
164 }
165 
167 {
168  getBytes(bytes, 8);
169 }
170 
172 {
173  getBytes(swapped, 2);
174  bytes[0] = swapped[1];
175  bytes[1] = swapped[0];
176 }
177 
179 {
180  getBytes(swapped, 4);
181  bytes[0] = swapped[3];
182  bytes[1] = swapped[2];
183  bytes[2] = swapped[1];
184  bytes[3] = swapped[0];
185 }
186 
188 {
189  getBytes(swapped, 8);
190  bytes[0] = swapped[7];
191  bytes[1] = swapped[6];
192  bytes[2] = swapped[5];
193  bytes[3] = swapped[4];
194  bytes[4] = swapped[3];
195  bytes[5] = swapped[2];
196  bytes[6] = swapped[1];
197  bytes[7] = swapped[0];
198 }
199 
201 {
202 }
203 
205 {
206  getBytes(swapped, 2);
207  bytes[0] = swapped[1];
208  bytes[1] = swapped[0];
209 }
210 
212 {
213  getBytes(swapped, 4);
214  bytes[0] = swapped[3];
215  bytes[1] = swapped[2];
216  bytes[2] = swapped[1];
217  bytes[3] = swapped[0];
218 }
219 
221 {
222  getBytes(swapped, 8);
223  bytes[0] = swapped[7];
224  bytes[1] = swapped[6];
225  bytes[2] = swapped[5];
226  bytes[3] = swapped[4];
227  bytes[4] = swapped[3];
228  bytes[5] = swapped[2];
229  bytes[6] = swapped[1];
230  bytes[7] = swapped[0];
231 }
232 
234 {
235  getBytes(bytes, 2);
236 }
237 
239 {
240  getBytes(bytes, 4);
241 }
242 
244 {
245  getBytes(bytes, 8);
246 }
247 
248 #endif
ByteStreamInIstream::ByteStreamInIstream
ByteStreamInIstream(istream &stream)
Definition: bytestreamin_istream.hpp:106
ByteStreamInIstreamBE::get16bitsLE
void get16bitsLE(U8 *bytes)
Definition: bytestreamin_istream.hpp:204
ByteStreamInIstreamLE::get64bitsBE
void get64bitsBE(U8 *bytes)
Definition: bytestreamin_istream.hpp:187
I64
long long I64
Definition: mydefs.hpp:48
ByteStreamInIstreamLE::get32bitsLE
void get32bitsLE(U8 *bytes)
Definition: bytestreamin_istream.hpp:161
ByteStreamInIstream::seekEnd
BOOL seekEnd(const I64 distance=0)
Definition: bytestreamin_istream.hpp:146
ByteStreamInIstreamBE::ByteStreamInIstreamBE
ByteStreamInIstreamBE(istream &stream)
Definition: bytestreamin_istream.hpp:200
ByteStreamInIstream::getBytes
void getBytes(U8 *bytes, const U32 num_bytes)
Definition: bytestreamin_istream.hpp:121
ByteStreamInIstream::~ByteStreamInIstream
~ByteStreamInIstream()
Definition: bytestreamin_istream.hpp:61
ByteStreamInIstream::isSeekable
BOOL isSeekable() const
Definition: bytestreamin_istream.hpp:130
ByteStreamInIstream::seek
BOOL seek(const I64 position)
Definition: bytestreamin_istream.hpp:140
ByteStreamInIstreamLE::swapped
U8 swapped[8]
Definition: bytestreamin_istream.hpp:83
ByteStreamInIstream::tell
I64 tell() const
Definition: bytestreamin_istream.hpp:135
ByteStreamInIstreamBE::get64bitsLE
void get64bitsLE(U8 *bytes)
Definition: bytestreamin_istream.hpp:220
ByteStreamInIstreamBE::swapped
U8 swapped[8]
Definition: bytestreamin_istream.hpp:103
bytestreamin.hpp
ByteStreamInIstreamLE::get32bitsBE
void get32bitsBE(U8 *bytes)
Definition: bytestreamin_istream.hpp:178
ByteStreamIn
Definition: bytestreamin.hpp:36
U8
unsigned char U8
Definition: mydefs.hpp:41
BOOL
int BOOL
Definition: mydefs.hpp:57
ByteStreamInIstreamBE::get64bitsBE
void get64bitsBE(U8 *bytes)
Definition: bytestreamin_istream.hpp:243
ByteStreamInIstreamLE
Definition: bytestreamin_istream.hpp:66
ByteStreamInIstream::getByte
U32 getByte()
Definition: bytestreamin_istream.hpp:111
ByteStreamInIstreamLE::get16bitsLE
void get16bitsLE(U8 *bytes)
Definition: bytestreamin_istream.hpp:156
std
Definition: HalfEdge.hpp:124
U32
unsigned int U32
Definition: mydefs.hpp:39
ByteStreamInIstream::stream
istream & stream
Definition: bytestreamin_istream.hpp:61
ByteStreamInIstreamLE::get64bitsLE
void get64bitsLE(U8 *bytes)
Definition: bytestreamin_istream.hpp:166
ByteStreamInIstreamBE::get16bitsBE
void get16bitsBE(U8 *bytes)
Definition: bytestreamin_istream.hpp:233
ByteStreamInIstreamBE::get32bitsBE
void get32bitsBE(U8 *bytes)
Definition: bytestreamin_istream.hpp:238
ByteStreamInIstream
Definition: bytestreamin_istream.hpp:44
ByteStreamInIstreamBE::get32bitsLE
void get32bitsLE(U8 *bytes)
Definition: bytestreamin_istream.hpp:211
ByteStreamInIstreamLE::ByteStreamInIstreamLE
ByteStreamInIstreamLE(istream &stream)
Definition: bytestreamin_istream.hpp:152
ByteStreamInIstreamLE::get16bitsBE
void get16bitsBE(U8 *bytes)
Definition: bytestreamin_istream.hpp:171
ByteStreamInIstreamBE
Definition: bytestreamin_istream.hpp:86


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:22