00001 /* 00002 00003 Copyright (C) 1996-2012 John W. Eaton 00004 00005 This file is part of Octave. 00006 00007 Octave is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License as published by the 00009 Free Software Foundation; either version 3 of the License, or (at your 00010 option) any later version. 00011 00012 Octave is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Octave; see the file COPYING. If not, see 00019 <http://www.gnu.org/licenses/>. 00020 00021 */ 00022 00023 #if !defined (octave_liboctave_utils_h) 00024 #define octave_liboctave_utils_h 1 00025 00026 #include <cstdio> 00027 00028 #include <iostream> 00029 #include <string> 00030 00031 #include "lo-cutils.h" 00032 #include "oct-cmplx.h" 00033 00034 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x); 00035 extern OCTAVE_API bool xis_one_or_zero (double x); 00036 extern OCTAVE_API bool xis_zero (double x); 00037 extern OCTAVE_API bool xtoo_large_for_float (double x); 00038 00039 extern OCTAVE_API bool xis_int_or_inf_or_nan (float x); 00040 extern OCTAVE_API bool xis_one_or_zero (float x); 00041 extern OCTAVE_API bool xis_zero (float x); 00042 extern OCTAVE_API bool xtoo_large_for_float (float x); 00043 00044 extern OCTAVE_API char *strsave (const char *); 00045 00046 extern OCTAVE_API void 00047 octave_putenv (const std::string&, const std::string&); 00048 00049 extern OCTAVE_API std::string octave_fgets (std::FILE *); 00050 extern OCTAVE_API std::string octave_fgetl (std::FILE *); 00051 00052 extern OCTAVE_API std::string octave_fgets (std::FILE *, bool& eof); 00053 extern OCTAVE_API std::string octave_fgetl (std::FILE *, bool& eof); 00054 00055 template <typename T> 00056 T 00057 octave_read_value (std::istream& is) 00058 { 00059 T retval; 00060 is >> retval; 00061 return retval; 00062 } 00063 00064 template <> OCTAVE_API double octave_read_value (std::istream& is); 00065 template <> OCTAVE_API Complex octave_read_value (std::istream& is); 00066 template <> OCTAVE_API float octave_read_value (std::istream& is); 00067 template <> OCTAVE_API FloatComplex octave_read_value (std::istream& is); 00068 00069 // The next four functions are provided for backward compatibility. 00070 inline double 00071 octave_read_double (std::istream& is) 00072 { 00073 return octave_read_value<double> (is); 00074 } 00075 00076 inline Complex 00077 octave_read_complex (std::istream& is) 00078 { 00079 return octave_read_value<Complex> (is); 00080 } 00081 00082 inline float 00083 octave_read_float (std::istream& is) 00084 { 00085 return octave_read_value<float> (is); 00086 } 00087 00088 inline FloatComplex 00089 octave_read_float_complex (std::istream& is) 00090 { 00091 return octave_read_value<FloatComplex> (is); 00092 } 00093 00094 extern OCTAVE_API void 00095 octave_write_double (std::ostream& os, double dval); 00096 00097 extern OCTAVE_API void 00098 octave_write_complex (std::ostream& os, const Complex& cval); 00099 00100 extern OCTAVE_API void 00101 octave_write_float (std::ostream& os, float dval); 00102 00103 extern OCTAVE_API void 00104 octave_write_float_complex (std::ostream& os, const FloatComplex& cval); 00105 00106 #endif