Compare commits
4 Commits
f9cbfdd018
...
70fd273a70
| Author | SHA1 | Date | |
|---|---|---|---|
| 70fd273a70 | |||
| 9626f5efc4 | |||
| 9c5a73e2bd | |||
| 50635a8e2f |
@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.21)
|
cmake_minimum_required(VERSION 3.21)
|
||||||
project(logger)
|
project(const_fmt)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
@ -11,14 +11,8 @@ endif()
|
|||||||
|
|
||||||
include_directories(.)
|
include_directories(.)
|
||||||
|
|
||||||
add_executable(logger src/main.cpp)
|
|
||||||
|
|
||||||
|
add_subdirectory(examples)
|
||||||
if(MSVC)
|
|
||||||
target_compile_options(logger PRIVATE /W4 /WX)
|
|
||||||
else()
|
|
||||||
target_compile_options(logger PRIVATE -O3 -Wall -Wextra -pedantic -fno-exceptions)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
option(PACKAGE_TESTS "Build the tests" ON)
|
option(PACKAGE_TESTS "Build the tests" ON)
|
||||||
|
|||||||
@ -1,52 +0,0 @@
|
|||||||
#ifndef LOGGER_LOGGER_H
|
|
||||||
#define LOGGER_LOGGER_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <iostream>
|
|
||||||
#include <tuple>
|
|
||||||
|
|
||||||
#include "format.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* Logger class
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
concept output_policy_c = requires(T t) {
|
|
||||||
t.write('c');
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
|
|
||||||
template <detail::output_policy_c output_policy_t>
|
|
||||||
class Logger {
|
|
||||||
|
|
||||||
public:
|
|
||||||
Logger(output_policy_t output_policy) : m_output_policy(output_policy) {
|
|
||||||
}
|
|
||||||
|
|
||||||
template <detail::ConstString msg, typename... args_t>
|
|
||||||
void log(args_t... args) {
|
|
||||||
const auto formatted_msg = format<msg>(args...);
|
|
||||||
|
|
||||||
for (const auto& c : formatted_msg) {
|
|
||||||
m_output_policy.write(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_output_policy.write('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
output_policy_t& m_output_policy;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // LOGGER_LOGGER_H
|
|
||||||
7
examples/CMakeLists.txt
Normal file
7
examples/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
add_executable(const_fmt_example src/examples.cpp)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
target_compile_options(const_fmt_example PRIVATE /W4 /WX)
|
||||||
|
else()
|
||||||
|
target_compile_options(const_fmt_example PRIVATE -O3 -Wall -Wextra -pedantic -fno-exceptions)
|
||||||
|
endif()
|
||||||
8
examples/src/examples.cpp
Normal file
8
examples/src/examples.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <const_fmt/format.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
13
src/main.cpp
13
src/main.cpp
@ -1,13 +0,0 @@
|
|||||||
#include <const_fmt/Logger.h>
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
|
||||||
auto formatted = "Test: {:12} {:012.5} {:8}"_fmt(argv[0], 123.45, -1234567);
|
|
||||||
|
|
||||||
for (const auto& c : formatted)
|
|
||||||
std::cout << c;
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
// return formatted[6];
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@ -14,8 +14,15 @@ macro(package_add_test TESTNAME)
|
|||||||
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
|
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
|
||||||
)
|
)
|
||||||
set_target_properties(${TESTNAME} PROPERTIES FOLDER tests)
|
set_target_properties(${TESTNAME} PROPERTIES FOLDER tests)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
target_compile_options(${TESTNAME} PRIVATE /W4 /WX)
|
||||||
|
else()
|
||||||
|
target_compile_options(${TESTNAME} PRIVATE -O3 -Wall -Wextra -pedantic -fno-exceptions)
|
||||||
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
|
||||||
package_add_test(utility_test src/utility.cpp)
|
package_add_test(utility_test src/utility.cpp)
|
||||||
package_add_test(parse_test src/parse.cpp)
|
package_add_test(parse_test src/parse.cpp)
|
||||||
package_add_test(format_test src/format.cpp)
|
package_add_test(format_test src/format.cpp)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user