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:
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
ByteStreamOutFile::isSeekable
BOOL isSeekable() const
Definition: bytestreamout_file.hpp:129
ByteStreamOutFileBE::ByteStreamOutFileBE
ByteStreamOutFileBE(FILE *file)
Definition: bytestreamout_file.hpp:209
ByteStreamOutFile::file
FILE * file
Definition: bytestreamout_file.hpp:62
ByteStreamOutFileBE::put16bitsLE
BOOL put16bitsLE(const U8 *bytes)
Definition: bytestreamout_file.hpp:213
ByteStreamOutFileBE::swapped
U8 swapped[8]
Definition: bytestreamout_file.hpp:104
ByteStreamOutFile::refile
BOOL refile(FILE *file)
Definition: bytestreamout_file.hpp:112
I64
long long I64
Definition: mydefs.hpp:48
ByteStreamOutFileLE::put16bitsBE
BOOL put16bitsBE(const U8 *bytes)
Definition: bytestreamout_file.hpp:180
ByteStreamOutFileLE::put16bitsLE
BOOL put16bitsLE(const U8 *bytes)
Definition: bytestreamout_file.hpp:165
ByteStreamOutFileBE::put64bitsLE
BOOL put64bitsLE(const U8 *bytes)
Definition: bytestreamout_file.hpp:229
TRUE
#define TRUE
Definition: mydefs.hpp:137
ByteStreamOutFile::putBytes
BOOL putBytes(const U8 *bytes, U32 num_bytes)
Definition: bytestreamout_file.hpp:124
ByteStreamOutFileBE::put32bitsLE
BOOL put32bitsLE(const U8 *bytes)
Definition: bytestreamout_file.hpp:220
ByteStreamOutFile
Definition: bytestreamout_file.hpp:43
ByteStreamOutFileBE::put32bitsBE
BOOL put32bitsBE(const U8 *bytes)
Definition: bytestreamout_file.hpp:247
ByteStreamOut
Definition: bytestreamout.hpp:36
ByteStreamOutFileLE::put64bitsLE
BOOL put64bitsLE(const U8 *bytes)
Definition: bytestreamout_file.hpp:175
ByteStreamOutFile::~ByteStreamOutFile
~ByteStreamOutFile()
Definition: bytestreamout_file.hpp:62
bytestreamout.hpp
ByteStreamOutFile::tell
I64 tell() const
Definition: bytestreamout_file.hpp:134
ByteStreamOutFileBE::put16bitsBE
BOOL put16bitsBE(const U8 *bytes)
Definition: bytestreamout_file.hpp:242
ByteStreamOutFileLE::swapped
U8 swapped[8]
Definition: bytestreamout_file.hpp:84
U8
unsigned char U8
Definition: mydefs.hpp:41
BOOL
int BOOL
Definition: mydefs.hpp:57
ByteStreamOutFileLE::ByteStreamOutFileLE
ByteStreamOutFileLE(FILE *file)
Definition: bytestreamout_file.hpp:161
FALSE
#define FALSE
Definition: mydefs.hpp:133
file
FILE * file
Definition: arithmeticencoder.cpp:77
ByteStreamOutFileBE
Definition: bytestreamout_file.hpp:87
ByteStreamOutFile::putByte
BOOL putByte(U8 byte)
Definition: bytestreamout_file.hpp:119
U32
unsigned int U32
Definition: mydefs.hpp:39
ByteStreamOutFileLE::put32bitsBE
BOOL put32bitsBE(const U8 *bytes)
Definition: bytestreamout_file.hpp:187
ByteStreamOutFile::ByteStreamOutFile
ByteStreamOutFile(FILE *file)
Definition: bytestreamout_file.hpp:107
ByteStreamOutFileBE::put64bitsBE
BOOL put64bitsBE(const U8 *bytes)
Definition: bytestreamout_file.hpp:252
ByteStreamOutFile::seek
BOOL seek(const I64 position)
Definition: bytestreamout_file.hpp:143
ByteStreamOutFileLE::put32bitsLE
BOOL put32bitsLE(const U8 *bytes)
Definition: bytestreamout_file.hpp:170
ByteStreamOutFile::seekEnd
BOOL seekEnd()
Definition: bytestreamout_file.hpp:152
ByteStreamOutFileLE
Definition: bytestreamout_file.hpp:67
ByteStreamOutFileLE::put64bitsBE
BOOL put64bitsBE(const U8 *bytes)
Definition: bytestreamout_file.hpp:196


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