Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_ls_oct_ascii_h)
00024 #define octave_ls_oct_ascii_h 1
00025
00026 #include <cfloat>
00027
00028 #include <sstream>
00029 #include <string>
00030
00031 #include "str-vec.h"
00032
00033 #include "ls-ascii-helper.h"
00034
00035
00036 #define CELL_ELT_TAG "<cell-element>"
00037
00038
00039
00040 #ifndef OCT_RBV
00041 #define OCT_RBV DBL_MAX / 100.0
00042 #endif
00043
00044 extern OCTINTERP_API std::string
00045 extract_keyword (std::istream& is, const char *keyword,
00046 const bool next_only = false);
00047
00048 extern OCTINTERP_API std::string
00049 read_ascii_data (std::istream& is, const std::string& filename, bool& global,
00050 octave_value& tc, octave_idx_type count);
00051
00052 extern OCTINTERP_API bool
00053 save_ascii_data (std::ostream& os, const octave_value& val_arg,
00054 const std::string& name, bool mark_as_global, int precision);
00055
00056 extern OCTINTERP_API bool
00057 save_ascii_data_for_plotting (std::ostream& os, const octave_value& t,
00058 const std::string& name);
00059
00060 extern OCTINTERP_API bool
00061 save_three_d (std::ostream& os, const octave_value& t,
00062 bool parametric = false);
00063
00064
00065
00066
00067
00068
00069
00070
00071 template <class T>
00072 bool
00073 extract_keyword (std::istream& is, const char *keyword, T& value,
00074 const bool next_only = false)
00075 {
00076 bool status = false;
00077 value = T();
00078
00079 char c;
00080 while (is.get (c))
00081 {
00082 if (c == '%' || c == '#')
00083 {
00084 std::ostringstream buf;
00085
00086 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#'))
00087 ;
00088
00089 if (isalpha (c))
00090 buf << c;
00091
00092 while (is.get (c) && isalpha (c))
00093 buf << c;
00094
00095 std::string tmp = buf.str ();
00096 bool match = (tmp.compare (0, strlen (keyword), keyword) == 0);
00097
00098 if (match)
00099 {
00100 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
00101 ;
00102
00103 is.putback (c);
00104 if (c != '\n' && c != '\r')
00105 is >> value;
00106 if (is)
00107 status = true;
00108 skip_until_newline (is, false);
00109 break;
00110 }
00111 else if (next_only)
00112 break;
00113 }
00114 }
00115 return status;
00116 }
00117
00118 template <class T>
00119 bool
00120 extract_keyword (std::istream& is, const std::string& kw, T& value,
00121 const bool next_only = false)
00122 {
00123 return extract_keyword (is, kw.c_str (), value, next_only);
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 template <class T>
00135 bool
00136 extract_keyword (std::istream& is, const string_vector& keywords,
00137 std::string& kw, T& value, const bool next_only = false)
00138 {
00139 bool status = false;
00140 kw = "";
00141 value = 0;
00142
00143 char c;
00144 while (is.get (c))
00145 {
00146 if (c == '%' || c == '#')
00147 {
00148 std::ostringstream buf;
00149
00150 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#'))
00151 ;
00152
00153 if (isalpha (c))
00154 buf << c;
00155
00156 while (is.get (c) && isalpha (c))
00157 buf << c;
00158
00159 std::string tmp = buf.str ();
00160
00161 for (int i = 0; i < keywords.length (); i++)
00162 {
00163 int match = (tmp == keywords[i]);
00164
00165 if (match)
00166 {
00167 kw = keywords[i];
00168
00169 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
00170 ;
00171
00172 is.putback (c);
00173 if (c != '\n' && c != '\r')
00174 is >> value;
00175 if (is)
00176 status = true;
00177 skip_until_newline (is, false);
00178 return status;
00179 }
00180 }
00181
00182 if (next_only)
00183 break;
00184 }
00185 }
00186 return status;
00187 }
00188
00189 #endif