fix alignment + refactor
Reviewed-on: #1 Co-authored-by: Persson-dev <sim16.prib@gmail.com> Co-committed-by: Persson-dev <sim16.prib@gmail.com>
This commit was merged in pull request #1.
This commit is contained in:
@@ -4,9 +4,6 @@
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
#include <sp/misc/Format.h>
|
||||
#include <sp/misc/Log.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
DataBuffer::DataBuffer() : m_ReadOffset(0) {}
|
||||
@@ -133,31 +130,19 @@ std::ostream& operator<<(std::ostream& os, const DataBuffer& buffer) {
|
||||
return os;
|
||||
}
|
||||
|
||||
bool DataBuffer::ReadFile(const std::string& fileName) {
|
||||
try {
|
||||
std::ifstream file(fileName, std::istream::binary);
|
||||
std::ostringstream ss;
|
||||
ss << file.rdbuf();
|
||||
const std::string& s = ss.str();
|
||||
m_Buffer = DataBuffer::Data(s.begin(), s.end());
|
||||
m_ReadOffset = 0;
|
||||
} catch (std::exception& e) {
|
||||
utils::LOGE(utils::Format("[IO] Failed to read file %s ! reason : %s", fileName.c_str(), e.what()));
|
||||
return false;
|
||||
}
|
||||
return m_Buffer.size() > 0;
|
||||
void DataBuffer::ReadFile(const std::string& fileName) {
|
||||
std::ifstream file(fileName, std::istream::binary);
|
||||
std::ostringstream ss;
|
||||
ss << file.rdbuf();
|
||||
const std::string& s = ss.str();
|
||||
m_Buffer = DataBuffer::Data(s.begin(), s.end());
|
||||
m_ReadOffset = 0;
|
||||
}
|
||||
|
||||
bool DataBuffer::WriteFile(const std::string& fileName) const {
|
||||
try {
|
||||
std::ofstream file(fileName, std::ostream::binary);
|
||||
file.write(reinterpret_cast<const char*>(m_Buffer.data()), static_cast<std::streamsize>(m_Buffer.size()));
|
||||
file.flush();
|
||||
} catch (std::exception& e) {
|
||||
utils::LOGE(utils::Format("[IO] Failed to read file %s ! reason : %s", fileName.c_str(), e.what()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
void DataBuffer::WriteFile(const std::string& fileName) const {
|
||||
std::ofstream file(fileName, std::ostream::binary);
|
||||
file.write(reinterpret_cast<const char*>(m_Buffer.data()), static_cast<std::streamsize>(m_Buffer.size()));
|
||||
file.flush();
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#include <sp/misc/Log.h>
|
||||
|
||||
|
||||
|
||||
#ifdef SP_ANDROID_LOGGING
|
||||
#include <android/log.h>
|
||||
#else
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
namespace sp {
|
||||
namespace utils {
|
||||
|
||||
void LOG(const std::string& msg) {
|
||||
#ifdef SP_ANDROID_LOGGING
|
||||
__android_log_print(ANDROID_LOG_INFO, "TRACKERS", "%s", msg.c_str());
|
||||
#else
|
||||
std::cout << msg << "\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void LOGD(const std::string& msg) {
|
||||
#if !defined(NDEBUG)
|
||||
LOG(msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
void LOGE(const std::string& err) {
|
||||
#ifdef SP_ANDROID_LOGGING
|
||||
__android_log_print(ANDROID_LOG_ERROR, "TRACKERS", "%s", err.c_str());
|
||||
#else
|
||||
std::cerr << err << "\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace sp
|
||||
@@ -1,14 +0,0 @@
|
||||
#include <sp/misc/Format.h>
|
||||
#include <sp/misc/Log.h>
|
||||
#include <sp/misc/Test.h>
|
||||
|
||||
namespace sp {
|
||||
namespace test {
|
||||
|
||||
void LogAssert(const char* expression, const char* file, int line, const char* function) {
|
||||
utils::LOGE(utils::Format("%s:%i: %s: Assertion failed !", file, line, function));
|
||||
utils::LOGE(utils::Format(" %i |\t%s;", line, expression));
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace sp
|
||||
Reference in New Issue
Block a user