Skip to content

Commit

Permalink
Fix traceable template and format
Browse files Browse the repository at this point in the history
  • Loading branch information
yunimoo committed Aug 21, 2024
1 parent 6fda281 commit f7c1a55
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions flow/include/flow/Traceable.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ struct Traceable : std::false_type {};
#define FORMAT_TRACEABLE(type, fmt) \
template <> \
struct Traceable<type> : std::true_type { \
static std::string toString(type value) { \
return format(fmt, value); \
} \
static std::string toString(type value) { return format(fmt, value); } \
}

FORMAT_TRACEABLE(bool, "%d");
Expand Down Expand Up @@ -175,15 +173,27 @@ struct TraceableString<char*> {
static std::string toString(char* value) { return std::string(value); }
};

template <>
struct TraceableString<std::filesystem::path> {
static auto begin(const std::filesystem::path& value) {
std::string pathString = value.string();
return pathString.begin();
}

static bool atEnd(const std::filesystem::path& value, std::string::iterator iter) {
std::string pathString = value.string();
return iter == pathString.end();
}

static std::string toString(const std::filesystem::path& value) {
return value.string();
}
};

template <class T>
struct TraceableStringImpl : std::true_type {
static constexpr bool isPrintable(char c) { return 32 <= c && c <= 126; }

template <class Str>
static std::string toString(std::filesystem::path& value) {
return value.string();
}

template <class Str>
static std::string toString(Str&& value) {
// if all characters are printable ascii, we simply return the string
Expand Down Expand Up @@ -247,7 +257,7 @@ struct Traceable<char[S]> : TraceableStringImpl<char[S]> {};
template <>
struct Traceable<std::string> : TraceableStringImpl<std::string> {};
template <>
struct Traceable<std::filesystem::path> : TraceableStringImpl<std::filesystem::path> {};
struct Traceable<std::filesystem::path> : TraceableString<std::filesystem::path> {};
template <>
struct Traceable<std::string_view> : TraceableStringImpl<std::string_view> {};

Expand Down

0 comments on commit f7c1a55

Please sign in to comment.