ADMB Documentation  11.1.2277
 All Classes Files Functions Variables Typedefs Friends Defines
string5a.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: string5a.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include <fvar.hpp>
00008 #include <stdlib.h>
00009 
00010   adstring_array& adstring_array::operator += (const adstring& s)
00011   {
00012     int tmp_min;
00013     int tmp_max;
00014     vector_shape * tmp_shape;
00015     if (!shape)
00016     {
00017       tmp_min=1;
00018       tmp_max=1;
00019     }
00020     else
00021     {
00022       tmp_min=shape->indexmin();
00023       tmp_max=shape->indexmax()+1;
00024       delete shape;
00025     }
00026     if (!(tmp_shape=new vector_shape(tmp_min,tmp_max)))
00027     {
00028       cerr << "Error allocating memory in adstring_array" << endl;
00029     }
00030     adstring ** tmp_ptr;
00031     if (!(tmp_ptr=new adstring* [tmp_max-tmp_min+1]))
00032     {
00033       cerr << "Error allocating memory in adstring_array +=" << endl;
00034     }
00035     tmp_ptr-=tmp_min;
00036     for (int i=tmp_min;i<=tmp_max-1;i++)
00037     {
00038       tmp_ptr[i]=new adstring(*(ptr[i]));
00039     }
00040     tmp_ptr[tmp_max]=new adstring();
00041     *tmp_ptr[tmp_max]=s;
00042     if (ptr)
00043     {
00044       for (int i=tmp_min;i<=tmp_max-1;i++)
00045       {
00046         delete ptr[i];
00047       }
00048       ptr+=tmp_min;
00049       delete [] ptr;
00050     }
00051     ptr=tmp_ptr;
00052     shape=tmp_shape;
00053     adstring_array * tmp = (adstring_array *) this->next;
00054     while (tmp != this)
00055     {
00056       tmp->shape = shape;
00057       tmp->ptr = ptr;
00058       tmp = (adstring_array *) tmp->next;
00059     }
00060     return *this;
00061   }
00062 
00063   adstring_array& adstring_array::append_distinct(const adstring& s)
00064   {
00065     int tmp_min;
00066     int tmp_max;
00067     vector_shape * tmp_shape;
00068     if (!shape)
00069     {
00070       tmp_min=1;
00071       tmp_max=1;
00072     }
00073     else
00074     {
00075       tmp_min=shape->indexmin();
00076       tmp_max=shape->indexmax()+1;
00077       delete shape;
00078     }
00079     if (!(tmp_shape=new vector_shape(tmp_min,tmp_max)))
00080     {
00081       cerr << "Error allocating memory in adstring_array" << endl;
00082     }
00083     adstring ** tmp_ptr;
00084     if (!(tmp_ptr=new adstring* [tmp_max-tmp_min+1]))
00085     {
00086       cerr << "Error allocating memory in adstring_array +=" << endl;
00087     }
00088     tmp_ptr-=tmp_min;
00089     for (int i=tmp_min;i<=tmp_max-1;i++)
00090     {
00091       tmp_ptr[i]=new adstring(*(ptr[i]));
00092     }
00093     tmp_ptr[tmp_max]=new adstring();
00094     *tmp_ptr[tmp_max]=s;
00095     if (ptr)
00096     {
00097       for (int i=tmp_min;i<=tmp_max-1;i++)
00098       {
00099         delete ptr[i];
00100       }
00101       ptr+=tmp_min;
00102       delete [] ptr;
00103     }
00104     ptr=tmp_ptr;
00105     shape=tmp_shape;
00106     adstring_array * tmp = (adstring_array *) this->next;
00107     while (tmp != this)
00108     {
00109       tmp->shape = shape;
00110       tmp->ptr = ptr;
00111       tmp = (adstring_array *) tmp->next;
00112     }
00113     return *this;
00114   }