MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin_Utils.h
Go to the documentation of this file.
1// ========================================================================================================
2// _______ _______ ______ ___ ___ _______ _______
3// | | | _ | __ \ | |_ _| | |
4// | | | < | |_| |_| |
5// |__|_|__|___|___|___|__|\_____/|_______|__|____|
6//
7// This file is part of the Marvin open source library and is licensed under the terms of the MIT License.
8//
9// ========================================================================================================
10
11#ifndef MARVIN_UTILS_H
12#define MARVIN_UTILS_H
13#include <marvin/library/marvin_Literals.h>
14#include <span>
15#include <string>
16#include <fstream>
17#include <sstream>
18#include <optional>
19#include <vector>
20
21namespace marvin::utils {
22
28 template <typename T>
29 void writeToCsv(const std::string& path, std::span<T> data) {
30 std::stringstream stream;
31 for (auto i = 0_sz; i < data.size(); ++i) {
32 stream << data[i];
33 if (i != data.size() - 1) {
34 stream << ",";
35 }
36 }
37 const auto asStr = stream.str();
38 std::ofstream outStream{ path, std::ios::out };
39 outStream << asStr;
40 outStream.flush();
41 }
42
47 [[nodiscard]] std::optional<std::string> getCurrentExecutablePath();
48
49 bool readBinaryFile(const std::string& path, std::vector<char>& data);
50
51} // namespace marvin::utils
52#endif
Utility helper functions and classes.
Definition marvin_Utils.h:21
void writeToCsv(const std::string &path, std::span< T > data)
Definition marvin_Utils.h:29
bool readBinaryFile(const std::string &path, std::vector< char > &data)
std::optional< std::string > getCurrentExecutablePath()