ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
string4.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 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 = (char)c.get();
00039   // throw away the newline at the end of the last line if necessary
00040   if (ch == '\n') ch = (char)c.get();
00041   unsigned int ii=0;
00042   while (ch != '\n' && ch != EOF)
00043   {
00044     if (ii==max_length)
00045     {
00046       cerr << "Error -- Maximum adstring length exceeded in"
00047         " istream& operator>>(istream& c, line_adstring& t)" <<endl;
00048       exit(1);
00049     }
00050     tmp[ii++] = ch;
00051     ch = (char)c.get();
00052   }
00053   tmp[ii]='\0';
00054   t=tmp;
00055   delete [] tmp;
00056   tmp = 0;
00057 
00058   return c;
00059 }