498
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 John W. Eaton |
498
|
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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
498
|
20 |
|
21 */ |
|
22 |
504
|
23 #if !defined (octave_oct_obj_h) |
|
24 #define octave_oct_obj_h 1 |
|
25 |
1297
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
1968
|
30 #include <string> |
|
31 |
498
|
32 #include "Array.h" |
1968
|
33 #include "str-vec.h" |
498
|
34 |
1738
|
35 // Including this is all we need because pt-const.h gives us |
|
36 // declarations for all the data types Octave knows about. |
|
37 |
|
38 #include "pt-const.h" |
498
|
39 |
737
|
40 class |
|
41 Octave_object : public Array<tree_constant> |
508
|
42 { |
|
43 public: |
|
44 |
1968
|
45 Octave_object (void) |
|
46 : Array<tree_constant> () { } |
|
47 |
511
|
48 Octave_object (int n, const tree_constant& val) |
|
49 : Array<tree_constant> (n, val) { } |
|
50 |
1968
|
51 Octave_object (const tree_constant& tc) |
|
52 : Array<tree_constant> (1, tc) { } |
|
53 |
|
54 Octave_object (double d) |
|
55 : Array<tree_constant> (1, tree_constant (d)) { } |
|
56 |
|
57 Octave_object (const Matrix& m) |
|
58 : Array<tree_constant> (1, tree_constant (m)) { } |
|
59 |
|
60 Octave_object (const DiagMatrix& d) |
|
61 : Array<tree_constant> (1, tree_constant (d)) { } |
526
|
62 |
1968
|
63 Octave_object (const RowVector& v, int pcv) |
|
64 : Array<tree_constant> (1, tree_constant (v, pcv)) { } |
|
65 |
|
66 Octave_object (const ColumnVector& v, int pcv) |
|
67 : Array<tree_constant> (1, tree_constant (v, pcv)) { } |
|
68 |
|
69 Octave_object (const Complex& c) |
|
70 : Array<tree_constant> (1, tree_constant (c)) { } |
|
71 |
|
72 Octave_object (const ComplexMatrix& m) |
|
73 : Array<tree_constant> (1, tree_constant (m)) { } |
526
|
74 |
1968
|
75 Octave_object (const ComplexDiagMatrix& d) |
|
76 : Array<tree_constant> (1, tree_constant (d)) { } |
|
77 |
|
78 Octave_object (const ComplexRowVector& v, int pcv) |
|
79 : Array<tree_constant> (1, tree_constant (v, pcv)) { } |
|
80 |
|
81 Octave_object (const ComplexColumnVector& v, int pcv) |
|
82 : Array<tree_constant> (1, tree_constant (v, pcv)) { } |
|
83 |
|
84 Octave_object (const char *s) |
|
85 : Array<tree_constant> (1, tree_constant (s)) { } |
526
|
86 |
1968
|
87 Octave_object (const string& s) |
|
88 : Array<tree_constant> (1, tree_constant (s)) { } |
|
89 |
|
90 Octave_object (const string_vector& s) |
|
91 : Array<tree_constant> (1, tree_constant (s)) { } |
526
|
92 |
1968
|
93 Octave_object (double base, double limit, double inc) |
|
94 : Array<tree_constant> (1, tree_constant (base, limit, inc)) { } |
526
|
95 |
1968
|
96 Octave_object (const Range& r) |
|
97 : Array<tree_constant> (1, tree_constant (r)) { } |
|
98 |
|
99 Octave_object (const Octave_object& obj) |
|
100 : Array<tree_constant> (obj) { } |
508
|
101 |
|
102 Octave_object& operator = (const Octave_object& obj) |
|
103 { |
1968
|
104 if (this != &obj) |
|
105 Array<tree_constant>::operator = (obj); |
|
106 |
508
|
107 return *this; |
|
108 } |
|
109 |
526
|
110 // Assignment will resize on range errors. |
508
|
111 |
1968
|
112 tree_constant& operator () (int n) { return elem (n); } |
|
113 |
|
114 tree_constant operator () (int n) const { return elem (n); } |
526
|
115 |
1968
|
116 int all_strings (void) const; |
|
117 |
|
118 string_vector make_argv (const string&) const; |
526
|
119 |
|
120 private: |
508
|
121 |
565
|
122 // This constructor is private with no definition to keep statements |
|
123 // like |
|
124 // |
|
125 // Octave_object foo = 5; |
|
126 // Octave_object foo = 5.0; |
|
127 // |
|
128 // from doing different things. Instead, you have to use the |
|
129 // constructor |
|
130 // |
|
131 // Octave_object (n, val); |
|
132 // |
|
133 // and supply a default value to create a vector-valued Octave_object. |
|
134 |
574
|
135 Octave_object (int n); |
565
|
136 |
1968
|
137 void maybe_resize (int n) |
|
138 { |
|
139 if (n >= length ()) |
|
140 resize (n + 1, Matrix ()); |
|
141 } |
526
|
142 |
1968
|
143 tree_constant& elem (int n) |
|
144 { |
|
145 maybe_resize (n); |
|
146 return Array<tree_constant>::elem (n); |
|
147 } |
|
148 |
526
|
149 tree_constant& checkelem (int n); |
|
150 |
508
|
151 tree_constant& xelem (int n); |
|
152 |
1968
|
153 tree_constant elem (int n) const |
|
154 { |
|
155 return Array<tree_constant>::operator () (n); |
|
156 } |
|
157 |
508
|
158 tree_constant checkelem (int n) const; |
|
159 }; |
498
|
160 |
504
|
161 #endif |
|
162 |
498
|
163 /* |
|
164 ;;; Local Variables: *** |
|
165 ;;; mode: C++ *** |
|
166 ;;; End: *** |
|
167 */ |