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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3978
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <iostream> |
5765
|
29 #include <sstream> |
3978
|
30 |
|
31 #include "lo-utils.h" |
|
32 |
|
33 #include "defun.h" |
|
34 #include "error.h" |
|
35 #include "ov-cs-list.h" |
|
36 #include "unwind-prot.h" |
|
37 |
|
38 DEFINE_OCTAVE_ALLOCATOR (octave_cs_list); |
|
39 |
4612
|
40 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cs_list, "cs-list", "cs-list"); |
3978
|
41 |
4591
|
42 octave_cs_list::octave_cs_list (const Cell& c) |
4664
|
43 : octave_base_value (), lst () |
3978
|
44 { |
5275
|
45 octave_idx_type n = c.length (); |
3978
|
46 |
4591
|
47 lst.resize (n); |
3978
|
48 |
5275
|
49 for (octave_idx_type i = 0; i < n; i++) |
4591
|
50 lst(i) = c(i); |
3978
|
51 } |
|
52 |
|
53 void |
4604
|
54 octave_cs_list::print (std::ostream& os, bool) const |
|
55 { |
|
56 print_raw (os); |
|
57 } |
|
58 |
|
59 void |
4499
|
60 octave_cs_list::print_raw (std::ostream& os, bool) const |
3978
|
61 { |
4591
|
62 unwind_protect::begin_frame ("octave_cs_list_print"); |
3978
|
63 |
5275
|
64 octave_idx_type n = lst.length (); |
3978
|
65 |
|
66 if (n > 0) |
|
67 { |
|
68 indent (os); |
4499
|
69 os << "(,"; |
3978
|
70 newline (os); |
|
71 |
|
72 increment_indent_level (); |
|
73 |
5275
|
74 for (octave_idx_type i = 0; i < n; i++) |
3978
|
75 { |
5765
|
76 std::ostringstream buf; |
|
77 buf << "[" << i+1 << "]"; |
3978
|
78 |
|
79 octave_value val = lst(i); |
|
80 |
5765
|
81 val.print_with_name (os, buf.str ()); |
3978
|
82 } |
|
83 |
|
84 decrement_indent_level (); |
|
85 |
|
86 indent (os); |
4499
|
87 os << ",)"; |
3978
|
88 } |
|
89 else |
4499
|
90 os << "(,,)"; |
3978
|
91 |
|
92 newline (os); |
|
93 |
4591
|
94 unwind_protect::run_frame ("octave_cs_list_print"); |
3978
|
95 } |
|
96 |
|
97 /* |
|
98 ;;; Local Variables: *** |
|
99 ;;; mode: C++ *** |
|
100 ;;; End: *** |
|
101 */ |