Skip to content

Commit 54ac294

Browse files
committed
added documentation to the utils header, moved utils into a subdirectory
1 parent 5c9ecbc commit 54ac294

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/meson.build

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

5050
inc_dirs += include_directories('.')
51+
52+
subdir('utils')

src/recording.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "input_event.hpp"
44
#include "random.hpp"
55
#include "types.hpp"
6-
#include "utils.hpp"
6+
#include "utils/utils.hpp"
77
#include <filesystem>
88
#include <fstream>
99
#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
@@ -9,8 +9,20 @@
99
#include <string>
1010

1111
namespace utils {
12+
/**
13+
* @brief Returns the current date and time as a string in ISO 8601 format without using any separators except for
14+
* 'T' between the date and the time.
15+
* @return The current date and time string.
16+
*/
1217
[[nodiscard]] std::string current_date_time_iso8601();
1318

19+
/**
20+
* @brief Converts between big endian and little endian. This function is needed since not all compilers support
21+
* std::byteswap as of yet.
22+
* @tparam Integral The type of the value to convert.
23+
* @param value The value to convert.
24+
* @return The converted value.
25+
*/
1426
template<std::integral Integral>
1527
[[nodiscard]] constexpr inline Integral byte_swap(Integral value) noexcept {
1628
// source: https://en.cppreference.com/w/cpp/numeric/byteswap
@@ -20,6 +32,12 @@ namespace utils {
2032
return std::bit_cast<Integral>(value_representation);
2133
}
2234

35+
/**
36+
* @brief Converts from the machine's native byte order to little endian. On a little endian machine, this function
37+
* does return the input value.
38+
* @param value A value in the machine's native byte order.
39+
* @return The value in little endian.
40+
*/
2341
[[nodiscard]] constexpr inline auto to_little_endian(std::integral auto value) {
2442
if constexpr (std::endian::native == std::endian::little) {
2543
return value;
@@ -28,6 +46,12 @@ namespace utils {
2846
}
2947
}
3048

49+
/**
50+
* @brief Converts from little endian to the machine's native byte order. On a little endian machine, this function
51+
* does return the input value.
52+
* @param value A value in little endian.
53+
* @return The value in the machine's native byte order.
54+
*/
3155
[[nodiscard]] constexpr inline auto from_little_endian(std::integral auto value) {
3256
return to_little_endian(value);
3357
}

0 commit comments

Comments
 (0)