Skip to content

Commit

Permalink
Merge pull request #16 from nkaaf/road_to_2_1_0
Browse files Browse the repository at this point in the history
PR for 2.1.0
  • Loading branch information
nkaaf authored Feb 22, 2022
2 parents 2fe5514 + 5cf8de8 commit fbbbace
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Arduino List Library"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.0.0
PROJECT_NUMBER = 2.1.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
15 changes: 15 additions & 0 deletions examples/List/ManageElements/ManageElements.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ void setup() {
Serial.print("After the deletion, the list has: ");
Serial.print(list.getSize());
Serial.println(" element(s)");

// Add 10 more elements
int e = 0;
for (int i = 0; i < 10; ++i) {
list.add(e);
}
Serial.print("After the insertion, the list has: ");
Serial.print(list.getSize());
Serial.println(" element(s)");

// Clear list
list.clear();
Serial.print("After the clear, the list has: ");
Serial.print(list.getSize());
Serial.println(" element(s)");
}

void loop() {}
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ addAtIndex KEYWORD2
addAll KEYWORD2
addFirst KEYWORD2
addLast KEYWORD2
clear KEYWORD2
getValue KEYWORD2
getPointer KEYWORD2
remove KEYWORD2
removeAll KEYWORD2
getSize KEYWORD2
isMutable KEYWORD2
isEmpty KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=List
version=2.0.0
version=2.1.0
author=Niklas Kaaf <[email protected]>
maintainer=Niklas Kaaf <[email protected]>
sentence=The Ultimate Collection of Lists
Expand Down
41 changes: 14 additions & 27 deletions src/AbstractList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ template <typename T> class AbstractList {

public:
/*!
* @brief Add a new entry at the end of the list.
* @copybrief AbstractList::addLast()
* @note Alias of addLast().
* @see addLast()
*
* @param value Value to add.
Expand Down Expand Up @@ -166,7 +167,7 @@ template <typename T> class AbstractList {

/*!
* @brief Add all entries from the given list at the end of the list.
* @see addLast()
* @see addAll()
*
* @param list Other list to copy from.
*/
Expand All @@ -188,13 +189,9 @@ template <typename T> class AbstractList {
void addLast(T &value) { addAtIndex(getSize(), value); }

/*!
* @brief Get a pointer to the entry at the given index. If the given index
* does not exists, null will be returned.
* @note If the list is immutable, the returned pointer has to be free'd with
* free() in order to prevent memory leaks.
*
* @param index Index of element to get.
* @return Pointer to the element.
* @copydoc AbstractList::get()
* @note Alias of get().
* @see get()
*/
T *getPointer(int index) { return get(index); }

Expand Down Expand Up @@ -228,8 +225,9 @@ template <typename T> class AbstractList {
virtual void remove(int index) = 0;

/*!
* @brief Remove all elements from the List.
* @copybrief AbstractList::clear()
* @note Alias of clear().
* @see clear().
*/
void removeAll() { clear(); }

Expand Down Expand Up @@ -301,37 +299,26 @@ template <typename T> class AbstractList {
}

/*!
* @brief Get the value of the element at the index.
* @copydoc AbstractList::getValue()
* @see getValue()
*
* @param index Index of the element to get.
* @return Value of the element.
*/
T operator[](int index) { return getValue(index); }

/*!
* @brief Compare two lists whether their attributes and entries are equal.
* @copydoc AbstractList::equals()
* @see equals()
*
* @param list Second list to compare.
* @return true if the lists are equal; false otherwise.
*/
bool operator==(AbstractList<T> &list) { return equals(list); }

/*!
* @brief Add a new entry at the end of the list.
* @see add()
* @see addLast()
*
* @param value Value to add.
* @copydoc AbstractList::add()
* @see add()
*/
void operator+(T &value) { this->add(value); }

/*!
* @brief Add all entries from the given list at the end of the list.
* @see addAll()
*
* @param list Other list to copy from.
* @copydoc AbstractList::addAll(AbstractList<T>&)
* @see addAll(AbstractList<T>&)
*/
void operator+(AbstractList<T> &list) { this->addAll(list); }
};
Expand Down
14 changes: 13 additions & 1 deletion src/DoubleLinkedList.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* @file SingleLinkedList.hpp
* @file DoubleLinkedList.hpp
*
* This file is part of the List library. It extends the arduino ecosystem with
* easy-to-use list implementations. They are specially designed and optimized
Expand Down Expand Up @@ -84,6 +84,9 @@ template <typename T> class DoubleLinkedList : public AbstractList<T> {
Entry *tail = nullptr; /// The last entry of the list.

protected:
/*!
* @copydoc AbstractList::get()
*/
T *get(int index) override {
if (this->isIndexOutOfBounds(index)) {
return nullptr;
Expand Down Expand Up @@ -128,6 +131,9 @@ template <typename T> class DoubleLinkedList : public AbstractList<T> {
*/
~DoubleLinkedList() { this->clear(); }

/*!
* @copydoc AbstractList::addAtIndex()
*/
void addAtIndex(int index, T &value) override {
// it is allowed, that index == this->getSize() to insert it behind the last
// entry
Expand Down Expand Up @@ -188,6 +194,9 @@ template <typename T> class DoubleLinkedList : public AbstractList<T> {
this->increaseSize();
};

/*!
* @copydoc AbstractList::clear()
*/
void clear() override {
if (this->getSize() > 0) {
Entry *current = head;
Expand All @@ -209,6 +218,9 @@ template <typename T> class DoubleLinkedList : public AbstractList<T> {
tail = nullptr;
}

/*!
* @copydoc AbstractList::remove()
*/
void remove(int index) override {
if (this->isIndexOutOfBounds(index)) {
return;
Expand Down
12 changes: 12 additions & 0 deletions src/SingleLinkedList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ template <typename T> class SingleLinkedList : public AbstractList<T> {
Entry *tail = nullptr; /// The last entry of the list.

protected:
/*!
* @copydoc AbstractList::get()
*/
T *get(int index) override {
if (this->isIndexOutOfBounds(index)) {
return nullptr;
Expand Down Expand Up @@ -106,6 +109,9 @@ template <typename T> class SingleLinkedList : public AbstractList<T> {
*/
~SingleLinkedList() { this->clear(); }

/*!
* @copydoc AbstractList::addAtIndex()
*/
void addAtIndex(int index, T &value) override {
// it is allowed, that index == this->getSize() to insert it behind the last
// entry
Expand Down Expand Up @@ -149,6 +155,9 @@ template <typename T> class SingleLinkedList : public AbstractList<T> {
this->increaseSize();
};

/*!
* @copydoc AbstractList::clear()
*/
void clear() override {
if (this->getSize() > 0) {
Entry *current = head;
Expand All @@ -170,6 +179,9 @@ template <typename T> class SingleLinkedList : public AbstractList<T> {
}
}

/*!
* @copydoc AbstractList::remove()
*/
void remove(int index) override {
if (this->isIndexOutOfBounds(index)) {
return;
Expand Down

0 comments on commit fbbbace

Please sign in to comment.