diff --git a/Jupiter/ArrayList.h b/Jupiter/ArrayList.h index 1716b33..703b6fb 100644 --- a/Jupiter/ArrayList.h +++ b/Jupiter/ArrayList.h @@ -25,14 +25,14 @@ */ #include "Jupiter.h" -#include "List.h" +#include "DataBuffer.h" namespace Jupiter { /** * @brief Provides an array-based list implementation using the List interface. */ - template class ArrayList : public List + template class ArrayList { public: @@ -74,6 +74,13 @@ namespace Jupiter */ void add(T *data); + /** + * @brief Returns the size of the list. + * + * @return Number of nodes in the list. + */ + size_t size() const { return m_length; }; + /** * @brief Empties the ArrayList of all elements. */ @@ -120,6 +127,7 @@ namespace Jupiter private: T **data; size_t dataSize; + size_t m_length; size_t expandArray(); }; @@ -130,7 +138,9 @@ namespace Jupiter template size_t Jupiter::ArrayList::expandArray() { T **tmp = new T *[Jupiter::ArrayList::dataSize * 2]; - for (size_t i = 0; i < Jupiter::ArrayList::dataSize; i++) tmp[i] = data[i]; + for (size_t i = 0; i < Jupiter::ArrayList::dataSize; i++) + tmp[i] = data[i]; + delete[] Jupiter::ArrayList::data; Jupiter::ArrayList::data = tmp; Jupiter::ArrayList::dataSize *= 2; @@ -145,18 +155,18 @@ template Jupiter::ArrayList::ArrayList(size_t length_) { Jupiter::ArrayList::dataSize = length_; Jupiter::ArrayList::data = new T*[Jupiter::ArrayList::dataSize]; - Jupiter::List::length = 0; + m_length = 0; } template Jupiter::ArrayList::ArrayList(const Jupiter::ArrayList &source) { Jupiter::ArrayList::dataSize = source.dataSize; Jupiter::ArrayList::data = new T*[Jupiter::ArrayList::dataSize]; - Jupiter::List::length = 0; - while (Jupiter::List::length != source.length) + m_length = 0; + while (m_length != source.m_length) { - Jupiter::ArrayList::data[Jupiter::List::length] = source.data[Jupiter::List::length]; - ++Jupiter::List::length; + Jupiter::ArrayList::data[m_length] = source.data[m_length]; + ++m_length; } } @@ -164,10 +174,10 @@ template Jupiter::ArrayList::ArrayList(ArrayList &&source) { Jupiter::ArrayList::dataSize = source.dataSize; Jupiter::ArrayList::data = source.data; - Jupiter::List::length = source.length; + m_length = source.m_length; source.dataSize = Jupiter::ArrayList::start_size; source.data = new T*[source.dataSize]; - source.length = 0; + source.m_length = 0; } template Jupiter::ArrayList::~ArrayList() @@ -184,45 +194,53 @@ template T *Jupiter::ArrayList::remove(size_t index) { T *r = Jupiter::ArrayList::data[index]; Jupiter::ArrayList::data[index] = nullptr; - for (size_t i = index + 1; i < Jupiter::List::length; i++) Jupiter::ArrayList::data[i - 1] = Jupiter::ArrayList::data[i]; - Jupiter::List::length--; + + for (size_t i = index + 1; i < m_length; i++) + Jupiter::ArrayList::data[i - 1] = Jupiter::ArrayList::data[i]; + + --m_length; return r; } template T *Jupiter::ArrayList::pop() { - return Jupiter::ArrayList::data[--Jupiter::List::length]; + return Jupiter::ArrayList::data[--m_length]; } template void Jupiter::ArrayList::add(T *ndata, size_t index) { - if (Jupiter::List::length == Jupiter::ArrayList::dataSize) Jupiter::ArrayList::expandArray(); - for (size_t i = Jupiter::List::length; i > index; i--) Jupiter::ArrayList::data[i] = Jupiter::ArrayList::data[i - 1]; + if (m_length == Jupiter::ArrayList::dataSize) Jupiter::ArrayList::expandArray(); + + for (size_t i = m_length; i > index; i--) + Jupiter::ArrayList::data[i] = Jupiter::ArrayList::data[i - 1]; + Jupiter::ArrayList::data[index] = ndata; - Jupiter::List::length++; + ++m_length; } template void Jupiter::ArrayList::add(T *ndata) { - Jupiter::ArrayList::add(ndata, Jupiter::List::length); + Jupiter::ArrayList::add(ndata, m_length); } template void Jupiter::ArrayList::empty() { - Jupiter::List::length = 0; + m_length = 0; } template void Jupiter::ArrayList::emptyAndDelete() { - while (Jupiter::List::length != 0) - delete Jupiter::ArrayList::data[--Jupiter::List::length]; + while (m_length != 0) + delete Jupiter::ArrayList::data[--m_length]; } template<> struct _Jupiter_DataBuffer_partial_specialization_impl { template static void push(Jupiter::DataBuffer *buffer, const Jupiter::ArrayList *data) { - _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); + buffer->push(data->size()); + for (size_t index = 0; index != data->size(); index++) + buffer->push(*data->get(index)); }; template static Jupiter::ArrayList interpret(uint8_t *&head) diff --git a/Jupiter/DLList.h b/Jupiter/DLList.h deleted file mode 100644 index 8ca999e..0000000 --- a/Jupiter/DLList.h +++ /dev/null @@ -1,318 +0,0 @@ -/** - * Copyright (C) 2013-2015 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 _DLLIST_H_HEADER -#define _DLLIST_H_HEADER - -/** - * @file DLList.h - * @brief Provides a generic Doubly Linked List implementation using the List interface. - */ - -#include "Jupiter.h" -#include "List.h" - -namespace Jupiter -{ - /** - * @brief Provides a Doubly Linked List implementation using the List interface. - */ - template class DLList : public List - { - public: - - /** - * @brief Stores a pointer to data, and a pointer to the next node in the list. - */ - struct Node - { - Node *next; - Node *previous; - T *data; - }; - - /* - * @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 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 a node from the list. - * - * @param data Node to remove. - * @return Contents of the node removed. - */ - T *remove(Node *data); - - /** - * @brief Adds data to the list at a specified index. - * - * @param data Data to add to the list. - * @param index Position in the list to add the data to. - */ - void add(T *data, size_t index); - - /** - * @brief Adds data to the tail of the list. - * - * @param data Data to add to the list. - */ - void add(T *data); - - /** - * @brief Default constructor for the DLList class. - */ - DLList() = default; - - /** - * @brief Copy constructor for the DLList class. - */ - DLList(const DLList &); - - /** - * @brief Destructor for the DLList class. - * Note: This does not delete data added to the list. - */ - ~DLList(); - - /** Private members */ - private: - Node *m_head = nullptr; - Node *m_tail = nullptr; - }; - -} - -// Implementation - -template Jupiter::DLList::DLList(const Jupiter::DLList &source) -{ - Jupiter::List::length = source.length; - if (Jupiter::List::length == 0) - { - m_head = nullptr; - m_tail = nullptr; - } - else if (Jupiter::List::length == 1) - { - Jupiter::DLList::Node *n = new Jupiter::DLList::Node; - n->data = source.getNode(0)->data; - m_head = n; - m_tail = n; - } - else - { - Jupiter::DLList::Node *sourceNode = source.getNode(0); - Jupiter::DLList::Node *n = new Jupiter::DLList::Node; - n->data = sourceNode->data; - m_head = n; - sourceNode = sourceNode->next; - - while (sourceNode->next != nullptr) - { - n->next = new Jupiter::DLList::Node; - n = n->next; - n->data = sourceNode->data; - sourceNode = sourceNode->next; - } - - n->next = new Jupiter::DLList::Node; - n = n->next; - n->data = sourceNode->data; - - m_tail = n; - } -} - -template Jupiter::DLList::~DLList() -{ - Jupiter::DLList::Node *p; - Jupiter::DLList::Node *c = m_head; - while (c != nullptr) - { - p = c; - c = c->next; - delete p; - } -} - -template typename Jupiter::DLList::Node *Jupiter::DLList::getHead() const -{ - return m_head; -} - -template typename Jupiter::DLList::Node *Jupiter::DLList::getTail() const -{ - return m_tail; -} - -template typename Jupiter::DLList::Node *Jupiter::DLList::getNode(size_t index) const -{ - Jupiter::DLList::Node *r; - if (index * 2 < Jupiter::List::length) - { - r = m_head; - for (size_t i = 0; i < index; i++) r = r->next; - return r; - } - r = m_tail; - for (size_t i = Jupiter::List::length - 1; i > index; i--) r = r->previous; - return r; -} - -template T *Jupiter::DLList::get(size_t index) const -{ - return Jupiter::DLList::getNode(index)->data; -} - -template T *Jupiter::DLList::remove(size_t index) -{ - return Jupiter::DLList::remove(Jupiter::DLList::getNode(index)); -} - -template T *Jupiter::DLList::remove(Node *data) -{ - if (m_head == data) - { - m_head = data->next; - if (data->next != nullptr) data->next->previous = data->previous; - else m_tail = nullptr; - } - else if (m_tail == data) - { - m_tail = data->previous; - m_tail->next = nullptr; - } - else - { - data->next->previous = data->previous; - data->previous->next = data->next; - } - T *r = data->data; - delete data; - Jupiter::List::length--; - return r; -} - -template void Jupiter::DLList::add(T *data, size_t index) -{ - Jupiter::DLList::Node *node = new Jupiter::DLList::Node(); - node->data = data; - if (index == 0) - { - node->next = m_head; - m_head->previous = node; - m_head = node; - node->previous = nullptr; - } - else if (index == Jupiter::List::length) - { - node->previous = m_tail; - m_tail->next = node; - m_tail = node; - node->next = nullptr; - } - else - { - Jupiter::DLList::Node *n = Jupiter::DLList::getNode(index); - node->next = n; - node->previous = n->previous; - node->previous->next = node; - n->previous = node; - } - Jupiter::List::length++; -} - -template void Jupiter::DLList::add(T *data) -{ - Jupiter::DLList::Node *n = new Jupiter::DLList::Node(); - n->data = data; - n->next = nullptr; - if (Jupiter::List::length == 0) - { - m_head = n; - m_tail = n; - n->previous = nullptr; - } - else - { - n->previous = m_tail; - m_tail->next = n; - m_tail = n; - } - Jupiter::List::length++; -} - -template<> struct _Jupiter_DataBuffer_partial_specialization_impl -{ - template static void push(Jupiter::DataBuffer *buffer, const Jupiter::DLList *data) - { - buffer->push(data->size()); - Jupiter::DLList::Node *head = data->getNode(0); - while (head != nullptr) - { - buffer->push(*head->data); - head++; - } - }; - - template static Jupiter::DLList interpret(uint8_t *&head) - { - size_t size_ = *reinterpret_cast(head); - head += sizeof(size_t); - Jupiter::DLList r; - while (size_-- != 0) - r.add(Jupiter::DataBuffer::interpret_data(head)); - return r; - } -}; - -#endif // _DLLIST_H_HEADER \ No newline at end of file diff --git a/Jupiter/Jupiter.vcxproj b/Jupiter/Jupiter.vcxproj index 594196c..6d0b231 100644 --- a/Jupiter/Jupiter.vcxproj +++ b/Jupiter/Jupiter.vcxproj @@ -192,7 +192,6 @@ - @@ -212,7 +211,6 @@ - @@ -227,9 +225,7 @@ - - diff --git a/Jupiter/Jupiter.vcxproj.filters b/Jupiter/Jupiter.vcxproj.filters index 3859a92..e24a2ab 100644 --- a/Jupiter/Jupiter.vcxproj.filters +++ b/Jupiter/Jupiter.vcxproj.filters @@ -22,9 +22,6 @@ {a7ca0e66-d9b7-43e2-a3f8-d89744bd3c06} - - {b0dabf12-3147-44f6-911e-01142cc4e3a4} - {6f290a91-7cd8-495e-ae20-22c956fcfbcb} @@ -72,9 +69,6 @@ Source Files - - Source Files\Lists - Source Files\Sockets @@ -140,15 +134,6 @@ Header Files - - Header Files\Lists - - - Header Files\Lists - - - Header Files\Lists - Header Files\Sockets diff --git a/Jupiter/List.h b/Jupiter/List.h deleted file mode 100644 index 8ef6e61..0000000 --- a/Jupiter/List.h +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright (C) 2013-2015 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 _LIST_H_HEADER -#define _LIST_H_HEADER - -/** - * @file List.h - * @brief Provides a generic List interface. - */ - -#include "Jupiter.h" -#include "DataBuffer.h" - -namespace Jupiter -{ - template class List - { - public: - - /** - * @brief Gets the data at a specified index. - * - * @param index Index of the data to get. - * @return Data stored at the specified index. - */ - virtual T *get(size_t index) const = 0; - - /** - * @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. - */ - virtual T *remove(size_t n) = 0; - - /** - * @brief Adds data to the list at a specified index. - * - * @param data Data to add to the list. - * @param index Position in the list to add the data to. - */ - virtual void add(T *data, size_t index) = 0; - - /** - * @brief Adds data to the list in an efficient manner. - * - * @param data Data to add to the list. - */ - virtual void add(T *data) = 0; - - /** - * @brief Returns the size of the list. - * - * @return Number of nodes in the list. - */ - size_t size() const { return Jupiter::List::length; }; - - protected: - size_t length = 0; /** Length (size) of the list. Returned by size(). Must be managed by extending classes. */ - }; -} - -template<> struct _Jupiter_DataBuffer_partial_specialization_impl -{ - template static void push(Jupiter::DataBuffer *buffer, const Jupiter::List *data) - { - buffer->push(data->size()); - for (size_t index = 0; index != data->size(); index++) - buffer->push(*data->get(index)); - }; -}; - -#endif // _LIST_H_HEADER \ No newline at end of file diff --git a/Jupiter/Queue.cpp b/Jupiter/Queue.cpp deleted file mode 100644 index ef46fcc..0000000 --- a/Jupiter/Queue.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (C) 2013-2015 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 - */ - -#include "Queue.h" - -struct Jupiter::Queue::Data -{ - Data *next; - void *data; -}; - -Jupiter::Queue::Queue() -{ - Jupiter::Queue::end = new Jupiter::Queue::Data(); - Jupiter::Queue::end->next = nullptr; - Jupiter::Queue::head = new Jupiter::Queue::Data(); - Jupiter::Queue::head->next = Jupiter::Queue::end; - Jupiter::Queue::head->data = nullptr; - Jupiter::Queue::length = 0; -} - -Jupiter::Queue::~Queue() -{ - Jupiter::Queue::Data *p; - Jupiter::Queue::Data *c = head; - do - { - p = c; - c = c->next; - delete p; - } - while (c != nullptr); -} - -void Jupiter::Queue::enqueue(void *data) -{ - Jupiter::Queue::Data *nEnd = new Jupiter::Queue::Data(); - nEnd->next = nullptr; - end->data = data; - end->next = nEnd; - end = nEnd; - Jupiter::Queue::length++; -} - -void *Jupiter::Queue::dequeue() -{ - if (Jupiter::Queue::length > 0) - { - Jupiter::Queue::Data *tmp = Jupiter::Queue::head->next; - Jupiter::Queue::head->next = tmp->next; - void *data = tmp->data; - delete tmp; - Jupiter::Queue::length--; - return data; - } - return nullptr; -} - -size_t Jupiter::Queue::size() const -{ - return Jupiter::Queue::length; -} \ No newline at end of file diff --git a/Jupiter/Queue.h b/Jupiter/Queue.h deleted file mode 100644 index 3ec450a..0000000 --- a/Jupiter/Queue.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (C) 2013-2015 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 _QUEUE_H_HEADER -#define _QUEUE_H_HEADER - -/** - * @file Queue.h - * @brief Provides a simple and efficient queue. - */ - -#include "Jupiter.h" - -namespace Jupiter -{ - /** - * @brief Provides a simple and efficient queue. - */ - class JUPITER_API Queue - { - public: - - /** - * @brief Adds data to the end of the Queue. - * - * @param data Pointer to the data to add. - */ - void enqueue(void *data); - - /** - * @brief Removes and returns data from the front of the Queue. - * - * @return Data in the front of the Queue. - */ - void *dequeue(); - - /** - * @brief Returns the number of elements waiting for processing in the Queue. - * - * @return Number of elements in the Queue. - */ - size_t size() const; - - /** - * @brief Default constructor for the Queue class. - */ - Queue(); - - /** - * @brief Destructor for the Queue class. - * Note: This does not delete data which was added to the queue. - */ - ~Queue(); - - /** Private members */ - private: - struct Data; - Data *head; - Data *end; - size_t length; - }; - -} - -#endif // _QUEUE_H_HEADER \ No newline at end of file diff --git a/Jupiter/Rehash.cpp b/Jupiter/Rehash.cpp index aab2464..f854d44 100644 --- a/Jupiter/Rehash.cpp +++ b/Jupiter/Rehash.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2016 Jessica James. + * Copyright (C) 2014-2017 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 @@ -16,8 +16,8 @@ * Written by Jessica James */ +#include #include "Rehash.h" -#include "DLList.h" /** * Considerations: @@ -47,28 +47,28 @@ public: }; /** List of Rehashable objects */ -Jupiter::DLList o_rehashables; +std::list o_rehashables; /** List of RehashFunction objects */ -Jupiter::DLList o_rehash_functions; +std::list o_rehash_functions; Jupiter::Rehashable::Rehashable() { - o_rehashables.add(this); + o_rehashables.push_back(this); } Jupiter::Rehashable::Rehashable(const Jupiter::Rehashable &) { - o_rehashables.add(this); + o_rehashables.push_back(this); } Jupiter::Rehashable::~Rehashable() { - for (Jupiter::DLList::Node *node = o_rehashables.getHead(); node != nullptr; node = node->next) + for (auto node = o_rehashables.begin(); node != o_rehashables.end(); ++node) { - if (node->data == this) + if (*node == this) { - o_rehashables.remove(node); + o_rehashables.erase(node); break; } } @@ -78,32 +78,31 @@ size_t Jupiter::rehash() { size_t total_errors = 0; int rehash_result; - Jupiter::DLList::Node *node = o_rehashables.getHead(); - Jupiter::DLList::Node *dead_node; + auto node = o_rehashables.begin(); - while (node != nullptr) + while (node != o_rehashables.end()) { - rehash_result = node->data->OnRehash(); + rehash_result = (*node)->OnRehash(); if (rehash_result != 0) { ++total_errors; if (rehash_result < 0) { - dead_node = node; - node = node->next; + auto dead_node = node; + ++node; - if (dead_node->data->OnBadRehash(true)) - delete o_rehashables.remove(dead_node); - else - o_rehashables.remove(dead_node); + if ((*dead_node)->OnBadRehash(true)) + delete *dead_node; + + o_rehashables.erase(dead_node); continue; } - o_rehashables.remove(node)->OnBadRehash(false); + (*node)->OnBadRehash(false); } - node = node->next; + ++node; } return total_errors; @@ -116,16 +115,17 @@ size_t Jupiter::getRehashableCount() void Jupiter::addOnRehash(OnRehashFunctionType in_function) { - o_rehash_functions.add(new RehashFunction(in_function)); + o_rehash_functions.push_back(new RehashFunction(in_function)); } bool Jupiter::removeOnRehash(OnRehashFunctionType in_function) { - for (Jupiter::DLList::Node *node = o_rehash_functions.getHead(); node != nullptr; node = node->next) + for (auto node = o_rehash_functions.begin(); node != o_rehash_functions.end(); ++node) { - if (node->data->m_function == in_function) + if ((*node)->m_function == in_function) { - delete o_rehash_functions.remove(node); + delete *node; + o_rehash_functions.erase(node); return true; } } @@ -138,7 +138,10 @@ size_t Jupiter::removeAllOnRehash() size_t result = o_rehash_functions.size(); while (o_rehash_functions.size() != 0) - delete o_rehash_functions.remove(size_t{ 0 }); + { + delete o_rehash_functions.front(); + o_rehash_functions.pop_front(); + } return result; } diff --git a/Jupiter/Timer.cpp b/Jupiter/Timer.cpp index 70ae26f..8c708bf 100644 --- a/Jupiter/Timer.cpp +++ b/Jupiter/Timer.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014-2016 Jessica James. + * Copyright (C) 2014-2017 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 @@ -16,10 +16,10 @@ * Written by Jessica James */ +#include #include "Timer.h" -#include "DLList.h" -Jupiter::DLList o_timers; +std::list o_timers; /** Deallocates timers when the library is unloaded. */ struct TimerKiller @@ -43,7 +43,7 @@ Jupiter::Timer::Timer(unsigned int in_iterations, std::chrono::milliseconds in_d if (in_immediate == false) m_next_call += m_delay; - o_timers.add(this); + o_timers.push_back(this); } Jupiter::Timer::Timer(unsigned int in_iterations, std::chrono::milliseconds in_delay, FunctionType in_function, bool in_immediate) @@ -56,7 +56,7 @@ Jupiter::Timer::Timer(unsigned int in_iterations, std::chrono::milliseconds in_d if (in_immediate == false) m_next_call += m_delay; - o_timers.add(this); + o_timers.push_back(this); } int Jupiter::Timer::think() @@ -79,11 +79,11 @@ int Jupiter::Timer::think() bool Jupiter::Timer::removeFromList() { - for (Jupiter::DLList::Node *node = o_timers.getHead(); node != nullptr; node = node->next) + for (auto node = o_timers.begin(); node != o_timers.end(); ++node) { - if (node->data == this) + if (*node == this) { - o_timers.remove(node); + o_timers.erase(node); return true; } } @@ -111,22 +111,22 @@ size_t Jupiter::Timer::total() size_t Jupiter::Timer::check() { size_t result = 0; - Jupiter::Timer *timer; - Jupiter::DLList::Node *dead_node; - Jupiter::DLList::Node *node = o_timers.getHead(); + auto node = o_timers.begin(); - while (node != nullptr) + while (node != o_timers.end()) { - timer = node->data; - if (timer->think() != 0) + if ((*node)->think() != 0) { - dead_node = node; - node = node->next; - delete o_timers.remove(dead_node); + auto dead_node = node; + ++node; + + delete *dead_node; + o_timers.erase(dead_node); + ++result; } else - node = node->next; + ++node; } return result; @@ -137,7 +137,10 @@ size_t Jupiter::Timer::killAll() size_t result = o_timers.size(); while (o_timers.size() != 0) - delete o_timers.remove(size_t{ 0 }); + { + delete o_timers.front(); + o_timers.pop_front(); + } return result; } \ No newline at end of file diff --git a/Tester/Test.cpp b/Tester/Test.cpp index 023ea9c..2bb6648 100644 --- a/Tester/Test.cpp +++ b/Tester/Test.cpp @@ -15,44 +15,45 @@ #include "Jupiter/HTTP_QueryString.h" #include "Jupiter/Hash.h" #include "Jupiter/Hash_Table.h" +#include "Jupiter/Algorithm.h" using namespace Jupiter; using namespace Jupiter::literals; -unsigned int goodTests = 0; -unsigned int totalTests = 0; +unsigned int good_tests = 0; +unsigned int total_tests = 0; void test(bool expr) { - ++totalTests; + ++total_tests; if (expr) - ++goodTests; + ++good_tests; else - printf("Test number %u failed!" ENDL, totalTests); + std::cout << "Test number " << total_tests << " failed!" << std::endl; } -Jupiter::StringS randstr(size_t length) +template void test(T result, T expected_result) { - StringS str; + ++total_tests; - while (length != 0) + if (result == expected_result) + ++good_tests; + else { - str += ' ' + rand() % ('z' - ' '); - --length; + std::cout << "Test number " << total_tests << " failed!" << std::endl; + std::cout << "\tExpected '" << expected_result << "' but got '" << result << "' instead" << std::endl; } - - return str; } int main() { - if (goodTests == totalTests) - printf("All %u tests succeeded." ENDL, totalTests); + if (good_tests == total_tests) + std::cout << "All " << total_tests << " tests succeeded." << std::endl; else - printf("ERROR: Only %u/%u tests succeeded. %u tests failed." ENDL, goodTests, totalTests, totalTests - goodTests); + std::cout << "ERROR: Only " << good_tests << "/" << total_tests << " tests succeeded. " << total_tests - good_tests << " tests failed." << std::endl; - puts("Press any key to continue..."); - fgetc(stdin); + std::cout << "Press any key to continue..." << std::endl; + std::cin.get(); return 0; }