file_format.h

00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006, 2007, 2008, 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_FILE_FORMAT_H
00024 #define O2SCL_FILE_FORMAT_H
00025 
00026 #include <iostream>
00027 #include <fstream>
00028 #include <sstream>
00029 
00030 #include <o2scl/lib_settings.h>
00031 
00032 #ifndef DOXYGENP
00033 namespace o2scl {
00034 #endif
00035   
00036   /** 
00037       \brief Make a temporary file
00038   */
00039   int o2scl_make_tfile(std::string &fname, int st=0);
00040 
00041   /** 
00042       \brief Abstract base class for output file formats
00043 
00044 
00045   */
00046   class out_file_format {
00047   public:
00048 
00049     virtual ~out_file_format() {}
00050 
00051     /** \brief Output a bool variable
00052      */
00053     virtual int bool_out(bool dat, std::string name="")=0;
00054 
00055     /** \brief Output a char variable
00056      */
00057     virtual int char_out(char dat, std::string name="")=0;
00058 
00059     /** \brief Output a float variable
00060      */
00061     virtual int float_out(float dat, std::string name="")=0;
00062 
00063     /** \brief Output a double variable
00064      */
00065     virtual int double_out(double dat, std::string name="")=0;
00066 
00067     /** \brief Output an int variable
00068      */
00069     virtual int int_out(int dat, std::string name="")=0;
00070 
00071     /** \brief Output an long variable
00072      */
00073     virtual int long_out(unsigned long int dat, std::string name="")=0;
00074 
00075     /** \brief Output a string
00076      */
00077     virtual int string_out(std::string dat, std::string name="")=0;
00078 
00079     /** \brief Output a word
00080      */
00081     virtual int word_out(std::string dat, std::string name="")=0;
00082 
00083     /** \brief Start object output
00084      */
00085     virtual int start_object(std::string type, std::string name="")=0;
00086 
00087     /** \brief End object output
00088      */
00089     virtual int end_object()=0;
00090 
00091     /** \brief End a line of output
00092      */
00093     virtual int end_line()=0;
00094 
00095     /** \brief Output initialization */
00096     virtual int init_file()=0;
00097     
00098     /// Finish the file
00099     virtual int clean_up()=0;
00100     
00101   };
00102   
00103   /** 
00104       \brief Abstract base class for input file formats
00105       
00106 
00107    */
00108   class in_file_format {
00109   public:
00110 
00111     virtual ~in_file_format() {}
00112 
00113     /** \brief Input a bool variable
00114      */
00115     virtual int bool_in(bool &dat, std::string name="")=0;
00116 
00117     /** \brief Input a char variable
00118      */
00119     virtual int char_in(char &dat, std::string name="")=0;
00120 
00121     /** \brief Input a double variable
00122      */
00123     virtual int double_in(double &dat, std::string name="")=0;
00124 
00125     /** \brief Input a float variable
00126      */
00127     virtual int float_in(float &dat, std::string name="")=0;
00128 
00129     /** \brief Input an int variable
00130      */
00131     virtual int int_in(int &dat, std::string name="")=0;
00132 
00133     /** \brief Input an long variable
00134      */
00135     virtual int long_in(unsigned long int &dat, std::string name="")=0;
00136 
00137     /** \brief Input a string variable
00138      */
00139     virtual int string_in(std::string &dat, std::string name="")=0;
00140 
00141     /** \brief Input a word variable
00142      */
00143     virtual int word_in(std::string &dat, std::string name="")=0;
00144     
00145     /// Start object input
00146     virtual int start_object(std::string &type, std::string &name)=0;
00147     
00148     /** \brief Skip the present object for the next call to read_type().
00149      */
00150     virtual int skip_object()=0;
00151     
00152     /// End object input
00153     virtual int end_object()=0;
00154 
00155     /** \brief Read initialization */
00156     virtual int init_file()=0;
00157 
00158     /// Finish file input
00159     virtual int clean_up()=0;
00160   };
00161 
00162 }
00163 
00164 #endif

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page