4645
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 2003, 2004, 2005, 2006, 2007 John W. Eaton |
4645
|
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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
4645
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
4645
|
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 { |
5781
|
54 gripe_implicit_conversion ("Octave:array-as-scalar", |
|
55 "streamoff array", "scalar streamoff"); |
4645
|
56 |
|
57 retval = matrix (0, 0); |
|
58 } |
|
59 else |
|
60 gripe_invalid_conversion ("streamoff array", "scalar streamoff"); |
|
61 |
|
62 return retval; |
|
63 } |
|
64 |
|
65 void |
|
66 octave_streamoff::print (std::ostream& os, bool) const |
|
67 { |
|
68 print_raw (os); |
|
69 newline (os); |
|
70 } |
|
71 |
|
72 void |
|
73 octave_streamoff::print_raw (std::ostream& os, bool) const |
|
74 { |
|
75 dim_vector dv = matrix.dims (); |
|
76 os << "<" << dv.str () << " streamoff object>"; |
|
77 } |
|
78 |
|
79 DEFUN (isstreamoff, args, , |
|
80 "-*- texinfo -*-\n\ |
|
81 @deftypefn {Built-in Function} {} isstreamoff (@var{x})\n\ |
|
82 Return true if @var{x} is a streamoff object. Otherwise, return\n\ |
|
83 false.\n\ |
|
84 @end deftypefn") |
|
85 { |
|
86 octave_value retval; |
|
87 |
|
88 if (args.length () == 1) |
|
89 retval = args(0).is_streamoff (); |
|
90 else |
5823
|
91 print_usage (); |
4645
|
92 |
|
93 return retval; |
|
94 } |
|
95 |
|
96 DEFUN (streamoff, args, , |
|
97 "-*- texinfo -*-\n\ |
|
98 @deftypefn {Built-in Function} {} streamoff (@var{x})\n\ |
|
99 @deftypefnx {Built-in Function} {} streamoff (@var{n}, @var{m})\n\ |
|
100 Create a new streamoff array object. If invoked with a single scalar\n\ |
|
101 argument, @code{streamoff} returns a square streamoff array with\n\ |
|
102 the dimension specified. If you supply two scalar arguments,\n\ |
|
103 @code{streamoff} takes them to be the number of rows and columns.\n\ |
|
104 If given a vector with two elements, @code{streamoff} uses the values\n\ |
|
105 of the elements as the number of rows and columns, respectively.\n\ |
|
106 @end deftypefn") |
|
107 { |
|
108 octave_value retval; |
|
109 |
|
110 int nargin = args.length (); |
|
111 |
|
112 dim_vector dims; |
|
113 |
|
114 switch (nargin) |
|
115 { |
|
116 case 0: |
|
117 dims = dim_vector (0, 0); |
|
118 break; |
|
119 |
|
120 case 1: |
|
121 get_dimensions (args(0), "streamoff", dims); |
|
122 break; |
|
123 |
|
124 default: |
|
125 { |
|
126 dims.resize (nargin); |
|
127 |
|
128 for (int i = 0; i < nargin; i++) |
|
129 { |
|
130 dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); |
|
131 |
|
132 if (error_state) |
|
133 { |
|
134 error ("streamoff: expecting scalar arguments"); |
|
135 break; |
|
136 } |
|
137 } |
|
138 } |
|
139 break; |
|
140 } |
|
141 |
|
142 if (! error_state) |
|
143 { |
|
144 int ndim = dims.length (); |
|
145 |
|
146 check_dimensions (dims, "streamoff"); |
|
147 |
|
148 if (! error_state) |
|
149 { |
|
150 switch (ndim) |
|
151 { |
|
152 case 1: |
|
153 retval = Cell (dims(0), dims(0), Matrix ()); |
|
154 break; |
|
155 |
|
156 default: |
|
157 retval = Cell (dims, Matrix ()); |
|
158 break; |
|
159 } |
|
160 } |
|
161 } |
|
162 |
|
163 return retval; |
|
164 } |
|
165 |
|
166 /* |
|
167 ;;; Local Variables: *** |
|
168 ;;; mode: C++ *** |
|
169 ;;; End: *** |
|
170 */ |