ADMB Documentation  11.1.1903
 All Classes Files Functions Variables Typedefs Friends Defines
string4.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: string4.cpp 1546 2014-01-22 18:41:06Z 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 istream & operator >> (istream & c, adstring & t)
00011 {
00012   const unsigned int max_length=1025;
00013   char * tmp= new char[max_length+1];
00014   c >> tmp;
00015   if (strlen(tmp)>max_length)
00016   {
00017     cerr << "Error -- Maximum adstring length exceeded in"
00018       " istream & operator >> (istream & c, adstring & t)"<<endl;
00019     exit(1);
00020   }
00021   t=tmp;
00022   delete [] tmp;
00023   tmp = 0;
00024 
00025   return (c);
00026 }
00027 
00028 istream & operator >> (istream & c, line_adstring & t)
00029 {
00030   const unsigned int max_length=1025;
00031   char* tmp = new char[max_length+1];
00032   int ch = c.get();
00033   // throw away the newline at the end of the last line if necessary
00034   if (ch == '\n') ch=c.get();
00035   unsigned int ii=0;
00036   while (ch != '\n' && ch != EOF)
00037   {
00038     if (ii==max_length)
00039     {
00040       cerr << "Error -- Maximum adstring length exceeded in"
00041         " istream & operator >> (istream & c, adstring & t)"<<endl;
00042       exit(1);
00043     }
00044     tmp[ii++]=ch;
00045     ch=c.get();
00046   }
00047   tmp[ii]='\0';
00048   t=tmp;
00049   delete tmp;
00050   tmp = 0;
00051 
00052   return (c);
00053 }