#pragma once #include <iterator> #include "../../common/specialized.hpp" #include "../../common/compat.hpp" namespace sprawl { template<typename ValueType, typename ParentType> class VectorIterator; } template<typename ValueType, typename ParentType> class sprawl::VectorIterator : public std::iterator<std::random_access_iterator_tag, ValueType, std::ptrdiff_t, ValueType*, ValueType&> { public: VectorIterator(ValueType* item, ParentType const* parent) : m_currentItem(item) , m_parent(parent) { // } ValueType& operator*() { return *m_currentItem; } ValueType* operator->() { return m_currentItem; } ValueType const& operator*() const { return *m_currentItem; } ValueType const* operator->() const { return m_currentItem; } ValueType& Value() { return *m_currentItem; } ValueType const& Value() const { return *m_currentItem; } ssize_t Index() const { return m_currentItem - m_parent->begin().m_currentItem; } VectorIterator<ValueType, ParentType>& operator++() { ++m_currentItem; return *this; } VectorIterator<ValueType, ParentType> operator++(int) { return VectorIterator<ValueType, ParentType>(m_currentItem++, m_parent); } VectorIterator<ValueType, ParentType> const& operator++() const { ++m_currentItem; return *this; } VectorIterator<ValueType, ParentType> const operator++(int) const { return VectorIterator<ValueType, ParentType>(m_currentItem++, m_parent); } VectorIterator<ValueType, ParentType> operator+(int steps) { return VectorIterator<ValueType, ParentType>(m_currentItem+steps, m_parent); } VectorIterator<ValueType, ParentType> const operator+(int steps) const { return VectorIterator<ValueType, ParentType>(m_currentItem+steps, m_parent); } VectorIterator<ValueType, ParentType>& operator--() { --m_currentItem; return *this; } VectorIterator<ValueType, ParentType> operator--(int) { return VectorIterator<ValueType, ParentType>(m_currentItem--, m_parent); } VectorIterator<ValueType, ParentType> const& operator--() const { --m_currentItem; return *this; } VectorIterator<ValueType, ParentType> const operator--(int) const { return VectorIterator<ValueType, ParentType>(m_currentItem--, m_parent); } VectorIterator<ValueType, ParentType> operator-(int steps) { return VectorIterator<ValueType, ParentType>(m_currentItem - steps, m_parent); } VectorIterator<ValueType, ParentType> const operator-(int steps) const { return VectorIterator<ValueType, ParentType>(m_currentItem - steps, m_parent); } bool operator==(VectorIterator<ValueType, ParentType> const& rhs) const { return m_currentItem == rhs.m_currentItem; } bool operator!=(VectorIterator<ValueType, ParentType> const& rhs) const { return !this->operator==(rhs); } operator bool() const { return Valid(); } bool operator!() const { return !Valid(); } bool Valid() const { return operator>=(m_parent->begin()) && operator<(m_parent->end()); } bool More() const { return Valid() && Next().Valid(); } VectorIterator<ValueType, ParentType> Next() { return VectorIterator<ValueType, ParentType>(m_currentItem + 1, m_parent); } VectorIterator<ValueType, ParentType> const Next() const { return VectorIterator<ValueType, ParentType>(m_currentItem + 1, m_parent); } size_t operator-(VectorIterator<ValueType, ParentType> const& other) { return m_currentItem - other.m_currentItem; } ValueType& operator[](size_t index) { return m_currentItem[index]; } ValueType const& operator[](size_t index) const { return m_currentItem[index]; } bool operator<(VectorIterator<ValueType, ParentType> const& rhs) const { return m_currentItem < rhs.m_currentItem; } bool operator>(VectorIterator<ValueType, ParentType> const& rhs) const { return m_currentItem > rhs.m_currentItem; } bool operator<=(VectorIterator<ValueType, ParentType> const& rhs) const { return m_currentItem <= rhs.m_currentItem; } bool operator>=(VectorIterator<ValueType, ParentType> const& rhs) const { return m_currentItem >= rhs.m_currentItem; } protected: mutable ValueType* m_currentItem; ParentType const* m_parent; };
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 16052 | ShadauxCat |
- Changed default block size for concurrent queue to a more reasonable value - Changed some memory orders to memory_order_seq_cst when they don't actually need to be that to get around a bug in visual studio 2013 - debug builds assert when memory_order_acq_rel is used for a compare_exchange_strong (this is a standard library bug and is fixed in VS2015) - Added Event API - events are an alternative to condition variables that do not require a mutex and are guaranteed not to miss any signals, even if the signal comes while the thread is not listening for it. Unlike condition variables, however, they do not support broadcasting (and in fact, in general, are not safe to use with multiple threads listening for the same event simultaneously - though notifying on the same event is fine) - Rewrote ThreadManager around ConcurrentQueue and Event API so it is now lock-free. Also improved some behaviors of the staged thread manager operation so it now supports tasks that can be run on multiple stages via a bitmask. - Fixed an issue where the Coroutine copy constructor was calling the std::function constructor instead and another where initializing with a stack might try to call the wrong constructor and vice-versa - Fixed Coroutine never calling munmap() on its stack in linux and causing a memory leak - Added default arguments to time functions - Attempted to fix some issues with BinaryTree. Fixed some but not all. It's currently not suitable for use, sadly. - Logging Improvements: - - Added thread ID to logging - - Fixed some issues with category handlers - - Added backtraces - - Added the following additional log macros: - - - LOG_IF - - - LOG_EVERY_N - - - LOG_FIRST_N - - - LOG_IF_EVERY_N - - - LOG_IF_FIRST_N - - - LOG_ASSERT - - Added the ability to set extra info callbacks to get data such as script backtraces - - Removed the thread-related handlers and replaced them with RunHandler_Threaded and RunHandler_ThreadManager, which will enable any passed-in handler to be run in a threaded fashion - Removed StaticPoolAllocator and renamed DynamicPoolAllocator to PoolAllocator; adjusted unit tests accordingly - PoolAllocator now allocates its pool with mmap and VirtualAlloc, rather than with malloc - Fixed a bug with Vector copy assignment operator - Improved performance of StringBuilder considerably for cases where there are no modifier strings - Removed Copy-On-Write behavior of JSONToken as it was broken; copies are now performed with explicit DeepCopy() and ShallowCopy() functions - Fixed some parser bugs with JSONToken - Added iteration to JSONToken to iterate its children - Fixed crash when reading a negative number of bytes from a file - Changed StringBuilder to favor speed instead of memory by default - Added some performance unit tests for JSON token #review-16053 |
||
#1 | 14091 | ShadauxCat |
-Created Vector class, iterator, and unit test -Made list iterator a bidirectional iterator when created from a doubly-linked list. (It still has operator-- when created from singly-linked list, but it won't compile if it's used.) -Changed front() and back() in list classes to Front() and Back() #review-14083 |