git-svn-id: svn://db.shs.com.ru/pip@400 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
45
src_main/containers/pilist.h
Normal file
45
src_main/containers/pilist.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user