2979
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 1999, 2002, 2004, 2005, 2007 |
|
4 John W. Eaton |
2979
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2979
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2979
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
3203
|
28 #include "error.h" |
2979
|
29 #include "oct-obj.h" |
|
30 #include "oct-lvalue.h" |
|
31 #include "ov.h" |
|
32 |
|
33 void |
|
34 octave_lvalue::assign (octave_value::assign_op op, const octave_value& rhs) |
|
35 { |
3933
|
36 octave_value tmp (idx.empty () |
|
37 ? val->assign (op, rhs) |
|
38 : val->assign (op, type, idx, rhs)); |
2979
|
39 |
7336
|
40 if (! error_state) |
3933
|
41 *val = tmp; |
3203
|
42 } |
|
43 |
|
44 void |
3933
|
45 octave_lvalue::set_index (const std::string& t, |
4219
|
46 const std::list<octave_value_list>& i) |
3357
|
47 { |
|
48 if (! index_set) |
|
49 { |
3933
|
50 type = t; |
3357
|
51 idx = i; |
|
52 index_set = true; |
|
53 } |
|
54 else |
|
55 error ("invalid index expression in assignment"); |
|
56 } |
|
57 |
|
58 void |
3203
|
59 octave_lvalue::do_unary_op (octave_value::unary_op op) |
|
60 { |
3933
|
61 octave_value tmp (idx.empty () |
|
62 ? val->do_non_const_unary_op (op) |
|
63 : val->do_non_const_unary_op (op, type, idx)); |
3203
|
64 |
7336
|
65 if (! error_state) |
3933
|
66 *val = tmp; |
2979
|
67 } |
|
68 |
5001
|
69 octave_value |
|
70 octave_lvalue::value (void) |
|
71 { |
|
72 octave_value retval; |
|
73 |
|
74 if (idx.empty ()) |
|
75 retval = *val; |
|
76 else |
|
77 { |
|
78 if (val->is_constant ()) |
|
79 retval = val->subsref (type, idx); |
|
80 else |
|
81 { |
|
82 octave_value_list t = val->subsref (type, idx, 1); |
|
83 if (t.length () > 0) |
|
84 retval = t(0); |
|
85 } |
|
86 } |
|
87 |
|
88 return retval; |
|
89 } |