ADMB Documentation  11.1.1542
 All Classes Files Functions Variables Typedefs Friends Defines
mycif.h
Go to the documentation of this file.
00001 /*
00002  * $Id: mycif.h 1106 2013-07-11 20:54:23Z johnoel $
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  */
00041 #ifndef CIFSTREM_H
00042   #define CIFSTREM_H
00043 
00044 #ifdef __BCPLUSPLUS__
00045   #include <fstream.h>
00046   #include <strstrea.h>
00047 #endif
00048 #ifdef __ZTC__
00049   #include <iomanip.hpp>
00050   #include <fstream.hpp>
00051   #include <strstrea.hpp>
00052 #endif
00053 #ifdef __NDPX__
00054   #include <fstream.h>
00055   #include <sstream.h>
00056   extern "C" {
00057   #include <dos.h>
00058   }
00059 #endif
00060 
00061 #if defined(__GNU__) || defined(__GNUDOS__)
00062   #include <fstream.h>
00063   #include <strstrea.h>
00064 #endif
00065 
00066 #include <ctype.h>
00067 #include <stdlib.h>
00068 #include <string.h>
00069 
00070 #ifndef FVAR_HPP
00071   class dvar_vector;
00072   class dvector;
00073   class svector;
00074   class ivector;
00075   class lvector;
00076   class dvar_matrix;
00077   class d3_array;
00078   class s3_array;
00079   class dmatrix;
00080   class smatrix;
00081   class imatrix;
00082   class lmatrix;
00083 #endif
00084 
00085 #ifndef DOUBLE
00086   class svector;
00087   class smatrix;
00088   class s3_array;
00089 #endif
00090 
00091 extern const int FILTER_BUF_SIZE;
00092 extern const int SIGNATURE_LENGTH;
00093 
00094 #define HERE cout << "reached line " << __LINE__ << " in " << __FILE__ << endl;
00095 
00096 class myifstream : public ifstream , myistream;
00097 
00098 class myistream : public istream, myios;
00099 
00100 
00101 
00102 class cifstream : public myifstream
00103 {
00104 #if defined(__ZTC__) || defined(__GNUDOS__)
00105   streambuf* bp;
00106 #endif
00107   char COMMENT_CHAR;
00108   char comment_line[SIGNATURE_LENGTH+1];
00109   char signature_line[SIGNATURE_LENGTH+1];
00110   char file_name[13];
00111   int  line;
00112   int  field;
00113   int  ignore_eof;
00114 
00115   void filter(void);
00116   void get_field(char * s);
00117   void report_error(const char* s = NULL);
00118   void set_eof_bit(void);
00119 
00120 public:
00121 
00122   cifstream(const char*, int = ios::nocreate, char cc = '#');
00123   #ifdef __BCPLUSPLUS__
00124   cifstream() : myifstream() { ; }
00125   #endif
00126   #ifdef __NDPX__
00127   cifstream() : myifstream() { ; }
00128   #endif
00129   #ifdef __ZTC__
00130   cifstream() : ios(&buffer), myifstream() { ; }
00131   #endif
00132 
00133   void open(const char*, int = ios::nocreate);
00134 
00135   char* comment() { return comment_line; }
00136   char* signature();
00137 
00138   cifstream& operator >> (long& i);
00139   cifstream& operator >> (int& i);
00140   cifstream& operator >> (double& x);
00141   cifstream& operator >> (float& x);
00142   cifstream& operator >> (char* x);
00143   cifstream& getline(char*, int, char = '\n');
00144 
00145   cifstream& operator>>(dvar_vector& z);
00146   cifstream& operator>>(dvector& z);
00147   //cifstream& operator>>(svector& z);
00148   cifstream& operator>>(lvector& z);
00149   cifstream& operator>>(ivector& z);
00150 
00151   void set_ignore_eof() {ignore_eof = 0;}
00152   void set_use_eof() {ignore_eof = 1;}
00153 };
00154 
00155 cifstream& operator>>(cifstream& istr, dvar_matrix& z);
00156 cifstream& operator>>(cifstream& istr, d3_array& z);
00157 //cifstream& operator>>(cifstream& istr, s3_array& z);
00158 cifstream& operator>>(cifstream& istr, dmatrix& z);
00159 //cifstream& operator>>(cifstream& istr, smatrix& z);
00160 cifstream& operator>>(cifstream& istr, imatrix& z);
00161 //cifstream& operator>>(cifstream& istr, lmatrix& z);
00162 
00163 #endif //#define CIFSTREM_H