cgv
Loading...
Searching...
No Matches
big_binary_file.h
1#pragma once
2
3#include <string>
4#include "lib_begin.h"
5
6namespace cgv {
7 namespace utils {
14class CGV_API big_binary_file
15{
16public:
17 enum MODE {READ = 1, WRITE = 2, READ_WRITE = 3};
18
19private:
20 MODE access_mode;
21 std::string filename;
22 bool fileopened;
23 void* file;
24public:
25
27 big_binary_file(const std::string &filename = "");
28
31
33 bool open(MODE m, const std::string& file_name = "");
34
36 void close();
37
39 bool is_open();
40
42 long long size();
43
45 bool read(unsigned char *targetbuffer,unsigned long num, unsigned long *numread=NULL);
46
48 bool write(const unsigned char *sourcebuffer,unsigned long num, unsigned long *numwrote=NULL);
49
51 template <typename T>
52 bool read(T& v) { return read((unsigned char*)(&v),sizeof(T)); }
54 template <typename T>
55 bool read_array(T* a, unsigned int n) { return read((unsigned char*)a,sizeof(T)*n); }
56
58 template <typename T>
59 bool write(const T& v) { return write((const unsigned char*)(&v),sizeof(T)); }
61 template <typename T>
62 bool write_array(const T* a, unsigned int n) { return write((const unsigned char*)a,sizeof(T)*n); }
63
64 //set the file pointer to index (position in bytes from the beginning of the file)
65 bool seek(long long index);
66
68 long long position();
69};
70
71 }
72}
73
74#include <cgv/config/lib_end.h>
class to handle files with very large sizes (>=2GB) hiding the ugly win32 api calls
bool read_array(T *a, unsigned int n)
read an array of typed values
void close()
close the file
big_binary_file(const std::string &filename="")
assosiates the new instance to the file filename
bool write_array(const T *a, unsigned int n)
write an array of typed values
bool read(T &v)
read a typedef value
long long position()
return the position of the file pointer in bytes
bool open(MODE m, const std::string &file_name="")
open a file in read or write mode
long long size()
return the size of the file in bytes
bool is_open()
return true if the file is opened
bool write(const T &v)
write a typedef value
bool read(unsigned char *targetbuffer, unsigned long num, unsigned long *numread=NULL)
read num bytes from the file into the targetbuffer
virtual ~big_binary_file()
close the file (if it is still opened)
bool write(const unsigned char *sourcebuffer, unsigned long num, unsigned long *numwrote=NULL)
write num bytes to the file from the sourcebuffer (file must be opened with write access first)
the cgv namespace
Definition print.h:11