File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,12 +9,14 @@ set( SRC_FOLDERS
99 ${CMAKE_CURRENT_SOURCE_DIR} /sources/
1010 ${CMAKE_CURRENT_SOURCE_DIR} /sources/file/
1111 ${CMAKE_CURRENT_SOURCE_DIR} /sources/pack/
12+ ${CMAKE_CURRENT_SOURCE_DIR} /sources/Log/
1213 )
1314## INCLUDE FOLDERS
1415set ( INC_FOLDERS
1516 ${CMAKE_CURRENT_SOURCE_DIR} /includes/
1617 ${CMAKE_CURRENT_SOURCE_DIR} /includes/file/
1718 ${CMAKE_CURRENT_SOURCE_DIR} /includes/pack/
19+ ${CMAKE_CURRENT_SOURCE_DIR} /includes/Log/
1820 )
1921
2022## GET SOURCES
Original file line number Diff line number Diff line change @@ -9,12 +9,17 @@ set( SRC_FOLDERS
99 ${CMAKE_CURRENT_SOURCE_DIR} /sources/
1010 ${CMAKE_CURRENT_SOURCE_DIR} /sources/file/
1111 ${CMAKE_CURRENT_SOURCE_DIR} /sources/unpack/
12+ ${CMAKE_CURRENT_SOURCE_DIR} /sources/exception/
13+ ${CMAKE_CURRENT_SOURCE_DIR} /sources/utils/
14+ ${CMAKE_CURRENT_SOURCE_DIR} /sources/log/
1215 )
1316## INCLUDE FOLDERS
1417set ( INC_FOLDERS
1518 ${CMAKE_CURRENT_SOURCE_DIR} /includes/
1619 ${CMAKE_CURRENT_SOURCE_DIR} /includes/file/
1720 ${CMAKE_CURRENT_SOURCE_DIR} /includes/unpack/
21+ ${CMAKE_CURRENT_SOURCE_DIR} /includes/exception/
22+ ${CMAKE_CURRENT_SOURCE_DIR} /includes/log/
1823 )
1924
2025## GET SOURCES
Original file line number Diff line number Diff line change 1+ /*
2+ ** ShipWreck Engine , 2023
3+ ** FileException.hpp
4+ */
5+
6+ #ifndef SW_PACKER_FILEEXCEPTION_HPP
7+ #define SW_PACKER_FILEEXCEPTION_HPP
8+
9+ #include < exception>
10+ #include < string>
11+
12+ namespace sw
13+ {
14+ class FileException : public std ::exception
15+ {
16+ private:
17+ std::string m_reason;
18+ public:
19+ explicit FileException (std::string&& reason);
20+ [[nodiscard]] const char *what () const override ;
21+ };
22+ }
23+
24+ #endif // SW_PACKER_FILEEXCEPTION_HPP
Original file line number Diff line number Diff line change 1+ /*
2+ ** ShipWreck Engine , 2023
3+ ** MemoryException.hpp
4+ */
5+
6+ #ifndef SW_PACKER_MEMORYEXCEPTION_HPP
7+ #define SW_PACKER_MEMORYEXCEPTION_HPP
8+
9+ #include < exception>
10+ #include < string>
11+
12+ namespace sw {
13+
14+ class MemoryException : public std ::exception
15+ {
16+ private:
17+ std::string m_message;
18+ public:
19+ explicit MemoryException (std::string message);
20+ [[nodiscard]]const char * what () const override ;
21+ };
22+
23+ } // sw
24+
25+ #endif // SW_PACKER_MEMORYEXCEPTION_HPP
Original file line number Diff line number Diff line change 1212
1313#include " Chunk.hpp"
1414
15+ #define FILE_TYPE " SWFP"
16+ #define FILE_VERSION 100
17+
1518namespace sw {
1619
1720 // / \brief Define the type of the file
Original file line number Diff line number Diff line change 1+ /*
2+ ** ShipWreck Engine , 2023
3+ ** Log.hpp
4+ */
5+
6+ #ifndef SW_PACKER_LOG_HPP
7+ #define SW_PACKER_LOG_HPP
8+
9+ #include < vector>
10+ #include < string>
11+ #include < map>
12+
13+ namespace sw {
14+
15+ class Log {
16+ public:
17+ enum Level {
18+ NONE,
19+ DEBUG,
20+ WARNING,
21+ ERROR,
22+ };
23+ static void AddLog (std::string&& message, Level logLevel = DEBUG);
24+ static void CloseLog ();
25+
26+ private:
27+ static std::vector<std::string> m_logs;
28+ static std::map<Level, std::string> m_levels;
29+ };
30+
31+ } // sw
32+
33+ #endif // SW_PACKER_LOG_HPP
Original file line number Diff line number Diff line change 1+ /*
2+ ** ShipWreck Engine , 2023
3+ ** utils.hpp
4+ */
5+
6+ #ifndef SW_PACKER_UTILS_HPP
7+ #define SW_PACKER_UTILS_HPP
8+
9+ namespace sw {
10+
11+ void *MemAlloc (size_t size);
12+
13+ }
14+
15+ #endif // SW_PACKER_UTILS_HPP
Original file line number Diff line number Diff line change 1+ /*
2+ ** ShipWreck Engine , 2023
3+ ** FileException.cpp
4+ */
5+
6+ #include " FileException.hpp"
7+
8+ sw::FileException::FileException (std::string&& reason) :
9+ m_reason(reason)
10+ {}
11+
12+ const char *sw::FileException::what () const
13+ {
14+ return m_reason.c_str ();
15+ }
Original file line number Diff line number Diff line change 1+ /*
2+ ** ShipWreck Engine , 2023
3+ ** MemoryException.cpp
4+ */
5+
6+ #include " MemoryException.hpp"
7+
8+ sw::MemoryException::MemoryException (std::string message) :
9+ m_message(message)
10+ {}
11+
12+ const char *sw::MemoryException::what () const
13+ {
14+ return m_message.c_str ();
15+ }
Original file line number Diff line number Diff line change 1+ /*
2+ ** ShipWreck Engine , 2023
3+ ** Log.cpp
4+ */
5+
6+ #include < fstream>
7+ #include < iomanip>
8+ #include < sstream>
9+ #include < iostream>
10+
11+ #include " Log.hpp"
12+
13+ std::vector<std::string> sw::Log::m_logs;
14+ std::map<sw::Log::Level, std::string> sw::Log::m_levels = {
15+ {NONE, " " },
16+ {DEBUG, " Debug" },
17+ {WARNING, " Warning" },
18+ {ERROR, " Error" },
19+ };
20+
21+ void sw::Log::AddLog (std::string&& message, Level logLevel)
22+ {
23+ auto t = std::time (nullptr );
24+ auto tm = *std::localtime (&t);
25+ std::ostringstream ossLog;
26+
27+ ossLog << " [" << std::put_time (&tm, " %H:%M:%S" ) << " ] " << m_levels[logLevel] << " : " << message;
28+ m_logs.emplace_back (ossLog.str ());
29+ }
30+
31+ void sw::Log::CloseLog ()
32+ {
33+ if (m_logs.empty ())
34+ return ;
35+ auto t = std::time (nullptr );
36+ auto tm = *std::localtime (&t);
37+ std::ostringstream oss;
38+ oss << std::put_time (&tm, " %d-%m-%Y_%H-%M-%S" );
39+ std::fstream outFile (" ./SWPacker_" + oss.str () + " .txt" , std::ios::out);
40+
41+ if (!outFile.is_open ()) {
42+ std::cerr << " ERROR: Unable to create log file! [" << " SWPacker_" + oss.str () << " ]" << std::endl;
43+ return ;
44+ }
45+ for (const auto & m_log : m_logs) {
46+ outFile.write (m_log.c_str (), m_log.size ());
47+ outFile.write (" \n " , 1 );
48+ }
49+ outFile.close ();
50+ }
You can’t perform that action at this time.
0 commit comments