Mercurial > hg > octave-thorsten
changeset 2901:e6d25bc478dd
[project @ 1997-04-30 03:41:26 by jwe]
author | jwe |
---|---|
date | Wed, 30 Apr 1997 03:43:29 +0000 |
parents | 5ed088015839 |
children | c5b7a019b9ed |
files | src/ov-base.cc src/ov-base.h src/ov-bool-mat.cc src/ov-bool-mat.h src/ov-bool.cc src/ov-bool.h src/ov-ch-mat.cc src/ov-ch-mat.h src/ov-colon.cc src/ov-colon.h src/ov-complex.cc src/ov-complex.h src/ov-cx-mat.cc src/ov-cx-mat.h src/ov-file.cc src/ov-file.h src/ov-list.cc src/ov-list.h src/ov-range.cc src/ov-range.h src/ov-re-mat.cc src/ov-re-mat.h src/ov-scalar.cc src/ov-scalar.h src/ov-str-mat.cc src/ov-str-mat.h src/ov-struct.cc src/ov-struct.h src/ov-va-args.cc src/ov-va-args.h |
diffstat | 30 files changed, 676 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ov-base.cc +++ b/src/ov-base.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <iostream.h> + #include "lo-ieee.h" #include "gripes.h" @@ -99,11 +101,27 @@ } void -octave_base_value::print (ostream&, bool) +octave_base_value::print (ostream&, bool) const { gripe_wrong_type_arg ("octave_base_value::print()", type_name ()); } +void +octave_base_value::print_raw (ostream&, bool) const +{ + gripe_wrong_type_arg ("octave_base_value::print_raw()", type_name ()); +} + +bool +octave_base_value::print_name_tag (ostream& os, const string& name) const +{ + indent (os); + os << name << " ="; + newline (os); + newline (os); + return true; +} + double octave_base_value::double_value (bool) const { @@ -178,6 +196,22 @@ return retval; } +octave_stream * +octave_base_value::stream_value (void) const +{ + octave_stream *retval = 0; + gripe_wrong_type_arg ("octave_base_value::stream_value()", type_name ()); + return retval; +} + +int +octave_base_value::stream_number (void) const +{ + int retval = -1; + gripe_wrong_type_arg ("octave_base_value::stream_number()", type_name ()); + return retval; +} + octave_value_list octave_base_value::list_value (void) const {
--- a/src/ov-base.h +++ b/src/ov-base.h @@ -100,6 +100,8 @@ bool is_map (void) const { return false; } + bool is_file (void) const { return false; } + bool is_list (void) const { return false; } bool is_magic_colon (void) const { return false; } @@ -152,6 +154,10 @@ Octave_map map_value (void) const; + octave_stream *stream_value (void) const; + + int stream_number (void) const; + octave_value_list list_value (void) const; bool bool_value (void) const; @@ -174,7 +180,11 @@ void convert_to_row_or_column_vector (void); - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-bool-mat.cc +++ b/src/ov-bool-mat.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <iostream.h> + #include "lo-ieee.h" #include "mx-base.h" @@ -209,11 +211,42 @@ } void -octave_bool_matrix::print (ostream& os, bool pr_as_read_syntax) +octave_bool_matrix::print (ostream& os, bool pr_as_read_syntax) const +{ + indent (os); + print_raw (os, pr_as_read_syntax); + newline (os); +} + +void +octave_bool_matrix::print_raw (ostream& os, bool pr_as_read_syntax) const { Matrix tmp (matrix); + octave_print_internal (os, tmp, pr_as_read_syntax, + current_print_indent_level ()); +} - octave_print_internal (os, tmp, pr_as_read_syntax, struct_indent); +bool +octave_bool_matrix::print_name_tag (ostream& os, const string& name) const +{ + bool retval = false; + + int nr = rows (); + int nc = columns (); + + indent (os); + + if (nr == 1 && nc == 1 || (nr == 0 || nc == 0)) + os << name << " = "; + else + { + os << name << " ="; + newline (os); + newline (os); + retval = true; + } + + return retval; } /*
--- a/src/ov-bool-mat.h +++ b/src/ov-bool-mat.h @@ -122,7 +122,11 @@ octave_value hermitian (void) const { return octave_value (matrix.transpose ()); } - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-bool.cc +++ b/src/ov-bool.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <iostream.h> + #include "mx-base.h" #include "gripes.h" @@ -111,11 +113,27 @@ } void -octave_bool::print (ostream& os, bool pr_as_read_syntax) +octave_bool::print (ostream& os, bool pr_as_read_syntax) const +{ + indent (os); + print_raw (os, pr_as_read_syntax); + newline (os); +} + +void +octave_bool::print_raw (ostream& os, bool pr_as_read_syntax) const { octave_print_internal (os, scalar, pr_as_read_syntax); } +bool +octave_bool::print_name_tag (ostream& os, const string& name) const +{ + indent (os); + os << name << " = "; + return false; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/ov-bool.h +++ b/src/ov-bool.h @@ -122,7 +122,11 @@ octave_value convert_to_str (void) const; - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-ch-mat.cc +++ b/src/ov-ch-mat.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <iostream.h> + #include "lo-ieee.h" #include "mx-base.h" @@ -94,9 +96,41 @@ } void -octave_char_matrix::print (ostream& os, bool pr_as_read_syntax) +octave_char_matrix::print (ostream& os, bool pr_as_read_syntax) const +{ + indent (os); + print_raw (os, pr_as_read_syntax); + newline (os); +} + +void +octave_char_matrix::print_raw (ostream& os, bool pr_as_read_syntax) const +{ + octave_print_internal (os, matrix, pr_as_read_syntax, false, + current_print_indent_level ()); +} + +bool +octave_char_matrix::print_name_tag (ostream& os, const string& name) const { - octave_print_internal (os, matrix, pr_as_read_syntax, false, struct_indent); + bool retval = false; + + int nr = rows (); + int nc = columns (); + + indent (os); + + if (nr == 1 && nc == 1 || (nr == 0 || nc == 0)) + os << name << " = "; + else + { + os << name << " ="; + newline (os); + newline (os); + retval = true; + } + + return retval; } /*
--- a/src/ov-ch-mat.h +++ b/src/ov-ch-mat.h @@ -122,7 +122,11 @@ octave_value hermitian (void) const { return octave_value (matrix.transpose ()); } - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-colon.cc +++ b/src/ov-colon.cc @@ -39,7 +39,14 @@ const string octave_magic_colon::t_name ("magic-colon"); void -octave_magic_colon::print (ostream& os, bool) +octave_magic_colon::print (ostream& os, bool) const +{ + indent (os); + print_raw (os); +} + +void +octave_magic_colon::print_raw (ostream& os, bool) const { os << ":"; }
--- a/src/ov-colon.h +++ b/src/ov-colon.h @@ -68,7 +68,9 @@ bool valid_as_zero_index (void) const { return false; } - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; int type_id (void) const { return t_id; }
--- a/src/ov-complex.cc +++ b/src/ov-complex.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <iostream.h> + #include "lo-ieee.h" #include "oct-obj.h" @@ -153,11 +155,27 @@ } void -octave_complex::print (ostream& os, bool pr_as_read_syntax) +octave_complex::print (ostream& os, bool pr_as_read_syntax) const +{ + indent (os); + print_raw (os, pr_as_read_syntax); + newline (os); +} + +void +octave_complex::print_raw (ostream& os, bool pr_as_read_syntax) const { octave_print_internal (os, scalar, pr_as_read_syntax); } +bool +octave_complex::print_name_tag (ostream& os, const string& name) const +{ + indent (os); + os << name << " = "; + return false; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/ov-complex.h +++ b/src/ov-complex.h @@ -120,7 +120,11 @@ void decrement (void) { scalar -= 1.0; } - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-cx-mat.cc +++ b/src/ov-cx-mat.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <iostream.h> + #include "lo-ieee.h" #include "mx-base.h" @@ -305,9 +307,41 @@ } void -octave_complex_matrix::print (ostream& os, bool pr_as_read_syntax) +octave_complex_matrix::print (ostream& os, bool pr_as_read_syntax) const +{ + indent (os); + print_raw (os, pr_as_read_syntax); + newline (os); +} + +void +octave_complex_matrix::print_raw (ostream& os, bool pr_as_read_syntax) const +{ + octave_print_internal (os, matrix, pr_as_read_syntax, + current_print_indent_level ()); +} + +bool +octave_complex_matrix::print_name_tag (ostream& os, const string& name) const { - octave_print_internal (os, matrix, pr_as_read_syntax, struct_indent); + bool retval = false; + + int nr = rows (); + int nc = columns (); + + indent (os); + + if (nr == 1 && nc == 1 || (nr == 0 || nc == 0)) + os << name << " = "; + else + { + os << name << " ="; + newline (os); + newline (os); + retval = true; + } + + return retval; } /*
--- a/src/ov-cx-mat.h +++ b/src/ov-cx-mat.h @@ -132,7 +132,11 @@ void decrement (void) { matrix -= 1.0; } - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
new file mode 100644 --- /dev/null +++ b/src/ov-file.cc @@ -0,0 +1,108 @@ +/* + +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.h> + +#include "oct-stream.h" +#include "ops.h" +#include "ov-file.h" +#include "ov-scalar.h" +#include "unwind-prot.h" + +octave_allocator +octave_file::allocator (sizeof (octave_file)); + +int +octave_file::t_id (-1); + +const string +octave_file::t_name ("file"); + +static octave_value * +default_numeric_conversion_function (const octave_value& a) +{ + CAST_CONV_ARG (const octave_file&); + + return new octave_scalar (static_cast<double> (v.stream_number ())); +} + +type_conv_fcn +octave_file::numeric_conversion_function (void) const +{ + return default_numeric_conversion_function; +} + +void +octave_file::print (ostream& os, bool) const +{ + indent (os); + print_raw (os); + newline (os); +} + +void +octave_file::print_raw (ostream& os, bool) const +{ + os << "{"; newline (os); + + if (stream) + { + increment_indent_level (); + + string name = stream->name (); + string mode = octave_stream::mode_as_string (stream->mode ()); + string arch + = oct_mach_info::float_format_as_string (stream->float_format ()); + + indent (os); os << "id = " << number; newline (os); + indent (os); os << "name = " << name; newline (os); + indent (os); os << "mode = " << mode; newline (os); + indent (os); os << "arch = " << arch; newline (os); + + decrement_indent_level (); + } + + indent (os); os << "}"; +} + +bool +octave_file::print_name_tag (ostream& os, const string& name) const +{ + indent (os); + os << name << " ="; + newline (os); + return false; +} + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
new file mode 100644 --- /dev/null +++ b/src/ov-file.h @@ -0,0 +1,122 @@ +/* + +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 (octave_file_h) +#define octave_file_h 1 + +#if defined (__GNUG__) +#pragma interface +#endif + +#include <cstdlib> + +#include <string> + +class ostream; + +#include "oct-alloc.h" +#include "ov-base.h" +#include "ov-typeinfo.h" + +class tree_walker; +class octave_stream; +class octave_value; +class octave_value_list; + +// Lists. + +class +octave_file : public octave_base_value +{ +public: + + octave_file (void) + : octave_base_value (), stream (0), number (-1) { } + + octave_file (octave_stream *s, int n) + : octave_base_value (), stream (s), number (n) { } + + octave_file (const octave_file& f) + : octave_base_value (), stream (f.stream), number (f.number) { } + + ~octave_file (void) { } + + octave_value *clone (void) { return new octave_file (*this); } + + void *operator new (size_t size) + { return allocator.alloc (size); } + + void operator delete (void *p, size_t size) + { allocator.free (p, size); } + + type_conv_fcn numeric_conversion_function (void) const; + + double double_value (void) const { return static_cast<double> (number); } + + octave_stream *stream_value (void) const { return stream; } + + int stream_number (void) const { return number; } + + bool is_defined (void) const { return true; } + + bool is_file (void) const { return true; } + + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; + + int type_id (void) const { return t_id; } + + string type_name (void) const { return t_name; } + + static int static_type_id (void) { return t_id; } + + static void register_type (void) + { t_id = octave_value_typeinfo::register_type (t_name); } + +private: + + // The stream object. + octave_stream *stream; + + // The number of the beast. + int number; + + // For custom memory management. + static octave_allocator allocator; + + // Type id of list objects, set by register_type(). + static int t_id; + + // Type name of list objects, defined in ov-list.cc. + static const string t_name; +}; + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
--- a/src/ov-list.cc +++ b/src/ov-list.cc @@ -80,50 +80,51 @@ } void -octave_list::print (ostream& os, bool) +octave_list::print (ostream& os, bool) const +{ + print_raw (os); +} + +void +octave_list::print_raw (ostream& os, bool) const { begin_unwind_frame ("octave_list_print"); - unwind_protect_int (list_indent); + indent (os); + os << "("; + newline (os); - os.form ("\n%*s{\n", list_indent, ""); - - increment_list_indent (); + increment_indent_level (); int n = lst.length (); for (int i = 0; i < n; i++) { - bool pad_after = false; - octave_value val = lst(i); - os.form ("%*s", list_indent, ""); - - if (val.print_as_scalar ()) - os << " "; - else if (val.is_list ()) - pad_after = true; - else - { - pad_after = true; - - os << "\n\n"; - } + indent (os); val.print (os); - - if (pad_after) - os << "\n"; } - decrement_list_indent (); + decrement_indent_level (); - os.form ("%*s%s", list_indent, "", "}\n"); + indent (os); + os << ")"; + newline (os); run_unwind_frame ("octave_list_print"); } +bool +octave_list::print_name_tag (ostream& os, const string& name) const +{ + indent (os); + os << name << " ="; + newline (os); + return false; +} + DEFUN (make_list, args, , "make_list (ARGS)\n\ \n\
--- a/src/ov-list.h +++ b/src/ov-list.h @@ -78,7 +78,11 @@ octave_value_list list_value (void) const { return lst; } - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-range.cc +++ b/src/ov-range.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <iostream.h> + #include "lo-ieee.h" #include "lo-utils.h" @@ -202,9 +204,40 @@ } void -octave_range::print (ostream& os, bool pr_as_read_syntax) +octave_range::print (ostream& os, bool pr_as_read_syntax) const +{ + indent (os); + print_raw (os, pr_as_read_syntax); + newline (os); +} + +void +octave_range::print_raw (ostream& os, bool pr_as_read_syntax) const +{ + octave_print_internal (os, range, pr_as_read_syntax, + current_print_indent_level ()); +} + +bool +octave_range::print_name_tag (ostream& os, const string& name) const { - octave_print_internal (os, range, pr_as_read_syntax, struct_indent); + bool retval = false; + + int n = range.nelem (); + + indent (os); + + if (n == 0 || n == 1) + os << name << " = "; + else + { + os << name << " ="; + newline (os); + newline (os); + retval = true; + } + + return retval; } /*
--- a/src/ov-range.h +++ b/src/ov-range.h @@ -147,7 +147,11 @@ octave_value convert_to_str (void) const; - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <iostream.h> + #include "lo-ieee.h" #include "lo-utils.h" #include "mx-base.h" @@ -259,9 +261,41 @@ } void -octave_matrix::print (ostream& os, bool pr_as_read_syntax) +octave_matrix::print (ostream& os, bool pr_as_read_syntax) const +{ + indent (os); + print_raw (os, pr_as_read_syntax); + newline (os); +} + +void +octave_matrix::print_raw (ostream& os, bool pr_as_read_syntax) const +{ + octave_print_internal (os, matrix, pr_as_read_syntax, + current_print_indent_level ()); +} + +bool +octave_matrix::print_name_tag (ostream& os, const string& name) const { - octave_print_internal (os, matrix, pr_as_read_syntax, struct_indent); + bool retval = false; + + int nr = rows (); + int nc = columns (); + + indent (os); + + if (nr == 1 && nc == 1 || (nr == 0 || nc == 0)) + os << name << " = "; + else + { + os << name << " ="; + newline (os); + newline (os); + retval = true; + } + + return retval; } /*
--- a/src/ov-re-mat.h +++ b/src/ov-re-mat.h @@ -133,7 +133,11 @@ octave_value convert_to_str (void) const; - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-scalar.cc +++ b/src/ov-scalar.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <iostream.h> + #include "defun.h" #include "gripes.h" #include "oct-obj.h" @@ -108,11 +110,27 @@ } void -octave_scalar::print (ostream& os, bool pr_as_read_syntax) +octave_scalar::print (ostream& os, bool pr_as_read_syntax) const +{ + indent (os); + print_raw (os, pr_as_read_syntax); + newline (os); +} + +void +octave_scalar::print_raw (ostream& os, bool pr_as_read_syntax) const { octave_print_internal (os, scalar, pr_as_read_syntax); } +bool +octave_scalar::print_name_tag (ostream& os, const string& name) const +{ + indent (os); + os << name << " = "; + return false; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/ov-scalar.h +++ b/src/ov-scalar.h @@ -121,7 +121,11 @@ octave_value convert_to_str (void) const; - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-str-mat.cc +++ b/src/ov-str-mat.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include <iostream.h> + #include "lo-ieee.h" #include "mx-base.h" @@ -216,10 +218,38 @@ } void -octave_char_matrix_str::print (ostream& os, bool pr_as_read_syntax) +octave_char_matrix_str::print (ostream& os, bool pr_as_read_syntax) const +{ + indent (os); + print_raw (os, pr_as_read_syntax); + newline (os); +} + +void +octave_char_matrix_str::print_raw (ostream& os, bool pr_as_read_syntax) const { octave_print_internal (os, matrix, pr_as_read_syntax, true, - struct_indent); + current_print_indent_level ()); +} + +bool +octave_char_matrix_str::print_name_tag (ostream& os, const string& name) const +{ + bool retval = false; + + indent (os); + + if (rows () == 1) + os << name << " = "; + else + { + os << name << " ="; + newline (os); + newline (os); + retval = true; + } + + return retval; } /*
--- a/src/ov-str-mat.h +++ b/src/ov-str-mat.h @@ -108,7 +108,11 @@ octave_value hermitian (void) const { return octave_value (matrix.transpose (), true); } - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -65,7 +65,13 @@ } void -octave_struct::print (ostream& os, bool) +octave_struct::print (ostream& os, bool) const +{ + print_raw (os); +} + +void +octave_struct::print_raw (ostream& os, bool) const { // XXX FIXME XXX -- would be nice to print the output in some // standard order. Maybe all substructures first, maybe @@ -73,59 +79,49 @@ begin_unwind_frame ("octave_struct_print"); - unwind_protect_int (struct_indent); unwind_protect_int (Vstruct_levels_to_print); if (Vstruct_levels_to_print-- > 0) { - os.form ("\n%*s{\n", struct_indent, ""); - - increment_struct_indent (); + newline (os); + indent (os); + os << "{"; + newline (os); - Pix p = map.first (); + increment_indent_level (); - while (p) + for (Pix p = map.first (); p; map.next (p)) { - bool pad_after = false; - string key = map.key (p); octave_value val = map.contents (p); - map.next (p); - - os.form ("%*s%s =", struct_indent, "", key.c_str ()); - - if (val.print_as_scalar ()) - os << " "; - else if (val.is_map ()) - { - if (p) - pad_after = true; - } - else - { - if (p) - pad_after = true; - - os << "\n\n"; - } - - val.print (os); - - if (pad_after) - os << "\n"; + val.print_with_name (os, key); } - decrement_struct_indent (); + decrement_indent_level (); - os.form ("%*s%s", struct_indent, "", "}\n"); + indent (os); + os << "}"; + newline (os); } else - os << " <structure>\n"; + { + os << " <structure>"; + newline (os); + } run_unwind_frame ("octave_struct_print"); } +bool +octave_struct::print_name_tag (ostream& os, const string& name) const +{ + indent (os); + os << name << " ="; + newline (os); + return false; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/ov-struct.h +++ b/src/ov-struct.h @@ -83,7 +83,11 @@ Octave_map map_value (void) const { return map; } - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; int type_id (void) const { return t_id; }
--- a/src/ov-va-args.cc +++ b/src/ov-va-args.cc @@ -39,7 +39,14 @@ const string octave_all_va_args::t_name ("va-arg"); void -octave_all_va_args::print (ostream& os, bool) +octave_all_va_args::print (ostream& os, bool) const +{ + indent (os); + print (os); +} + +void +octave_all_va_args::print_raw (ostream& os, bool) const { os << "all_va_args"; }
--- a/src/ov-va-args.h +++ b/src/ov-va-args.h @@ -62,7 +62,9 @@ bool is_all_va_args (void) const { return true; } - void print (ostream& os, bool pr_as_read_syntax = false); + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; int type_id (void) const { return t_id; }