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) |
3357
|
40 : val (v), idx (), chg_fcn (f), struct_elt_name (), index_set (false) { } |
2979
|
41 |
3523
|
42 octave_lvalue (octave_value *v, const std::string& nm, |
3005
|
43 symbol_record::change_function f = 0) |
3357
|
44 : val (v), idx (), chg_fcn (f), struct_elt_name (nm), index_set (false) { } |
2979
|
45 |
|
46 octave_lvalue (const octave_lvalue& vr) |
|
47 : val (vr.val), idx (vr.idx), chg_fcn (vr.chg_fcn), |
3357
|
48 struct_elt_name (vr.struct_elt_name), index_set (vr.index_set) { } |
2979
|
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; |
3357
|
58 index_set = vr.index_set; |
2979
|
59 } |
|
60 |
|
61 return *this; |
|
62 } |
|
63 |
|
64 ~octave_lvalue (void) { } |
|
65 |
|
66 bool is_defined (void) { return val->is_defined (); } |
|
67 |
|
68 bool is_undefined (void) { return val->is_undefined (); } |
|
69 |
|
70 bool is_map (void) { return val->is_map (); } |
|
71 |
|
72 void define (const octave_value& v) { *val = v; } |
|
73 |
|
74 void assign (octave_value::assign_op, const octave_value&); |
|
75 |
3523
|
76 octave_lvalue struct_elt_ref (const std::string& nm) |
3060
|
77 { |
|
78 val->make_unique (); |
|
79 return val->struct_elt_ref (nm); |
|
80 } |
2979
|
81 |
3357
|
82 void set_index (const octave_value_list& i); |
2984
|
83 |
|
84 void clear_index (void) { idx = octave_value_list (); } |
|
85 |
3203
|
86 void do_unary_op (octave_value::unary_op op); |
2979
|
87 |
|
88 octave_value value (void) |
|
89 { |
|
90 return struct_elt_name.empty () |
|
91 ? (idx.empty () |
|
92 ? *val |
|
93 : val->do_index_op (idx)) |
|
94 : (idx.empty () |
|
95 ? val->do_struct_elt_index_op (struct_elt_name) |
|
96 : val->do_struct_elt_index_op (struct_elt_name, idx)); |
|
97 } |
|
98 |
|
99 private: |
|
100 |
|
101 octave_value *val; |
|
102 |
|
103 octave_value_list idx; |
|
104 |
3005
|
105 symbol_record::change_function chg_fcn; |
2979
|
106 |
3523
|
107 std::string struct_elt_name; |
3357
|
108 |
|
109 bool index_set; |
2979
|
110 }; |
|
111 |
|
112 #endif |
|
113 |
|
114 /* |
|
115 ;;; Local Variables: *** |
|
116 ;;; mode: C++ *** |
|
117 ;;; End: *** |
|
118 */ |