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