ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
clist.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include "clist.h"
00008 #include <new>
00009 
00010 clist* clist::prev() const
00011 {
00012   clist* t = this->next;
00013   while (t != this)
00014   {
00015     if (!t)
00016     {
00017       //unexpected
00018       throw std::bad_alloc();
00019     }
00020     else if (t->next == this)
00021     {
00022       return t;
00023     }
00024     else
00025     {
00026       t = t->next;
00027     }
00028   }
00029   return 0;
00030 }
00031 
00032 int clist::length(const int& max) const
00033 {
00034   int num = 1;
00035   clist* t = this->next;
00036   while (num <= max)
00037   {
00038     if (!t)
00039     {
00040       //unexpected
00041       throw std::bad_alloc();
00042     }
00043     else if (t == this)
00044     {
00045       return num;
00046     }
00047     else
00048     {
00049       t = t->next;
00050     }
00051     ++num;
00052   }
00053   return -1;
00054 }
00055 
00059 clist::clist(const clist& t)
00060 {
00061   clist& tmp=*(clist *)(&t);
00062   next = t.next;
00063   tmp.next = this;
00064 }
00065 
00069 clist::~clist()
00070 {
00071   if (next == this)
00072   {
00073     next = 0;
00074   }
00075   else
00076   {
00077     prev()->next = next;
00078   }
00079 }