bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
file_handler_base.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 <copyright holder> <email>
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef FILE_HANDLER_BASE_H
5#define FILE_HANDLER_BASE_H
6
8#include "boost/noncopyable.hpp"
9
10#include <string>
11
12namespace bitrl
13{
14namespace utils
15{
16namespace io
17{
21template <typename HandlerType> class FileHandlerBase : private boost::noncopyable
22{
23 public:
25
30
35
40
45
49 std::string get_filename() const noexcept { return file_name_; }
50
55 bool is_open() const noexcept { return f_.is_open(); }
56
62 virtual void close();
63
67 virtual void open() = 0;
68
69 protected:
75
81 std::string file_name_;
82
87
92};
93
94template <typename HandlerType>
96 : file_name_(file_name), t_(t)
97{
98}
99
100template <typename HandlerType> FileHandlerBase<HandlerType>::~FileHandlerBase() { close(); }
101
102template <typename HandlerType> void FileHandlerBase<HandlerType>::close()
103{
104
105 if (f_.is_open())
106 f_.close();
107}
108
109} // namespace io
110} // namespace utils
111} // namespace bitrl
112
113#endif // FILE_HANDLER_BASE_H
Definition file_handler_base.h:22
handler_type & get_file_stream() noexcept
Returns the underlying file stream.
Definition file_handler_base.h:39
FileFormats::Type get_type() const noexcept
Returns the type of the file.
Definition file_handler_base.h:34
std::string file_name_
The name of the file to write.
Definition file_handler_base.h:81
const handler_type & get_file_stream() const noexcept
Returns the underlying file stream.
Definition file_handler_base.h:44
virtual void open()=0
Open the file.
HandlerType handler_type
Definition file_handler_base.h:24
virtual void close()
Close the file. Return true if and only if the file was closed successfully false otherwise.
Definition file_handler_base.h:102
FileHandlerBase(const std::string &file_name, FileFormats::Type t)
protected Constructor so that explicit instantiation of the class fails
Definition file_handler_base.h:95
virtual ~FileHandlerBase()
Constructor.
Definition file_handler_base.h:100
bool is_open() const noexcept
Return true if and only if the file is open.
Definition file_handler_base.h:55
const FileFormats::Type t_
The format of the file.
Definition file_handler_base.h:86
handler_type f_
The low level file handler.
Definition file_handler_base.h:91
std::string get_filename() const noexcept
Returns the filename that is used to write.
Definition file_handler_base.h:49
OutT resolve(const std::string &name, const std::map< std::string, std::any > &input)
Definition std_map_utils.h:25
Definition bitrl_consts.h:14
Type
Definition file_formats.h:24