/*! \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) 2020 Ivan Pelipenko peri4ko@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #ifndef PILIST_H #define PILIST_H #include "pibase.h" #include template > class PIP_EXPORT PIList: public std::list { typedef PIList _CList; typedef std::list _stlc; public: PIList() {} PIList(const Type & value) {_stlc::resize(1, value);} PIList(const Type & v0, const Type & v1) {_stlc::push_back(v0); _stlc::push_back(v1);} PIList(const Type & v0, const Type & v1, const Type & v2) {_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) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);} PIList(uint size, const Type & value = Type()) {_stlc::resize(size, value);} virtual ~PIList() {} 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(_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 toVector() const {PIVector v; for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) v << *i; return v;} }; //! \relatesalso PIByteArray \brief Store operator template inline PIByteArray & operator <<(PIByteArray & s, const PIList & v); //! \relatesalso PIByteArray \brief Restore operator template inline PIByteArray & operator >>(PIByteArray & s, PIList & v); template inline PIByteArray & operator <<(PIByteArray & s, const PIList & v) {s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s;} template inline PIByteArray & operator >>(PIByteArray & s, PIList & 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