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 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
|
32 #include <string> |
|
33 |
|
34 class ostream; |
|
35 |
|
36 #include "mx-base.h" |
|
37 #include "str-vec.h" |
|
38 |
|
39 #include "error.h" |
2477
|
40 #include "oct-alloc.h" |
2376
|
41 #include "oct-map.h" |
|
42 #include "ov-base.h" |
|
43 #include "ov-typeinfo.h" |
|
44 |
|
45 class Octave_map; |
|
46 class octave_value_list; |
|
47 |
|
48 class tree_walker; |
|
49 |
2477
|
50 // Data structures. |
2376
|
51 |
|
52 class |
|
53 octave_struct : public octave_base_value |
|
54 { |
|
55 public: |
|
56 |
|
57 octave_struct (void) |
|
58 : octave_base_value () { } |
|
59 |
|
60 octave_struct (const Octave_map& m) |
|
61 : octave_base_value (), map (m) { } |
|
62 |
|
63 octave_struct (const octave_struct& s) |
|
64 : octave_base_value (), map (s.map) { } |
|
65 |
|
66 ~octave_struct (void) { } |
|
67 |
|
68 octave_value *clone (void) { return new octave_struct (*this); } |
|
69 |
2477
|
70 void *operator new (size_t size) |
|
71 { return allocator.alloc (size); } |
|
72 |
|
73 void operator delete (void *p, size_t size) |
|
74 { allocator.free (p, size); } |
2376
|
75 |
2962
|
76 octave_value |
|
77 do_struct_elt_index_op (const string& nm, const octave_value_list& idx, |
|
78 bool silent); |
|
79 |
|
80 octave_value do_struct_elt_index_op (const string& nm, bool silent); |
2376
|
81 |
2948
|
82 octave_variable_reference |
|
83 struct_elt_ref (octave_value *parent, const string& nm); |
2376
|
84 |
|
85 bool is_defined (void) const { return true; } |
|
86 |
2974
|
87 bool is_constant (void) const { return false; } |
|
88 |
2376
|
89 bool is_map (void) const { return true; } |
|
90 |
|
91 Octave_map map_value (void) const { return map; } |
|
92 |
2901
|
93 void print (ostream& os, bool pr_as_read_syntax = false) const; |
|
94 |
|
95 void print_raw (ostream& os, bool pr_as_read_syntax = false) const; |
|
96 |
|
97 bool print_name_tag (ostream& os, const string& name) const; |
2376
|
98 |
|
99 int type_id (void) const { return t_id; } |
|
100 |
|
101 string type_name (void) const { return t_name; } |
|
102 |
|
103 static int static_type_id (void) { return t_id; } |
|
104 |
|
105 static void register_type (void) |
|
106 { t_id = octave_value_typeinfo::register_type (t_name); } |
|
107 |
|
108 private: |
|
109 |
2477
|
110 // The associative array used to manage the structure data. |
2376
|
111 Octave_map map; |
|
112 |
2477
|
113 // For custom memory management. |
|
114 static octave_allocator allocator; |
|
115 |
|
116 // Type id of struct objects, set by register_type(). |
2376
|
117 static int t_id; |
|
118 |
2477
|
119 // Type name of struct objects, defined in ov-struct.cc. |
2376
|
120 static const string t_name; |
|
121 }; |
|
122 |
|
123 #endif |
|
124 |
|
125 /* |
|
126 ;;; Local Variables: *** |
|
127 ;;; mode: C++ *** |
|
128 ;;; End: *** |
|
129 */ |