diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/is_one_of.hpp | 9 | ||||
-rw-r--r-- | src/utils/time.cpp | 3 | ||||
-rw-r--r-- | src/utils/time.hpp | 5 | ||||
-rw-r--r-- | src/utils/uuid.cpp | 14 | ||||
-rw-r--r-- | src/utils/uuid.hpp | 8 |
5 files changed, 33 insertions, 6 deletions
diff --git a/src/utils/is_one_of.hpp b/src/utils/is_one_of.hpp index c706421..4d6770e 100644 --- a/src/utils/is_one_of.hpp +++ b/src/utils/is_one_of.hpp @@ -3,12 +3,15 @@ #include <type_traits> template <typename...> -struct is_one_of { +struct is_one_of_implem { static constexpr bool value = false; }; template <typename F, typename S, typename... T> -struct is_one_of<F, S, T...> { +struct is_one_of_implem<F, S, T...> { static constexpr bool value = - std::is_same<F, S>::value || is_one_of<F, T...>::value; + std::is_same<F, S>::value || is_one_of_implem<F, T...>::value; }; + +template<typename... T> +constexpr bool is_one_of = is_one_of_implem<T...>::value; diff --git a/src/utils/time.cpp b/src/utils/time.cpp index bc2c18d..71306fd 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -9,9 +9,10 @@ namespace utils { -std::string to_string(const std::time_t& timestamp) +std::string to_string(const std::chrono::system_clock::time_point::rep& time) { constexpr std::size_t stamp_size = 21; + const std::time_t timestamp = static_cast<std::time_t>(time); char date_buf[stamp_size]; if (std::strftime(date_buf, stamp_size, "%FT%TZ", std::gmtime(×tamp)) != stamp_size - 1) return ""; diff --git a/src/utils/time.hpp b/src/utils/time.hpp index c71cd9c..4b19634 100644 --- a/src/utils/time.hpp +++ b/src/utils/time.hpp @@ -2,9 +2,10 @@ #include <ctime> #include <string> +#include <chrono> namespace utils { -std::string to_string(const std::time_t& timestamp); +std::string to_string(const std::chrono::system_clock::time_point::rep& timestamp); std::time_t parse_datetime(const std::string& stamp); -}
\ No newline at end of file +} diff --git a/src/utils/uuid.cpp b/src/utils/uuid.cpp new file mode 100644 index 0000000..23b71fe --- /dev/null +++ b/src/utils/uuid.cpp @@ -0,0 +1,14 @@ +#include <utils/uuid.hpp> +#include <uuid/uuid.h> + +namespace utils +{ +std::string gen_uuid() +{ + char uuid_str[37]; + uuid_t uuid; + uuid_generate(uuid); + uuid_unparse(uuid, uuid_str); + return uuid_str; +} +} diff --git a/src/utils/uuid.hpp b/src/utils/uuid.hpp new file mode 100644 index 0000000..d550475 --- /dev/null +++ b/src/utils/uuid.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include <string> + +namespace utils +{ +std::string gen_uuid(); +} |