ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
string5a.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 <fvar.hpp>
00008 #include <stdlib.h>
00009 
00010 adstring_array& adstring_array::operator+=(const adstring& s)
00011 {
00012   return append_distinct(s);
00013 }
00014 
00015 adstring_array& adstring_array::append_distinct(const adstring& s)
00016 {
00017   int tmp_min = 1;
00018   int tmp_max = 1;
00019   if (shape)
00020   {
00021     tmp_min=shape->indexmin();
00022     tmp_max=shape->indexmax()+1;
00023     delete shape;
00024     shape = 0;
00025   }
00026   vector_shape* tmp_shape = new vector_shape(tmp_min,tmp_max);
00027   if (!tmp_shape)
00028   {
00029     cerr << "Error allocating memory in adstring_array" << endl;
00030   }
00031   adstring** tmp_ptr=new adstring*[tmp_max-tmp_min+1];
00032   if (!tmp_ptr)
00033   {
00034     cerr << "Error allocating memory in adstring_array +=" << endl;
00035   }
00036   tmp_ptr-=tmp_min;
00037   for (int i=tmp_min;i<=tmp_max-1;i++)
00038   {
00039     tmp_ptr[i]=new adstring(*(ptr[i]));
00040   }
00041   tmp_ptr[tmp_max]=new adstring();
00042   *tmp_ptr[tmp_max]=s;
00043   if (ptr)
00044   {
00045     for (int i=tmp_min;i<=tmp_max-1;i++)
00046     {
00047       delete ptr[i];
00048       ptr[i] = 0;
00049     }
00050     ptr+=tmp_min;
00051     delete [] ptr;
00052     ptr = 0;
00053   }
00054   ptr=tmp_ptr;
00055   shape=tmp_shape;
00056   adstring_array* tmp = (adstring_array*)this->next;
00057   while (tmp != this)
00058   {
00059     if (tmp)
00060     {
00061       tmp->shape = shape;
00062       tmp->ptr = ptr;
00063       tmp = (adstring_array*)tmp->next;
00064     }
00065   }
00066   return *this;
00067 }