feat update

This commit is contained in:
tqcq
2024-02-28 00:23:29 +08:00
parent d4deb0ae03
commit b4e2d0fd66
9 changed files with 124 additions and 57 deletions

View File

@@ -6,6 +6,7 @@
#ifndef LOG_H
#define LOG_H
#include "sled/system/location.h"
#include <fmt/format.h>
namespace sled {
@@ -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, ...) \

View File

@@ -0,0 +1,24 @@
/**
* @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

View File

@@ -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

View File

@@ -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 {