ADMB Documentation  11.2.2828
 All Classes Files Functions Variables Typedefs Friends Defines
ufstream.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: ufstream.cpp 2497 2014-10-24 00:24:18Z johnoel $
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 #ifdef __ZTC__
00060 uostream::uostream(const char* name, int  m, int prot)
00061 :ios(&buffer), ofstream(name, m, prot) { }
00062 
00063 uistream::uistream(const char* name, int m, int prot)
00064 :ios(&buffer), ifstream(name, m| ios::nocreate , prot) { }
00065 #endif
00066 
00067 // implement insertion operators for various types in class uostream
00068 #ifndef __SUN__
00069 INSERT_IMPLEMENT(signed char)
00070 #endif
00071 INSERT_IMPLEMENT(unsigned char)
00072 INSERT_IMPLEMENT(short)
00073 INSERT_IMPLEMENT(int)
00074 INSERT_IMPLEMENT(long)
00075 INSERT_IMPLEMENT(unsigned short)
00076 INSERT_IMPLEMENT(unsigned long)
00077 INSERT_IMPLEMENT(float)
00078 INSERT_IMPLEMENT(double)
00079 
00080 #ifdef __TURBOC__
00081 INSERT_IMPLEMENT(long double)
00082 #endif
00083 
00084 // implement extraction operators for various types in class uistream
00085 #ifndef __SUN__
00086 //#  if (__BORLANDC__  > 0x0520 || defined(__linux__))
00087 EXTRACT_IMPLEMENT(signed char)
00088 EXTRACT_IMPLEMENT(unsigned char)
00089 EXTRACT_IMPLEMENT(char)
00090 EXTRACT_IMPLEMENT(short)
00091 EXTRACT_IMPLEMENT(int)
00092 EXTRACT_IMPLEMENT(long)
00093 EXTRACT_IMPLEMENT(unsigned short)
00094 EXTRACT_IMPLEMENT(unsigned long)
00095 EXTRACT_IMPLEMENT(float)
00096 EXTRACT_IMPLEMENT(double)
00097  // #  else
00098  // EXTRACT_IMPLEMENT(const signed char)
00099  // EXTRACT_IMPLEMENT(const unsigned char)
00100  // EXTRACT_IMPLEMENT(const char)
00101  // EXTRACT_IMPLEMENT(const short)
00102  // EXTRACT_IMPLEMENT(const int)
00103  // EXTRACT_IMPLEMENT(const long)
00104  // EXTRACT_IMPLEMENT(const unsigned short)
00105  // EXTRACT_IMPLEMENT(const unsigned long)
00106  // EXTRACT_IMPLEMENT(const float)
00107  // EXTRACT_IMPLEMENT(const double)
00108  // #  endif
00109 #endif
00110 
00111 #ifdef __TURBOC__
00112 #  if (__BORLANDC__  > 0x0520)
00113 EXTRACT_IMPLEMENT(long double)
00114 #  else
00115 EXTRACT_IMPLEMENT(const long double)
00116 #endif
00117 #endif
00118