1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
//===============================================================
// vSList Class for working with C_List char string lists
//
// Copyright (C) 1995,1996, 1997, 1998 Bruce E. Wampler
//
// This file is part of the V C++ GUI Framework, and is covered
// under the terms of the GNU Library General Public License,
// Version 2. This library has NO WARRANTY. See the source file
// vapp.cxx for more complete information about license terms.
//===============================================================
#include <v/v_defs.h>
#include <v/vslist.h>
#include <v/vutil.h>
//===========================>>> vSList::vSList <<<=======================
vSList::vSList(int maxsize)
{
list = new char*[maxsize];
max = maxsize;
init();
}
//===========================>>> vSList::~vSList <<<=======================
vSList::~vSList()
{
erase(); // delete contents
delete [] list; // delete the array itself
}
//=============================>>> vSList::= <<<==========================
// vSList& vSList::operator =(const vSList& slist)
// {
// if (this == &slist)
// return *this;
//
// }
//=============================>>> vSList::init <<<==========================
void vSList::init()
{
for (int ix = 0 ; ix < max ; ++ix)
list[ix] = 0;
}
//=============================>>> vsList::erase <<<==========================
void vSList::erase()
{
for (int ix = 0 ; ix < max ; ++ix)
{
if (list[ix] != 0)
delete [] list[ix];
list[ix] = 0;
}
}
//========================>>> vSList::size <<<==========================
int vSList::size() const
{
int ix;
for (ix = 0 ; ix < max && list[ix] != 0 ; ++ix)
;
return ix;
}
//========================>>> vSList::insert <<<==========================
int vSList::insert(int insAt, const char* strn) const
{
int items = size();
int iWhere = insAt;
if (items >= max)
return -1;
if (iWhere < 0 || iWhere > max) // append to end
iWhere = items;
// First, shift the list down by one
for (int ix = items + 1 ; ix > iWhere ; --ix)
list[ix] = list[ix-1];
list[iWhere] = new char[strlen(strn)+1];
strcpy(list[iWhere],strn);
return items + 1;
}
//========================>>> vSList::replace <<<==========================
int vSList::replace(int repAt, const char* strn) const
{
int items = size();
int iWhere = repAt;
if (items >= max || iWhere < 0 || iWhere >= items)
return -1;
if (list[iWhere] == 0)
return -1;
delete [] list[iWhere];
list[iWhere] = new char[strlen(strn)+1];
strcpy(list[iWhere],strn);
return items;
}
//========================>>> vSList::deleteItem <<<==========================
int vSList::deleteItem(int delAt) const
{
int items = size();
int iWhere = delAt;
if (iWhere < 0 || iWhere > max) // delete last item
iWhere = items - 1;
if (iWhere >= items)
return -1;
// First, delete the given item
if (list[iWhere] == 0) // oops!
return -1;
delete [] list[iWhere]; // free the space!
// Now, shift the list up by one
for (int ix = iWhere ; ix < items ; ++ix)
list[ix] = list[ix+1];
--items;
list[items] = 0;
return items;
}
|