00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 2009, Andrew W. Steiner 00005 00006 This file is part of O2scl. 00007 00008 O2scl is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 O2scl is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with O2scl. If not, see <http://www.gnu.org/licenses/>. 00020 00021 ------------------------------------------------------------------- 00022 */ 00023 #ifndef O2SCL_BINARY_FILE_H 00024 #define O2SCL_BINARY_FILE_H 00025 00026 #include <iostream> 00027 #include <o2scl/misc.h> 00028 #include <o2scl/err_hnd.h> 00029 #include <o2scl/file_format.h> 00030 #include <o2scl/lib_settings.h> 00031 00032 #ifndef DOXYGENP 00033 namespace o2scl { 00034 #endif 00035 00036 /** 00037 \brief Binary output file 00038 00039 This class is experimental. 00040 00041 */ 00042 class binary_out_file : public out_file_format { 00043 public: 00044 00045 /** \brief Create a binary output file with name \c file_name 00046 */ 00047 binary_out_file(std::string file_name); 00048 00049 virtual ~binary_out_file(); 00050 00051 /** \brief Output a bool variable 00052 */ 00053 virtual int bool_out(bool dat, std::string name=""); 00054 00055 /** \brief Output a char variable 00056 */ 00057 virtual int char_out(char dat, std::string name=""); 00058 00059 /** \brief Output a double variable 00060 */ 00061 virtual int double_out(double dat, std::string name=""); 00062 00063 /** \brief Output a float variable 00064 */ 00065 virtual int float_out(float dat, std::string name=""); 00066 00067 /** \brief Output an int variable 00068 */ 00069 virtual int int_out(int dat, std::string name=""); 00070 00071 /** \brief Output an long variable 00072 */ 00073 virtual int long_out(unsigned long int dat, std::string name=""); 00074 00075 /** \brief Output a string 00076 */ 00077 virtual int string_out(std::string dat, std::string name=""); 00078 00079 /** \brief Output a word 00080 */ 00081 virtual int word_out(std::string dat, std::string name=""); 00082 00083 /// Start an object 00084 virtual int start_object(std::string type, std::string name=""); 00085 00086 /** \brief End object output (does nothing for a binary file) 00087 */ 00088 virtual int end_object(); 00089 00090 /** \brief End a line of output (does nothing for a binary file) 00091 */ 00092 virtual int end_line(); 00093 00094 /** \brief Output initialization */ 00095 virtual int init_file(); 00096 00097 /// Finish the file 00098 virtual int clean_up() { 00099 return 0; 00100 } 00101 00102 #ifndef DOXYGEN_INTERNAL 00103 00104 protected: 00105 00106 friend class collection; 00107 00108 /// True if the file is to be compressed 00109 bool compressed; 00110 00111 /// True if the compression is to be performed by gzip 00112 bool gzip; 00113 00114 /// The output stream 00115 std::ofstream outs; 00116 00117 /// The filename specified by the user 00118 std::string user_filename; 00119 00120 /// The temporary filename 00121 std::string temp_filename; 00122 00123 /// \name The output format 00124 //@{ 00125 int fill, precision; 00126 //std::_Ios_Fmtflags flags; 00127 //@} 00128 00129 #endif 00130 00131 }; 00132 00133 /** 00134 \brief Binary input file 00135 00136 This class is experimental. 00137 00138 */ 00139 class binary_in_file : public in_file_format { 00140 public: 00141 00142 /** \brief Read an input file with name \c file_name */ 00143 binary_in_file(std::string file_name); 00144 00145 virtual ~binary_in_file(); 00146 00147 virtual int bool_in(bool &dat, std::string name=""); 00148 virtual int char_in(char &dat, std::string name=""); 00149 virtual int double_in(double &dat, std::string name=""); 00150 virtual int float_in(float &dat, std::string name=""); 00151 virtual int int_in(int &dat, std::string name=""); 00152 virtual int long_in(unsigned long int &dat, std::string name=""); 00153 virtual int string_in(std::string &dat, std::string name=""); 00154 virtual int word_in(std::string &dat, std::string name=""); 00155 00156 /// Read the initialization 00157 virtual int init_file(); 00158 00159 /// Clean up the file 00160 virtual int clean_up() { 00161 return 0; 00162 } 00163 00164 /// Begin reading an object 00165 virtual int start_object(std::string &type, std::string &name); 00166 00167 virtual int skip_object(); 00168 00169 /// Finish reading an object 00170 virtual int end_object() { 00171 return 0; 00172 } 00173 00174 #ifndef DOXYGEN_INTERNAL 00175 00176 protected: 00177 00178 /// The input stream 00179 std::ifstream ins; 00180 00181 #endif 00182 }; 00183 00184 } 00185 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page