-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFelissCore.hpp
More file actions
86 lines (74 loc) · 2.11 KB
/
FelissCore.hpp
File metadata and controls
86 lines (74 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once
#include <string>
#include <fstream>
#include <iostream>
#include <memory>
#include <mutex>
#include <filesystem>
#include <chrono>
namespace FelissCore {
// Memory Manager
class MemoryManager {
public:
static void* Allocate(size_t size) {
return ::operator new(size);
}
static void Deallocate(void* ptr) {
::operator delete(ptr);
}
};
enum class LogLevel {
Info,
Warning,
Error,
Debug
};
class Logger {
public:
static void Log(const std::string& message, LogLevel level = LogLevel::Info) {
const char* prefix;
switch (level) {
case LogLevel::Info: prefix = "[INFO] "; break;
case LogLevel::Warning: prefix = "[WARN] "; break;
case LogLevel::Error: prefix = "[ERR!] "; break;
case LogLevel::Debug: prefix = "[DBG ] "; break;
}
std::cout << prefix << message << std::endl;
}
};
class FileSystem {
public:
static bool Exists(const std::string& path) {
return std::filesystem::exists(path);
}
static std::string ReadTextFile(const std::string& path) {
std::ifstream file(path);
if (!file.is_open()) {
Logger::Log("Failed to open file: " + path, LogLevel::Error);
return "";
}
std::string content((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
return content;
}
static bool WriteTextFile(const std::string& path, const std::string& data) {
std::ofstream file(path);
if (!file.is_open()) {
Logger::Log("Failed to write file: " + path, LogLevel::Error);
return false;
}
file << data;
return true;
}
};
// Cross-Platform
class Timer {
public:
static double GetTimeSeconds() {
using namespace std::chrono;
auto now = high_resolution_clock::now();
auto duration = now.time_since_epoch();
return duration_cast<duration<double>>(duration).count();
}
};
}