riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
Loading...
Searching...
No Matches
FileConnector.cpp
Go to the documentation of this file.
1/* Copyright (C) 2021 Thomas Friedrich, Chu-Ping Yu,
2 * University of Antwerp - All Rights Reserved.
3 * You may use, distribute and modify
4 * this code under the terms of the GPL3 license.
5 * You should have received a copy of the GPL3 license with
6 * this file. If not, please visit:
7 * https://www.gnu.org/licenses/gpl-3.0.en.html
8 *
9 * Authors:
10 * Thomas Friedrich <thomas.friedrich@uantwerpen.be>
11 * Chu-Ping Yu <chu-ping.yu@uantwerpen.be>
12 */
13
14#include "FileConnector.h"
15
17{
18 if (!path.empty())
19 {
20 file_size = std::filesystem::file_size(path);
21 stream.open(path, std::ios::in | std::ios::binary);
22 if (stream.is_open())
23 {
24 reset_file();
25 }
26 else
27 {
28 std::cout << "FileConnector::open_file(): Error opening file!" << std::endl;
29 }
30 }
31 else
32 {
33 std::cout << "FileConnector::open_file(): Path argument is empty!" << std::endl;
34 }
35}
36
38{
39 if (stream.is_open())
40 {
41 stream.close();
42 }
43}
44
45// Reading data stream from File
46void FileConnector::read_data(char *buffer, size_t data_size)
47{
48 stream.read(buffer, data_size);
49 pos += data_size;
50 // Reset file to the beginning for repeat reading
51 if (file_size - pos < data_size)
52 {
53 reset_file();
54 }
55};
56
57void FileConnector::reset_file()
58{
59 pos = 0;
60 stream.clear();
61 stream.seekg(0, std::ios::beg);
62}
63
64FileConnector::FileConnector(): path(), stream(), file_size(0), pos(0) {};
void read_data(char *buffer, size_t data_size)
std::filesystem::path path