Skip to content

Commit

Permalink
Renamed missing log folder to logging
Browse files Browse the repository at this point in the history
  • Loading branch information
matt77hias committed Oct 25, 2016
1 parent 43a16f3 commit a481ae0
Show file tree
Hide file tree
Showing 11 changed files with 697 additions and 39 deletions.
16 changes: 8 additions & 8 deletions MAGE/MAGE.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
<ClInclude Include="MAGE\src\core\version.hpp" />
<ClInclude Include="MAGE\src\io\input.hpp" />
<ClInclude Include="MAGE\src\io\io.hpp" />
<ClInclude Include="MAGE\src\log\debug.hpp" />
<ClInclude Include="MAGE\src\log\error.hpp" />
<ClInclude Include="MAGE\src\log\log.hpp" />
<ClInclude Include="MAGE\src\log\progressreporter.hpp" />
<ClInclude Include="MAGE\src\log\timer.hpp" />
<ClInclude Include="MAGE\src\logging\debug.hpp" />
<ClInclude Include="MAGE\src\logging\error.hpp" />
<ClInclude Include="MAGE\src\logging\logging.hpp" />
<ClInclude Include="MAGE\src\logging\progressreporter.hpp" />
<ClInclude Include="MAGE\src\logging\timer.hpp" />
<ClInclude Include="MAGE\src\math\geometry.hpp" />
<ClInclude Include="MAGE\src\math\math.hpp" />
<ClInclude Include="MAGE\src\memory\allocation.hpp" />
Expand All @@ -52,9 +52,9 @@
<ItemGroup>
<ClCompile Include="MAGE\src\core\engine.cpp" />
<ClCompile Include="MAGE\src\io\input.cpp" />
<ClCompile Include="MAGE\src\log\error.cpp" />
<ClCompile Include="MAGE\src\log\progressreporter.cpp" />
<ClCompile Include="MAGE\src\log\timer.cpp" />
<ClCompile Include="MAGE\src\logging\error.cpp" />
<ClCompile Include="MAGE\src\logging\progressreporter.cpp" />
<ClCompile Include="MAGE\src\logging\timer.cpp" />
<ClCompile Include="MAGE\src\parallel\lock.cpp" />
<ClCompile Include="MAGE\src\parallel\task.cpp" />
<ClCompile Include="MAGE\src\resource\resource_manager.cpp" />
Expand Down
60 changes: 30 additions & 30 deletions MAGE/MAGE.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@
<Filter Include="Source Files\parallel">
<UniqueIdentifier>{23b667d5-379d-444b-8454-b21d92f99a67}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\log">
<UniqueIdentifier>{c7374162-a25a-4c28-8475-0b93646cf99c}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\log">
<UniqueIdentifier>{dbb452e9-4d9e-4ce3-9101-98b8782a0759}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\state">
<UniqueIdentifier>{8463f1af-bd9e-4155-89f6-bb804a124c73}</UniqueIdentifier>
</Filter>
Expand All @@ -73,6 +67,12 @@
<Filter Include="Source Files\scripting">
<UniqueIdentifier>{69b1cee0-5512-4d9b-ab9a-f0dbb346243b}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\logging">
<UniqueIdentifier>{dbb452e9-4d9e-4ce3-9101-98b8782a0759}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\logging">
<UniqueIdentifier>{c7374162-a25a-4c28-8475-0b93646cf99c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MAGE\src\collection\collection.hpp">
Expand All @@ -87,21 +87,6 @@
<ClInclude Include="MAGE\src\core\engine.hpp">
<Filter>Header Files\core</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\log\debug.hpp">
<Filter>Header Files\log</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\log\error.hpp">
<Filter>Header Files\log</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\log\log.hpp">
<Filter>Header Files\log</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\log\progressreporter.hpp">
<Filter>Header Files\log</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\log\timer.hpp">
<Filter>Header Files\log</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\math\geometry.hpp">
<Filter>Header Files\math</Filter>
</ClInclude>
Expand Down Expand Up @@ -162,20 +147,26 @@
<ClInclude Include="MAGE\src\scripting\variable.hpp">
<Filter>Header Files\scripting</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\logging\debug.hpp">
<Filter>Header Files\logging</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\logging\error.hpp">
<Filter>Header Files\logging</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\logging\logging.hpp">
<Filter>Header Files\logging</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\logging\progressreporter.hpp">
<Filter>Header Files\logging</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\logging\timer.hpp">
<Filter>Header Files\logging</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MAGE\src\core\engine.cpp">
<Filter>Source Files\core</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\log\error.cpp">
<Filter>Source Files\log</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\log\progressreporter.cpp">
<Filter>Source Files\log</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\log\timer.cpp">
<Filter>Source Files\log</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\parallel\lock.cpp">
<Filter>Source Files\parallel</Filter>
</ClCompile>
Expand All @@ -194,5 +185,14 @@
<ClCompile Include="MAGE\src\scripting\script.cpp">
<Filter>Source Files\scripting</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\logging\error.cpp">
<Filter>Source Files\logging</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\logging\progressreporter.cpp">
<Filter>Source Files\logging</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\logging\timer.cpp">
<Filter>Source Files\logging</Filter>
</ClCompile>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion MAGE/MAGE/src/core/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace mage {
#include "collection\collection.hpp"
#include "math\math.hpp"
#include "parallel\parallel.hpp"
#include "log\log.hpp"
#include "logging\logging.hpp"
#include "memory\memory.hpp"
#include "resource\resource.hpp"
#include "state\state.hpp"
Expand Down
24 changes: 24 additions & 0 deletions MAGE/MAGE/src/logging/debug.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

//-----------------------------------------------------------------------------
// System Includes
//-----------------------------------------------------------------------------
#pragma region

#include <assert.h>

#pragma endregion

//-----------------------------------------------------------------------------
// Engine Defines
//-----------------------------------------------------------------------------
#pragma region

#ifdef NDEBUG
#define Assert(expr) (__noop)
#else
#define Assert(expr) ((expr) ? __noop : Severe("Assertion \"%s\" failed in %s, line %d", \
#expr, __FILE__, __LINE__))
#endif

#pragma endregion
148 changes: 148 additions & 0 deletions MAGE/MAGE/src/logging/error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
//-----------------------------------------------------------------------------
// System Includes
//-----------------------------------------------------------------------------
#pragma region

#include <stdarg.h>

#pragma endregion

//-----------------------------------------------------------------------------
// Engine Includes
//-----------------------------------------------------------------------------
#pragma region

#include "engine.hpp"

#pragma endregion

//-----------------------------------------------------------------------------
// Engine Declarations and Definitions
//-----------------------------------------------------------------------------
namespace mage {

/**
Finds the end of a word.
@param[in] buffer
Pointer to the first character.
@return Pointer to the end of the word.
This means the pointer points to a space
or null-terminating character.
*/
const char *FindWordEnd(const char *buffer) {
while (*buffer != '\0' && !isspace(*buffer)) {
++buffer;
}
return buffer;
}

/**
Process the given error.
@param[in] format
The format of the error string.
@param[in] args
The arguments of the format string.
@param[in] error_type
The type of the error.
@param[in] error_disposition
Disposition of the error.
*/
void ProcessError(const char *format, const va_list args,
const string &error_type, int error_disposition) {

if (error_disposition == MAGE_ERROR_IGNORE) {
// MAGE_ERROR_IGNORE
return;
}

// MAGE_ERROR_CONTINUE and MAGE_ERROR_ABORT
// Print formatted error message
const int width = max(20, TerminalWidth() - 2);
string error_string = error_type + ": ";
size_t error_pos = error_string.size();

char error_buffer[2048];
// Write formatted output using a pointer to a list of arguments.
vsnprintf_s(error_buffer, sizeof(error_buffer), _TRUNCATE, format, args);

const char *msg_pos = error_buffer;
while (true) {
while (*msg_pos != '\0' && isspace(*msg_pos)) {
++msg_pos;
}
if (*msg_pos == '\0') {
break;
}

// isspace(*msg_pos) == true

const char *word_end = FindWordEnd(msg_pos);
if (error_pos + word_end - msg_pos > width) {
error_string += "\n ";
error_pos = 4;
}
while (msg_pos != word_end) {
error_string += *msg_pos;
++msg_pos;
++error_pos;
}
error_string += ' ';
++error_pos;
}

// Writes the error_string pointed by format to stderr.
fprintf(stderr, "%s\n", error_string.c_str());

if (error_disposition == MAGE_ERROR_ABORT) {
// MAGE_ERROR_ABORT
__debugbreak();
}
}

void Info(const char *format, ...) {
if (!general_configuration.IsVerbose() || general_configuration.IsQuiet()) {
// Do not process info in non-verbose mode.
// Do not process info in quiet mode.
return;
}
va_list args;
// Retrieve the additional arguments after format
va_start(args, format);
ProcessError(format, args, "Notice", MAGE_ERROR_CONTINUE);
// End using variable argument list
va_end(args);
}

void Warning(const char *format, ...) {
if (general_configuration.IsQuiet()) {
// Do not process warning in quiet mode.
return;
}
va_list args;
// Retrieve the additional arguments after format
va_start(args, format);
ProcessError(format, args, "Warning", MAGE_ERROR_CONTINUE);
// End using variable argument list
va_end(args);
}

void Error(const char *format, ...) {
va_list args;
// Retrieve the additional arguments after format
va_start(args, format);
ProcessError(format, args, "Error", MAGE_ERROR_CONTINUE);
// End using variable argument list
va_end(args);
}

void Severe(const char *format, ...) {
va_list args;
// Retrieve the additional arguments after format
va_start(args, format);
ProcessError(format, args, "Fatal Error", MAGE_ERROR_ABORT);
// End using variable argument list
va_end(args);
}
}
50 changes: 50 additions & 0 deletions MAGE/MAGE/src/logging/error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

//-----------------------------------------------------------------------------
// Engine Defines
//-----------------------------------------------------------------------------
#pragma region

#define MAGE_ERROR_IGNORE 0
#define MAGE_ERROR_CONTINUE 1
#define MAGE_ERROR_ABORT 2

#pragma endregion

//-----------------------------------------------------------------------------
// Engine Declarations and Definitions
//-----------------------------------------------------------------------------
namespace mage {

/**
Notifies an info message.
@param[in] format
Pointer to the message format.
*/
void Info(const char *format, ...);

/**
Notifies a warning message.
@param[in] format
Pointer to the message format.
*/
void Warning(const char *format, ...);

/**
Notifies an error message.
@param[in] format
Pointer to the message format.
*/
void Error(const char *format, ...);

/**
Notifies a severe message.
@param[in] format
Pointer to the message format.
*/
void Severe(const char *format, ...);
}
Loading

0 comments on commit a481ae0

Please sign in to comment.