-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
104 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "error_handle.h" | ||
|
||
#include <iostream> | ||
|
||
void __m_assert( | ||
const char* expected_str, | ||
bool expected, | ||
const char* file, | ||
int line, | ||
const char* function, | ||
const char* message | ||
) { | ||
if (expected) { | ||
return; | ||
} | ||
|
||
if(message) { | ||
std::cerr << "M_ASSERT FAILED: " | ||
<< function << " [ERROR::" << expected_str << "] at [" << file << ":" << line << "]\n" | ||
<< "Message: " << message << "\n"; | ||
} else { | ||
std::cerr << "M_ASSERT FAILED: " | ||
<< function << " [ERROR::" << expected_str << "] at [" << file << ":" << line << "]\n"; | ||
} | ||
|
||
#ifdef _WIN32 | ||
__debugbreak(); | ||
#else | ||
abort(); | ||
#endif | ||
} |
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,36 @@ | ||
#pragma once | ||
|
||
/** | ||
* @brief Private function called only by the macro | ||
* m_assert used for printing the assert | ||
* | ||
* @note Assert print is been called only if the given | ||
* expectation is wrong. There are two print formats. | ||
* The first is without a comment message and the | ||
* second is with comment message. __FILE__, __LINE__ | ||
* and __FUNCTION__ are equal of the file, line and | ||
* funtion the M_ASSERT is being executed. __VA_ARGS__ | ||
* is the representation of the comment message | ||
* | ||
* @param[in] expected_str | ||
* @param[in] expected | ||
* @param[in] file | ||
* @param[in] line | ||
* @param[in] function | ||
* @param[in] message | ||
*/ | ||
void __m_assert( | ||
const char* expected_str, | ||
bool expected, | ||
const char* file, | ||
int line, | ||
const char* function, | ||
const char* message = nullptr | ||
); | ||
|
||
#ifdef NDEBUG | ||
#define M_ASSERT(Expected, ...) | ||
#else | ||
#define M_ASSERT(Expected, ...) \ | ||
__m_assert(#Expected, Expected, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__) | ||
#endif |
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,22 @@ | ||
#include "file_read.h" | ||
|
||
#include <fstream> | ||
|
||
#include "error/error_handle.h" | ||
|
||
std::string fileToString(const std::string &file_name) { | ||
std::ifstream file(file_name); | ||
|
||
if(file_name.empty()) { return ""; } | ||
|
||
M_ASSERT(file.is_open()); | ||
|
||
std::string buffer = std::string( | ||
std::istreambuf_iterator<char>(file), | ||
std::istreambuf_iterator<char>() | ||
); | ||
|
||
M_ASSERT(!buffer.empty()); | ||
|
||
return buffer; | ||
} |
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,15 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
/** | ||
* @brief Reads the given file by seeking through it. | ||
* | ||
* @note There is a check if the file_name is valid or not. | ||
* We get the size of the file by seeing to the end of it | ||
* and ftell(). The buffer we return is been filled by fread() | ||
* | ||
* @param[in] file_name | ||
* @return std::string | ||
*/ | ||
std::string fileToString(const std::string &file_name); |