Skip to content

Commit

Permalink
clang formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaaf committed Oct 26, 2023
1 parent a267565 commit 82f6496
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 71 deletions.
66 changes: 66 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: DontAlign
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 4
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never
134 changes: 72 additions & 62 deletions src/AbstractList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@
*
* @tparam T Data Type of entries, that should be stored in the list.
*/
template<typename T>
class AbstractList {
private:
size_t size = 0; /// Size of the list.
bool mutableList = false; /// Is the list mutable or immutable.
template <typename T> class AbstractList {
private:
size_t size = 0; /// Size of the list.
bool mutableList = false; /// Is the list mutable or immutable.

protected:
protected:
/// Sometimes it is allowed, that index == this->getSize() to insert it behind
/// the last entry
#define extendedIsIndexOutOfBounds(index) \
Expand All @@ -51,10 +50,10 @@ class AbstractList {
* Class representing an abstract entry in the list.
*/
class AbstractEntry {
private:
private:
T value; /// The raw value.

public:
public:
/*!
* @brief Get a reference to the value.
*
Expand All @@ -67,9 +66,7 @@ class AbstractList {
*
* @param val Reference to the value.
*/
void setValue(T &val) {
value = val;
}
void setValue(T &val) { value = val; }
};

/*!
Expand All @@ -83,9 +80,11 @@ class AbstractList {
* @brief Get a pointer to the element, stored at specific index-
*
* @param index The index of the element to retrieve.
* @return The nullptr, if the index is out of bounds, otherwise the address of the element.
* @return The nullptr, if the index is out of bounds, otherwise the address
* of the element.
*
* @note This is independent from their mutability. It will always return the correct address (pointer) to the element.
* @note This is independent from their mutability. It will always return the
* correct address (pointer) to the element.
*/
virtual T *getPointer(int index) = 0;

Expand Down Expand Up @@ -116,7 +115,7 @@ class AbstractList {
*/
bool isIndexOutOfBounds(int index) { return index < 0 || index >= getSize(); }

public:
public:
/*!
* @copybrief AbstractList::addLast()
* @note Alias of addLast().
Expand All @@ -135,7 +134,8 @@ class AbstractList {
* @brief Add the value to the list at the given index. The original entry at
* this index, and followings, will be placed directly after the new
* entry.
* @note Allowed indices are 0 to getSize(). If the index is out of bounds, nothing will happen.
* @note Allowed indices are 0 to getSize(). If the index is out of bounds,
* nothing will happen.
*
* @param index Index of the entry, where the value should be added.
* @param value Value of the new entry.
Expand All @@ -146,14 +146,12 @@ class AbstractList {
/*!
* @copydoc AbstractList::addAtIndex()
*/
virtual void addAtIndex(int index, T &&value) {
addAtIndex(index, value);
}
virtual void addAtIndex(int index, T &&value) { addAtIndex(index, value); }
#endif

/*!
* @brief Add all entries from the given list to this list at a specified index.
* The original entry at this index, and followings, will be placed
* @brief Add all entries from the given list to this list at a specified
* index. The original entry at this index, and followings, will be placed
* directly after the entries of the given list.
* @note The elements from the other list, remain untouched.
*
Expand All @@ -180,11 +178,11 @@ class AbstractList {
* directly after the entries of the given list.
* @note The elements from the other list, remain untouched.
*
* @param index Index of tehis list, at which all entries should be added.
* @param index Index of this list, at which all entries should be added.
* @param arr Array.
* @param arrSize Size of the array.
*/
void addAll(int index, T* arr, size_t arrSize) {
void addAll(int index, T *arr, size_t arrSize) {
for (size_t i = 0; i < arrSize; ++i) {
addAtIndex(index++, arr[i]);
}
Expand Down Expand Up @@ -212,8 +210,8 @@ class AbstractList {

#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
/*!
* @copydoc AbstractList::addFirst()
*/
* @copydoc AbstractList::addFirst()
*/
void addFirst(T &&value) { addAtIndex(0, value); }
#endif

Expand All @@ -234,24 +232,29 @@ class AbstractList {
/*!
* @brief Get the raw value at a specified index.
*
* @note Allowed indices are 0 to getSize() - 1. If the index is out of bounds, undefined behaviour will happen. Please ne sure, that the index is valid!
* @note This will method will always return an immutable object. If you want to get the mutable object from your mutable list, plese use getMutableValue().
* @note Allowed indices are 0 to getSize() - 1. If the index is out of
* bounds, undefined behaviour will happen. Please ne sure, that the index is
* valid!
* @note This will method will always return an immutable object. If you want
* to get the mutable object from your mutable list, please use
* getMutableValue().
*
* @param index Index of the element to get.
* @return Immutable object.
*/
T get(int index) {
return *this->getPointer(index);
}
T get(int index) { return *this->getPointer(index); }

/*!
* @brief Get the pointer to the mutable object at a specified index.
*
* @note Allowed indices are 0 to getSize() -1. If the index is out of bounds, a nullptr will be returned.
* @note This method will only return a valid object for a mutable list. A immutable list will return always the nullptr.
* @note Allowed indices are 0 to getSize() -1. If the index is out of bounds,
* a nullptr will be returned.
* @note This method will only return a valid object for a mutable list. A
* immutable list will return always the nullptr.
*
* @param index Index of teh element to get.
* @return Mutable object, or nullptr if the index is out of bounds or the list is immutable.
* @return Mutable object, or nullptr if the index is out of bounds or the
* list is immutable.
*/
T *getMutableValue(int index) {
if (!this->isMutable()) {
Expand All @@ -269,7 +272,8 @@ class AbstractList {
/*!
* @brief Remove the entry at the given index.
*
* @note Allowed indices are 0 to getSize() - 1. If the index is out of bounds, nothing will happen.
* @note Allowed indices are 0 to getSize() - 1. If the index is out of
* bounds, nothing will happen.
*
* @param index Index of element to remove.
*/
Expand Down Expand Up @@ -317,11 +321,15 @@ class AbstractList {
* @brief Get an array which represent the list.
*
* @note If this list is empty, a nullptr will be returned.
* @note The memory for the array is dynamically allocated. the returned pointer has to be free'd with free() in order to
* prevent memory leaks. For further processing of the array, e.g. inserting new elements, the other method toArray(T* arr) is preferred!
* @note The array contains always immutable representations of the elements, saved in the list.
* @note The memory for the array is dynamically allocated. the returned
* pointer has to be free'd with free() in order to prevent memory leaks. For
* further processing of the array, e.g. inserting new elements, the other
* method toArray(T* arr) is preferred!
* @note The array contains always immutable representations of the elements,
* saved in the list.
*
* @return Array representation of the list or nullptr if the list is empty.
* @return Array representation of the list or nullptr if the list is
* empty.
*/
T *toArray() {
if (getSize() == 0) {
Expand All @@ -337,8 +345,10 @@ class AbstractList {
/*!
* @brief Fill the passed array with immutable objects.
*
* @note The array contains always immutable representations of the elements, saved in the list.
* @note Be sure, that the array has enough free space for all elements of the list.
* @note The array contains always immutable representations of the elements,
* saved in the list.
* @note Be sure, that the array has enough free space for all elements of the
* list.
*
* @param arr Array to fill.
*/
Expand All @@ -348,23 +358,23 @@ class AbstractList {
}
}

/*!
* @brief Create the list from given array.
* @note Removes all entries in current list.
*
* @param arr Array
* @param arrSize Size of Array
*/
/*!
* @brief Create the list from given array.
* @note Removes all entries in current list.
*
* @param arr Array
* @param arrSize Size of Array
*/
void fromArray(T *arr, size_t arrSize) {
this->clear();
addAll(arr, arrSize);
}

/*!
* @brief Sort the entries in the list with Quicksort.
*
* @param compFunc Comparator Method
*/
/*!
* @brief Sort the entries in the list with Quicksort.
*
* @param compFunc Comparator Method
*/
void sort(int (*compFunc)(const void *, const void *)) {
T *arr = this->toArray();

Expand All @@ -374,14 +384,14 @@ class AbstractList {
free(arr);
}

/*!
* @brief Compare two lists whether their attributes and entries are equal.
* @note If you use this list for non-primitive data types, check if the
* data type implements the != operator!
*
* @param other Second list to compare.
* @return true if the lists are equal; false otherwise.
*/
/*!
* @brief Compare two lists whether their attributes and entries are equal.
* @note If you use this list for non-primitive data types, check if the
* data type implements the != operator!
*
* @param other Second list to compare.
* @return true if the lists are equal; false otherwise.
*/
bool equals(AbstractList<T> &other) {
if (other.isMutable() != this->isMutable()) {
return false;
Expand Down Expand Up @@ -434,9 +444,9 @@ class AbstractList {

#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
/*!
* @copydoc AbstractList::add()
* @see add()
*/
* @copydoc AbstractList::add()
* @see add()
*/
void operator+(T &&value) { this->add(value); }
#endif

Expand Down
20 changes: 11 additions & 9 deletions src/SingleLinkedList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@
*
* @tparam T Data Type of entries, that should be stored in the list.
*/
template<typename T>
class SingleLinkedList : public AbstractList<T> {
private:
template <typename T> class SingleLinkedList : public AbstractList<T> {
private:
/*!
* @brief Class representing one entry of the list.
*/
class Entry : public AbstractList<T>::AbstractEntry {
private:
private:
Entry *next = nullptr; /// Pointer to the next element of the list

public:
public:
/*!
* @brief Destructor of an Entry Object.
*/
Expand All @@ -67,11 +66,12 @@ class SingleLinkedList : public AbstractList<T> {
Entry *head = nullptr; /// The first entry of the list.
Entry *tail = nullptr; /// The last entry of the list.

protected:
protected:
/*!
* Get the pointer to the element at the specified index.
*
* @note Allowed indices are 0 to getSize() -1. If the index is out of bounds, a nullptr will be returned.
* @note Allowed indices are 0 to getSize() -1. If the index is out of bounds,
* a nullptr will be returned.
*
* @param index
* @return
Expand All @@ -90,7 +90,7 @@ class SingleLinkedList : public AbstractList<T> {
return current->getValue();
}

public:
public:
/*!
* @brief Constructor of a SingleLinkedList Object.
*
Expand All @@ -105,7 +105,9 @@ class SingleLinkedList : public AbstractList<T> {
*/
~SingleLinkedList() { this->clear(); }

using AbstractList<T>::addAtIndex; ///'Using' the addAtIndex method, to prevent name hiding of the addAtIndex method from AbstractList
using AbstractList<T>::addAtIndex; ///'Using' the addAtIndex method, to
///prevent name hiding of the addAtIndex
///method from AbstractList

/*!
* @copydoc AbstractList::addAtIndex()
Expand Down

0 comments on commit 82f6496

Please sign in to comment.