bytestreamout_ostream.hpp
Go to the documentation of this file.
1 /*
2 ===============================================================================
3 
4  FILE: bytestreamout_ostream.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_OUT_OSTREAM_H
32 #define BYTE_STREAM_OUT_OSTREAM_H
33 
34 #include "bytestreamout.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  ByteStreamOutOstream(ostream& stream);
48 /* write a single byte */
49  BOOL putByte(U8 byte);
50 /* write an array of bytes */
51  BOOL putBytes(const U8* bytes, U32 num_bytes);
52 /* is the stream seekable (e.g. standard out 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();
60 /* destructor */
62 protected:
63  ostream& stream;
64 };
65 
67 {
68 public:
69  ByteStreamOutOstreamLE(ostream& stream);
70 /* write 16 bit low-endian field */
71  BOOL put16bitsLE(const U8* bytes);
72 /* write 32 bit low-endian field */
73  BOOL put32bitsLE(const U8* bytes);
74 /* write 64 bit low-endian field */
75  BOOL put64bitsLE(const U8* bytes);
76 /* write 16 bit big-endian field */
77  BOOL put16bitsBE(const U8* bytes);
78 /* write 32 bit big-endian field */
79  BOOL put32bitsBE(const U8* bytes);
80 /* write 64 bit big-endian field */
81  BOOL put64bitsBE(const U8* bytes);
82 private:
83  U8 swapped[8];
84 };
85 
87 {
88 public:
89  ByteStreamOutOstreamBE(ostream& stream);
90 /* write 16 bit low-endian field */
91  BOOL put16bitsLE(const U8* bytes);
92 /* write 32 bit low-endian field */
93  BOOL put32bitsLE(const U8* bytes);
94 /* write 64 bit low-endian field */
95  BOOL put64bitsLE(const U8* bytes);
96 /* write 16 bit big-endian field */
97  BOOL put16bitsBE(const U8* bytes);
98 /* write 32 bit big-endian field */
99  BOOL put32bitsBE(const U8* bytes);
100 /* write 64 bit big-endian field */
101  BOOL put64bitsBE(const U8* bytes);
102 private:
103  U8 swapped[8];
104 };
105 
106 inline ByteStreamOutOstream::ByteStreamOutOstream(ostream& stream_param) :
107  stream(stream_param)
108 {
109 }
110 
112 {
113  stream.put(byte);
114  return stream.good();
115 }
116 
117 inline BOOL ByteStreamOutOstream::putBytes(const U8* bytes, U32 num_bytes)
118 {
119  stream.write((const char*)bytes, num_bytes);
120  return stream.good();
121 }
122 
124 {
125  return !!(static_cast<ofstream&>(stream));
126 }
127 
129 {
130  return (I64)stream.tellp();
131 }
132 
134 {
135  stream.seekp(static_cast<streamoff>(position));
136  return stream.good();
137 }
138 
140 {
141  stream.seekp(0, ios::end);
142  return stream.good();
143 }
144 
146 {
147 }
148 
150 {
151  return putBytes(bytes, 2);
152 }
153 
155 {
156  return putBytes(bytes, 4);
157 }
158 
160 {
161  return putBytes(bytes, 8);
162 }
163 
165 {
166  swapped[0] = bytes[1];
167  swapped[1] = bytes[0];
168  return putBytes(swapped, 2);
169 }
170 
172 {
173  swapped[0] = bytes[3];
174  swapped[1] = bytes[2];
175  swapped[2] = bytes[1];
176  swapped[3] = bytes[0];
177  return putBytes(swapped, 4);
178 }
179 
181 {
182  swapped[0] = bytes[7];
183  swapped[1] = bytes[6];
184  swapped[2] = bytes[5];
185  swapped[3] = bytes[4];
186  swapped[4] = bytes[3];
187  swapped[5] = bytes[2];
188  swapped[6] = bytes[1];
189  swapped[7] = bytes[0];
190  return putBytes(swapped, 8);
191 }
192 
194 {
195 }
196 
198 {
199  swapped[0] = bytes[1];
200  swapped[1] = bytes[0];
201  return putBytes(swapped, 2);
202 }
203 
205 {
206  swapped[0] = bytes[3];
207  swapped[1] = bytes[2];
208  swapped[2] = bytes[1];
209  swapped[3] = bytes[0];
210  return putBytes(swapped, 4);
211 }
212 
214 {
215  swapped[0] = bytes[7];
216  swapped[1] = bytes[6];
217  swapped[2] = bytes[5];
218  swapped[3] = bytes[4];
219  swapped[4] = bytes[3];
220  swapped[5] = bytes[2];
221  swapped[6] = bytes[1];
222  swapped[7] = bytes[0];
223  return putBytes(swapped, 8);
224 }
225 
227 {
228  return putBytes(bytes, 2);
229 }
230 
232 {
233  return putBytes(bytes, 4);
234 }
235 
237 {
238  return putBytes(bytes, 8);
239 }
240 
241 #endif
BOOL put16bitsLE(const U8 *bytes)
int BOOL
Definition: mydefs.hpp:57
BOOL put64bitsBE(const U8 *bytes)
BOOL put32bitsBE(const U8 *bytes)
BOOL putBytes(const U8 *bytes, U32 num_bytes)
BOOL put32bitsLE(const U8 *bytes)
ByteStreamOutOstream(ostream &stream)
BOOL put64bitsLE(const U8 *bytes)
unsigned int U32
Definition: mydefs.hpp:39
long long I64
Definition: mydefs.hpp:48
unsigned char U8
Definition: mydefs.hpp:41
BOOL put64bitsBE(const U8 *bytes)
BOOL put64bitsLE(const U8 *bytes)
BOOL put16bitsBE(const U8 *bytes)
BOOL seek(const I64 position)
BOOL put16bitsLE(const U8 *bytes)
ByteStreamOutOstreamBE(ostream &stream)
BOOL put32bitsBE(const U8 *bytes)
BOOL put16bitsBE(const U8 *bytes)
BOOL put32bitsLE(const U8 *bytes)
ByteStreamOutOstreamLE(ostream &stream)


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 Mon Feb 28 2022 22:46:06