4645
|
1 /* |
|
2 |
|
3 Copyright (C) 2003 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 2, or (at your option) any |
|
10 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, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include <iostream> |
|
32 |
4646
|
33 #include "so-array.h" |
4645
|
34 |
|
35 #include "defun.h" |
|
36 #include "error.h" |
|
37 #include "gripes.h" |
|
38 #include "ov-streamoff.h" |
|
39 #include "oct-obj.h" |
|
40 #include "utils.h" |
|
41 #include "ov-base-mat.h" |
|
42 #include "ov-base-mat.cc" |
|
43 |
|
44 template class octave_base_matrix<streamoff_array>; |
|
45 |
|
46 DEFINE_OCTAVE_ALLOCATOR (octave_streamoff); |
|
47 |
|
48 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_streamoff, |
|
49 "streamoff", "streamoff"); |
|
50 |
|
51 std::streamoff |
|
52 octave_streamoff::streamoff_value (void) const |
|
53 { |
|
54 std::streamoff retval (-1); |
|
55 |
|
56 if (numel () > 0) |
|
57 { |
|
58 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
59 if (Vwarn_fortran_indexing) |
|
60 gripe_implicit_conversion ("streamoff array", "scalar streamoff"); |
|
61 |
|
62 retval = matrix (0, 0); |
|
63 } |
|
64 else |
|
65 gripe_invalid_conversion ("streamoff array", "scalar streamoff"); |
|
66 |
|
67 return retval; |
|
68 } |
|
69 |
|
70 void |
|
71 octave_streamoff::print (std::ostream& os, bool) const |
|
72 { |
|
73 print_raw (os); |
|
74 newline (os); |
|
75 } |
|
76 |
|
77 void |
|
78 octave_streamoff::print_raw (std::ostream& os, bool) const |
|
79 { |
|
80 dim_vector dv = matrix.dims (); |
|
81 os << "<" << dv.str () << " streamoff object>"; |
|
82 } |
|
83 |
|
84 DEFUN (isstreamoff, args, , |
|
85 "-*- texinfo -*-\n\ |
|
86 @deftypefn {Built-in Function} {} isstreamoff (@var{x})\n\ |
|
87 Return true if @var{x} is a streamoff object. Otherwise, return\n\ |
|
88 false.\n\ |
|
89 @end deftypefn") |
|
90 { |
|
91 octave_value retval; |
|
92 |
|
93 if (args.length () == 1) |
|
94 retval = args(0).is_streamoff (); |
|
95 else |
|
96 print_usage ("isstreamoff"); |
|
97 |
|
98 return retval; |
|
99 } |
|
100 |
|
101 DEFUN (streamoff, args, , |
|
102 "-*- texinfo -*-\n\ |
|
103 @deftypefn {Built-in Function} {} streamoff (@var{x})\n\ |
|
104 @deftypefnx {Built-in Function} {} streamoff (@var{n}, @var{m})\n\ |
|
105 Create a new streamoff array object. If invoked with a single scalar\n\ |
|
106 argument, @code{streamoff} returns a square streamoff array with\n\ |
|
107 the dimension specified. If you supply two scalar arguments,\n\ |
|
108 @code{streamoff} takes them to be the number of rows and columns.\n\ |
|
109 If given a vector with two elements, @code{streamoff} uses the values\n\ |
|
110 of the elements as the number of rows and columns, respectively.\n\ |
|
111 @end deftypefn") |
|
112 { |
|
113 octave_value retval; |
|
114 |
|
115 int nargin = args.length (); |
|
116 |
|
117 dim_vector dims; |
|
118 |
|
119 switch (nargin) |
|
120 { |
|
121 case 0: |
|
122 dims = dim_vector (0, 0); |
|
123 break; |
|
124 |
|
125 case 1: |
|
126 get_dimensions (args(0), "streamoff", dims); |
|
127 break; |
|
128 |
|
129 default: |
|
130 { |
|
131 dims.resize (nargin); |
|
132 |
|
133 for (int i = 0; i < nargin; i++) |
|
134 { |
|
135 dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); |
|
136 |
|
137 if (error_state) |
|
138 { |
|
139 error ("streamoff: expecting scalar arguments"); |
|
140 break; |
|
141 } |
|
142 } |
|
143 } |
|
144 break; |
|
145 } |
|
146 |
|
147 if (! error_state) |
|
148 { |
|
149 int ndim = dims.length (); |
|
150 |
|
151 check_dimensions (dims, "streamoff"); |
|
152 |
|
153 if (! error_state) |
|
154 { |
|
155 switch (ndim) |
|
156 { |
|
157 case 1: |
|
158 retval = Cell (dims(0), dims(0), Matrix ()); |
|
159 break; |
|
160 |
|
161 default: |
|
162 retval = Cell (dims, Matrix ()); |
|
163 break; |
|
164 } |
|
165 } |
|
166 } |
|
167 |
|
168 return retval; |
|
169 } |
|
170 |
|
171 /* |
|
172 ;;; Local Variables: *** |
|
173 ;;; mode: C++ *** |
|
174 ;;; End: *** |
|
175 */ |