-
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.
- Loading branch information
Showing
13 changed files
with
494 additions
and
263 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
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,14 @@ | ||
#include "device.h" | ||
|
||
Device::Device() | ||
{} | ||
|
||
bool Device::read(unsigned char* bytes) | ||
{ | ||
return read(bytes, 1); | ||
} | ||
|
||
bool Device::write(const unsigned char* bytes) | ||
{ | ||
return write(bytes, 1); | ||
} |
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 @@ | ||
#ifndef DEVICE_H | ||
#define DEVICE_H | ||
|
||
#include <span> | ||
|
||
class Device | ||
{ | ||
public: | ||
Device(); | ||
|
||
bool read(unsigned char* bytes); | ||
bool write(const unsigned char* bytes); | ||
|
||
virtual bool read(unsigned char* bytes, size_t size) = 0; | ||
virtual bool write(const unsigned char* bytes, size_t size) = 0; | ||
}; | ||
|
||
#endif // DEVICE_H |
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,49 @@ | ||
#include <iostream> | ||
|
||
#include "logger.h" | ||
|
||
#include <string> | ||
#include <string_view> | ||
|
||
Logger::Logger() | ||
: m_log{false} | ||
{} | ||
|
||
Logger &Logger::get() | ||
{ | ||
static Logger instance; | ||
return instance; | ||
} | ||
|
||
bool Logger::setup(std::string& filePath) | ||
{ | ||
m_stream.open(filePath, std::ofstream::out | std::ofstream::trunc); | ||
|
||
m_log = !m_stream.fail(); | ||
return m_log; | ||
} | ||
|
||
void Logger::close() | ||
{ | ||
get() << NewLine; | ||
|
||
if (m_log) | ||
m_stream.close(); | ||
} | ||
|
||
template<typename T> | ||
Logger& operator<<(Logger& logger, T text) | ||
{ | ||
std::cerr << text; | ||
if (logger.m_log) logger.m_stream << text; | ||
return logger; | ||
} | ||
|
||
template Logger& operator<<(Logger& logger, size_t); | ||
template Logger& operator<<(Logger& logger, int32_t); | ||
template Logger& operator<<(Logger& logger, bool); | ||
template Logger& operator<<(Logger& logger, char); | ||
template Logger& operator<<(Logger& logger, char*); | ||
template Logger& operator<<(Logger& logger, char const*); | ||
template Logger& operator<<(Logger& logger, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>); | ||
template Logger& operator<<(Logger& logger, unsigned short); |
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,28 @@ | ||
#ifndef LOGGER_H | ||
#define LOGGER_H | ||
|
||
#include <memory> | ||
#include <ostream> | ||
#include <fstream> | ||
|
||
class Logger | ||
{ | ||
public: | ||
Logger(); | ||
|
||
static Logger& get(); | ||
bool setup(std::string& filePath); | ||
void close(); | ||
|
||
constexpr static char NewLine {'\n'}; | ||
|
||
template<typename T> | ||
friend Logger& operator<<(Logger& logger, T text); | ||
|
||
private: | ||
bool m_log; | ||
std::ofstream m_stream; | ||
}; | ||
|
||
|
||
#endif // LOGGER_H |
Oops, something went wrong.