Mercurial > hg > octave-lyh
view src/ov-struct.cc @ 3932:2e2e32198722
[project @ 2002-05-07 18:10:44 by jwe]
author | jwe |
---|---|
date | Tue, 07 May 2002 18:10:44 +0000 |
parents | ab7fa5a8f23f |
children | f9ea3dcf58ee |
line wrap: on
line source
/* Copyright (C) 1996, 1997 John W. Eaton This file is part of Octave. Octave is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. Octave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Octave; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #if defined (__GNUG__) #pragma implementation #endif #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <iostream> #include "error.h" #include "oct-lvalue.h" #include "ov-list.h" #include "ov-struct.h" #include "unwind-prot.h" #include "variables.h" DEFINE_OCTAVE_ALLOCATOR(octave_struct); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_struct, "struct"); octave_value octave_struct::do_struct_elt_index_op (const std::string& nm, const octave_value_list& idx, bool silent) { // XXX DO_ME XXX return octave_value (); } octave_value octave_struct::do_struct_elt_index_op (const std::string& nm, bool silent) { octave_value retval; Pix idx = map.seek (nm); if (idx) retval = map.contents (idx); else if (! silent) error ("structure has no member `%s'", nm.c_str ()); return retval; } octave_lvalue octave_struct::struct_elt_ref (octave_value *, const std::string& nm) { // XXX FIXME XXX -- struct array return octave_lvalue (&map[nm](0)); } void octave_struct::print (std::ostream& os, bool) const { print_raw (os); } void octave_struct::print_raw (std::ostream& os, bool) const { // XXX FIXME XXX -- would be nice to print the output in some // standard order. Maybe all substructures first, maybe // alphabetize entries, etc. unwind_protect::begin_frame ("octave_struct_print"); unwind_protect_int (Vstruct_levels_to_print); if (Vstruct_levels_to_print-- > 0) { indent (os); os << "{"; newline (os); increment_indent_level (); int n = map.array_length (); for (Pix p = map.first (); p; map.next (p)) { std::string key = map.key (p); octave_value_list val = map.contents (p); if (n == 1) val(0).print_with_name (os, key); else { octave_list tmp (val); tmp.print_with_name (os, key); } } decrement_indent_level (); indent (os); os << "}"; newline (os); } else { os << " <structure>"; newline (os); } unwind_protect::run_frame ("octave_struct_print"); } bool octave_struct::print_name_tag (std::ostream& os, const std::string& name) const { indent (os); os << name << " ="; newline (os); return false; } /* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** */