3978
|
1 /* |
|
2 |
|
3 Copyright (C) 2002 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include <iostream> |
|
28 |
4051
|
29 #include "lo-sstream.h" |
3978
|
30 #include "lo-utils.h" |
|
31 |
|
32 #include "defun.h" |
|
33 #include "error.h" |
|
34 #include "ov-cs-list.h" |
|
35 #include "unwind-prot.h" |
|
36 |
|
37 DEFINE_OCTAVE_ALLOCATOR (octave_cs_list); |
|
38 |
4612
|
39 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cs_list, "cs-list", "cs-list"); |
3978
|
40 |
4591
|
41 octave_cs_list::octave_cs_list (const Cell& c) |
4664
|
42 : octave_base_value (), lst () |
3978
|
43 { |
4591
|
44 int n = c.length (); |
3978
|
45 |
4591
|
46 lst.resize (n); |
3978
|
47 |
4591
|
48 for (int i = 0; i < n; i++) |
|
49 lst(i) = c(i); |
3978
|
50 } |
|
51 |
|
52 void |
4604
|
53 octave_cs_list::print (std::ostream& os, bool) const |
|
54 { |
|
55 print_raw (os); |
|
56 } |
|
57 |
|
58 void |
4499
|
59 octave_cs_list::print_raw (std::ostream& os, bool) const |
3978
|
60 { |
4591
|
61 unwind_protect::begin_frame ("octave_cs_list_print"); |
3978
|
62 |
|
63 int n = lst.length (); |
|
64 |
|
65 if (n > 0) |
|
66 { |
|
67 indent (os); |
4499
|
68 os << "(,"; |
3978
|
69 newline (os); |
|
70 |
|
71 increment_indent_level (); |
|
72 |
|
73 for (int i = 0; i < n; i++) |
|
74 { |
4051
|
75 OSSTREAM buf; |
|
76 buf << "[" << i+1 << "]" << OSSTREAM_ENDS; |
3978
|
77 |
|
78 octave_value val = lst(i); |
|
79 |
4051
|
80 val.print_with_name (os, OSSTREAM_STR (buf)); |
3978
|
81 |
4051
|
82 OSSTREAM_FREEZE (buf); |
3978
|
83 } |
|
84 |
|
85 decrement_indent_level (); |
|
86 |
|
87 indent (os); |
4499
|
88 os << ",)"; |
3978
|
89 } |
|
90 else |
4499
|
91 os << "(,,)"; |
3978
|
92 |
|
93 newline (os); |
|
94 |
4591
|
95 unwind_protect::run_frame ("octave_cs_list_print"); |
3978
|
96 } |
|
97 |
|
98 /* |
|
99 ;;; Local Variables: *** |
|
100 ;;; mode: C++ *** |
|
101 ;;; End: *** |
|
102 */ |