gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit 79505b1f5d3afc118e9c59d8d25e4ebc8d6ce20e
parent 1f7af0f018b5619a904f0846109f5d85ac7623b0
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Wed,  6 Nov 2024 07:48:09 +0100

hybrid container improvements

Diffstat:
Msource/baseLib/hybridcontainer.h | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+), 0 deletions(-)

diff --git a/source/baseLib/hybridcontainer.h b/source/baseLib/hybridcontainer.h @@ -53,6 +53,44 @@ namespace baseLib push_back<U>(std::forward<U>(_value)); } + void pop_back() + { + if (m_useArray) + { + if (m_size == 0) + throw std::out_of_range("Container is empty"); + --m_size; + return; + } + + m_vector.pop_back(); + --m_size; + } + + const T& front() const + { + if (m_useArray) + { + if (m_size == 0) + throw std::out_of_range("Container is empty"); + return m_array.front(); + } + + return m_vector.front(); + } + + const T& back() const + { + if (m_useArray) + { + if (m_size == 0) + throw std::out_of_range("Container is empty"); + return m_array[m_size - 1]; + } + + return m_vector.back(); + } + T& operator[](const size_t _index) { if (m_useArray) @@ -72,6 +110,11 @@ namespace baseLib return const_cast<HybridContainer*>(this)->operator[](_index); } + bool empty() const + { + return m_size == 0; + } + size_t size() const { return m_size; @@ -130,6 +173,62 @@ namespace baseLib return *this; } + template<size_t OtherFixedSize> HybridContainer& operator=(const HybridContainer<T, OtherFixedSize>& _source) + { + m_size = _source.size(); + + if(_source.empty()) + { + m_useArray = true; + return *this; + } + + if(m_size <= MaxFixedSize) + { + std::copy(_source.begin(), _source.end(), m_array.begin()); + m_useArray = true; + } + else + { + m_vector.assign(_source.begin(), _source.end()); + m_useArray = false; + } + + return *this; + } + + template<size_t OtherFixedSize> HybridContainer& operator=(HybridContainer<T, OtherFixedSize>&& _source) + { + m_size = _source.size(); + + if(!m_size) + { + m_useArray = true; + _source.clear(); + return *this; + } + + if(m_size <= MaxFixedSize) + { + std::move(_source.begin(), _source.end(), m_array.begin()); + m_useArray = true; + } + else if(!_source.m_useArray) + { + m_vector = std::move(_source.m_vector); + m_useArray = false; + } + else + { + m_vector.assign(_source.begin(), _source.end()); + m_useArray = false; + } + + _source.clear(); + + return *this; + } + HybridContainer& operator=(std::vector<T>&& _source) { m_vector = std::move(_source);