#pragma once #include <stdexcept> #include "iterator/VectorIterator.hpp" #include "array/Helpers.hpp" #include "../common/compat.hpp" #include "../common/errors.hpp" #include "string.h" namespace sprawl { namespace collections { template<typename T, ssize_t size> class Array; } } template<typename T, ssize_t size> class sprawl::collections::Array { public: typedef VectorIterator<T, Array<T, size>> iterator; typedef VectorIterator<T, Array<T, size>> const const_iterator; T& operator[](ssize_t index) { if (index < 0) { index += size; } return m_array[index]; } sprawl::ErrorState<T&> At(ssize_t index) { if (index < 0) { index += size; } if(index > size) { SPRAWL_THROW_EXCEPTION(sprawl::OutOfRangeError()); } return m_array[index]; } T const& operator[](ssize_t index) const { if (index < 0) { index += size; } return m_array[index]; } sprawl::ErrorState<T const&> At(ssize_t index) const { if (index < 0) { index += size; } if(index > size) { SPRAWL_THROW_EXCEPTION(sprawl::OutOfRangeError()); } return m_array[index]; } T& Front() { return m_array[0]; } T& Back() { return m_array[size -1]; } T const& Front() const { return m_array[0]; } T const& Back() const { return m_array[size -1]; } T* Data() { return m_array; } ssize_t Size() { return size; } bool Empty() { return size == 0; } iterator begin() { return iterator(m_array, this); } iterator end() { return iterator(m_array + size, this); } const_iterator cbegin() const { return const_iterator(m_array, this); } const_iterator cend() const { return const_iterator(m_array + size, this); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } void Fill(T const& value) { for(ssize_t i = 0; i < size; ++i) { m_array[i] = value; } } private: T m_array[size]; };
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 16768 | ShadauxCat |
Improvements to error handling in builds with exceptions disabled: - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if Get() is called when an error flag is set. (In release buils or with SPRAWL_ERRORSTATE_PERMISSIVE defined, Get() will return junk memory in this case.) - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if its destructor is called without checking the errorstate if an error is present (equivalent to an exception terminating the application if no catch() block is present for it). - On linux builds and when running "Analyze" through visual studio, a warning will be issued if any function returning ErrorState has its return value ignored. (This only applies to builds with exceptions not enabled; when exceptions are enabled no warning is issued) - Many functions that could return ErrorState were having their return values silently ignored in internal sprawl code so the user would not find out about errors if exceptions are disabled; now anything in sprawl code that calls a function returning ErrorState will either handle the error, or (in most cases) surface it back up to the user. - As a positive side-effect of the warnings for ignoring ErrorState, several constructors that were capable of throwing exceptions are no longer capable of doing so. #review-16769 |
||
#3 | 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 |
||
#2 | 14168 | ShadauxCat |
-Implemented Array -Fixed compile error when calling Vector::Swap() -Fixed missing constness on functions called from const functions in Deque -Added fill, copy, and move constructor unit tests for Vector and Deque, and Swap() unit test for Vector #review-14169 |
||
#1 | 11496 | ShadauxCat | Initial checkin: Current states for csbuild and libSprawl |