2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 #if !defined (octave_struct_h) |
|
24 #define octave_struct_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
3503
|
32 #include <iostream> |
2376
|
33 #include <string> |
|
34 |
|
35 #include "mx-base.h" |
|
36 #include "str-vec.h" |
|
37 |
|
38 #include "error.h" |
2477
|
39 #include "oct-alloc.h" |
2376
|
40 #include "oct-map.h" |
|
41 #include "ov-base.h" |
|
42 #include "ov-typeinfo.h" |
|
43 |
|
44 class Octave_map; |
|
45 class octave_value_list; |
|
46 |
|
47 class tree_walker; |
|
48 |
2477
|
49 // Data structures. |
2376
|
50 |
|
51 class |
|
52 octave_struct : public octave_base_value |
|
53 { |
|
54 public: |
|
55 |
|
56 octave_struct (void) |
|
57 : octave_base_value () { } |
|
58 |
|
59 octave_struct (const Octave_map& m) |
|
60 : octave_base_value (), map (m) { } |
|
61 |
|
62 octave_struct (const octave_struct& s) |
|
63 : octave_base_value (), map (s.map) { } |
|
64 |
|
65 ~octave_struct (void) { } |
|
66 |
3933
|
67 octave_value *clone (void) const { return new octave_struct (*this); } |
|
68 octave_value *empty_clone (void) const { return new octave_struct (); } |
|
69 |
|
70 octave_value_list dotref (const octave_value_list& idx); |
2376
|
71 |
3933
|
72 octave_value subsref (const std::string type, |
|
73 const SLList<octave_value_list>& idx); |
2962
|
74 |
3933
|
75 static octave_value numeric_conv (const octave_value_list& val, |
|
76 const std::string& type); |
2376
|
77 |
3933
|
78 octave_value subsasgn (const std::string type, |
|
79 const SLList<octave_value_list>& idx, |
|
80 const octave_value& rhs); |
2376
|
81 |
4200
|
82 int rows (void) const { return map.rows (); } |
|
83 |
|
84 int columns (void) const { return map.columns (); } |
|
85 |
|
86 int length (void) const |
|
87 { |
|
88 int r = rows (); |
|
89 int c = columns (); |
|
90 |
|
91 return (r == 0 || c == 0) ? 0 : ((r > c) ? r : c); |
|
92 } |
|
93 |
2376
|
94 bool is_defined (void) const { return true; } |
|
95 |
3933
|
96 bool is_constant (void) const { return true; } |
2974
|
97 |
2376
|
98 bool is_map (void) const { return true; } |
|
99 |
|
100 Octave_map map_value (void) const { return map; } |
|
101 |
3933
|
102 string_vector map_keys (void) const { return map.keys (); } |
|
103 |
3523
|
104 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
105 |
3523
|
106 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
107 |
3523
|
108 bool print_name_tag (std::ostream& os, const std::string& name) const; |
2376
|
109 |
|
110 private: |
|
111 |
2477
|
112 // The associative array used to manage the structure data. |
2376
|
113 Octave_map map; |
|
114 |
3219
|
115 DECLARE_OCTAVE_ALLOCATOR |
2477
|
116 |
3219
|
117 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
118 }; |
|
119 |
|
120 #endif |
|
121 |
|
122 /* |
|
123 ;;; Local Variables: *** |
|
124 ;;; mode: C++ *** |
|
125 ;;; End: *** |
|
126 */ |