/************************************************************************ Copy Handler 1.x - program for copying data in Microsoft Windows systems. Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.pl) 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 2 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, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *************************************************************************/ #ifndef __CHARVECT_H__ #define __CHARVECT_H__ #include using namespace std; class char_vector : public vector { public: char_vector() : vector() { }; char_vector(const char_vector& cv, bool bCopy) { insert(begin(), cv.begin(), cv.end(), bCopy); }; ~char_vector() { erase(begin(), end(), true); }; void assign(size_type _Count, const PTSTR& _Type, bool bDelete, bool bCopy) { erase(begin(), end(), bDelete); insert(begin(), _Count, _Type, bCopy); }; template void assign(_It _First, _It _Last, bool bDelete, bool bCopy) { erase(begin(), end(), bDelete); insert(begin(), _First, _Last, bCopy); }; void clear(bool bDelete) { erase(begin(), end(), bDelete); }; iterator erase(iterator _Where, bool bDelete) { if (bDelete) delete [] (*_Where); return ((vector*)this)->erase(_Where); }; iterator erase(iterator _First, iterator _Last, bool bDelete) { if (bDelete) for (iterator _Run=_First;_Run != _Last;_Run++) delete [] (*_Run); return ((vector*)this)->erase(_First, _Last); }; void replace(iterator _Where, const PTSTR& _Val, bool bDelete, bool bCopy) { if (bDelete) delete [] (*_Where); if (bCopy) { (*_Where)=new TCHAR[_tcslen(_Val)+1]; _tcscpy(*_Where, _Val); } else (*_Where)=_Val; }; iterator insert(iterator _Where, const PTSTR& _Val, bool bCopy) { size_type _O = _Where - begin(); insert(_Where, 1, _Val, bCopy); return (begin() + _O); }; void insert(iterator _Where, size_type _Count, const PTSTR& _Val, bool bCopy) { if (bCopy) { size_type _Size=_tcslen(_Val)+1; PTSTR *ppsz=new PTSTR[_Count]; for (size_type i=0;i<_Count;i++) { ppsz[i]=new TCHAR[_Size]; _tcscpy(ppsz[i], _Val); } ((vector*)this)->insert(_Where, ppsz, ppsz+_Count); delete [] ppsz; } else ((vector*)this)->insert(_Where, _Count, _Val); }; void insert(iterator _Where, size_type _Count, const PCTSTR& _Val) { size_type _Size=_tcslen(_Val)+1; PTSTR *ppsz=new PTSTR[_Count]; for(size_type i=0;i<_Count;i++) { ppsz[i]=new TCHAR[_Size]; _tcscpy(ppsz[i], _Val); } ((vector*)this)->insert(_Where, ppsz, ppsz+_Count); delete [] ppsz; }; template void insert(iterator _Where, _It _First, _It _Last, bool bCopy) { if (bCopy) { size_type _Cnt=_Last-_First; PTSTR *ppsz=new PTSTR[_Cnt]; for (size_type i=0;i<_Cnt;i++) { ppsz[i]=new TCHAR[_tcslen(*_First)+1]; _tcscpy(ppsz[i], *_First); _First++; } ((vector*)this)->insert(_Where, ppsz, ppsz+_Cnt); delete [] ppsz; } else ((vector*)this)->insert(_Where, _First, _Last); }; void swap_items(iterator _Item1, iterator _Item2) { PTSTR psz=(*_Item1); (*_Item1)=(*_Item2); (*_Item2)=psz; }; void pop_back(bool bDelete) { if (bDelete) delete [] (*(end()-1)); ((vector*)this)->pop_back(); }; void push_back(const PTSTR& _Val, bool bCopy) { insert(end(), 1, _Val, bCopy); }; void push_back(const PCTSTR& _Val) { insert(end(), 1, _Val); }; }; #endif