2979
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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 #if !defined (octave_lvalue_h) |
|
24 #define octave_lvalue_h 1 |
|
25 |
|
26 class octave_value; |
|
27 class octave_value_list; |
|
28 |
|
29 #include <string> |
|
30 |
|
31 #include "oct-obj.h" |
|
32 #include "symtab.h" |
|
33 |
|
34 class |
|
35 octave_lvalue |
|
36 { |
|
37 public: |
|
38 |
3005
|
39 octave_lvalue (octave_value *v = 0, symbol_record::change_function f = 0) |
2979
|
40 : val (v), idx (), chg_fcn (f), struct_elt_name () { } |
|
41 |
|
42 octave_lvalue (octave_value *v, const string& nm, |
3005
|
43 symbol_record::change_function f = 0) |
2979
|
44 : val (v), idx (), chg_fcn (f), struct_elt_name (nm) { } |
|
45 |
|
46 octave_lvalue (const octave_lvalue& vr) |
|
47 : val (vr.val), idx (vr.idx), chg_fcn (vr.chg_fcn), |
|
48 struct_elt_name (vr.struct_elt_name) { } |
|
49 |
|
50 octave_lvalue& operator = (const octave_lvalue& vr) |
|
51 { |
|
52 if (this != &vr) |
|
53 { |
|
54 val = vr.val; |
|
55 idx = vr.idx; |
|
56 chg_fcn = vr.chg_fcn; |
|
57 struct_elt_name = vr.struct_elt_name; |
|
58 } |
|
59 |
|
60 return *this; |
|
61 } |
|
62 |
|
63 ~octave_lvalue (void) { } |
|
64 |
|
65 bool is_defined (void) { return val->is_defined (); } |
|
66 |
|
67 bool is_undefined (void) { return val->is_undefined (); } |
|
68 |
|
69 bool is_map (void) { return val->is_map (); } |
|
70 |
|
71 void define (const octave_value& v) { *val = v; } |
|
72 |
|
73 void assign (octave_value::assign_op, const octave_value&); |
|
74 |
|
75 octave_lvalue struct_elt_ref (const string& nm) |
3060
|
76 { |
|
77 val->make_unique (); |
|
78 return val->struct_elt_ref (nm); |
|
79 } |
2979
|
80 |
2984
|
81 void set_index (const octave_value_list& i) { idx = i; } |
|
82 |
|
83 void clear_index (void) { idx = octave_value_list (); } |
|
84 |
|
85 // XXX FIXME XXX -- need to handle index increment and decrement too. |
2979
|
86 |
|
87 void increment (void) { val->increment (); } |
|
88 |
|
89 void decrement (void) { val->decrement (); } |
|
90 |
|
91 octave_value value (void) |
|
92 { |
|
93 return struct_elt_name.empty () |
|
94 ? (idx.empty () |
|
95 ? *val |
|
96 : val->do_index_op (idx)) |
|
97 : (idx.empty () |
|
98 ? val->do_struct_elt_index_op (struct_elt_name) |
|
99 : val->do_struct_elt_index_op (struct_elt_name, idx)); |
|
100 } |
|
101 |
|
102 private: |
|
103 |
|
104 octave_value *val; |
|
105 |
|
106 octave_value_list idx; |
|
107 |
3005
|
108 symbol_record::change_function chg_fcn; |
2979
|
109 |
|
110 string struct_elt_name; |
|
111 }; |
|
112 |
|
113 #endif |
|
114 |
|
115 /* |
|
116 ;;; Local Variables: *** |
|
117 ;;; mode: C++ *** |
|
118 ;;; End: *** |
|
119 */ |