iceoryx_doc  1.0.1
file_reader.hpp
1 // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 #ifndef IOX_UTILS_FILE_READER_FILE_READER_HPP
17 #define IOX_UTILS_FILE_READER_FILE_READER_HPP
18 
19 #include "iceoryx_utils/error_handling/error_handling.hpp"
20 
21 #include <fstream>
22 
23 namespace iox
24 {
25 namespace cxx
26 {
41 {
42  public:
45  enum class ErrorMode
46  {
47  Ignore,
48  Inform,
49  Terminate
50  };
51 
54  FileReader(const std::string& f_fileName,
55  const std::string& f_filePath = "",
56  ErrorMode f_errorMode = ErrorMode::Inform);
57 
58  FileReader(const FileReader&) = delete;
59  FileReader(FileReader&&) = delete;
60  FileReader& operator=(const FileReader&) = delete;
61  FileReader& operator=(FileReader&&) = delete;
62 
63  ~FileReader() = default;
64 
66  bool IsOpen() const;
68  bool ReadLine(std::string& f_string);
69 
70  private:
71 #ifdef _WIN32
72  static constexpr char PATH_SEPARATOR[] = "\\";
73 #else
74  static constexpr char PATH_SEPARATOR[] = "/";
75 #endif
76  std::fstream m_fileStream;
77  std::string m_file;
78  ErrorMode m_errorMode;
79 };
80 
81 } // namespace cxx
82 } // namespace iox
83 
84 #endif // IOX_UTILS_FILE_READER_FILE_READER_HPP
Wrapper class for file reading operations. Tries to open a file in the constructor....
Definition: file_reader.hpp:41
bool IsOpen() const
Check if the associated file is open.
ErrorMode
Definition: file_reader.hpp:46
FileReader(const std::string &f_fileName, const std::string &f_filePath="", ErrorMode f_errorMode=ErrorMode::Inform)
bool ReadLine(std::string &f_string)
Read one line from the file and store the result in f_string.
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28