Commit 950ca345 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Independent reading and writing

- Separate pointers for reading and writing
- Overwrite read() and write() routines
parent f09fde83
......@@ -37,6 +37,9 @@ std::string format;
std::string filename="";
// File stream
std::fstream file;
// Read and writing position
std::streampos readpos;
std::streampos writepos;
//
......@@ -60,7 +63,10 @@ public: virtual int put(data_obs* data)=0;
public: virtual int pop(data_obs* data)=0;
/** Get last element and delete */
public: virtual data_obs pop()=0;
/** Read from file **/
public: std::istream& read(char* s, std::streamsize n);
/** Write to file **/
public: std::ostream& write(const char* s, std::streamsize n);
//
// Private Methods
//
......
......@@ -70,6 +70,33 @@ int buffer_obs_file::init() {
}
/********************************************************************************
* *
* Read data from the buffer. *
* *
********************************************************************************/
std::istream& buffer_obs_file::read(char* s, std::streamsize n) {
file.seekg(readpos,file.beg);
readpos=file.tellg()+n;
return(file.read(s,n));
}
/********************************************************************************
* *
* Write data to the buffer. *
* *
********************************************************************************/
std::ostream& buffer_obs_file::write(const char* s, std::streamsize n) {
file.seekg(writepos,file.beg);
writepos=file.tellg()+n;
return(file.write(s,n));
}
/********************************************************************************
* *
* Create directories and open file *
......@@ -95,13 +122,19 @@ int buffer_obs_file::open(std::string filename) {
}
// Open new file
file.open(filename_full,std::ios::out | std::ios::app);
std::cerr << "OPEN FILE: " << filename_full << std::endl;
file.open(filename_full,std::ios::in | std::ios::out |
std::ios::app | std::ios::ate );
if (!file.is_open()){
std::cerr << "Opening file failed: "
<< filename_full
<< std::endl;
}
// Set reading and writing pos;
writepos=file.tellp();
readpos=0;
// Set filename
this->filename = filename;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment