69 lines
3.8 KiB
C++
69 lines
3.8 KiB
C++
/*! \file pilist.h
|
|
* \brief Linked list container, wrapper for std::list
|
|
*
|
|
* This file declares PIList
|
|
*/
|
|
/*
|
|
PIP - Platform Independent Primitives
|
|
Linked list container, wrapper for std::list
|
|
Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru
|
|
|
|
This program 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.
|
|
|
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef PILIST_H
|
|
#define PILIST_H
|
|
#include "pibase.h"
|
|
#include <list>
|
|
|
|
template<typename Type, typename Allocator = std::allocator<Type> >
|
|
class PIP_EXPORT PIList: public std::list<Type, Allocator> {
|
|
typedef PIList<Type, Allocator> _CList;
|
|
typedef std::list<Type, Allocator> _stlc;
|
|
public:
|
|
PIList() {piMonitor.containers++;}
|
|
PIList(const Type & value) {piMonitor.containers++; _stlc::resize(1, value);}
|
|
PIList(const Type & v0, const Type & v1) {piMonitor.containers++; _stlc::push_back(v0); _stlc::push_back(v1);}
|
|
PIList(const Type & v0, const Type & v1, const Type & v2) {piMonitor.containers++; _stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2);}
|
|
PIList(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {piMonitor.containers++; _stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);}
|
|
PIList(uint size, const Type & value = Type()) {piMonitor.containers++; _stlc::resize(size, value);}
|
|
~PIList() {piMonitor.containers--;}
|
|
Type & operator [](uint index) {return (*this)[index];}
|
|
Type & operator [](uint index) const {return (*this)[index];}
|
|
const Type * data(uint index = 0) const {return &(*this)[index];}
|
|
Type * data(uint index = 0) {return &(*this)[index];}
|
|
int size_s() const {return static_cast<int>(_stlc::size());}
|
|
bool isEmpty() const {return _stlc::empty();}
|
|
bool has(const Type & t) const {for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) if (t == *i) return true; return false;}
|
|
int etries(const Type & t) const {int ec = 0; for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) if (t == *i) ++ec; return ec;}
|
|
_CList & fill(const Type & t) {_stlc::assign(_stlc::size(), t); return *this;}
|
|
_CList & remove(uint index) {_stlc::erase(_stlc::begin() + index); return *this;}
|
|
_CList & remove(uint index, uint count) {_stlc::erase(_stlc::begin() + index, _stlc::begin() + index + count); return *this;}
|
|
_CList & insert(uint pos, const Type & t) {_stlc::insert(_stlc::begin() + pos, t); return *this;}
|
|
_CList & operator <<(const Type & t) {_stlc::push_back(t); return *this;}
|
|
PIVector<Type> toVector() const {PIVector<Type> v; for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) v << *i; return v;}
|
|
};
|
|
|
|
//! \relatesalso PIByteArray \brief Store operator
|
|
template<typename T> inline PIByteArray & operator <<(PIByteArray & s, const PIList<T> & v);
|
|
//! \relatesalso PIByteArray \brief Restore operator
|
|
template<typename T> inline PIByteArray & operator >>(PIByteArray & s, PIList<T> & v);
|
|
|
|
template<typename T>
|
|
inline PIByteArray & operator <<(PIByteArray & s, const PIList<T> & v) {s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s;}
|
|
template<typename T>
|
|
inline PIByteArray & operator >>(PIByteArray & s, PIList<T> & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;}
|
|
|
|
|
|
#endif // PILIST_H
|