Adding stb lib

main
anulax1225 ago%!(EXTRA string=6 months)
parent db00552d84
commit 74846d6deb
  1. 3
      premake5.lua
  2. 7
      src/bakatools.h
  3. 5
      src/bakatools/container/data_stream.h
  4. 37
      src/bakatools/container/types.h
  5. 6
      src/bakatools/file_system/dir_entry.cpp
  6. 6
      src/bakatools/file_system/dir_entry.h
  7. 2
      src/bakatools/file_system/file_watcher.cpp
  8. 6
      src/bakatools/file_system/file_watcher.h
  9. 2
      src/bakatools/json/fs_manager.cpp
  10. 3
      src/bakatools/json/fs_manager.h
  11. 10
      src/bakatools/logging/assert.h
  12. 36
      src/bakatools/thread/task_delayer.h
  13. 43
      src/bakatools/thread/task_timer.h
  14. 56
      src/bakatools/time/time_point.h
  15. 38
      src/bakatools/time/time_span.h

@ -8,9 +8,6 @@ project "bakatools"
targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}")
objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}")
pchheader "bakatoolspch.h"
pchsource "bakatoolspch.cpp"
includedirs
{
"%{IncludeDirs.spdlog}",

@ -15,14 +15,11 @@
#include "bakatools/container/data_stream.h"
#include "bakatools/container/trie.h"
#include "bakatools/container/types.h"
#include "bakatools/thread/task_timer.h"
#include "bakatools/thread/task_delayer.h"
#include "bakatools/file_system/dir_entry.h"
#include "bakatools/file_system/directory.h"
#include "bakatools/file_system/file.h"
#include "bakatools/file_system/file_watcher.h"
#include "bakatools/time/time_span.h"
#include "bakatools/time/time_point.h"
#include "bakatools/file_system/file_watcher.h"

@ -1,12 +1,15 @@
#pragma once
#include <bakatoolspch.h>
#include <initializer_list>
namespace Bk::Type {
class DataStream
{
public:
DataStream() = default;
DataStream(std::initializer_list<char> list)
: payload(list) {}
DataStream(std::vector<char> data)
: payload(data) {}
@ -56,7 +59,7 @@ namespace Bk::Type {
std::memcpy(payload.data() + i, data.data(), sizeof(char) * data.size());
return true;
}
std::vector<char> payload;
};
}

@ -1,14 +1,31 @@
#pragma once
#include <cstdint>
#include <memory>
namespace Bk {
using u1 = bool;
using u8 = unsigned char;
using u16 = unsigned short;
using u32 = unsigned long;
using u64 = unsigned long long;
using i1 = bool;
using i8 = signed char;
using i16 = signed short;
using i32 = signed long;
using i64 = signed long long;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
template<typename T>
using Scope = std::unique_ptr<T>;
template<typename T, typename ... Args>
constexpr Scope<T> CreateScope(Args&& ... args)
{
return std::make_unique<T>(std::forward<Args>(args)...);
}
template<typename T>
using Ref = std::shared_ptr<T>;
template<typename T, typename ... Args>
constexpr Ref<T> CreateRef(Args&& ... args)
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
}

@ -1,4 +1,6 @@
#include "dir_entry.h"
#include <bits/chrono.h>
#include <chrono>
namespace Bk
{
@ -27,9 +29,9 @@ namespace Bk
return ent.file_size();
}
TimePoint<FileClock, Second> DirEntry::last_write()
std::chrono::time_point<std::filesystem::__file_clock> DirEntry::last_write()
{
return TimePoint<FileClock, Second>(ent.last_write_time());
return ent.last_write_time();
}
bool DirEntry::exists()

@ -1,8 +1,8 @@
#pragma once
#include <bakatoolspch.h>
#include <bakatools/time/time_span.h>
#include <bakatools/time/time_point.h>
#include <bits/chrono.h>
#include <chrono>
namespace Bk
{
@ -34,7 +34,7 @@ namespace Bk
std::string name();
uintmax_t size();
TimePoint<FileClock, Second> last_write();
std::chrono::time_point<std::filesystem::__file_clock> last_write();
bool exists();
FilePerms perms();
uintmax_t hard_links();

@ -1,7 +1,7 @@
#include "file_watcher.h"
namespace Bk {
FileWatcher::FileWatcher(std::string path, TimeSpan<Millisecond> ts)
FileWatcher::FileWatcher(std::string path, int ts)
: target(path), ttm(ts)
{
for (const std::filesystem::directory_entry& file : std::filesystem::recursive_directory_iterator(target))

@ -1,7 +1,7 @@
#pragma once
#include "bakatools/thread/task_delayer.h"
#include <bakatoolspch.h>
#include <bakatools/thread/task_timer.h>
namespace Bk {
enum class FileStat
@ -14,7 +14,7 @@ namespace Bk {
class FileWatcher
{
public:
FileWatcher(std::string path, TimeSpan<Millisecond> ts);
FileWatcher(std::string path, int ts = 1000);
~FileWatcher();
void start(const std::function<void (std::string, FileStat)>& action);
@ -24,6 +24,6 @@ namespace Bk {
private:
std::string target;
std::unordered_map<std::string, std::filesystem::file_time_type> paths;
TaskTimer<Millisecond> ttm;
TaskDelayer ttm;
};
}

@ -1,4 +1,6 @@
#include "fs_manager.h"
#include "bakatools/json/parser.h"
#include "bakatools/json/tools.h"
namespace Bk::Json
{

@ -1,8 +1,7 @@
#include "bakatools/json/node.h"
#include <bakatoolspch.h>
#include <bakatools/file_system/directory.h>
#include <bakatools/file_system/file.h>
#include "parser.h"
#include "tools.h"
namespace Bk::Json
{

@ -7,14 +7,8 @@ This file contains the assert macros. CORE macros musn't be used by the applicat
#include "log.h"
#include <bakatools/string/format.h>
#if defined(BK_PLATFORM_WINDOWS)
#define BK_STATIC_DEBUGBREAK() __debugbreak()
#elif defined(BK_PLATFORM_LINUX)
#include <signal.h>
#define BK_STATIC_DEBUGBREAK() raise(SIGTRAP)
#else
#error "Plaform doesn't support debug yet"
#endif
#define BK_STATIC_DEBUGBREAK() exit(1)
#define BK_STATIC_CORE_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_STATIC_CORE_ERROR(Tools::format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_STATIC_DEBUGBREAK(); }
#define BK_STATIC_CORE_MSG_ASSERT(check, msg) if(!(check)) { BK_STATIC_CORE_ERROR("Assertion [{0}] failed at {1}:{2}\n\tError : {3}", BK_STRINGIFY(check), __FILE__, __LINE__, msg); BK_STATIC_DEBUGBREAK(); }

@ -1,30 +1,44 @@
#pragma once
#include <bakatoolspch.h>
#include <bakatools/time/time_span.h>
#include <bakatools/time/time_point.h>
#include <thread>
#include <functional>
#include <chrono>
#include <ratio>
namespace Bk {
template<typename P>
class TaskDelayer
{
public:
TaskDelayer(int n_ts,
std::unique_ptr<std::function<void()>> action
): ts(n_ts)
TaskDelayer(int ts, bool repeat = false)
: ts(ts), repeat(repeat) {}
~TaskDelayer() { stop(); }
void start(std::unique_ptr<std::function<void()>> action)
{
if(running) stop();
running = true;
worker = std::thread([this](std::unique_ptr<std::function<void()>> action)
{
std::function<void()>& task = *action;
std::this_thread::sleep_for(ts.interval);
task();
while(running && repeat)
{
std::this_thread::sleep_for(ts);
task();
}
}, std::move(action));
}
~TaskDelayer() { worker.join(); }
void stop()
{
if (!running) return;
running = false;
worker.join();
}
private:
bool running = false;
bool repeat;
std::thread worker;
TimeSpan<P> ts;
std::chrono::duration<int, std::milli> ts;
};
}

@ -1,43 +0,0 @@
#pragma once
#include <bakatoolspch.h>
#include <bakatools/time/time_span.h>
#include <bakatools/time/time_point.h>
namespace Bk {
template<typename P>
class TaskTimer
{
public:
TaskTimer(TimeSpan<P> ts)
: ts(ts) {}
~TaskTimer() { stop(); }
void start(std::unique_ptr<std::function<void()>> action)
{
if(running) stop();
running = true;
worker = std::thread([this](std::unique_ptr<std::function<void()>> action)
{
std::function<void()>& task = *action;
while(running)
{
std::this_thread::sleep_for(ts.interval);
task();
}
}, std::move(action));
}
void stop()
{
if (!running) return;
running = false;
worker.join();
}
private:
bool running = false;
std::thread worker;
TimeSpan<P> ts;
};
}

@ -1,56 +0,0 @@
#pragma once
#include <bakatoolspch.h>
#include "time_span.h"
namespace Bk
{
using SysClock = std::chrono::system_clock;
using SteadyClock = std::chrono::steady_clock;
using FileClock = std::chrono::file_clock;
using UtcClock = std::chrono::utc_clock;
template<typename C, typename P>
struct TimePoint
{
TimePoint() = default;
TimePoint(std::chrono::time_point<C> point)
{
this->point = std::chrono::time_point_cast<std::chrono::duration<long int, P>>(point);
}
template<typename Pi>
TimePoint<C, Pi> as_unit()
{
return TimePoint<C, Pi>(std::chrono::time_point_cast<std::chrono::duration<long int, Pi>>(point));
}
template<typename Ci>
TimePoint<Ci, P> as_clock()
{
return TimePoint(std::chrono::clock_cast<Ci>(point));
}
TimeSpan<P> elasped()
{
return TimeSpan<P>(point.time_since_epoch());
}
bool is_steady()
{
return C::is_steady;
}
TimeSpan<P> operator-(TimePoint<C, P>& tp)
{
return TimeSpan<P>(point - tp.point);
}
static TimePoint<C, P> now()
{
return TimePoint<C, P>(C::now());
}
std::chrono::time_point<C, std::chrono::duration<long int, P>> point;
};
}

@ -1,38 +0,0 @@
#pragma once
#include <bakatoolspch.h>
namespace Bk
{
using Nanosecond = std::ratio<1,1000000000>;
using Microsecond = std::ratio<1,1000000>;
using Millisecond = std::ratio<1,1000>;
using Second = std::ratio<1,1>;
using Minute = std::ratio<60, 1>;
using Hour = std::ratio<3600, 1>;
using Day = std::ratio<84600, 1>;
template<typename P>
struct TimeSpan
{
TimeSpan(int interval = 0)
: interval(std::chrono::duration<long int, P>(interval)) {}
TimeSpan(std::chrono::duration<long int, P> interval)
: interval(interval) {}
template<typename T>
TimeSpan<T> as_unit()
{
return TimeSpan<T>(std::chrono::duration_cast<std::chrono::duration<long int, T>>(interval));
}
int count() { return interval.count(); }
TimeSpan<P> operator-(TimeSpan<P>& time_span)
{
return TimeSpan<P>(interval - time_span.interval);
}
std::chrono::duration<long int, P> interval;
};
}
Loading…
Cancel
Save