ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
cifstrem.h
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  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "BSD" license.
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00046 #ifndef CIFSTREM_H
00047 #define CIFSTREM_H
00048 
00049 #include <fvar.hpp>
00050 
00051 #if defined(__GNUC__) && (__GNUC__ < 3)
00052   #pragma interface
00053 #endif
00054 
00055 #include <stdio.h>
00056 
00057 #ifdef __WAT32__
00058   #include <iostream.h>
00059   #include <strstrea.h>
00060 #endif
00061 #ifdef __BCPLUSPLUS__
00062   #include <strstrea.h>
00063 #endif
00064 #ifdef __ZTC__
00065   #include <iomanip.hpp>
00066   #include <strstrea.hpp>
00067 #endif
00068 #ifdef __NDPX__
00069   #include <sstream.h>
00070   extern "C" {
00071   #include <dos.h>
00072   }
00073 #endif
00074 #if defined(__GNUC__)
00075   #if (__GNUC__  < 3)
00076     #include <strstream.h>
00077   #else
00078     #include <sstream>
00079   #endif
00080 #endif
00081 
00082 #include <ctype.h>
00083 #include <stdlib.h>
00084 #include <string.h>
00085 #include <adstring.hpp>
00086 
00087 #ifndef FVAR_HPP
00088   class dvar_vector;
00089   class dvector;
00090   class svector;
00091   class ivector;
00092   class lvector;
00093   class dvar_matrix;
00094   class d3_array;
00095   class d4_array;
00096   class dvar3_array;
00097   class dvar4_array;
00098   class s3_array;
00099   class dmatrix;
00100   class smatrix;
00101   class imatrix;
00102   class lmatrix;
00103   class prevariable;
00104   class dvariable;
00105 #endif
00106 
00107 #ifndef DOUBLE
00108   class svector;
00109   class smatrix;
00110   class s3_array;
00111 #endif
00112 
00113 
00114 #define FILTER_BUF_SIZE 8000
00115 #define SIGNATURE_LENGTH  80
00116 
00117 class cifstream : public ifstream
00118 {
00119   streambuf* bp;
00120   char COMMENT_CHAR;
00121   char comment_line[SIGNATURE_LENGTH+1];
00122   char signature_line[SIGNATURE_LENGTH+1];
00123   adstring file_name;
00124   int  line;
00125   int  field;
00126   int  ignore_eof;
00127 
00128   void filter(void);
00129   void get_field(char * s,int space_flag=0);
00130   void report_error(const char* s = NULL);
00131   void set_eof_bit(void);
00132 
00133 public:
00134 #ifdef __BCPLUSPLUS__
00135   cifstream() : ifstream() { ; }
00136 #endif
00137 #ifdef __NDPX__
00138   cifstream() : ifstream() { ; }
00139 #endif
00140 #ifdef __ZTC__
00141   cifstream() : ios(&buffer), ifstream() { ; }
00142 #endif
00143 
00144 #if defined(__BORLANDC__)
00145   #if (__BORLANDC__  > 0x0520)
00146   cifstream(const char*, int=0 , char cc = '#');
00147   #else
00148   cifstream(const char*, int = ios::nocreate, char cc = '#');
00149   #endif
00150 #else
00151   #if defined(__GNUC__)
00152     #if (__GNUC__  >= 3)
00153   cifstream(const char*, int = std::ios_base::in , char cc = '#');
00154     #else
00155   cifstream(const char*, int = ios::nocreate, char cc = '#');
00156     #endif
00157   #elif defined(_MSC_VER)
00158   cifstream(const char*, int = std::ios_base::in , char cc = '#');
00159   #else
00160   cifstream(const char*, int = ios::nocreate, char cc = '#');
00161   #endif
00162 #endif
00163 
00164   ~cifstream(){}
00165 
00166 #if defined(__BORLANDC__)
00167 #  if (__BORLANDC__  > 0x0520)
00168   void open(const char*, int );
00169 #  else
00170   void open(const char*, int = ios::nocreate);
00171 #  endif
00172 #else // not BORLAND
00173 #  if defined(__GNUC__)
00174 #    if (__GNUC__  >= 3)
00175        void open(const char*, int);
00176 #    else
00177        void open(const char*, int = ios::nocreate);
00178 #    endif
00179 #  elif defined(_MSC_VER)
00180        void open(const char*, int);
00181 #  else
00182      void open(const char*, int = ios::nocreate);
00183 #  endif
00184 #endif
00185 
00186   adstring get_file_name(void);
00187   char* comment() { return comment_line; }
00188   char* signature();
00189 
00190   cifstream& operator>>(const dvariable& z);
00191  //  cifstream& operator>>(const prevariable& z);
00192   cifstream& operator >> (long long& i);
00193   cifstream& operator>>(const long& i);
00194   cifstream& operator>>(const int& i);
00195   cifstream& operator>>(const double& x);
00196   cifstream& operator>>(const float& x);
00197   cifstream& operator >> (char* x);
00198   cifstream& operator >> (const char* x);
00199   cifstream& operator >> (const adstring& x);
00200   cifstream& operator >> (adstring& x);
00201   cifstream& operator >> (const line_adstring& x);
00202   cifstream& getline(char*, int, char = '\n');
00203 
00204   cifstream& operator>>(const dvar_vector& z);
00205   cifstream& operator>>(const dvector& z);
00206   //cifstream& operator>>(svector& z);
00207   cifstream& operator>>(const lvector& z);
00208   cifstream& operator>>(const ivector& z);
00209 
00210   void set_ignore_eof() {ignore_eof = 0;}
00211   void set_use_eof() {ignore_eof = 1;}
00212 };
00213 
00214 cifstream& operator>>(cifstream& istr, const prevariable& z);
00215 cifstream& operator>>(cifstream& istr, const dvar_matrix& z);
00216 cifstream& operator>>(cifstream& istr, const d3_array& z);
00217 cifstream& operator>>(cifstream& istr, const d4_array& z);
00218 cifstream& operator>>(cifstream& istr, const d5_array& z);
00219 cifstream& operator>>(cifstream& istr, const dvar3_array& z);
00220 cifstream& operator>>(cifstream& istr, const dvar4_array& z);
00221 cifstream& operator>>(cifstream& istr, const dvar5_array& z);
00222 //cifstream& operator>>(cifstream& istr, s3_array& z);
00223 cifstream& operator>>(cifstream& istr, const dmatrix& z);
00224 //cifstream& operator>>(cifstream& istr,smatrix& z);
00225 cifstream& operator>>(cifstream& istr, const imatrix& z);
00226 cifstream& operator>>(cifstream& istr, const i3_array& z);
00227 cifstream& operator>>(cifstream& istr, const i4_array& z);
00228 //cifstream& operator>>(cifstream& istr, lmatrix& z);
00229 
00230 #endif //#define CIFSTREM_H