7338
|
1 /* |
|
2 |
|
3 Copyright (C) 2007 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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_class_h) |
|
25 #define octave_class_h 1 |
|
26 |
|
27 #include <cstdlib> |
|
28 |
|
29 #include <iostream> |
|
30 #include <string> |
|
31 |
|
32 #include "mx-base.h" |
|
33 #include "str-vec.h" |
|
34 |
|
35 #include "error.h" |
|
36 #include "oct-alloc.h" |
|
37 #include "oct-map.h" |
|
38 #include "ov-base.h" |
|
39 #include "ov-typeinfo.h" |
|
40 |
|
41 class octave_value_list; |
|
42 |
|
43 class tree_walker; |
|
44 |
|
45 // Data structures. |
|
46 |
|
47 class |
|
48 octave_class : public octave_base_value |
|
49 { |
|
50 public: |
|
51 |
|
52 octave_class (void) |
|
53 : octave_base_value () { } |
|
54 |
|
55 octave_class (const Octave_map& m, const std::string& id) |
|
56 : octave_base_value (), map (m), c_name (id) { } |
|
57 |
|
58 octave_class (const octave_class& s) |
|
59 : octave_base_value (s), map (s.map), c_name (s.c_name) { } |
|
60 |
|
61 ~octave_class (void) { } |
|
62 |
|
63 octave_base_value *clone (void) const { return new octave_class (*this); } |
|
64 octave_base_value *empty_clone (void) const { return new octave_class (); } |
|
65 |
|
66 Cell dotref (const octave_value_list& idx); |
|
67 |
|
68 octave_value subsref (const std::string&, |
|
69 const std::list<octave_value_list>&) |
|
70 { |
|
71 panic_impossible (); |
|
72 return octave_value_list (); |
|
73 } |
|
74 |
|
75 octave_value_list subsref (const std::string& type, |
|
76 const std::list<octave_value_list>& idx, |
|
77 int nargout); |
|
78 |
|
79 static octave_value numeric_conv (const Cell& val, |
|
80 const std::string& type); |
|
81 |
|
82 octave_value subsasgn (const std::string& type, |
|
83 const std::list<octave_value_list>& idx, |
|
84 const octave_value& rhs); |
|
85 |
|
86 dim_vector dims (void) const { return map.dims (); } |
|
87 |
|
88 size_t byte_size (void) const; |
|
89 |
|
90 // This is the number of elements in each field. The total number |
|
91 // of elements is numel () * nfields (). |
|
92 octave_idx_type numel (void) const |
|
93 { |
|
94 dim_vector dv = dims (); |
|
95 return dv.numel (); |
|
96 } |
|
97 |
|
98 octave_idx_type nfields (void) const { return map.nfields (); } |
|
99 |
|
100 octave_value reshape (const dim_vector& new_dims) const |
|
101 { return map.reshape (new_dims); } |
|
102 |
|
103 octave_value resize (const dim_vector& dv, bool = false) const |
|
104 { Octave_map tmap = map; tmap.resize (dv); return tmap; } |
|
105 |
|
106 bool is_defined (void) const { return true; } |
|
107 |
|
108 bool is_map (void) const { return false; } |
|
109 |
|
110 bool is_object (void) const { return true; } |
|
111 |
|
112 Octave_map map_value (void) const; |
|
113 |
|
114 string_vector map_keys (void) const; |
|
115 |
|
116 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
117 |
|
118 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
119 |
|
120 bool print_name_tag (std::ostream& os, const std::string& name) const; |
|
121 |
|
122 void print_with_name (std::ostream& os, const std::string& name, |
|
123 bool print_padding = true) const; |
|
124 |
|
125 bool save_ascii (std::ostream& os, bool& infnan_warned); |
|
126 |
|
127 bool load_ascii (std::istream& is); |
|
128 |
|
129 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
130 |
|
131 bool load_binary (std::istream& is, bool swap, |
|
132 oct_mach_info::float_format fmt); |
|
133 |
|
134 #if defined (HAVE_HDF5) |
|
135 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
136 |
|
137 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
138 #endif |
|
139 |
|
140 mxArray *as_mxArray (void) const; |
|
141 |
|
142 private: |
|
143 |
|
144 Octave_map map; |
|
145 |
|
146 DECLARE_OCTAVE_ALLOCATOR |
|
147 |
|
148 public: |
|
149 int type_id (void) const { return t_id; } |
|
150 std::string type_name (void) const { return t_name; } |
|
151 std::string class_name (void) const { return c_name; } |
|
152 |
|
153 static int static_type_id (void) { return t_id; } |
|
154 static std::string static_type_name (void) { return t_name; } |
|
155 static std::string static_class_name (void) { return "<unknown>"; } |
|
156 static void register_type (void); |
|
157 |
|
158 private: |
|
159 static int t_id; |
|
160 |
|
161 static const std::string t_name; |
|
162 std::string c_name; |
|
163 |
|
164 bool in_class_method (void) const; |
|
165 }; |
|
166 |
|
167 #endif |
|
168 |
|
169 /* |
|
170 ;;; Local Variables: *** |
|
171 ;;; mode: C++ *** |
|
172 ;;; End: *** |
|
173 */ |