[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
showing structure names
From: |
John W. Eaton |
Subject: |
showing structure names |
Date: |
Mon, 3 Jun 2002 13:18:21 -0500 |
On 3-Jun-2002, Iago Mosqueira <address@hidden> wrote:
| I am trying to configure octave so that when I call an structure name I get
| to see the names of the matrices only. If I set struct_levels_to_print to 0,
| I get nothing but the structure name, but if I set it to 1 I get all the
| data. Can this be achieved?
The following patch (relative to the current CVS sources) allows the
follwoing behavior:
octave:1> x.a = 1;
octave:2> x.b = rand (100);
octave:3> struct_levels_to_print = 0;
octave:4> x
x =
{
a: scalar
b: matrix
}
octave:5> struct_levels_to_print = -1;
octave:6> x
x = <structure>
jwe
Index: ov-struct.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov-struct.cc,v
retrieving revision 1.21
diff -u -r1.21 ov-struct.cc
--- ov-struct.cc 15 May 2002 03:21:00 -0000 1.21
+++ ov-struct.cc 3 Jun 2002 18:15:22 -0000
@@ -379,8 +379,12 @@
unwind_protect_int (Vstruct_levels_to_print);
- if (Vstruct_levels_to_print-- > 0)
+ if (Vstruct_levels_to_print >= 0)
{
+ bool print_keys_only = (Vstruct_levels_to_print == 0);
+
+ Vstruct_levels_to_print--;
+
indent (os);
os << "{";
newline (os);
@@ -394,13 +398,16 @@
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_value tmp = (n == 1) ? val(0) : octave_list (val);
+
+ if (print_keys_only)
{
- octave_list tmp (val);
- tmp.print_with_name (os, key);
+ indent (os);
+ os << key << ": " << tmp.type_name ();
+ newline (os);
}
+ else
+ val(0).print_with_name (os, key);
}
decrement_indent_level ();
@@ -411,7 +418,8 @@
}
else
{
- os << " <structure>";
+ indent (os);
+ os << "<structure>";
newline (os);
}
@@ -421,10 +429,20 @@
bool
octave_struct::print_name_tag (std::ostream& os, const std::string& name) const
{
+ bool retval = false;
+
indent (os);
- os << name << " =";
- newline (os);
- return false;
+
+ if (Vstruct_levels_to_print < 0)
+ os << name << " = ";
+ else
+ {
+ os << name << " =";
+ newline (os);
+ retval = true;
+ }
+
+ return retval;
}
/*
Index: ov.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov.cc,v
retrieving revision 1.56
diff -u -r1.56 ov.cc
--- ov.cc 15 May 2002 03:21:01 -0000 1.56
+++ ov.cc 3 Jun 2002 18:15:22 -0000
@@ -1608,7 +1608,7 @@
&& ! xisnan (val))
{
int ival = NINT (val);
- if (ival >= 0 && ival == val)
+ if (ival == val)
{
Vstruct_levels_to_print = ival;
return 0;
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------