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