-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from rhasler1/main
Add example: Cipher
- Loading branch information
Showing
25 changed files
with
85,386 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
# UnoAPI:CMakeLists-targetlibraries:begin | ||
|
||
add_executable(cipher main.cpp scramble.cpp file_ops.cpp timestamps.cpp) | ||
target_link_libraries(cipher spdlog::spdlog CLI11::CLI11) | ||
|
||
enable_testing() | ||
add_executable(cipher_tests test.cpp scramble.cpp file_ops.cpp) | ||
target_link_libraries(cipher_tests gtest_main fmt::fmt spdlog::spdlog CLI11::CLI11) | ||
include(GoogleTest) | ||
gtest_discover_tests(cipher_tests) | ||
|
||
# UnoAPI: CMakeLists-targetlibraries:end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "file_ops.h" | ||
|
||
// If the file cannot be opened, then the function will notify the caller | ||
// by returning 1. | ||
int read_from_binary(std::vector<std::byte> & buffer, std::string path_to_file) | ||
{ | ||
std::ifstream input(path_to_file, std::ios::binary); | ||
if (!input.is_open()) { | ||
spdlog::error("Error opening file to read from: {}", path_to_file); | ||
return 1; | ||
} | ||
std::uintmax_t size = std::filesystem::file_size(path_to_file); | ||
buffer.resize(size); | ||
// TODO: See if it is possible to read binary data from file without casting. | ||
input.read(reinterpret_cast<char*>(buffer.data()), size); | ||
input.close(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef FILEOPS_H | ||
#define FILEOPS_H | ||
|
||
#include <spdlog/spdlog.h> | ||
#include <spdlog/sinks/stdout_color_sinks.h> | ||
|
||
#include <fstream> | ||
#include <filesystem> | ||
|
||
int read_from_binary( | ||
std::vector<std::byte> & buffer, | ||
std::string path_to_file | ||
); | ||
|
||
// If the file cannot be opened, then the function will notify the caller | ||
// by returning 1. | ||
template <class Writable> | ||
int write_to_binary(Writable & buffer, std::string path_to_file) | ||
{ | ||
std::ofstream output(path_to_file, std::ios::binary); | ||
if (!output.is_open()) { | ||
spdlog::error("Error opening file to read from: {}", path_to_file); | ||
return 1; | ||
} | ||
// TODO: See if it is possible to write binary data to file without casting. | ||
output.write(reinterpret_cast<char*>(&buffer[0]), buffer.size()); | ||
output.close(); | ||
return 0; | ||
} | ||
|
||
#endif |
Empty file.
Empty file.
Oops, something went wrong.