Skip to content

Commit 79d31a6

Browse files
committed
Add Doxygen documentation
- Add documentation for C++ API functions. - Add matrix data sanity check to ensure uniform rows.
1 parent 7769ba9 commit 79d31a6

File tree

10 files changed

+80
-32
lines changed

10 files changed

+80
-32
lines changed

include/fn/calc.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
#pragma once
3737

3838
#include "fn/root.hpp"
39-
#include "steppable/number.hpp"
4039
#include "output.hpp"
40+
#include "steppable/number.hpp"
4141
#include "types/result.hpp"
4242

4343
#include <string>
@@ -46,8 +46,8 @@
4646
using namespace std::literals;
4747

4848
/**
49-
* @namespace steppable::__internals
50-
* @brief The namespace containing internal functions for the Steppable library.
49+
* @namespace steppable::__internals::calc
50+
* @brief The namespace containing number calculating functions for the Steppable library.
5151
*/
5252
namespace steppable::__internals::calc
5353
{

include/fn/root.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
#include <string>
2626

27+
/**
28+
* @namespace steppable::__internals
29+
* @brief The namespace containing internal functions for the Steppable library.
30+
*/
2731
namespace steppable::__internals::calc
2832
{
2933
/**

include/steppable/mat2d.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,25 @@ namespace steppable
7777
size_t prec = 10; ///< Precision of numbers in the matrix.
7878
MatVec2D<Number> data; ///< The data of the matrix.
7979

80+
/**
81+
* @brief Checks whether a point is inside the matrix. Errors and exits the program if not.
82+
* @param point The point to check.
83+
*/
8084
void _checkIdxSanity(const YXPoint* point) const;
8185

86+
/**
87+
* @brief Checks whether the matrix data is correct in format.
88+
* @details This method checks for non-uniform rows inside the matrix.
89+
*
90+
* @param data The matrix data vector.
91+
*/
92+
static void _checkDataSanity(const MatVec2D<Number>& data);
93+
94+
/**
95+
* @brief Rounds off all data inside a vector to a specified precision.
96+
* @param data A double `std::vector` object containing matrix data.
97+
* @param prec Precision of the matrix.
98+
*/
8299
static MatVec2D<Number> roundOffValues(const MatVec2D<Number>& data, size_t prec);
83100

84101
public:
@@ -109,6 +126,12 @@ namespace steppable
109126
*/
110127
Matrix(const MatVec2D<Number>& data, size_t prec = 5);
111128

129+
/**
130+
* @brief Constructs a matrix from a 2D vector of C++ numbers.
131+
* @param data The 2D vector representing the matrix data.
132+
* @param prec Precision of the numbers.
133+
* @tparam ValueT Type of value in the `data` parameter.
134+
*/
112135
template<concepts::Numeric ValueT>
113136
Matrix(const MatVec2D<ValueT>& data, const size_t prec) :
114137
_cols(data.front().size()), _rows(data.size()), prec(prec)
@@ -428,6 +451,10 @@ namespace steppable
428451
*/
429452
[[nodiscard]] size_t getCols() const { return _cols; }
430453

454+
/**
455+
* @brief Get the data std::vector object from the matrix.
456+
* @return A std::vector object containing all the matrix data.
457+
*/
431458
[[nodiscard]] MatVec2D<Number> getData() const { return data; }
432459
};
433460
} // namespace steppable

include/steppable/number.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ namespace steppable
6767

6868
enum class Rounding : std::uint8_t
6969
{
70-
ROUND_DOWN = 0x00,
71-
ROUND_UP = 0x01,
72-
ROUND_OFF = 0x02,
70+
ROUND_DOWN = 0x00, ///< Rounds the number down.
71+
ROUND_UP = 0x01, ///< Rounds the number up.
72+
ROUND_OFF = 0x02, ///< Rounds the number off.
7373
};
7474

7575
/**
@@ -309,7 +309,7 @@ namespace steppable
309309
};
310310

311311
/**
312-
* @namespace literals
312+
* @namespace steppable::literals
313313
* @brief Literal suffixes for literals to be converted to Steppable objects.
314314
*/
315315
namespace literals

include/types/concepts.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
namespace steppable::concepts
3737
{
3838
template<typename T>
39-
concept Numeric = std::integral<T> || std::floating_point<T>;
39+
concept Numeric = std::integral<T> || std::floating_point<T>; ///< Represents any C++ numeral literals.
4040

4141
template<typename ObjectT>
42+
/// @brief Represents any object with a `.present()` method.
4243
concept Presentable = requires(ObjectT object) {
4344
{ object.present() } -> std::same_as<std::string>;
4445
};

include/types/data.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ namespace steppable
6060

6161
enum class _Weekday : std::uint8_t
6262
{
63-
Sunday = 0,
64-
Monday = 1,
65-
Tuesday = 2,
66-
Wednesday = 3,
67-
Thursday = 4,
68-
Friday = 5,
69-
Saturday = 6,
63+
Sunday = 0, ///< Sunday
64+
Monday = 1, ///< Monday
65+
Tuesday = 2, ///< Tuesday
66+
Wednesday = 3, ///< Wednesday
67+
Thursday = 4, ///< Thursday
68+
Friday = 5, ///< Friday
69+
Saturday = 6, ///< Saturday
7070
};
7171

7272
using Weekday = Data<_Weekday, StringLiteral{ "Weekday" }>;

include/types/point.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ namespace steppable
3131
*/
3232
struct XYPoint
3333
{
34-
size_t x = 0;
35-
size_t y = 0;
34+
size_t x = 0; ///< Coordinate x.
35+
size_t y = 0; ///< Coordinate y.
3636
};
3737

3838
/**
@@ -42,8 +42,8 @@ namespace steppable
4242
*/
4343
struct YXPoint
4444
{
45-
size_t y = 0;
46-
size_t x = 0;
45+
size_t y = 0; ///< Coordinate y.
46+
size_t x = 0; ///< Coordinate x.
4747
};
4848

4949
/**
@@ -53,9 +53,9 @@ namespace steppable
5353
*/
5454
struct YX2Points
5555
{
56-
size_t y1 = 0;
57-
size_t x1 = 0;
58-
size_t y2 = 0;
59-
size_t x2 = 0;
56+
size_t y1 = 0; ///< Point 1 coordinate y.
57+
size_t x1 = 0; ///< Point 1 coordinate x.
58+
size_t y2 = 0; ///< Point 2 coordinate y.
59+
size_t x2 = 0; ///< Point 2 coordinate x.
6060
};
6161
} // namespace steppable

include/types/result.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ namespace steppable::types
4444
*/
4545
enum class Status : std::uint8_t
4646
{
47-
CALCULATED_SIMPLIFIED,
48-
CALCULATED_UNSIMPLIFIED,
49-
MATH_ERROR
47+
CALCULATED_SIMPLIFIED, ///< The calculation is done by taking simplified steps.
48+
CALCULATED_UNSIMPLIFIED, ///< The calculation is done.
49+
MATH_ERROR ///< The calculation is not done because of an error.
5050
};
5151

5252
/**
5353
* @brief The status of a boolean calculation.
5454
*/
5555
enum class StatusBool : std::uint8_t
5656
{
57-
CALCULATED_SIMPLIFIED_YES,
58-
CALCULATED_SIMPLIFIED_NO,
59-
CALCULATED_UNSIMPLIFIED_YES,
60-
CALCULATED_UNSIMPLIFIED_NO,
61-
MATH_ERROR
57+
CALCULATED_SIMPLIFIED_YES, ///< The calculation is done by taking simplified steps, the result it True.
58+
CALCULATED_SIMPLIFIED_NO, ///< The calculation is done by taking simplified steps, the result it False.
59+
CALCULATED_UNSIMPLIFIED_YES, ///< The calculation is done, the result it True.
60+
CALCULATED_UNSIMPLIFIED_NO, ///< The calculation is done, the result it False.
61+
MATH_ERROR ///< The calculation is not done because of an error.
6262
};
6363

6464
/**

src/steppable/mat2d.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,28 @@ namespace steppable
9898
}
9999
} // namespace prettyPrint::printers
100100

101+
void Matrix::_checkDataSanity(const MatVec2D<Number>& data)
102+
{
103+
size_t size = 0;
104+
for (const auto& row : data)
105+
{
106+
const size_t rowSize = row.size();
107+
if (rowSize != size)
108+
{
109+
output::error("Matrix::_checkDataSanity"s, "Matrix has non-uniform dimensions."s);
110+
utils::programSafeExit(1);
111+
}
112+
size = rowSize;
113+
}
114+
}
115+
101116
Matrix::Matrix() : data({ {} }) { _cols = _rows = 0; }
102117

103118
Matrix::Matrix(const size_t rows, const size_t cols, const Number& fill) :
104119
data(std::vector(rows, std::vector(cols, fill))), _cols(cols), _rows(rows)
105120
{
106121
data = roundOffValues(data, static_cast<int>(prec));
122+
_checkDataSanity(data);
107123
}
108124

109125
Matrix::Matrix(const MatVec2D<Number>& data, const size_t prec) :

0 commit comments

Comments
 (0)