GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lo-utils.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_lo_utils_h)
24 #define octave_lo_utils_h 1
25 
26 #include <cstdio>
27 
28 #include <iostream>
29 #include <string>
30 
31 #include "quit.h"
32 
33 #include "lo-cutils.h"
34 #include "oct-cmplx.h"
35 
36 // Generic any/all test functionality with arbitrary predicate.
37 
38 template <class F, class T, bool zero>
39 bool
40 any_all_test (F fcn, const T *m, octave_idx_type len)
41 {
43 
44  for (i = 0; i < len - 3; i += 4)
45  {
46  octave_quit ();
47 
48  if (fcn (m[i]) != zero
49  || fcn (m[i+1]) != zero
50  || fcn (m[i+2]) != zero
51  || fcn (m[i+3]) != zero)
52  return ! zero;
53  }
54 
55  octave_quit ();
56 
57  for (; i < len; i++)
58  if (fcn (m[i]) != zero)
59  return ! zero;
60 
61  return zero;
62 }
63 
64 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
65 extern OCTAVE_API bool xis_one_or_zero (double x);
66 extern OCTAVE_API bool xis_zero (double x);
67 extern OCTAVE_API bool xtoo_large_for_float (double x);
68 
69 extern OCTAVE_API bool xtoo_large_for_float (const Complex& x);
70 
71 extern OCTAVE_API bool xis_int_or_inf_or_nan (float x);
72 extern OCTAVE_API bool xis_one_or_zero (float x);
73 extern OCTAVE_API bool xis_zero (float x);
74 extern OCTAVE_API bool xtoo_large_for_float (float x);
75 
76 extern OCTAVE_API char *strsave (const char *);
77 
78 extern OCTAVE_API void
79 octave_putenv (const std::string&, const std::string&);
80 
81 extern OCTAVE_API std::string octave_fgets (std::FILE *);
82 extern OCTAVE_API std::string octave_fgetl (std::FILE *);
83 
84 extern OCTAVE_API std::string octave_fgets (std::FILE *, bool& eof);
85 extern OCTAVE_API std::string octave_fgetl (std::FILE *, bool& eof);
86 
87 template <typename T>
88 T
89 octave_read_value (std::istream& is)
90 {
91  T retval;
92  is >> retval;
93  return retval;
94 }
95 
96 template <> OCTAVE_API double octave_read_value (std::istream& is);
97 template <> OCTAVE_API Complex octave_read_value (std::istream& is);
98 template <> OCTAVE_API float octave_read_value (std::istream& is);
99 template <> OCTAVE_API FloatComplex octave_read_value (std::istream& is);
100 
101 // The next four functions are provided for backward compatibility.
102 inline double
103 octave_read_double (std::istream& is)
104 {
105  return octave_read_value<double> (is);
106 }
107 
108 inline Complex
109 octave_read_complex (std::istream& is)
110 {
111  return octave_read_value<Complex> (is);
112 }
113 
114 inline float
115 octave_read_float (std::istream& is)
116 {
117  return octave_read_value<float> (is);
118 }
119 
120 inline FloatComplex
121 octave_read_float_complex (std::istream& is)
122 {
123  return octave_read_value<FloatComplex> (is);
124 }
125 
126 extern OCTAVE_API void
127 octave_write_double (std::ostream& os, double dval);
128 
129 extern OCTAVE_API void
130 octave_write_complex (std::ostream& os, const Complex& cval);
131 
132 extern OCTAVE_API void
133 octave_write_float (std::ostream& os, float dval);
134 
135 extern OCTAVE_API void
136 octave_write_float_complex (std::ostream& os, const FloatComplex& cval);
137 
138 // Maybe this is overkill, but it allos
139 
140 class
142 {
143 public:
144 
145  static bool ifexited (int status)
146  {
147  return octave_wifexited (status);
148  }
149 
150  static int exitstatus (int status)
151  {
152  return octave_wexitstatus (status);
153  }
154 
155  static bool ifsignaled (int status)
156  {
157  return octave_wifsignaled (status);
158  }
159 
160  static int termsig (int status)
161  {
162  return octave_wtermsig (status);
163  }
164 
165  static bool coredump (int status)
166  {
167  return octave_wcoredump (status);
168  }
169 
170  static bool ifstopped (int status)
171  {
172  return octave_wifstopped (status);
173  }
174 
175  static int stopsig (int status)
176  {
177  return octave_wstopsig (status);
178  }
179 
180  static bool ifcontinued (int status)
181  {
182  return octave_wifcontinued (status);
183  }
184 };
185 
186 #endif