Revert "Refactoring in ObserversManager."
This reverts commit 9c2f61991869b7eacbb2bf3bfc257480aa1b24ba. Conflicts: src/observersmanager.hpp
This commit is contained in:
parent
1682b1ade7
commit
61f0c28983
1 changed files with 0 additions and 195 deletions
|
@ -1,195 +0,0 @@
|
|||
/*
|
||||
Copyright 2014 Michele "King_DuckZ" Santullo
|
||||
|
||||
This file is part of CloonelJump.
|
||||
|
||||
CloonelJump is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
CloonelJump is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with CloonelJump. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef idEA67296D7EC847B58BB3D52DBC9E51BA
|
||||
#define idEA67296D7EC847B58BB3D52DBC9E51BA
|
||||
|
||||
#include <vector>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <iterator>
|
||||
#include <ciso646>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
namespace cloonel {
|
||||
namespace implem {
|
||||
template <typename I, typename S>
|
||||
class LinearMapIterator : public boost::iterator_facade<LinearMapIterator<I, S>, typename std::iterator_traits<I>::value_type, typename std::iterator_traits<I>::iterator_category, typename std::iterator_traits<I>::reference, typename std::iterator_traits<I>::difference_type> {
|
||||
|
||||
typedef boost::iterator_facade<LinearMapIterator<I, S>, typename std::iterator_traits<I>::value_type, typename std::iterator_traits<I>::iterator_category, typename std::iterator_traits<I>::reference, typename std::iterator_traits<I>::difference_type> parent_type;
|
||||
|
||||
typedef typename parent_type::reference reference;
|
||||
typedef typename parent_type::value_type value_type;
|
||||
typedef S size_type;
|
||||
public:
|
||||
LinearMapIterator ( I parItemsStart, I parItemsEnd, std::vector<bool>::const_iterator parOccupiedStart ) :
|
||||
m_itStart(parItemsStart),
|
||||
m_itEnd(parItemsEnd),
|
||||
m_itOccupied(parOccupiedStart)
|
||||
{
|
||||
}
|
||||
~LinearMapIterator ( void ) noexcept = default;
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
|
||||
void increment ( void ) {
|
||||
do {
|
||||
++m_itStart;
|
||||
++m_itOccupied;
|
||||
} while (m_itEnd != m_itStart and not *m_itOccupied);
|
||||
}
|
||||
bool equal ( const LinearMapIterator& parOther ) const {
|
||||
return m_itStart == parOther.m_itStart;
|
||||
}
|
||||
reference dereference ( void ) const {
|
||||
return *m_itStart;
|
||||
}
|
||||
void advance ( size_type parAdv ) {
|
||||
while (parAdv and m_itEnd != m_itStart) {
|
||||
increment();
|
||||
--parAdv;
|
||||
}
|
||||
}
|
||||
|
||||
I m_itStart;
|
||||
const I m_itEnd;
|
||||
std::vector<bool>::const_iterator m_itOccupied;
|
||||
};
|
||||
} //namespace implem
|
||||
|
||||
template <typename T, typename Container=std::vector<T> >
|
||||
class LinearMap {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef T value_type;
|
||||
typedef typename implem::LinearMapIterator<typename Container::iterator, size_type> iterator;
|
||||
typedef typename implem::LinearMapIterator<typename Container::const_iterator, size_type> const_iterator;
|
||||
|
||||
LinearMap ( void ) = default;
|
||||
LinearMap ( LinearMap&& parOther );
|
||||
~LinearMap ( void ) noexcept = default;
|
||||
|
||||
size_type size ( void ) const { return m_usedCount; }
|
||||
size_type max_size ( void ) const noexcept { return m_list.max_size(); }
|
||||
size_type capacity ( void ) const noexcept { return m_list.capacity(); }
|
||||
void shrink_to_fit ( void );
|
||||
bool empty ( void ) const noexcept { return m_list.empty(); }
|
||||
void push_back ( const value_type& parNew );
|
||||
void push_back ( value_type&& parNew );
|
||||
void swap ( LinearMap& parOther );
|
||||
void clear ( void );
|
||||
iterator erase_absolute ( size_type parIndex );
|
||||
iterator at_absolute ( size_type parIndex );
|
||||
|
||||
iterator begin ( void ) { return iterator(m_list.begin(), m_list.end(), m_occupied.cbegin()); }
|
||||
iterator end ( void ) { return iterator(m_list.end(), m_list.end(), m_occupied.cend()); }
|
||||
const_iterator begin ( void ) const { return const_iterator(m_list.begin(), m_list.end(), m_occupied.cbegin()); }
|
||||
const_iterator end ( void ) const { return const_iterator(m_list.end(), m_list.end(), m_occupied.cend()); }
|
||||
const_iterator cbegin ( void ) const { return const_iterator(m_list.begin(), m_list.end(), m_occupied.cbegin()); }
|
||||
const_iterator cend ( void ) const { return const_iterator(m_list.end(), m_list.end(), m_occupied.cend()); }
|
||||
|
||||
private:
|
||||
Container m_list;
|
||||
std::vector<bool> m_occupied;
|
||||
size_type m_usedCount;
|
||||
};
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, typename Container>
|
||||
void LinearMap<T, Container>::shrink_to_fit() {
|
||||
m_list.shrink_to_fit();
|
||||
m_occupied.shrink_to_fit();
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, typename Container>
|
||||
void LinearMap<T, Container>::push_back (const value_type& parNew) {
|
||||
m_list.push_back(parNew);
|
||||
m_occupied.push_back(true);
|
||||
++m_usedCount;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, typename Container>
|
||||
void LinearMap<T, Container>::push_back (value_type&& parNew) {
|
||||
m_list.push_back(std::move(parNew));
|
||||
m_occupied.push_back(true);
|
||||
++m_usedCount;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, typename Container>
|
||||
void LinearMap<T, Container>::swap (LinearMap& parOther) {
|
||||
m_list.swap(parOther.m_list);
|
||||
m_occupied.swap(parOther.m_occupied);
|
||||
std::swap(m_usedCount, parOther.m_usedCount);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, typename Container>
|
||||
void LinearMap<T, Container>::clear() {
|
||||
m_list.clear();
|
||||
m_occupied.clear();
|
||||
m_usedCount = 0;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, typename Container>
|
||||
typename LinearMap<T, Container>::iterator LinearMap<T, Container>::erase_absolute (size_type parIndex) {
|
||||
auto ret = at_absolute(parIndex);
|
||||
++ret;
|
||||
|
||||
m_occupied[parIndex] = false;
|
||||
--m_usedCount;
|
||||
|
||||
size_type deleCount = 0;
|
||||
for (auto itOcc = m_occupied.rbegin(), itOccEND = m_occupied.rend(); itOcc != itOccEND and not *itOcc; ++itOcc) {
|
||||
++deleCount;
|
||||
}
|
||||
|
||||
if (deleCount) {
|
||||
assert(deleCount <= m_occupied.size());
|
||||
const auto newSize = m_occupied.size() - deleCount;
|
||||
m_occupied.resize(newSize);
|
||||
m_list.resize(newSize);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, typename Container>
|
||||
typename LinearMap<T, Container>::iterator LinearMap<T, Container>::at_absolute (size_type parIndex) {
|
||||
assert(m_usedCount > 0);
|
||||
assert(m_list.size() == m_occupied.size());
|
||||
assert(parIndex < m_list.size());
|
||||
assert(m_occupied[parIndex]);
|
||||
|
||||
return begin() + std::count_if(m_occupied.begin(), m_occupied.begin() + parIndex, [] (bool a) { return a; });
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue