From 20dd00fad3b9d57bae8f4ccd2fbde9f7bae3494b Mon Sep 17 00:00:00 2001 From: cobrapitz <12397702+cobrapitz@users.noreply.github.com> Date: Fri, 21 Apr 2023 23:47:03 +0200 Subject: [PATCH] added types --- CMakeLists.txt | 6 ++++-- include/cb.h | 7 +++++++ include/cb/string_utils/string_utils.h | 14 ++++++++++++++ include/cb/types/types.h | 2 ++ src/cb/string_utils/string_utils.cpp | 12 ++++++++++++ src/cb/time/time.cpp | 4 ++-- 6 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 include/cb/string_utils/string_utils.h create mode 100644 src/cb/string_utils/string_utils.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a18267..b57bb9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,12 +22,14 @@ set(CBLIB_HEADERS ${CBLIB_INCLUDE_DIR}/types/types.h ${CBLIB_INCLUDE_DIR}/time/time.h ${CBLIB_INCLUDE_DIR}/test/test.h + ${CBLIB_INCLUDE_DIR}/string_utils/string_utils.h ) set(CBLIB_SOURCES ${CBLIB_SOURCE_DIR}/base.cpp ${CBLIB_SOURCE_DIR}/types/types.cpp ${CBLIB_SOURCE_DIR}/time/time.cpp ${CBLIB_SOURCE_DIR}/test/test.cpp + ${CBLIB_SOURCE_DIR}/string_utils/string_utils.cpp ) @@ -44,8 +46,8 @@ target_include_directories(${PROJECT_NAME} PUBLIC $ $ -# PRIVATE -# ${CMAKE_CURRENT_SOURCE_DIR}/src + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src ) diff --git a/include/cb.h b/include/cb.h index 9dd2771..e536f99 100644 --- a/include/cb.h +++ b/include/cb.h @@ -8,11 +8,18 @@ #define assertm(exp, msg) = assert(((void)msg, exp)) +#define or || +#define and && +#define xor ^ +#define compl ~ +#define not ! + #endif #include "cb/test/test.h" #include "cb/time/time.h" #include "cb/types/types.h" +#include "cb/string_utils/string_utils.h" #endif //GODOT_HUB_MAP_CB_H diff --git a/include/cb/string_utils/string_utils.h b/include/cb/string_utils/string_utils.h new file mode 100644 index 0000000..a61d0cd --- /dev/null +++ b/include/cb/string_utils/string_utils.h @@ -0,0 +1,14 @@ + +#ifndef GODOTHUB_STRING_UTILS_H +#define GODOTHUB_STRING_UTILS_H + + +#include + + +namespace cb::string { + bool starts_with(std::string_view content, std::string_view begins_with); + bool ends_with(std::string_view content, std::string_view ends_with); +} + +#endif //GODOTHUB_STRING_UTILS_H diff --git a/include/cb/types/types.h b/include/cb/types/types.h index 98f2d80..2fdfaee 100644 --- a/include/cb/types/types.h +++ b/include/cb/types/types.h @@ -5,6 +5,8 @@ using i64 = int64_t; using u64 = uint64_t; +using i32 = int32_t; +using u32 = uint32_t; using f64 = double; using f32 = float; diff --git a/src/cb/string_utils/string_utils.cpp b/src/cb/string_utils/string_utils.cpp new file mode 100644 index 0000000..b053a02 --- /dev/null +++ b/src/cb/string_utils/string_utils.cpp @@ -0,0 +1,12 @@ +#include "cb/string_utils/string_utils.h" + + +namespace cb { + bool string::starts_with(std::string_view content, std::string_view begins_with) { + return content.find(begins_with) != std::string::npos; + } + + bool string::ends_with(std::string_view content, std::string_view ends_with) { + return content.find(ends_with) != std::string::npos; + } +} diff --git a/src/cb/time/time.cpp b/src/cb/time/time.cpp index eceae5f..cff5ef0 100644 --- a/src/cb/time/time.cpp +++ b/src/cb/time/time.cpp @@ -11,7 +11,7 @@ namespace cb { } void time::start_measure(const std::string_view &id) { - _name_to_measurement.insert({id, chrono_now()}); + _name_to_measurement.insert_or_assign(id, chrono_now()); } long long time::get_duration(const std::string_view &id) { @@ -26,7 +26,7 @@ namespace cb { } void time::measure(const std::string_view &id) { - std::cout << "measurement: " << id << " took: " << get_duration(id) << "\n"; + std::cout << "measurement: " << id << " took: " << (double)get_duration(id) / 1'000'000'000.0 << "\n"; } const time::time_point_map &time::get_measurements() {