-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e89768
commit 081038f
Showing
23 changed files
with
4,496 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "BinaryStore.hpp" | ||
|
||
binary_store::binary_store(const std::string file_name,int given_element_size, bool flag):element_size(given_element_size) | ||
{ | ||
open(file_name,flag); | ||
} | ||
void binary_store::open(const std::string file_name,bool flag) | ||
{ | ||
const char * f_name = file_name.c_str(); | ||
file_ptr = fopen(f_name,flag?"wb":"rb"); | ||
if( file_ptr == NULL ) | ||
{ | ||
std::cerr << "error during fopen" << std::endl; | ||
exit(1); | ||
} | ||
} | ||
void binary_store::write_element(void *element) | ||
{ | ||
|
||
if (!fwrite(element, element_size, 1, file_ptr)) | ||
{ | ||
std::cerr <<"error: can't fwrite (disk full?)" << std::endl; | ||
exit(1); | ||
} | ||
|
||
} | ||
size_t binary_store::read_element( void *element) | ||
{ | ||
return fread(element, element_size,1, file_ptr); | ||
} | ||
|
||
size_t binary_store::read_element_buffer(void *element,size_t nb_elements) | ||
{ | ||
return fread(element, element_size,nb_elements, file_ptr); | ||
} | ||
|
||
void binary_store::write( void *element, int given_element_size) | ||
{ | ||
if (!fwrite(element, given_element_size, 1, file_ptr)) | ||
{ | ||
std::cerr <<"error: can't fwrite (disk full?)" << std::endl; | ||
exit(1); | ||
} | ||
} | ||
|
||
size_t binary_store::read( void *element, int given_element_size) | ||
{ | ||
return fread(element, given_element_size,1, file_ptr); | ||
} | ||
|
||
void binary_store::rewind_all() | ||
{ | ||
rewind(file_ptr); | ||
} | ||
|
||
void binary_store::close() | ||
{ | ||
fclose(file_ptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef BINARYSTORE_H | ||
#define BINARYSTORE_H | ||
#include <string> | ||
#include <stdio.h> | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
class binary_store | ||
{ | ||
public: | ||
binary_store(const std::string file_name,int given_element_size, bool flag); | ||
void write_element(void *element); | ||
size_t read_element(void *element); | ||
void write( void *element, int given_element_size); | ||
size_t read( void *element, int given_element_size); | ||
size_t read_element_buffer(void *element,size_t nb_elements); | ||
void rewind_all(); | ||
void close(); | ||
void open(const std::string file_name,bool write); | ||
private: | ||
FILE * file_ptr; | ||
const int element_size; | ||
}; | ||
|
||
|
||
#endif // BINARYSTORE_H |
Oops, something went wrong.