Loading CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ target_sources( src/synchronization/mutex.cc src/synchronization/sequence_checker_internal.cc src/synchronization/thread_local.cc src/system/location.cc src/system/thread.cc src/task_queue/pending_task_safety_flag.cc src/task_queue/task_queue_base.cc Loading include/sled/log/log.h +11 −2 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #ifndef LOG_H #define LOG_H #include "sled/system/location.h" #include <fmt/format.h> namespace sled { Loading @@ -32,8 +33,16 @@ void Log(LogLevel level, // sled::Log(level, tag, fmt, __FILE__, __FUNCTION__, __VA_ARGS__) #define _SLOG(level, tag, fmt_str, ...) \ sled::Log(level, tag, fmt::format(fmt_str, ##__VA_ARGS__).c_str(), \ __FILE__, __LINE__, __FUNCTION__) do { \ std::string __fmt_str; \ try { \ __fmt_str = fmt::format(fmt_str, ##__VA_ARGS__); \ } catch (const std::exception &e) { \ __fmt_str = " fmt error: " + std::string(e.what()); \ } \ sled::Log(level, tag, __fmt_str.c_str(), __FILE__, __LINE__, \ __FUNCTION__); \ } while (0) #define SLOG(level, tag, fmt, ...) _SLOG(level, tag, fmt, ##__VA_ARGS__) #define SLOG_TRACE(tag, fmt, ...) \ Loading include/sled/reflect/reflect.h 0 → 100644 +24 −0 Original line number Diff line number Diff line /** * @file : reflect * @created : 星期一 2 26, 2024 09:55:19 CST * @license : MIT **/ #ifndef SLED_REFLECT_REFLECT_H #define SLED_REFLECT_REFLECT_H #if !defined(__NO_META_PARSER__) && !defined(__META_PARSER__) #define __META_PARSER__ #endif #if defined(__META_PARSER__) #define REFLECT_CLASS __attribute__((annotate("reflect-class"))) #define PROPERTY() __attribute__((annotate("reflect-property"))) #define METHOD() __attribute__((annotate("reflect-method"))) #else #define REFLECT_CLASS #define PROPERTY() #define METHOD() #endif #endif// SLED_REFLECT_REFLECT_H include/sled/system/location.h +19 −2 Original line number Diff line number Diff line Loading @@ -7,13 +7,30 @@ #ifndef LOCATION_H #define LOCATION_H #include <string> namespace sled { class Location { class Location final { public: static Location Current() { return Location(); } Location() = delete; static Location Current(const char *file_name = __builtin_FILE(), int file_line = __builtin_LINE(), const char *function = __builtin_FUNCTION()); std::string ToString() const; private: Location(const char *file_name, int file_line, const char *function); const char *file_name; int file_line; const char *function; }; }// namespace sled #define SLED_FROM_HERE sled::Location::Current(); #endif// LOCATION_H include/sled/time_utils.h +6 −3 Original line number Diff line number Diff line Loading @@ -13,9 +13,12 @@ namespace sled { static const int64_t kNumMillisecsPerSec = 1000; static const int64_t kNumMicrosecsPerSec = 1000000; static const int64_t kNumNanosecsPerSec = 1000000000; static const int64_t kNumMicrosecsPerMillisec = kNumMicrosecsPerSec / kNumMillisecsPerSec; static const int64_t kNumNanosecsPerMillisec = kNumNanosecsPerSec / kNumMillisecsPerSec; static const int64_t kNumNanosecsPerMicrosec = kNumNanosecsPerSec / kNumMicrosecsPerSec; static const int64_t kNumMicrosecsPerMillisec = kNumMicrosecsPerSec / kNumMillisecsPerSec; static const int64_t kNumNanosecsPerMillisec = kNumNanosecsPerSec / kNumMillisecsPerSec; static const int64_t kNumNanosecsPerMicrosec = kNumNanosecsPerSec / kNumMicrosecsPerSec; constexpr int64_t kNtpJan1970Millisecs = 2208988800 * kNumMillisecsPerSec; class ClockInterface { Loading Loading
CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ target_sources( src/synchronization/mutex.cc src/synchronization/sequence_checker_internal.cc src/synchronization/thread_local.cc src/system/location.cc src/system/thread.cc src/task_queue/pending_task_safety_flag.cc src/task_queue/task_queue_base.cc Loading
include/sled/log/log.h +11 −2 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #ifndef LOG_H #define LOG_H #include "sled/system/location.h" #include <fmt/format.h> namespace sled { Loading @@ -32,8 +33,16 @@ void Log(LogLevel level, // sled::Log(level, tag, fmt, __FILE__, __FUNCTION__, __VA_ARGS__) #define _SLOG(level, tag, fmt_str, ...) \ sled::Log(level, tag, fmt::format(fmt_str, ##__VA_ARGS__).c_str(), \ __FILE__, __LINE__, __FUNCTION__) do { \ std::string __fmt_str; \ try { \ __fmt_str = fmt::format(fmt_str, ##__VA_ARGS__); \ } catch (const std::exception &e) { \ __fmt_str = " fmt error: " + std::string(e.what()); \ } \ sled::Log(level, tag, __fmt_str.c_str(), __FILE__, __LINE__, \ __FUNCTION__); \ } while (0) #define SLOG(level, tag, fmt, ...) _SLOG(level, tag, fmt, ##__VA_ARGS__) #define SLOG_TRACE(tag, fmt, ...) \ Loading
include/sled/reflect/reflect.h 0 → 100644 +24 −0 Original line number Diff line number Diff line /** * @file : reflect * @created : 星期一 2 26, 2024 09:55:19 CST * @license : MIT **/ #ifndef SLED_REFLECT_REFLECT_H #define SLED_REFLECT_REFLECT_H #if !defined(__NO_META_PARSER__) && !defined(__META_PARSER__) #define __META_PARSER__ #endif #if defined(__META_PARSER__) #define REFLECT_CLASS __attribute__((annotate("reflect-class"))) #define PROPERTY() __attribute__((annotate("reflect-property"))) #define METHOD() __attribute__((annotate("reflect-method"))) #else #define REFLECT_CLASS #define PROPERTY() #define METHOD() #endif #endif// SLED_REFLECT_REFLECT_H
include/sled/system/location.h +19 −2 Original line number Diff line number Diff line Loading @@ -7,13 +7,30 @@ #ifndef LOCATION_H #define LOCATION_H #include <string> namespace sled { class Location { class Location final { public: static Location Current() { return Location(); } Location() = delete; static Location Current(const char *file_name = __builtin_FILE(), int file_line = __builtin_LINE(), const char *function = __builtin_FUNCTION()); std::string ToString() const; private: Location(const char *file_name, int file_line, const char *function); const char *file_name; int file_line; const char *function; }; }// namespace sled #define SLED_FROM_HERE sled::Location::Current(); #endif// LOCATION_H
include/sled/time_utils.h +6 −3 Original line number Diff line number Diff line Loading @@ -13,9 +13,12 @@ namespace sled { static const int64_t kNumMillisecsPerSec = 1000; static const int64_t kNumMicrosecsPerSec = 1000000; static const int64_t kNumNanosecsPerSec = 1000000000; static const int64_t kNumMicrosecsPerMillisec = kNumMicrosecsPerSec / kNumMillisecsPerSec; static const int64_t kNumNanosecsPerMillisec = kNumNanosecsPerSec / kNumMillisecsPerSec; static const int64_t kNumNanosecsPerMicrosec = kNumNanosecsPerSec / kNumMicrosecsPerSec; static const int64_t kNumMicrosecsPerMillisec = kNumMicrosecsPerSec / kNumMillisecsPerSec; static const int64_t kNumNanosecsPerMillisec = kNumNanosecsPerSec / kNumMillisecsPerSec; static const int64_t kNumNanosecsPerMicrosec = kNumNanosecsPerSec / kNumMicrosecsPerSec; constexpr int64_t kNtpJan1970Millisecs = 2208988800 * kNumMillisecsPerSec; class ClockInterface { Loading