ADMB Documentation  11.5.3285
 All Classes Files Functions Variables Typedefs Friends Defines
ufstream.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  */
00011 #include "fvar.hpp"
00012 
00013 #define INSERT_IMPLEMENT(TYPE) \
00014 uostream& uostream::operator<< (TYPE x) \
00015 { \
00016   write((char*)&x, sizeof(TYPE)); \
00017   return *this; \
00018 }
00019 
00020 #define EXTRACT_IMPLEMENT(TYPE) \
00021 uistream& uistream::operator>> (const TYPE& x) \
00022 { \
00023   read((char*)&x, sizeof(TYPE)); \
00024   return *this; \
00025 }
00026 
00027 uostream::uostream(const char* name, int  m, int prot)
00028   :ofstream(name, std::ios::binary | std::ios::openmode(m))
00029 {
00030 }
00031 
00036 void uistream::open(const char* name, int m, int prot)
00037 {
00038   ifstream::open(name, std::ios::binary | std::ios::openmode(m));
00039 }
00040 
00045 void uostream::open(const char* name, int m, int prot)
00046 {
00047   ofstream::open(name, std::ios::binary | std::ios::openmode(m));
00048 }
00049 
00054 uistream::uistream(const char* name, int m, int prot)
00055   :ifstream(name, std::ios::binary | std::ios::openmode(m))
00056 {
00057 }
00058 
00059 uistream& uistream::operator>>(int& x)
00060 {
00061   read((char*)&x, sizeof(int));
00062   return *this;
00063 }
00064 
00065 #ifdef __ZTC__
00066 uostream::uostream(const char* name, int  m, int prot)
00067 :ios(&buffer), ofstream(name, m, prot) { }
00068 
00069 uistream::uistream(const char* name, int m, int prot)
00070 :ios(&buffer), ifstream(name, m| ios::nocreate , prot) { }
00071 #endif
00072 
00073 // implement insertion operators for various types in class uostream
00074 #ifndef __SUN__
00075 INSERT_IMPLEMENT(signed char)
00076 #endif
00077 INSERT_IMPLEMENT(unsigned char)
00078 INSERT_IMPLEMENT(short)
00079 INSERT_IMPLEMENT(int)
00080 INSERT_IMPLEMENT(long)
00081 INSERT_IMPLEMENT(unsigned short)
00082 INSERT_IMPLEMENT(unsigned long)
00083 INSERT_IMPLEMENT(float)
00084 INSERT_IMPLEMENT(double)
00085 
00086 #ifdef __TURBOC__
00087 INSERT_IMPLEMENT(long double)
00088 #endif
00089 
00090 // implement extraction operators for various types in class uistream
00091 #ifndef __SUN__
00092 //#  if (__BORLANDC__  > 0x0520 || defined(__linux__))
00093 EXTRACT_IMPLEMENT(signed char)
00094 EXTRACT_IMPLEMENT(unsigned char)
00095 EXTRACT_IMPLEMENT(char)
00096 EXTRACT_IMPLEMENT(short)
00097 EXTRACT_IMPLEMENT(int)
00098 EXTRACT_IMPLEMENT(long)
00099 EXTRACT_IMPLEMENT(unsigned short)
00100 EXTRACT_IMPLEMENT(unsigned long)
00101 EXTRACT_IMPLEMENT(float)
00102 EXTRACT_IMPLEMENT(double)
00103  // #  else
00104  // EXTRACT_IMPLEMENT(const signed char)
00105  // EXTRACT_IMPLEMENT(const unsigned char)
00106  // EXTRACT_IMPLEMENT(const char)
00107  // EXTRACT_IMPLEMENT(const short)
00108  // EXTRACT_IMPLEMENT(const int)
00109  // EXTRACT_IMPLEMENT(const long)
00110  // EXTRACT_IMPLEMENT(const unsigned short)
00111  // EXTRACT_IMPLEMENT(const unsigned long)
00112  // EXTRACT_IMPLEMENT(const float)
00113  // EXTRACT_IMPLEMENT(const double)
00114  // #  endif
00115 #endif
00116 
00117 #ifdef __TURBOC__
00118 #  if (__BORLANDC__  > 0x0520)
00119 EXTRACT_IMPLEMENT(long double)
00120 #  else
00121 EXTRACT_IMPLEMENT(const long double)
00122 #endif
00123 #endif
00124