![]() |
#2
rjsp2017-03-30 21:51
|
ListArray_id<Coord> gridlist;
这句声明是什么意思呢?其中ListArray_id是个类吗?

template<class tdata> class ListArray_id {
class Item {
public:
Item* pnext;
Item* pprev;
tdata object;
};
private:
Item** array;
Item* pfirstitem;
Item* plastitem;
Item* pthisitem;
unsigned int nseg;
unsigned int id;
unsigned int thisobj;
public:
bool isobj;
unsigned int nobj;
public:
ListArray_id() {
pfirstitem=NULL;
plastitem=NULL;
pthisitem=NULL;
isobj=false;
nobj=0;
nseg=0;
id=0;
}
void killall() {
Item* pitem=pfirstitem;
Item* pnext;
while (pitem) {
pnext=pitem->pnext;
delete pitem;
pitem=pnext;
}
if (nseg) delete[] array;
pfirstitem=NULL;
plastitem=NULL;
pthisitem=NULL;
isobj=false;
nobj=0;
nseg=0;
id=0;
}
~ListArray_id() {
killall();
}
void initarray(unsigned int nitem) {
unsigned int i;
killall();
if (nitem<=0) return;
nseg=nitem%SEGSIZE;
if (nseg*SEGSIZE<nitem) nseg++;
array=new Item*[nseg*SEGSIZE];
if (!array) fail();
for (i=0;i<nitem;i++) createobj();
pthisitem=0;
thisobj=0;
}
tdata& createobj() {
Item* pitem=new Item;
if (!pitem) fail();
pitem->object.id=id++;
pitem->pprev=plastitem;
pitem->pnext=NULL;
if (plastitem) plastitem->pnext=pitem;
else pfirstitem=pitem;
plastitem=pitem;
pthisitem=pitem;
isobj=true;
thisobj=nobj++;
if (nobj>nseg*SEGSIZE) {
Item** newarray=new Item*[(nseg+1)*SEGSIZE];
if (!newarray) fail();
if (nseg++) {
unsigned int i;
for (i=0;i<nobj-1;i++)
newarray[i]=array[i];
delete[] array;
}
array=newarray;
}
array[nobj-1]=pitem;
return pitem->object;
}
bool firstobj() {
if (pfirstitem) {
pthisitem=pfirstitem;
isobj=true;
thisobj=0;
return true;
}
return false;
}
bool nextobj() {
if (pthisitem) {
pthisitem=pthisitem->pnext;
thisobj++;
}
if (pthisitem) return true;
isobj=false;
return false;
}
tdata& getobj() {
return pthisitem->object;
}
tdata& operator[](unsigned int i) {
return array[i]->object;
}
void killobj() {
unsigned int i;
if (!pthisitem) return;
if (pthisitem==pfirstitem) pfirstitem=pthisitem->pnext;
if (pthisitem==plastitem) plastitem=pthisitem->pprev;
Item* pnextitem=pthisitem->pnext;
if (pthisitem->pprev) pthisitem->pprev->pnext=pthisitem->pnext;
if (pthisitem->pnext) pthisitem->pnext->pprev=pthisitem->pprev;
delete pthisitem;
pthisitem=pnextitem;
if (!pthisitem) isobj=false;
for (i=thisobj+1;i<nobj;i++)
array[i-1]=array[i];
nobj--;
}
};
coord应该是个结构体这个没错吧?class Item {
public:
Item* pnext;
Item* pprev;
tdata object;
};
private:
Item** array;
Item* pfirstitem;
Item* plastitem;
Item* pthisitem;
unsigned int nseg;
unsigned int id;
unsigned int thisobj;
public:
bool isobj;
unsigned int nobj;
public:
ListArray_id() {
pfirstitem=NULL;
plastitem=NULL;
pthisitem=NULL;
isobj=false;
nobj=0;
nseg=0;
id=0;
}
void killall() {
Item* pitem=pfirstitem;
Item* pnext;
while (pitem) {
pnext=pitem->pnext;
delete pitem;
pitem=pnext;
}
if (nseg) delete[] array;
pfirstitem=NULL;
plastitem=NULL;
pthisitem=NULL;
isobj=false;
nobj=0;
nseg=0;
id=0;
}
~ListArray_id() {
killall();
}
void initarray(unsigned int nitem) {
unsigned int i;
killall();
if (nitem<=0) return;
nseg=nitem%SEGSIZE;
if (nseg*SEGSIZE<nitem) nseg++;
array=new Item*[nseg*SEGSIZE];
if (!array) fail();
for (i=0;i<nitem;i++) createobj();
pthisitem=0;
thisobj=0;
}
tdata& createobj() {
Item* pitem=new Item;
if (!pitem) fail();
pitem->object.id=id++;
pitem->pprev=plastitem;
pitem->pnext=NULL;
if (plastitem) plastitem->pnext=pitem;
else pfirstitem=pitem;
plastitem=pitem;
pthisitem=pitem;
isobj=true;
thisobj=nobj++;
if (nobj>nseg*SEGSIZE) {
Item** newarray=new Item*[(nseg+1)*SEGSIZE];
if (!newarray) fail();
if (nseg++) {
unsigned int i;
for (i=0;i<nobj-1;i++)
newarray[i]=array[i];
delete[] array;
}
array=newarray;
}
array[nobj-1]=pitem;
return pitem->object;
}
bool firstobj() {
if (pfirstitem) {
pthisitem=pfirstitem;
isobj=true;
thisobj=0;
return true;
}
return false;
}
bool nextobj() {
if (pthisitem) {
pthisitem=pthisitem->pnext;
thisobj++;
}
if (pthisitem) return true;
isobj=false;
return false;
}
tdata& getobj() {
return pthisitem->object;
}
tdata& operator[](unsigned int i) {
return array[i]->object;
}
void killobj() {
unsigned int i;
if (!pthisitem) return;
if (pthisitem==pfirstitem) pfirstitem=pthisitem->pnext;
if (pthisitem==plastitem) plastitem=pthisitem->pprev;
Item* pnextitem=pthisitem->pnext;
if (pthisitem->pprev) pthisitem->pprev->pnext=pthisitem->pnext;
if (pthisitem->pnext) pthisitem->pnext->pprev=pthisitem->pprev;
delete pthisitem;
pthisitem=pnextitem;
if (!pthisitem) isobj=false;
for (i=thisobj+1;i<nobj;i++)
array[i-1]=array[i];
nobj--;
}
};

struct Coord {
// Type for storing grid cell longitude, latitude and description text
int id;
double lon;
double lat;
xtring descrip;
};
// Type for storing grid cell longitude, latitude and description text
int id;
double lon;
double lat;
xtring descrip;
};