Skip to content

Commit 78066c7

Browse files
committed
added documentation to the utils header, moved utils into a subdirectory
1 parent c1acdfb commit 78066c7

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ add_executable(oopetris
5757
src/random.hpp
5858
src/recording.hpp
5959
src/input_event.hpp
60-
src/utils.hpp
61-
src/utils.cpp
60+
src/utils/utils.hpp
61+
src/utils/utils.cpp
6262
src/command_line_arguments.hpp
6363
src/controls.hpp
6464
src/mino_stack.cpp

src/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ src_files += files(
5252
)
5353

5454
inc_dirs += include_directories('.')
55+
56+
subdir('utils')

src/recording.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "tetrion.hpp"
66
#include "tetrion_snapshot.hpp"
77
#include "types.hpp"
8-
#include "utils.hpp"
8+
#include "utils/utils.hpp"
99
#include <filesystem>
1010
#include <fstream>
1111
#include <spdlog/spdlog.h>

src/utils/meson.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src_files += files(
2+
'utils.hpp',
3+
'utils.cpp',
4+
)
5+
6+
inc_dirs += include_directories('.')

src/utils.cpp renamed to src/utils/utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "utils.hpp"
2+
#include "spdlog/spdlog.h"
23
#include <chrono>
34
#include <ctime>
4-
#include <spdlog/spdlog.h>
55

66
namespace utils {
77
[[nodiscard]] std::string current_date_time_iso8601() {

src/utils.hpp renamed to src/utils/utils.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,20 @@ namespace utils {
1515
template<class T>
1616
concept integral = std::is_integral_v<T>;
1717

18+
/**
19+
* @brief Returns the current date and time as a string in ISO 8601 format without using any separators except for
20+
* 'T' between the date and the time.
21+
* @return The current date and time string.
22+
*/
1823
[[nodiscard]] std::string current_date_time_iso8601();
1924

25+
/**
26+
* @brief Converts between big endian and little endian. This function is needed since not all compilers support
27+
* std::byteswap as of yet.
28+
* @tparam Integral The type of the value to convert.
29+
* @param value The value to convert.
30+
* @return The converted value.
31+
*/
2032
template<integral Integral>
2133
[[nodiscard]] constexpr Integral byte_swap(Integral value) noexcept {
2234
// based on source: slartibartswift
@@ -29,6 +41,12 @@ namespace utils {
2941
return result;
3042
}
3143

44+
/**
45+
* @brief Converts from the machine's native byte order to little endian. On a little endian machine, this function
46+
* does return the input value.
47+
* @param value A value in the machine's native byte order.
48+
* @return The value in little endian.
49+
*/
3250
[[nodiscard]] constexpr auto to_little_endian(integral auto value) {
3351
if constexpr (std::endian::native == std::endian::little) {
3452
return value;
@@ -37,6 +55,12 @@ namespace utils {
3755
}
3856
}
3957

58+
/**
59+
* @brief Converts from little endian to the machine's native byte order. On a little endian machine, this function
60+
* does return the input value.
61+
* @param value A value in little endian.
62+
* @return The value in the machine's native byte order.
63+
*/
4064
[[nodiscard]] constexpr auto from_little_endian(integral auto value) {
4165
return to_little_endian(value);
4266
}

0 commit comments

Comments
 (0)