Fixed the Logging system to actually be able to handle errors. Database is also fixed to use directories.
This commit is contained in:
@@ -9,26 +9,53 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Log;
|
||||
|
||||
typedef void (*LogRaisedCb)(const Log &);
|
||||
typedef void (*LogOutputCb)(const Array<Log> &);
|
||||
|
||||
enum class LogType : UInt_8
|
||||
{
|
||||
SUCCESS,
|
||||
ERR,
|
||||
WARN,
|
||||
INFO
|
||||
};
|
||||
|
||||
/// A helper class for holding error information and handling them.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The number data type to use.
|
||||
class Log
|
||||
{
|
||||
private:
|
||||
static void (*logCb)(const Log&);
|
||||
static void DefaultRaisedCb(const Log &log);
|
||||
|
||||
static void DefaultOutputCb(const Array<Log> &logs);
|
||||
|
||||
static LogRaisedCb raisedCb;
|
||||
static LogOutputCb outputCb;
|
||||
static Array<Log> logs;
|
||||
static Log lastLog;
|
||||
static bool immediate;
|
||||
LogType type;
|
||||
Array<Str_8> tags;
|
||||
UInt_64 code;
|
||||
Str_8 msg;
|
||||
|
||||
public:
|
||||
static void SetCallback(void (*newLogCb)(const Log&));
|
||||
static void SetRaisedCallback(LogRaisedCb newCb);
|
||||
|
||||
static void Raise(const Log& log);
|
||||
static void SetOutputCallback(LogOutputCb newCb);
|
||||
|
||||
static void OnExit();
|
||||
|
||||
static void Raise(Log log);
|
||||
|
||||
/// Retrieves the last log raised.
|
||||
static Log GetLastLog();
|
||||
|
||||
static void EnableImmediateMode(bool enable);
|
||||
|
||||
/// Default members initialization.
|
||||
Log();
|
||||
|
||||
@@ -36,22 +63,26 @@ namespace ehs
|
||||
/// @param [in] tags The tags to associate this log with.
|
||||
/// @param [in] code The unique code to use.
|
||||
/// @param [in] msg Detailed information about what happened.
|
||||
Log(std::initializer_list<Str_8> tags, const UInt_64 code, const Str_8& msg);
|
||||
Log(LogType type, const std::initializer_list<Str_8> &tags, UInt_64 code, Str_8 msg);
|
||||
|
||||
/// Initializes members with the given information.
|
||||
/// @param [in] tags The tags to associate this log with.
|
||||
/// @param [in] code The unique code to use.
|
||||
/// @param [in] msg Detailed information about what happened.
|
||||
Log(Array<Str_8>& tags, const UInt_64 code, const Str_8& msg);
|
||||
Log(LogType type, Array<Str_8> tags, UInt_64 code, Str_8 msg);
|
||||
|
||||
Log(Log &&log) noexcept;
|
||||
|
||||
/// Copies all members from the given log.
|
||||
/// @param [in] log The log to copy from.
|
||||
Log(const Log& log);
|
||||
Log(const Log &log);
|
||||
|
||||
Log &operator=(Log &&log) noexcept;
|
||||
|
||||
/// Copies all members from the given log.
|
||||
/// @param [in] log The log to copy from.
|
||||
/// @returns The log that has been assigned to.
|
||||
Log& operator=(const Log& log);
|
||||
Log &operator=(const Log &log);
|
||||
|
||||
/*
|
||||
/// Compares with another given log.
|
||||
@@ -65,24 +96,26 @@ namespace ehs
|
||||
bool operator!=(const Log log);
|
||||
*/
|
||||
|
||||
/// Checks whether or not this log has the given tags.
|
||||
/// @param [in] tags The tags to look for.
|
||||
/// @returns True if all tags were found, otherwise false.
|
||||
bool HasTags(const std::initializer_list<Str_8> tags) const;
|
||||
LogType GetType() const;
|
||||
|
||||
/// Checks whether or not this log has the given tags.
|
||||
/// @param [in] tags The tags to look for.
|
||||
/// @returns True if all tags were found, otherwise false.
|
||||
bool HasTags(const Array<Str_8>& tags) const;
|
||||
bool HasTags(const std::initializer_list<Str_8> &tags) const;
|
||||
|
||||
/// Checks whether or not this log has the given tags.
|
||||
/// @param [in] tags The tags to look for.
|
||||
/// @returns True if all tags were found, otherwise false.
|
||||
bool HasTags(const Array<Str_8> &tags) const;
|
||||
|
||||
/// Checks whether or not this log has the given tag.
|
||||
/// @param [in] tag The tag to look for.
|
||||
/// @returns True if tag was found, otherwise false.
|
||||
bool HasTag(const Str_8& tag) const;
|
||||
bool HasTag(const Str_8 &tag) const;
|
||||
|
||||
/// Retrieves all the tags.
|
||||
/// @returns The result.
|
||||
Array<Str_8> GetTags() const;
|
||||
const Array<Str_8> &GetTags() const;
|
||||
|
||||
UInt_64 GetCode() const;
|
||||
|
||||
@@ -101,16 +134,20 @@ namespace ehs
|
||||
|
||||
#ifndef EHS_LOG_INT
|
||||
#ifdef EHS_DEBUG
|
||||
#define EHS_LOG_INT(type, code, msg) Log::Raise({{type, GetAcronym_8(), EHS_FILE, EHS_FUNC, Str_8::FromNum((UInt_32)EHS_LINE)}, code, msg})
|
||||
#define EHS_LOG_INT(type, code, msg) ehs::Log::Raise({type, {ehs::GetAcronym_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg})
|
||||
#else
|
||||
#define EHS_LOG_INT(type, code, msg) Log::Raise({{type, GetAcronym_8(), EHS_FUNC}, code, msg})
|
||||
#define EHS_LOG_INT(type, code, msg) ehs::Log::Raise({type, {ehs::GetAcronym_8(), EHS_FUNC}, code, msg})
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef EHS_LOG
|
||||
#ifdef EHS_DEBUG
|
||||
#define EHS_LOG(type, code, msg) ehs::Log::Raise({{type, ehs::GetAppName_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg})
|
||||
#define EHS_LOG(type, code, msg) ehs::Log::Raise({type, {ehs::GetAppName_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg})
|
||||
#else
|
||||
#define EHS_LOG(type, code, msg) ehs::Log::Raise({{type, ehs::GetAppName_8(), EHS_FUNC}, code, msg})
|
||||
#define EHS_LOG(type, code, msg) ehs::Log::Raise({type, {ehs::GetAppName_8(), EHS_FUNC}, code, msg})
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef EHS_LOG_SUCCESS
|
||||
#define EHS_LOG_SUCCESS() ehs::Log::Raise({})
|
||||
#endif
|
@@ -130,7 +130,7 @@ namespace ehs
|
||||
case 3:
|
||||
return h;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
@@ -148,7 +148,7 @@ namespace ehs
|
||||
case 3:
|
||||
return h;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
@@ -87,7 +87,7 @@ namespace ehs
|
||||
{
|
||||
if (index >= size)
|
||||
{
|
||||
EHS_LOG_INT("Warning", 0, "Cannot insert value at " + Str_8::FromNum(index) + " because it is outside of array range of " + size + ".");
|
||||
EHS_LOG_INT(LogType::WARN, 0, "Cannot insert value at " + Str_8::FromNum(index) + " because it is outside of array range of " + size + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -1075,7 +1075,7 @@ namespace ehs
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, typename O>
|
||||
template<typename T = Char_8, typename O = UInt_64>
|
||||
Str<T, O> ReadStr(O size = 0)
|
||||
{
|
||||
bool sizeKnown = size;
|
||||
|
@@ -229,7 +229,7 @@ namespace ehs
|
||||
case 1:
|
||||
return y;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
@@ -243,7 +243,7 @@ namespace ehs
|
||||
case 1:
|
||||
return y;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
@@ -266,7 +266,7 @@ namespace ehs
|
||||
case 2:
|
||||
return z;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ namespace ehs
|
||||
case 2:
|
||||
return z;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
@@ -279,7 +279,7 @@ namespace ehs
|
||||
case 3:
|
||||
return w;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 4.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 4.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
@@ -297,7 +297,7 @@ namespace ehs
|
||||
case 3:
|
||||
return w;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 4.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 4.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
@@ -12,13 +12,14 @@ namespace ehs
|
||||
Str_8 id;
|
||||
Version version;
|
||||
Array<DbTable> tables;
|
||||
Str_8 dir;
|
||||
|
||||
public:
|
||||
Database();
|
||||
|
||||
Database(Str_8 id, const Version& version);
|
||||
|
||||
Database(const Str_8& filePath);
|
||||
Database(Str_8 filePath);
|
||||
|
||||
Database(Database&& db) noexcept;
|
||||
|
||||
@@ -48,6 +49,8 @@ namespace ehs
|
||||
|
||||
DbTable* GetTable(const Str_8& id) const;
|
||||
|
||||
void Save(const Str_8& directory) const;
|
||||
Str_8 GetDirectory() const;
|
||||
|
||||
void Save(Str_8 directory);
|
||||
};
|
||||
}
|
@@ -8,12 +8,16 @@
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Database;
|
||||
|
||||
class DbTable
|
||||
{
|
||||
private:
|
||||
friend class Database;
|
||||
friend class DbVar;
|
||||
friend class DbObject;
|
||||
|
||||
Database *parent;
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
Array<DbVarTmpl> varTmpls;
|
||||
@@ -55,8 +59,8 @@ namespace ehs
|
||||
private:
|
||||
DbVarTmpl *GetVariableTemplate(UInt_64 hashId) const;
|
||||
|
||||
void Serialize(Serializer<UInt_64>& data) const;
|
||||
void Serialize(const Str_8 &dir, Serializer<UInt_64>& data) const;
|
||||
|
||||
void Deserialize(Serializer<UInt_64>& data);
|
||||
void Deserialize(const Str_8 &dir, Serializer<UInt_64>& data);
|
||||
};
|
||||
}
|
||||
|
@@ -8,6 +8,10 @@ namespace ehs
|
||||
class BaseDirectory
|
||||
{
|
||||
public:
|
||||
static Array<Str_8> GetAllFiles(const Str_8& dir);
|
||||
static Array<Str_8> GetAllFiles(const Str_8 &dir);
|
||||
|
||||
static void CreateRecursive(Str_8 dir);
|
||||
|
||||
static void Create(const Str_8 &dir);
|
||||
};
|
||||
}
|
@@ -7,6 +7,10 @@ namespace ehs
|
||||
class Directory : public BaseDirectory
|
||||
{
|
||||
public:
|
||||
static Array<Str_8> GetAllFiles(const Str_8& dir);
|
||||
static Array<Str_8> GetAllFiles(const Str_8 &dir);
|
||||
|
||||
static void CreateRecursive(Str_8 dir);
|
||||
|
||||
static void Create(const Str_8 &dir);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user