2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 (octave_char_matrix_h) |
|
24 #define octave_char_matrix_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
|
32 #include <string> |
|
33 |
|
34 class ostream; |
|
35 |
|
36 #include "mx-base.h" |
2477
|
37 #include "oct-alloc.h" |
2376
|
38 #include "str-vec.h" |
|
39 |
|
40 #include "error.h" |
|
41 #include "ov-base.h" |
|
42 #include "ov-typeinfo.h" |
|
43 |
|
44 class Octave_map; |
|
45 class octave_value_list; |
|
46 |
|
47 class tree_walker; |
|
48 |
2477
|
49 // Character matrix values. |
2376
|
50 |
|
51 class |
|
52 octave_char_matrix : public octave_base_value |
|
53 { |
|
54 public: |
|
55 |
|
56 octave_char_matrix (void) |
|
57 : octave_base_value () { } |
|
58 |
|
59 octave_char_matrix (const charMatrix& chm, bool = false) |
|
60 : octave_base_value (), matrix (chm) { } |
|
61 |
3189
|
62 octave_char_matrix (char c) |
|
63 : octave_base_value (), matrix (c) { } |
|
64 |
2376
|
65 octave_char_matrix (const char *s) |
|
66 : octave_base_value (), matrix (s) { } |
|
67 |
|
68 octave_char_matrix (const string& s) |
|
69 : octave_base_value (), matrix (s) { } |
|
70 |
|
71 octave_char_matrix (const string_vector& s) |
|
72 : octave_base_value (), matrix (s) { } |
|
73 |
|
74 octave_char_matrix (const octave_char_matrix& chm) |
|
75 : octave_base_value (), matrix (chm.matrix) { } |
|
76 |
|
77 ~octave_char_matrix (void) { } |
|
78 |
|
79 octave_value *clone (void) { return new octave_char_matrix (*this); } |
|
80 |
2477
|
81 void *operator new (size_t size) |
|
82 { return allocator.alloc (size); } |
|
83 |
|
84 void operator delete (void *p, size_t size) |
|
85 { allocator.free (p, size); } |
2376
|
86 |
|
87 int rows (void) const { return matrix.rows (); } |
|
88 int columns (void) const { return matrix.columns (); } |
|
89 |
3195
|
90 int length (void) const |
|
91 { |
|
92 int r = rows (); |
|
93 int c = columns (); |
|
94 |
|
95 return r > c ? r : c; |
|
96 } |
|
97 |
2974
|
98 bool is_constant (void) const { return true; } |
|
99 |
2376
|
100 bool is_defined (void) const { return true; } |
|
101 |
|
102 bool is_char_matrix (void) const { return true; } |
3180
|
103 bool is_real_matrix (void) const { return true; } |
2376
|
104 |
3136
|
105 octave_value all (void) const { return matrix.all (); } |
|
106 octave_value any (void) const { return matrix.any (); } |
2376
|
107 |
|
108 bool is_real_type (void) const { return true; } |
|
109 |
|
110 bool is_matrix_type (void) const { return true; } |
|
111 |
|
112 bool is_numeric_type (void) const { return true; } |
|
113 |
|
114 bool valid_as_scalar_index (void) const; |
|
115 bool valid_as_zero_index (void) const; |
|
116 |
|
117 bool is_true (void) const; |
|
118 |
|
119 double double_value (bool = false) const; |
|
120 |
3145
|
121 double scalar_value (bool frc_str_conv = false) const |
|
122 { return double_value (frc_str_conv); } |
2916
|
123 |
2376
|
124 Matrix matrix_value (bool = false) const { return matrix; } |
|
125 |
|
126 Complex complex_value (bool = false) const; |
|
127 |
3145
|
128 ComplexMatrix complex_matrix_value (bool = false) const |
|
129 { return matrix; } |
2376
|
130 |
3145
|
131 charMatrix char_matrix_value (bool = false) const |
|
132 { return matrix; } |
2376
|
133 |
2449
|
134 octave_value convert_to_str (void) const |
3110
|
135 { return octave_value (matrix, true); } |
2449
|
136 |
2901
|
137 void print (ostream& os, bool pr_as_read_syntax = false) const; |
|
138 |
|
139 void print_raw (ostream& os, bool pr_as_read_syntax = false) const; |
|
140 |
|
141 bool print_name_tag (ostream& os, const string& name) const; |
2376
|
142 |
|
143 int type_id (void) const { return t_id; } |
|
144 |
|
145 string type_name (void) const { return t_name; } |
|
146 |
|
147 static int static_type_id (void) { return t_id; } |
|
148 |
|
149 static void register_type (void) |
|
150 { t_id = octave_value_typeinfo::register_type (t_name); } |
|
151 |
|
152 protected: |
|
153 |
|
154 charMatrix matrix; |
|
155 |
2477
|
156 static octave_allocator allocator; |
|
157 |
|
158 // Type id of character matrix objects, set by register_type(). |
2376
|
159 static int t_id; |
|
160 |
2477
|
161 // Type name of character matrix objects, defined in ov-ch-mat.cc. |
2376
|
162 static const string t_name; |
|
163 }; |
|
164 |
|
165 #endif |
|
166 |
|
167 /* |
|
168 ;;; Local Variables: *** |
|
169 ;;; mode: C++ *** |
|
170 ;;; End: *** |
|
171 */ |