ADMB Documentation  11.1.2503
 All Classes Files Functions Variables Typedefs Friends Defines
string4.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: string4.cpp 2292 2014-09-04 21:10:28Z 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 
00034 istream& operator>>(istream& c, line_adstring& t)
00035 {
00036   const unsigned int max_length=1025;
00037   char* tmp = new char[max_length+1];
00038   char ch;
00039   c.get(ch);
00040   // throw away the newline at the end of the last line if necessary
00041   if (ch == '\n') c.get(ch);
00042   unsigned int ii=0;
00043   while (ch != '\n' && ch != EOF)
00044   {
00045     if (ii==max_length)
00046     {
00047       cerr << "Error -- Maximum adstring length exceeded in"
00048         " istream& operator>>(istream& c, line_adstring& t)" <<endl;
00049       exit(1);
00050     }
00051     tmp[ii++]=ch;
00052     c.get(ch);
00053   }
00054   tmp[ii]='\0';
00055   t=tmp;
00056   delete [] tmp;
00057   tmp = 0;
00058 
00059   return c;
00060 }