Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
file.hpp
Go to the documentation of this file.
1 #ifndef _READFILE_H_
2 #define _READFILE_H_
3 
4 #include "logger.hpp"
5 #include <fstream>
6 #include <memory>
7 #include <vector>
8 #include <map>
9 
10 #include <iostream>
11 #include <string>
12 
13 using namespace std;
14 
15 namespace galaxis {
16  namespace utils {
17  shared_ptr<vector<string>> read_from_file_to_string(string const& p_filepath);
18  shared_ptr<vector<float>> read_from_file_to_float(string const& p_filepath);
19 
20  template <typename T>
21  void write_to_file(string const& p_filepath, std::vector<std::vector<T>> const& p_data, string const& p_delimiter = ",") {
22  ofstream file;
23  file.open(p_filepath);
24 
25  if(file.is_open()) {
26 
27  for(auto const& r: p_data) {
28  for(auto const& c: r) {
29  file << c << p_delimiter;
30  }
31  file << "\n";
32  }
33 
34  } else {
35  log_error("Failed to write file.");
36  }
37 
38  file.close();
39  }
40 
41  shared_ptr<std::map<std::string, std::string>> read_configuration(string const& p_filepath);
42 
43  } // namespace utils
44 } // namespace galaxis
45 
46 #endif // _READFILE_H_
galaxis::utils::log_error
void log_error(const Args &... args)
Definition: logger.hpp:50
galaxis::utils::write_to_file
void write_to_file(string const &p_filepath, std::vector< std::vector< T >> const &p_data, string const &p_delimiter=",")
Definition: file.hpp:21
galaxis
Definition: MapClasses.hpp:10
galaxis::utils::read_configuration
shared_ptr< std::map< std::string, std::string > > read_configuration(string const &p_filepath)
Definition: file.cpp:41
logger.hpp
galaxis::utils::read_from_file_to_float
shared_ptr< vector< float > > read_from_file_to_float(string const &p_filepath)
Definition: file.cpp:29
galaxis::utils::read_from_file_to_string
shared_ptr< vector< string > > read_from_file_to_string(string const &p_filepath)
Definition: file.cpp:5