Browse Source

Refactoring

Kajetan Johannes Hammerle 10 months ago
parent
commit
fb6ac9b462
6 changed files with 26 additions and 26 deletions
  1. 1 1
      test/Test.cpp
  2. 10 0
      utils/ArrayString.hpp
  3. 12 1
      utils/Logger.cpp
  4. 3 1
      utils/Logger.hpp
  5. 0 11
      utils/Utility.cpp
  6. 0 12
      utils/Utility.hpp

+ 1 - 1
test/Test.cpp

@@ -4,7 +4,7 @@ Core::HashMap<Core::Test::Internal::FileName, Core::Test::Internal::Result>
     Core::Test::Internal::results;
 
 void Core::Test::Internal::warn(const char* file, int line, Error e) {
-    CORE_LOG_WARNING("#:# | ", Core::getFileName(file), line, e);
+    CORE_LOG_WARNING("#:# | #", Core::Logger::getFileName(file), line, e);
 }
 
 bool Core::Test::Internal::checkFloat(const char* file, int line, float wanted,

+ 10 - 0
utils/ArrayString.hpp

@@ -7,6 +7,16 @@
 #include "utils/Utility.hpp"
 
 namespace Core {
+    template<typename T>
+    constexpr int stringLength(const T* c) {
+        int i = 0;
+        while(*c != '\0') {
+            c++;
+            i++;
+        }
+        return i;
+    }
+
     template<int N, typename CharType>
     class ArrayString final {
         int length;

+ 12 - 1
utils/Logger.cpp

@@ -1,3 +1,14 @@
 #include "utils/Logger.hpp"
 
-Core::Logger::Level Core::Logger::level = Core::Logger::Level::DEBUG;
+Core::Logger::Level Core::Logger::level = Core::Logger::Level::DEBUG;
+
+const char* Core::Logger::getFileName(const char* path) {
+    int end = 0;
+    while(path[end] != '\0') {
+        end++;
+    }
+    while(end > 0 && path[end - 1] != '/') {
+        end--;
+    }
+    return path + end;
+}

+ 3 - 1
utils/Logger.hpp

@@ -7,6 +7,8 @@ namespace Core::Logger {
     enum class Level { ERROR, WARNING, INFO, DEBUG };
     extern Level level;
 
+    const char* getFileName(const char* path);
+
     inline bool filterError(Error e) {
         return e != Error::NONE && e != Error::CAPACITY_REACHED;
     }
@@ -18,7 +20,7 @@ namespace Core::Logger {
         if(Core::Logger::level < l) {
             return;
         }
-        file = Core::getFileName(file);
+        file = getFileName(file);
         Core::String32<2048> s;
         if(filterError(s.append(start)) || filterError(s.append("#:# | ")) ||
            filterError(s.format(file, line)) || filterError(s.append(format)) ||

+ 0 - 11
utils/Utility.cpp

@@ -84,15 +84,4 @@ Core::Error Core::reallocate(char*& p, int n) {
 
 void Core::free(void* p) {
     ::free(p);
-}
-
-const char* Core::getFileName(const char* path) {
-    int end = 0;
-    while(path[end] != '\0') {
-        end++;
-    }
-    while(end > 0 && path[end - 1] != '/') {
-        end--;
-    }
-    return path + end;
 }

+ 0 - 12
utils/Utility.hpp

@@ -43,18 +43,6 @@ namespace Core {
     bool memoryCompare(const void* a, const void* b, int n);
     check_return Error reallocate(char*& p, int n);
     void free(void* p);
-
-    const char* getFileName(const char* path);
-
-    template<typename T>
-    constexpr int stringLength(const T* c) {
-        int i = 0;
-        while(*c != '\0') {
-            c++;
-            i++;
-        }
-        return i;
-    }
 }
 
 #endif