bytestreamout_file.hpp
Go to the documentation of this file.
1 /*
2 ===============================================================================
3 
4  FILE: bytestreamout_file.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_FILE_H
32 #define BYTE_STREAM_OUT_FILE_H
33 
34 #include "bytestreamout.hpp"
35 
36 #include <stdio.h>
37 
38 #if defined(_MSC_VER) && (_MSC_VER < 1300)
39 extern "C" int _cdecl _fseeki64(FILE*, __int64, int);
40 extern "C" __int64 _cdecl _ftelli64(FILE*);
41 #endif
42 
44 {
45 public:
46  ByteStreamOutFile(FILE* file);
47 /* replace a closed FILE* with a reopened FILE* in "ab" mode */
48  BOOL refile(FILE* file);
49 /* write a single byte */
50  BOOL putByte(U8 byte);
51 /* write an array of bytes */
52  BOOL putBytes(const U8* bytes, U32 num_bytes);
53 /* is the stream seekable (e.g. standard out is not) */
54  BOOL isSeekable() const;
55 /* get current position of stream */
56  I64 tell() const;
57 /* seek to this position in the stream */
58  BOOL seek(const I64 position);
59 /* seek to the end of the file */
60  BOOL seekEnd();
61 /* destructor */
63 protected:
64  FILE* file;
65 };
66 
68 {
69 public:
71 /* write 16 bit low-endian field */
72  BOOL put16bitsLE(const U8* bytes);
73 /* write 32 bit low-endian field */
74  BOOL put32bitsLE(const U8* bytes);
75 /* write 64 bit low-endian field */
76  BOOL put64bitsLE(const U8* bytes);
77 /* write 16 bit big-endian field */
78  BOOL put16bitsBE(const U8* bytes);
79 /* write 32 bit big-endian field */
80  BOOL put32bitsBE(const U8* bytes);
81 /* write 64 bit big-endian field */
82  BOOL put64bitsBE(const U8* bytes);
83 private:
84  U8 swapped[8];
85 };
86 
88 {
89 public:
91 /* write 16 bit low-endian field */
92  BOOL put16bitsLE(const U8* bytes);
93 /* write 32 bit low-endian field */
94  BOOL put32bitsLE(const U8* bytes);
95 /* write 64 bit low-endian field */
96  BOOL put64bitsLE(const U8* bytes);
97 /* write 16 bit big-endian field */
98  BOOL put16bitsBE(const U8* bytes);
99 /* write 32 bit big-endian field */
100  BOOL put32bitsBE(const U8* bytes);
101 /* write 64 bit big-endian field */
102  BOOL put64bitsBE(const U8* bytes);
103 private:
104  U8 swapped[8];
105 };
106 
108 {
109  this->file = file;
110 }
111 
113 {
114  if (file == 0) return FALSE;
115  this->file = file;
116  return TRUE;
117 }
118 
120 {
121  return (fputc(byte, file) == byte);
122 }
123 
124 inline BOOL ByteStreamOutFile::putBytes(const U8* bytes, U32 num_bytes)
125 {
126  return (fwrite(bytes, 1, num_bytes, file) == num_bytes);
127 }
128 
130 {
131  return (file != stdout);
132 }
133 
135 {
136 #ifdef _WIN32
137  return _ftelli64(file);
138 #else
139  return (I64)ftello(file);
140 #endif
141 }
142 
144 {
145 #ifdef _WIN32
146  return !(_fseeki64(file, position, SEEK_SET));
147 #else
148  return !(fseeko(file, (off_t)position, SEEK_SET));
149 #endif
150 }
151 
153 {
154 #ifdef _WIN32
155  return !(_fseeki64(file, 0, SEEK_END));
156 #else
157  return !(fseeko(file, (off_t)0, SEEK_END));
158 #endif
159 }
160 
162 {
163 }
164 
166 {
167  return putBytes(bytes, 2);
168 }
169 
171 {
172  return putBytes(bytes, 4);
173 }
174 
176 {
177  return putBytes(bytes, 8);
178 }
179 
181 {
182  swapped[0] = bytes[1];
183  swapped[1] = bytes[0];
184  return putBytes(swapped, 2);
185 }
186 
188 {
189  swapped[0] = bytes[3];
190  swapped[1] = bytes[2];
191  swapped[2] = bytes[1];
192  swapped[3] = bytes[0];
193  return putBytes(swapped, 4);
194 }
195 
197 {
198  swapped[0] = bytes[7];
199  swapped[1] = bytes[6];
200  swapped[2] = bytes[5];
201  swapped[3] = bytes[4];
202  swapped[4] = bytes[3];
203  swapped[5] = bytes[2];
204  swapped[6] = bytes[1];
205  swapped[7] = bytes[0];
206  return putBytes(swapped, 8);
207 }
208 
210 {
211 }
212 
214 {
215  swapped[0] = bytes[1];
216  swapped[1] = bytes[0];
217  return putBytes(swapped, 2);
218 }
219 
221 {
222  swapped[0] = bytes[3];
223  swapped[1] = bytes[2];
224  swapped[2] = bytes[1];
225  swapped[3] = bytes[0];
226  return putBytes(swapped, 4);
227 }
228 
230 {
231  swapped[0] = bytes[7];
232  swapped[1] = bytes[6];
233  swapped[2] = bytes[5];
234  swapped[3] = bytes[4];
235  swapped[4] = bytes[3];
236  swapped[5] = bytes[2];
237  swapped[6] = bytes[1];
238  swapped[7] = bytes[0];
239  return putBytes(swapped, 8);
240 }
241 
243 {
244  return putBytes(bytes, 2);
245 }
246 
248 {
249  return putBytes(bytes, 4);
250 }
251 
253 {
254  return putBytes(bytes, 8);
255 }
256 
257 #endif
int BOOL
Definition: mydefs.hpp:57
virtual BOOL put16bitsBE(const U8 *bytes)=0
BOOL putBytes(const U8 *bytes, U32 num_bytes)
BOOL put64bitsBE(const U8 *bytes)
#define FALSE
Definition: mydefs.hpp:133
BOOL put32bitsBE(const U8 *bytes)
BOOL put32bitsLE(const U8 *bytes)
BOOL put64bitsBE(const U8 *bytes)
unsigned int U32
Definition: mydefs.hpp:39
BOOL put16bitsLE(const U8 *bytes)
BOOL put16bitsBE(const U8 *bytes)
BOOL refile(FILE *file)
long long I64
Definition: mydefs.hpp:48
unsigned char U8
Definition: mydefs.hpp:41
virtual BOOL put32bitsBE(const U8 *bytes)=0
virtual BOOL put16bitsLE(const U8 *bytes)=0
BOOL put64bitsLE(const U8 *bytes)
virtual BOOL put64bitsLE(const U8 *bytes)=0
BOOL put32bitsLE(const U8 *bytes)
virtual BOOL put32bitsLE(const U8 *bytes)=0
virtual BOOL put64bitsBE(const U8 *bytes)=0
BOOL seek(const I64 position)
#define TRUE
Definition: mydefs.hpp:137
BOOL put32bitsBE(const U8 *bytes)
BOOL put16bitsBE(const U8 *bytes)
BOOL put16bitsLE(const U8 *bytes)
BOOL put64bitsLE(const U8 *bytes)


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