2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 // ------ Constructor add delete get methods -------------------------------------
43 void List::add(void *newData)
45 Node *temp = new Node(newData, current);
50 prev->setPtr(current);
54 void *List::getCurrent(void) const
56 if (current == 0) return 0;
57 else return current->getData();
60 void *List::remove(void)
62 if (current == 0) return 0;
66 start = current->getPtr();
68 prev->setPtr(current->getPtr());
70 current = current->getPtr();
72 // saved a reference to the Node in dN and current points to where it should
73 // that's dN out of the list but it still needs to be deleted, and what it
77 returnObject = dN->getData();
83 void List::remove(void *removeThis)
86 while((!eol()) && (current->getData() != removeThis)) next();
87 // Now use method above to actually remove the node and get the object
91 unsigned long int List::getNumElements()
96 // ------ Pointer shift methods -----------------------------------------------
98 void List::reset(void)
104 void List::next(void)
106 if (current == 0) return;
108 current = current->getPtr();
111 // ------ Boolean methods -----------------------------------------------------
113 short List::isEmpty(void) const
118 short List::eol(void) const
120 return (current == 0);
123 // ------ Save / load methods method --------------------------------------------
125 void List::save(char *fileName, long int objectLength)
127 FILE *f = fopen(fileName, "w");
128 fwrite(&objectLength, sizeof(long int), 1, f);
135 fwrite(v, objectLength, 1, f);
141 int List::load(char *fileName)
146 long int objectLength = 0;
147 FILE *f = fopen(fileName, "r");
148 if (!f) return readIn;
150 if (fread(&objectLength, sizeof(long int), 1, f) != 1)
160 temp = malloc(objectLength);
161 if ((temp1=fread(temp, objectLength, 1, f)) < 1) break;
166 // We allocated temp but then fread failed