COPASI API  4.16.103
Public Member Functions | Private Attributes | List of all members
ObjectList Class Reference

#include <ObjectBrowserItem.h>

Collaboration diagram for ObjectList:
Collaboration graph
[legend]

Public Member Functions

ObjectBrowserItembucketPop (int &cursor)
 
void createBucketIndex (int max)
 
void delDuplicate ()
 
void destroyBucket ()
 
ObjectListItemgetRoot ()
 
void insert (ObjectBrowserItem *pItem)
 
void insertBucket (ObjectBrowserItem *pItem)
 
int len ()
 
 ObjectList ()
 
ObjectBrowserItempop ()
 
void sortList ()
 
bool sortListInsert (ObjectBrowserItem *pItem)
 
 ~ObjectList ()
 

Private Attributes

int index_length
 
int length
 
ObjectBrowserItem ** pointerList
 
bool * quickIndex
 
ObjectListItemroot
 

Detailed Description

Definition at line 157 of file ObjectBrowserItem.h.

Constructor & Destructor Documentation

ObjectList::ObjectList ( )

Definition at line 225 of file ObjectBrowserItem.cpp.

225  :
226  quickIndex(NULL),
227  pointerList(NULL),
228  index_length(0),
229  root(NULL),
230  length(0)
231 {}
ObjectBrowserItem ** pointerList
ObjectListItem * root
ObjectList::~ObjectList ( )
inline

Definition at line 168 of file ObjectBrowserItem.h.

References index_length, length, pointerList, pop(), and quickIndex.

169  {
170  if (index_length != 0)
171  {
172  delete[] quickIndex;
173  delete[] pointerList;
174  }
175 
176  while (length > 0)
177  pop();
178  }
ObjectBrowserItem ** pointerList
ObjectBrowserItem * pop()

Member Function Documentation

ObjectBrowserItem * ObjectList::bucketPop ( int &  cursor)

Definition at line 407 of file ObjectBrowserItem.cpp.

References index_length, pointerList, and quickIndex.

Referenced by ObjectBrowserWidget::updateUI().

408 {
409  for (; cursor < index_length; cursor++)
410  if (quickIndex[cursor])
411  {
412  cursor++;
413  return pointerList[cursor - 1];
414  }
415 
416  //nothing avaiable in list
417  return NULL;
418 }
ObjectBrowserItem ** pointerList
void ObjectList::createBucketIndex ( int  max)

Definition at line 362 of file ObjectBrowserItem.cpp.

References getRoot(), index_length, ObjectBrowserItem::key(), KEYBASE, length, max, pdelete, ObjectListItem::pItem, ObjectListItem::pLast, ObjectListItem::pNext, pointerList, quickIndex, and root.

Referenced by ObjectBrowserWidget::updateUI().

363 {
364  index_length = max;
365  quickIndex = new bool[max];
367  int i = 0;
368 
369  for (; i < max; i++)
370  quickIndex[i] = false;
371 
372  int tmpIndex;
373  ObjectListItem* pDel;
374 
375  for (ObjectListItem* pHead = getRoot(); pHead != NULL;)
376  {
377  tmpIndex = pHead->pItem->key(0, 0).toInt() - KEYBASE;
378 
379  if (quickIndex[tmpIndex]) //delete
380  {
381  pDel = pHead;
382  if (pHead->pLast) pHead->pLast->pNext = pHead->pNext; else root = pHead->pNext;
383 
384  if (pHead->pNext)
385  pHead->pNext->pLast = pHead->pLast;
386 
387  pHead = pHead->pNext;
388  pdelete(pDel);
389  length--;
390  }
391  else //
392  {
393  quickIndex[tmpIndex] = true;
394  pointerList[tmpIndex] = pHead->pItem;
395  pHead = pHead->pNext;
396  }
397  }
398 }
#define pdelete(p)
Definition: copasi.h:215
ObjectListItem * pNext
ObjectListItem * pLast
ObjectBrowserItem ** pointerList
ObjectListItem * root
ObjectBrowserItem * pItem
virtual QString key(int C_UNUSED(column), bool C_UNUSED(ascending)) const
#define KEYBASE
ObjectListItem * getRoot()
#define max(a, b)
Definition: f2c.h:176
void ObjectList::delDuplicate ( )

Definition at line 277 of file ObjectBrowserItem.cpp.

References getRoot(), ObjectBrowserItem::key(), length, pdelete, ObjectListItem::pItem, ObjectListItem::pLast, and ObjectListItem::pNext.

278 {
279  ObjectListItem* objectLast = getRoot();
280  ObjectListItem* objectNext = (objectLast != NULL) ? objectLast->pNext : NULL;
281 
282  for (; objectNext != NULL; objectNext = objectNext->pNext)
283  {
284  if (objectLast->pItem->key(0, 0) == objectNext->pItem->key(0, 0)) //delete the current item
285  {
286  objectLast->pNext = objectNext->pNext;
287 
288  if (objectNext->pNext) objectNext->pNext->pLast = objectLast;
289 
290  pdelete(objectNext);
291  length--;
292  objectNext = objectLast;
293  }
294  else // objectLast.key<objectNext.Key
295  objectLast = objectNext; //next step
296  }
297 }
#define pdelete(p)
Definition: copasi.h:215
ObjectListItem * pNext
ObjectListItem * pLast
ObjectBrowserItem * pItem
virtual QString key(int C_UNUSED(column), bool C_UNUSED(ascending)) const
ObjectListItem * getRoot()
void ObjectList::destroyBucket ( )

Definition at line 420 of file ObjectBrowserItem.cpp.

References index_length, pointerList, pop(), and quickIndex.

Referenced by ObjectBrowserWidget::updateUI().

421 {
422  delete[] quickIndex;
423  delete[] pointerList;
424 
425  for (ObjectBrowserItem* pHead = pop(); pHead != NULL; pHead = pop());
426 
427  index_length = 0;
428 }
ObjectBrowserItem ** pointerList
ObjectBrowserItem * pop()
ObjectListItem * ObjectList::getRoot ( )
void ObjectList::insert ( ObjectBrowserItem pItem)

Definition at line 233 of file ObjectBrowserItem.cpp.

References length, ObjectListItem::pLast, ObjectListItem::pNext, and root.

Referenced by ObjectBrowserWidget::clickToReverseCheck(), ObjectBrowserWidget::loadChild(), ObjectBrowserItem::ObjectBrowserItem(), ObjectBrowserWidget::removeDuplicate(), ObjectBrowserWidget::selectObjects(), ObjectBrowserWidget::setCheck(), ObjectBrowserWidget::setUncheck(), and sortListInsert().

234 {
235  int i = 0;
236  ObjectListItem* pNewItem = new ObjectListItem(pItem, NULL, NULL);
237 
238  if (length == 0)
239  {
240  root = pNewItem;
241  length++;
242  return;
243  }
244 
245  ObjectListItem* pCurrent = root;
246 
247  for (; i < length - 1; i++)
248  pCurrent = pCurrent->pNext;
249 
250  pCurrent->pNext = pNewItem;
251  pNewItem->pLast = pCurrent;
252  length++;
253 }
ObjectListItem * pNext
ObjectListItem * pLast
ObjectListItem * root
void ObjectList::insertBucket ( ObjectBrowserItem pItem)

Definition at line 400 of file ObjectBrowserItem.cpp.

References ObjectBrowserItem::key(), KEYBASE, pointerList, and quickIndex.

Referenced by ObjectBrowserWidget::updateUI().

401 {
402  int tmpIndex = pItem->key(0, 0).toInt() - KEYBASE;
403  quickIndex[tmpIndex] = true;
404  pointerList[tmpIndex] = pItem;
405 }
ObjectBrowserItem ** pointerList
virtual QString key(int C_UNUSED(column), bool C_UNUSED(ascending)) const
#define KEYBASE
int ObjectList::len ( )
inline

Definition at line 183 of file ObjectBrowserItem.h.

References length.

Referenced by ObjectBrowserWidget::loadChild(), ObjectBrowserWidget::removeDuplicate(), and sortList().

183 {return length;};
ObjectBrowserItem * ObjectList::pop ( )

Definition at line 260 of file ObjectBrowserItem.cpp.

References length, pdelete, ObjectListItem::pItem, ObjectListItem::pLast, ObjectListItem::pNext, and root.

Referenced by destroyBucket(), ObjectBrowserWidget::loadChild(), ObjectBrowserWidget::removeDuplicate(), and ~ObjectList().

261 {
262  if (length == 0) return NULL;
263 
264  ObjectBrowserItem* returnValue = root->pItem;
265  ObjectListItem* delNode = root;
266  root = root->pNext;
267 
268  if (root)
269  root->pLast = NULL;
270 
271  length--;
272  pdelete(delNode);
273  return returnValue;
274 }
#define pdelete(p)
Definition: copasi.h:215
ObjectListItem * pNext
ObjectListItem * pLast
ObjectListItem * root
ObjectBrowserItem * pItem
void ObjectList::sortList ( )

Definition at line 299 of file ObjectBrowserItem.cpp.

References getRoot(), ObjectBrowserItem::key(), len(), ObjectListItem::pItem, and ObjectListItem::pNext.

300 {
301  if (len() <= 1) //sorted
302  return;
303 
304  ObjectListItem* pHead = getRoot();
305  ObjectListItem* pTail = pHead->pNext;
306 
307  for (; pHead->pNext != NULL; pHead = pHead->pNext)
308  {
309  for (pTail = pHead->pNext; pTail != NULL; pTail = pTail->pNext)
310  if (pHead->pItem->key(0, 0) > pTail->pItem->key(0, 0))
311  {
312  ObjectBrowserItem * pTmp = pHead->pItem;
313  pHead->pItem = pTail->pItem;
314  pTail->pItem = pTmp;
315  }
316  }
317 }
ObjectListItem * pNext
ObjectBrowserItem * pItem
virtual QString key(int C_UNUSED(column), bool C_UNUSED(ascending)) const
ObjectListItem * getRoot()
bool ObjectList::sortListInsert ( ObjectBrowserItem pItem)

Definition at line 320 of file ObjectBrowserItem.cpp.

References getRoot(), insert(), ObjectBrowserItem::key(), length, ObjectListItem::pItem, ObjectListItem::pLast, ObjectListItem::pNext, and root.

321 {
322  if (getRoot() == NULL) //list is empty
323  {
324  ObjectListItem* pNewItem = new ObjectListItem(pItem, NULL, NULL);
325  root = pNewItem;
326  length++;
327  return true;
328  }
329 
330  if (pItem->key(0, 0) < getRoot()->pItem->key(0, 0)) //insert at the front
331  {
332  ObjectListItem* pNewItem = new ObjectListItem(pItem, root, NULL);
333  root->pLast = pNewItem;
334  root = pNewItem;
335  length++;
336  return true;
337  }
338 
339  ObjectListItem* pHead = getRoot();
340 
341  for (; (pHead != NULL) && (pItem->key(0, 0) > pHead->pItem->key(0, 0)); pHead = pHead->pNext)
342  ;
343 
344  if (pHead && (pHead->pItem->key(0, 0) == pItem->key(0, 0))) //duplicate key
345  return false;
346 
347  //else insert
348 
349  if (pHead == NULL) //insert at the end of the list
350  {
351  insert(pItem);
352  return true;
353  }
354 
355  length++;
356  ObjectListItem* pNewItem = new ObjectListItem(pItem, pHead, pHead->pLast);
357  pHead->pLast = pNewItem;
358  pNewItem->pLast->pNext = pNewItem;
359  return true;
360 }
void insert(ObjectBrowserItem *pItem)
ObjectListItem * pNext
ObjectListItem * pLast
ObjectListItem * root
ObjectBrowserItem * pItem
virtual QString key(int C_UNUSED(column), bool C_UNUSED(ascending)) const
ObjectListItem * getRoot()

Member Data Documentation

int ObjectList::index_length
private

Definition at line 162 of file ObjectBrowserItem.h.

Referenced by bucketPop(), createBucketIndex(), destroyBucket(), and ~ObjectList().

int ObjectList::length
private
ObjectBrowserItem** ObjectList::pointerList
private
bool* ObjectList::quickIndex
private
ObjectListItem* ObjectList::root
private

Definition at line 163 of file ObjectBrowserItem.h.

Referenced by createBucketIndex(), getRoot(), insert(), pop(), and sortListInsert().


The documentation for this class was generated from the following files: