Ok i forgot the menu, all done i guess, now yes do doxyfile

This commit is contained in:
2026-03-22 00:29:38 -06:00
parent c7020d6739
commit 17e5db78e3
2 changed files with 211 additions and 1 deletions

View File

@@ -46,6 +46,54 @@ enum class LinkedListErr {
LINKEDLIST_EMPTY, /**< The list is empty */
};
/**
* @brief Converts a LinkedListErr value to its string representation.
*
* Provides a human-readable, null-terminated string corresponding to
* the given LinkedListErr enumeration value. This function is primarily
* intended for logging, debugging, and formatting purposes (e.g., with
* std::format / std::print).
*
* @param err The LinkedListErr value to convert.
*
* @return const char* A pointer to a statically allocated string literal
* representing the error. The returned pointer remains valid for the
* lifetime of the program and must not be freed.
*
* @note This function does not throw exceptions.
* @note If an unknown or invalid enumeration value is provided, the
* string "UNKNOWN_ERROR" is returned.
*
* @see std::formatter<LinkedListErr>
*/
[[nodiscard]] inline const char* to_string(LinkedListErr err) {
switch (err) {
case LinkedListErr::LINKEDLIST_OK:
return "OK";
case LinkedListErr::LINKEDLIST_BAD_ALLOC:
return "The program couldn't allocate memory for the list.";
case LinkedListErr::LINKEDLIST_OUT_OF_BOUNDS:
return "The index is out of bounds.";
case LinkedListErr::LINKEDLIST_INVALID_SIZE:
return "Is an invalid size fo the list.";
case LinkedListErr::LINKEDLIST_NOT_FOUND:
return "The value was not found.";
case LinkedListErr::LINKEDLIST_EMPTY:
return "The list is empty";
default:
return "UNKNOWN_ERROR";
}
}
template <>
struct std::formatter<LinkedListErr> : std::formatter<const char*> {
auto format(LinkedListErr err, format_context& ctx) const {
return std::formatter<const char*>::format(to_string(err), ctx);
}
};
/**
* @brief Node of a singly linked list.
*
@@ -172,6 +220,15 @@ public:
* @return size_t Number of stored elements.
*/
size_t len();
/**
* @brief Clears the list by deleting all its elements.
*
* Frees all nodes and resets the list to an empty state.
*
* @note After this call, the list size is 0 and both head and tail are nullptr.
*/
void clear();
};
template <LinkedListSupported T>
@@ -431,4 +488,19 @@ bool LinkedList<T>::is_empty() {
return this->len() < 1;
}
template <LinkedListSupported T>
void LinkedList<T>::clear() {
Node<T>* current = head;
while (current != nullptr) {
Node<T>* next = current->next;
delete current;
current = next;
}
head = nullptr;
tail = nullptr;
size = 0;
}
#endif // !