Skip to content

Commit 8da6543

Browse files
committed
🔥 Remove sc from log, msg and match libraries
Problem: - `sc` is superseded by stdx::ct_string functionality. Solution: - Remove dependency on `sc` for some libraries. Note: - For now, the flow library still uses `sc`.
1 parent 31ff329 commit 8da6543

37 files changed

+233
-203
lines changed

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ target_sources(
5252

5353
add_library(cib_match INTERFACE)
5454
target_compile_features(cib_match INTERFACE cxx_std_20)
55-
target_link_libraries_system(cib_match INTERFACE cib_sc stdx)
55+
target_link_libraries_system(cib_match INTERFACE stdx)
5656

5757
target_sources(
5858
cib_match
@@ -79,7 +79,7 @@ target_sources(
7979

8080
add_library(cib_interrupt INTERFACE)
8181
target_compile_features(cib_interrupt INTERFACE cxx_std_20)
82-
target_link_libraries_system(cib_interrupt INTERFACE cib_sc concurrency stdx)
82+
target_link_libraries_system(cib_interrupt INTERFACE concurrency stdx)
8383

8484
target_sources(
8585
cib_interrupt
@@ -123,7 +123,7 @@ target_sources(
123123

124124
add_library(cib_log INTERFACE)
125125
target_compile_features(cib_log INTERFACE cxx_std_20)
126-
target_link_libraries_system(cib_log INTERFACE cib_sc stdx)
126+
target_link_libraries_system(cib_log INTERFACE stdx)
127127

128128
target_sources(
129129
cib_log
@@ -149,7 +149,6 @@ target_link_libraries_system(
149149
cib_log
150150
cib_lookup
151151
cib_match
152-
cib_sc
153152
stdx)
154153

155154
target_sources(

docs/intro.adoc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,23 @@ library that contains all the functionality.
5757
[mermaid, format="svg"]
5858
----
5959
flowchart BT
60-
sc(cib_sc)
6160
nexus(cib_nexus)
61+
sc(cib_sc)
62+
log(cib_log)
63+
match(cib_match)
6264
lookup(cib_lookup)
6365
6466
flow(cib_flow) --> nexus
67+
flow --> sc
6568
flow --> log
6669
67-
interrupt(cib_interrupt) --> sc
68-
match(cib_match) --> sc
69-
log(cib_log) --> sc
70-
71-
7270
log_fmt(cib_log_fmt) --> log
7371
msg(cib_msg) --> log & match
7472
msg --> lookup
7573
7674
log_binary(cib_log_binary) --> msg
7775
seq(cib_seq) --> flow
7876
79-
cib --> interrupt & seq & log_fmt & log_binary
77+
interrupt(cib_interrupt)
78+
cib --> seq & log_fmt & log_binary & interrupt
8079
----

include/flow/impl.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <flow/log.hpp>
55
#include <log/log.hpp>
66

7+
#include <stdx/ct_format.hpp>
78
#include <stdx/ct_string.hpp>
89
#include <stdx/span.hpp>
910
#include <stdx/type_traits.hpp>
@@ -22,8 +23,8 @@ constexpr auto run_func() -> void {
2223
logging::log<
2324
decltype(get_log_env<CTNode, log_env_id_t<FlowName>>())>(
2425
__FILE__, __LINE__,
25-
sc::format("flow.{}({})"_sc, typename CTNode::type_t{},
26-
typename CTNode::name_t{}));
26+
stdx::ct_format<"flow.{}({})">(stdx::cts_t<CTNode::ct_type>{},
27+
stdx::cts_t<CTNode::ct_name>{}));
2728
}
2829
typename CTNode::func_t{}();
2930
}
@@ -56,19 +57,18 @@ template <stdx::ct_string Name, auto... FuncPtrs> struct inlined_func_list {
5657
__attribute__((flatten, always_inline)) auto operator()() const -> void {
5758
constexpr static bool loggingEnabled = not Name.empty();
5859

59-
constexpr auto name =
60-
stdx::ct_string_to_type<Name, sc::string_constant>();
61-
6260
if constexpr (loggingEnabled) {
6361
logging::log<decltype(get_log_env<inlined_func_list>())>(
64-
__FILE__, __LINE__, sc::format("flow.start({})"_sc, name));
62+
__FILE__, __LINE__,
63+
stdx::ct_format<"flow.start({})">(stdx::cts_t<Name>{}));
6564
}
6665

6766
(FuncPtrs(), ...);
6867

6968
if constexpr (loggingEnabled) {
7069
logging::log<decltype(get_log_env<inlined_func_list>())>(
71-
__FILE__, __LINE__, sc::format("flow.end({})"_sc, name));
70+
__FILE__, __LINE__,
71+
stdx::ct_format<"flow.end({})">(stdx::cts_t<Name>{}));
7272
}
7373
}
7474
};

include/flow/step.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct ct_node {
2424
decltype(stdx::ct_string_to_type<Name, sc::string_constant>());
2525
using func_t = F;
2626

27+
constexpr static auto ct_type = Type;
2728
constexpr static auto ct_name = Name;
2829
constexpr static auto identity = Identity;
2930
constexpr static auto condition = Cond{};

include/log/catalog/encoder.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace logging::binary {
2222
namespace detail {
2323
template <typename S, typename... Args> constexpr static auto to_message() {
24-
constexpr auto s = S::value;
24+
constexpr auto s = std::string_view{S::value};
2525
using char_t = typename std::remove_cv_t<decltype(s)>::value_type;
2626
return [&]<std::size_t... Is>(std::integer_sequence<std::size_t, Is...>) {
2727
return sc::message<
@@ -74,20 +74,22 @@ template <typename T> log_writer(T) -> log_writer<T>;
7474

7575
template <typename Writer> struct log_handler {
7676
template <typename Env, typename FilenameStringType,
77-
typename LineNumberType, typename MsgType>
78-
auto log(FilenameStringType, LineNumberType, MsgType const &msg) -> void {
79-
log_msg<Env>(msg);
77+
typename LineNumberType, typename FmtResult>
78+
auto log(FilenameStringType, LineNumberType, FmtResult const &fr) -> void {
79+
log_msg<Env>(fr);
8080
}
8181

82-
template <typename Env, typename Msg> auto log_msg(Msg msg) -> void {
83-
msg.apply([&]<typename S, typename... Args>(S, Args... args) {
82+
template <typename Env, typename FmtResult>
83+
auto log_msg(FmtResult const &fr) -> void {
84+
fr.args.apply([&]<typename... Args>(Args &&...args) {
8485
auto builder = get_builder(Env{});
8586
constexpr auto L = stdx::to_underlying(get_level(Env{}));
8687
using Message = typename decltype(builder)::template convert_args<
87-
detail::to_message_t<S>::template fn, Args...>;
88+
detail::to_message_t<decltype(fr.str)>::template fn,
89+
std::remove_cvref_t<Args>...>;
8890
using Module = decltype(detail::to_module<get_module(Env{})>());
8991
w(builder.template build<L>(catalog<Message>(), module<Module>(),
90-
args...));
92+
std::forward<Args>(args)...));
9193
});
9294
}
9395

include/log/fmt/logger.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ template <typename TDestinations> struct log_handler {
4040
constexpr explicit log_handler(TDestinations &&ds) : dests{std::move(ds)} {}
4141

4242
template <typename Env, typename FilenameStringType,
43-
typename LineNumberType, typename MsgType>
44-
auto log(FilenameStringType, LineNumberType, MsgType const &msg) -> void {
43+
typename LineNumberType, typename FmtResult>
44+
auto log(FilenameStringType, LineNumberType, FmtResult const &fr) -> void {
4545
auto const currentTime =
4646
std::chrono::duration_cast<std::chrono::microseconds>(
4747
std::chrono::steady_clock::now() - start_time)
@@ -52,10 +52,11 @@ template <typename TDestinations> struct log_handler {
5252
::fmt::format_to(out, "{:>8}us {} [{}]: ", currentTime,
5353
level_wrapper<get_level(Env{})>{},
5454
get_module(Env{}));
55-
msg.apply(
56-
[&]<typename StringType>(StringType, auto const &...args) {
57-
::fmt::format_to(out, StringType::value, args...);
58-
});
55+
constexpr auto fmtstr =
56+
std::string_view{decltype(fr.str)::value};
57+
fr.args.apply([&](auto const &...args) {
58+
::fmt::format_to(out, fmtstr, args...);
59+
});
5960
*out = '\n';
6061
},
6162
dests);

include/log/log.hpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
#include <log/flavor.hpp>
55
#include <log/level.hpp>
66
#include <log/module.hpp>
7-
#include <sc/format.hpp>
8-
#include <sc/fwd.hpp>
97

108
#include <stdx/compiler.hpp>
9+
#include <stdx/ct_format.hpp>
1110
#include <stdx/ct_string.hpp>
1211
#include <stdx/panic.hpp>
1312
#include <stdx/type_traits.hpp>
@@ -58,13 +57,13 @@ static auto log(TArgs &&...args) -> void {
5857
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
5958

6059
#define CIB_LOG(MSG, ...) \
61-
logging::log<cib_log_env_t>( \
62-
__FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__))
60+
logging::log<cib_log_env_t>(__FILE__, __LINE__, \
61+
stdx::ct_format<MSG>(__VA_ARGS__))
6362

6463
#define CIB_LOG_WITH_LEVEL(LEVEL, MSG, ...) \
6564
logging::log< \
6665
stdx::extend_env_t<cib_log_env_t, logging::get_level, LEVEL>>( \
67-
__FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__))
66+
__FILE__, __LINE__, stdx::ct_format<MSG>(__VA_ARGS__))
6867

6968
#define CIB_TRACE(...) \
7069
CIB_LOG_WITH_LEVEL(logging::level::TRACE __VA_OPT__(, ) __VA_ARGS__)
@@ -76,14 +75,13 @@ static auto log(TArgs &&...args) -> void {
7675
CIB_LOG_WITH_LEVEL(logging::level::ERROR __VA_OPT__(, ) __VA_ARGS__)
7776

7877
#define CIB_FATAL(MSG, ...) \
79-
[](auto &&str) { \
78+
[](auto &&s) { \
8079
CIB_LOG_ENV(logging::get_level, logging::level::FATAL); \
81-
logging::log<cib_log_env_t>(__FILE__, __LINE__, str); \
82-
FWD(str).apply([]<typename S, typename... Args>(S s, Args... args) { \
83-
constexpr auto cts = stdx::ct_string_from_type(s); \
84-
stdx::panic<cts>(args...); \
80+
logging::log<cib_log_env_t>(__FILE__, __LINE__, s); \
81+
FWD(s).args.apply([](auto &&...args) { \
82+
stdx::panic<decltype(s.str)::value>(FWD(args)...); \
8583
}); \
86-
}(sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__))
84+
}(stdx::ct_format<MSG>(__VA_ARGS__))
8785

8886
#define CIB_ASSERT(expr) \
8987
((expr) ? void(0) : CIB_FATAL("Assertion failure: " #expr))
@@ -102,9 +100,8 @@ template <typename Env, typename... Ts> static auto log_version() -> void {
102100
CIB_LOG_ENV(logging::get_level, logging::level::MAX);
103101
l_cfg.logger.template log<cib_log_env_t>(
104102
"", 0,
105-
sc::format("Version: {} ({})"_sc, sc::uint_<v_cfg.build_id>,
106-
stdx::ct_string_to_type<v_cfg.version_string,
107-
sc::string_constant>()));
103+
stdx::ct_format<"Version: {} ({})">(
104+
CX_VALUE(v_cfg.build_id), CX_VALUE(v_cfg.version_string)));
108105
}
109106
}
110107
} // namespace logging

include/match/and.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <match/implies.hpp>
77
#include <match/simplify.hpp>
88
#include <match/sum_of_products.hpp>
9-
#include <sc/string_constant.hpp>
109

1110
#include <cstddef>
1211
#include <type_traits>
@@ -15,7 +14,7 @@
1514
namespace match {
1615
template <matcher, matcher> struct or_t;
1716

18-
template <matcher L, matcher R> struct and_t : bin_op_t<and_t, " and ", L, R> {
17+
template <matcher L, matcher R> struct and_t : bin_op_t<and_t, "and", L, R> {
1918
[[nodiscard]] constexpr auto operator()(auto const &event) const -> bool {
2019
return this->lhs(event) and this->rhs(event);
2120
}

include/match/bin_op.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <match/cost.hpp>
55
#include <match/negate.hpp>
66
#include <match/simplify.hpp>
7-
#include <sc/string_constant.hpp>
87

8+
#include <stdx/ct_format.hpp>
99
#include <stdx/ct_string.hpp>
1010
#include <stdx/type_traits.hpp>
1111

@@ -32,16 +32,16 @@ struct bin_op_t {
3232

3333
private:
3434
[[nodiscard]] constexpr auto form_description(auto const &f) const {
35+
using namespace stdx::literals;
3536
auto const desc = [&]<matcher M>(M const &m) {
3637
if constexpr (stdx::is_specialization_of_v<M, Term>) {
3738
return f(m);
3839
} else {
39-
return "("_sc + f(m) + ")"_sc;
40+
return "("_ctst + f(m) + ")"_ctst;
4041
}
4142
};
42-
return desc(lhs) +
43-
stdx::ct_string_to_type<OpName, sc::string_constant>() +
44-
desc(rhs);
43+
return stdx::ct_format<"{} {} {}">(desc(lhs), stdx::cts_t<OpName>{},
44+
desc(rhs));
4545
}
4646
};
4747

include/match/concepts.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include <sc/fwd.hpp>
4-
53
#include <concepts>
64
#include <type_traits>
75

@@ -12,7 +10,7 @@ concept matcher = requires { typename std::remove_cvref_t<T>::is_matcher; };
1210
template <typename T, typename Event>
1311
concept matcher_for = matcher<T> and requires(T const &t, Event const &e) {
1412
{ t(e) } -> std::convertible_to<bool>;
15-
{ t.describe() } -> sc::sc_like;
16-
{ t.describe_match(e) } -> sc::sc_like;
13+
t.describe();
14+
t.describe_match(e);
1715
};
1816
} // namespace match

0 commit comments

Comments
 (0)