oct-lvalue.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "error.h"
00028 #include "oct-obj.h"
00029 #include "oct-lvalue.h"
00030 #include "ov.h"
00031 
00032 void
00033 octave_lvalue::assign (octave_value::assign_op op, const octave_value& rhs)
00034 {
00035   if (val)
00036     {
00037       if (idx.empty ())
00038         val->assign (op, rhs);
00039       else
00040         val->assign (op, type, idx, rhs);
00041     }
00042 }
00043 
00044 void
00045 octave_lvalue::set_index (const std::string& t,
00046                           const std::list<octave_value_list>& i)
00047 {
00048   if (idx.empty ())
00049     {
00050       type = t;
00051       idx = i;
00052     }
00053   else
00054     error ("invalid index expression in assignment");
00055 }
00056 
00057 void
00058 octave_lvalue::do_unary_op (octave_value::unary_op op)
00059 {
00060   if (val)
00061     {
00062       if (idx.empty ())
00063         val->do_non_const_unary_op (op);
00064       else
00065         val->do_non_const_unary_op (op, type, idx);
00066     }
00067   else
00068     error ("internal: invalid operation on ~");
00069 }
00070 
00071 octave_value
00072 octave_lvalue::value (void)
00073 {
00074   octave_value retval;
00075 
00076   if (val)
00077     {
00078       if (idx.empty ())
00079         retval = *val;
00080       else
00081         {
00082           if (val->is_constant ())
00083             retval = val->subsref (type, idx);
00084           else
00085             {
00086               octave_value_list t = val->subsref (type, idx, 1);
00087               if (t.length () > 0)
00088                 retval = t(0);
00089             }
00090         }
00091     }
00092 
00093   return retval;
00094 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines