diff --git a/Jupiter/Jupiter.vcxproj b/Jupiter/Jupiter.vcxproj index a05d185..594196c 100644 --- a/Jupiter/Jupiter.vcxproj +++ b/Jupiter/Jupiter.vcxproj @@ -239,7 +239,6 @@ - diff --git a/Jupiter/Jupiter.vcxproj.filters b/Jupiter/Jupiter.vcxproj.filters index 0bb565a..3859a92 100644 --- a/Jupiter/Jupiter.vcxproj.filters +++ b/Jupiter/Jupiter.vcxproj.filters @@ -149,9 +149,6 @@ Header Files\Lists - - Header Files\Lists - Header Files\Sockets diff --git a/Jupiter/SLList.h b/Jupiter/SLList.h deleted file mode 100644 index 231918c..0000000 --- a/Jupiter/SLList.h +++ /dev/null @@ -1,441 +0,0 @@ -/** - * Copyright (C) 2013-2016 Jessica James. - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Written by Jessica James - */ - -#if !defined _SLLIST_H_HEADER -#define _SLLIST_H_HEADER - -/** - * @file SLList.h - * @brief Provides a generic Singly Linked List implementation using the List interface. - */ - -#include "Jupiter.h" -#include "List.h" - -namespace Jupiter -{ - /** - * @brief Provides a Singly Linked List implementation using the List interface. - */ - template class SLList : public List - { - public: - - /** - * @brief Stores a pointer to data, and a pointer to the next node in the list. - */ - struct Node - { - Node *next = nullptr; - T *data = nullptr; - }; - - /* - * @brief Returns the head of the list - * - * @return Head of the list - */ - Node *getHead() const; - - /* - * @brief Returns the tail of the list - * - * @return Tail of the list - */ - Node *getTail() const; - - /** - * @brief Returns the Node at the specified index in the list. - * - * @param index Index of the node to return. - * @return Node at specified index in the list. - */ - Node *getNode(size_t index) const; - - /** - * @brief Gets the data at a specified index. - * - * @param index Index of the data to get. - * @return Data stored at the specified index. - */ - T *get(size_t index) const; - - /** - * @brief Removes the head of the list - * - * @return Value that was stored in the head of the list - */ - T *removeHead(); - - /** - * @brief Removes the n'th Node in the list, and returns its contents. - * - * @param n Index of the node to remove. - * @return Contents of the node removed. - */ - T *remove(size_t n); - - /** - * @brief Removes the next node in the list. - * - * @param data Node that preceeds the node to be removed. - * @return Contents of the node removed if the node exists, nullptr otherwise. - */ - T *removeNext(Node *data); - - /** - * @brief Adds data to the end of the list. - * - * @param data Data to add to the list. - */ - void add(T *data); - - /** - * @brief Inserts data to the specified index in the list. - * - * @param data Data to insert into the list. - * @param index Position in the list to insert data to. - */ - void add(T *data, size_t index); - - /** - * @brief Inserts data to the head of the list. - * - * @param data Data to insert into the list. - */ - void addHead(T *data); - - /** - * @breif Erases all entries in the list - */ - void erase(); - - /** - * @breif Erases and deletes all entries in the list - */ - void eraseAndDelete(); - - SLList &operator=(const SLList &in_list); - SLList &operator=(SLList &&in_list); - - /** - * @brief Default constructor for the SLList class. - */ - SLList() = default; - - /** - * @brief Copy constructor for the SLList class. - * - * @param in_list List to copy data from - */ - SLList(const SLList &in_list); - - /** - * @brief Move constructor for the SLList class - * - * @param in_list List to move data from - */ - SLList(SLList &&in_list); - - /** - * @brief Destructor for the SLList class. - * Note: This does not delete data added to the list. - */ - ~SLList(); - - /** Private members */ - private: - void copy_from_internal(const SLList &in_list); - - Node *m_head = nullptr; - Node *m_tail = nullptr; - }; - -} - -// Implementation - -template typename Jupiter::SLList::Node *Jupiter::SLList::getHead() const -{ - return m_head; -} - -template typename Jupiter::SLList::Node *Jupiter::SLList::getTail() const -{ - return m_tail; -} - -template typename Jupiter::SLList::Node *Jupiter::SLList::getNode(size_t in_index) const -{ - if (in_index == Jupiter::SLList::length) - return m_tail; - - Jupiter::SLList::Node *node = m_head; - - while (in_index != 0) - { - node = node->next; - --in_index; - } - - return node; -} - -template T *Jupiter::SLList::get(size_t in_index) const -{ - return Jupiter::SLList::getNode(in_index)->data; -} - -template T *Jupiter::SLList::removeHead() -{ - if (m_head == nullptr) - return nullptr; - - T *result = m_head->data; - - Jupiter::SLList::Node *node = m_head; - m_head = m_head->next; - delete node; - --Jupiter::List::length; - - return result; -} - -template T *Jupiter::SLList::remove(size_t in_index) -{ - if (in_index == 0) - return Jupiter::SLList::removeHead(); - - Jupiter::SLList::Node *node = m_head; - - while (in_index != 1) - { - node = node->next; - --in_index; - } - - Jupiter::SLList::Node *tmp = node->next; - T *result = tmp->data; - - node->next = tmp->next; - delete tmp; - --Jupiter::List::length; - - return result; -} - -template T *Jupiter::SLList::removeNext(Node *in_data) -{ - Jupiter::SLList::Node *node = in_data->next; - - if (node == nullptr) - return nullptr; - - T *result = node->data; - - in_data->next = node->next; - delete node; - --Jupiter::List::length; - - return result; -} - -template void Jupiter::SLList::add(T *data) -{ - Jupiter::SLList::Node *node = new Jupiter::SLList::Node(); - node->data = data; - - if (m_head == nullptr) - m_head = node; - else - m_tail->next = node; - - m_tail = node; - ++Jupiter::List::length; -} - -template void Jupiter::SLList::add(T *in_data, size_t in_index) -{ - if (in_index == 0) - { - Jupiter::SLList::addHead(in_data); - return; - } - - if (in_index >= Jupiter::List::length) - { - Jupiter::SLList::add(in_data); - return; - } - - Jupiter::SLList::Node *node = new Jupiter::SLList::Node(); - node->data = in_data; - - Jupiter::SLList::Node *itr = m_head; - - while (in_index != 1) - { - itr = itr->next; - --in_index; - } - - node->next = itr->next; - itr->next = node; - - ++Jupiter::List::length; -} - -template void Jupiter::SLList::addHead(T *data) -{ - Jupiter::SLList::Node *node = new Jupiter::SLList::Node(); - node->data = data; - node->next = m_head; - m_head = node; - - if (m_tail == nullptr) - m_tail = node; - - ++Jupiter::List::length; -} - -template void Jupiter::SLList::erase() -{ - Jupiter::SLList::Node *node = m_head; - - if (node == nullptr) - return; - - Jupiter::SLList::Node *tmp; - - do - { - tmp = node; - node = node->next; - delete tmp; - } while (node != nullptr); - - m_head = nullptr; - m_tail = nullptr; - Jupiter::List::length = 0; -} - -template void Jupiter::SLList::eraseAndDelete() -{ - Jupiter::SLList::Node *node = m_head; - - if (node == nullptr) - return; - - Jupiter::SLList::Node *tmp; - - do - { - tmp = node; - node = node->next; - delete tmp->data; - delete tmp; - } while (node != nullptr); - - m_head = nullptr; - m_tail = nullptr; - Jupiter::List::length = 0; -} - -template<> struct _Jupiter_DataBuffer_partial_specialization_impl -{ - template static void push(Jupiter::DataBuffer *buffer, const Jupiter::SLList *data) - { - buffer->push(data->size()); - Jupiter::SLList::Node *head = data->getHead(); - while (head != nullptr) - buffer->push(*head++->data); - }; - - template static Jupiter::SLList interpret(uint8_t *&head) - { - size_t size_ = *reinterpret_cast(head); - head += sizeof(size_t); - Jupiter::SLList r; - while (size_-- != 0) - r.add(Jupiter::DataBuffer::interpret_data(head)); - return r; - } -}; - -template Jupiter::SLList &Jupiter::SLList::operator=(const SLList &in_list) -{ - Jupiter::SLList::erase(); - - Jupiter::SLList::copy_from_internal(in_list); - - return *this; -} - -template Jupiter::SLList &Jupiter::SLList::operator=(SLList &&in_list) -{ - m_head = in_list.m_head; - m_tail = in_list.m_tail; - - return *this; -} - -template Jupiter::SLList::SLList(const Jupiter::SLList &in_list) -{ - Jupiter::SLList::copy_from_internal(in_list); -} - -template Jupiter::SLList::SLList(Jupiter::SLList &&in_list) -{ - m_head = in_list.m_head; - m_tail = in_list.m_tail; - - in_list.m_head = nullptr; - in_list.m_tail = nullptr; -} - -template Jupiter::SLList::~SLList() -{ - Jupiter::SLList::erase(); -} - -/** Internal */ - -template void Jupiter::SLList::copy_from_internal(const SLList &in_list) -{ - Jupiter::SLList::Node *source_node = in_list.m_head; - - if (source_node == nullptr) - return; - - Jupiter::SLList::Node *node = new Jupiter::SLList::Node(); - node->data = source_node->data; - source_node = source_node->next; - - while (source_node != nullptr) - { - node->next = new Jupiter::SLList::Node(); - node = node->next; - node->data = source_node->data; - source_node = source_node->next; - } - - m_tail = node; - Jupiter::List::length = in_list.length; -} - -#endif // _SLLIST_H_HEADER \ No newline at end of file