Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Achim Morschhauser
GeomagLogger
Commits
950ca345
Commit
950ca345
authored
Feb 19, 2021
by
Achim Morschhauser
Browse files
Independent reading and writing
- Separate pointers for reading and writing - Overwrite read() and write() routines
parent
f09fde83
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/buffer_obs_file.hpp
View file @
950ca345
...
...
@@ -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
//
...
...
src/buffer_obs_file.cpp
View file @
950ca345
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment