ADMB Documentation  11.1.1660
 All Classes Files Functions Variables Typedefs Friends Defines
tescl.h
Go to the documentation of this file.
00001 /*
00002  * $Id: tescl.h 1106 2013-07-11 20:54:23Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "BSD" license.
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00041 #ifndef CLIST_H
00042 #define CLIST_H
00043 class clist
00044 {
00045 public :
00046   int length(const int & max = 1000);
00047 protected :
00048   clist * next;
00049   virtual here()=0;
00050   clist() { next = here(); }
00051   clist(const clist & pt);
00052   clist * prev(void);
00053 public:
00054   ~clist();
00055 };
00056 
00057 
00058 clist * clist::prev(void)
00059 {
00060   clist * tmp = this->next;
00061   while (tmp->next != this) tmp = tmp->next;
00062   return (tmp);
00063 }
00064 
00065 int  clist::length(const int & max)
00066 {
00067   int num = 1;
00068   clist * tmp = this;
00069   while (tmp->next != this)
00070   {
00071     tmp = tmp->next;
00072     if (++num > max)
00073     {
00074       return (-1);
00075     }
00076   }
00077   return (num);
00078 }
00079 
00080 clist::clist(const clist & t)
00081 {
00082   clist& tmp=t.here();
00083   next = t.next;
00084   tmp.next = this;
00085 }
00086 
00087 clist::~clist()
00088 {
00089   if (next == here())
00090   {
00091     next = 0;
00092   }
00093   else
00094   {
00095     prev()->next = next;
00096   }
00097 }
00098 
00099 class mmm : public clist
00100 {
00101   virtual mmm * here(){return this;}
00102 }
00103 
00104 
00105 #include <adstring.hpp>
00106 #include <string.h>
00107 #include <stdlib.h>
00108 #include <safe_mem.h>
00109 
00110 adstring::adstring(int lb, int ub) : clist()
00111 {
00112   if (lb != 1)
00113   {
00114     cerr << " Error in adstring::adstring(int lb,int ub) : clist()\n"
00115     " At present minimum index for adstring must equal 1\n";
00116     exit(1);
00117   }
00118   unsigned int sz = ub;
00119 //  shape = new adstring_shape(sz);
00120 //  s = new char[size_t(sz + 1)];
00121   allocate(sz);
00122   s--;
00123   for (int i = 1; i <= sz; i++)
00124   {
00125     s[i] = '\0'; //' ';
00126   }
00127   s[sz + 1] = '\0';
00128 }
00129 
00130 /*
00131 adstring::adstring(const unsigned char ub) : clist()
00132 {
00133   unsigned int sz = 1;
00134 //  shape = new adstring_shape(sz);
00135 //  s = new char[size_t(sz + 1)];
00136   allocate(sz);
00137   s--;
00138   s[1] = ub;
00139   s[2] = '\0';
00140 }
00141 */
00142 
00143 adstring::adstring(const char ub) : clist()
00144 {
00145   unsigned int sz = 1;
00146 //  shape = new adstring_shape(sz);
00147 //  s = new char[size_t(sz + 1)];
00148   allocate(sz);
00149   s--;
00150   s[1] = ub;
00151   s[2] = '\0';
00152 }
00153 
00154 adstring::adstring(const adstring & v) : clist(v)
00155 {
00156   shape = v.shape;
00157   s = v.s;
00158 }
00159 
00160 adstring operator+(const adstring & u, const adstring & v)
00161 {
00162   int us = u.size ();
00163   int vs = v.size ();
00164   adstring tmp(1, us + vs);
00165   for (int i = 1; i <= us; i++)
00166   {
00167     tmp(i) = u(i);
00168   }
00169   for (i = 1; i <= vs; i++)
00170   {
00171     tmp(i + us) = v(i);
00172   }
00173   return (tmp);
00174 }
00175 
00176 #endif