comparison src/variables.h @ 2953:ca7d3625ee01

[project @ 1997-05-09 14:56:52 by jwe]
author jwe
date Fri, 09 May 1997 14:57:34 +0000
parents 49b42be38aa1
children ac3368dba5d3
comparison
equal deleted inserted replaced
2952:c4bc40161199 2953:ca7d3625ee01
36 class string_vector; 36 class string_vector;
37 37
38 #include <string> 38 #include <string>
39 39
40 #include "ov.h" 40 #include "ov.h"
41 41 #include "symtab.h"
42 typedef int (*sv_Function)(void);
43 42
44 struct builtin_variable 43 struct builtin_variable
45 { 44 {
46 builtin_variable (const string& n, const octave_value& v, bool iaf, 45 builtin_variable (const string& n, const octave_value& v, bool iaf,
47 bool p, bool e, sv_Function svf, const string& h) 46 bool p, bool e, sv_Function svf, const string& h)
48 : name (n), value (v), install_as_function (iaf), protect (p), 47 : name (n), value (v), install_as_function (iaf), protect (p),
49 eternal (e), sv_function (svf), help_string (h) { } 48 eternal (e), sv_fcn (svf), help_string (h) { }
50 49
51 string name; 50 string name;
52 octave_value value; 51 octave_value value;
53 bool install_as_function; 52 bool install_as_function;
54 bool protect; 53 bool protect;
55 bool eternal; 54 bool eternal;
56 sv_Function sv_function; 55 symbol_record::sv_function sv_fcn;
57 string help_string; 56 string help_string;
58 };
59
60 class
61 octave_variable_reference
62 {
63 public:
64
65 octave_variable_reference (octave_value *v = 0, sv_Function f = 0)
66 : val (v), chg_fcn (f), struct_elt_name () { }
67
68 octave_variable_reference (octave_value *v, const string& nm,
69 sv_Function f = 0)
70 : val (v), chg_fcn (f), struct_elt_name (nm) { }
71
72 octave_variable_reference (const octave_variable_reference& vr)
73 : val (vr.val), chg_fcn (vr.chg_fcn),
74 struct_elt_name (vr.struct_elt_name) { }
75
76 octave_variable_reference& operator = (const octave_variable_reference& vr)
77 {
78 if (this != &vr)
79 {
80 val = vr.val;
81 chg_fcn = vr.chg_fcn;
82 struct_elt_name = vr.struct_elt_name;
83 }
84
85 return *this;
86 }
87
88 ~octave_variable_reference (void) { }
89
90 bool is_undefined (void) { return val->is_undefined (); }
91
92 void define (const octave_value& v) { *val = v; }
93
94 void assign (octave_value::assign_op, const octave_value&);
95
96 void assign (octave_value::assign_op, const octave_value_list&,
97 const octave_value&);
98
99 octave_variable_reference struct_elt_ref (const string& nm)
100 { return val->struct_elt_ref (nm); }
101
102 void increment (void) { val->increment (); }
103
104 void decrement (void) { val->decrement (); }
105
106 octave_value value (void)
107 {
108 return struct_elt_name.empty ()
109 ? *val : val->struct_elt_val (struct_elt_name);
110 }
111
112 private:
113
114 octave_value *val;
115
116 sv_Function chg_fcn;
117
118 string struct_elt_name;
119 }; 57 };
120 58
121 typedef octave_value_list (*Octave_builtin_fcn)(const octave_value_list&, int); 59 typedef octave_value_list (*Octave_builtin_fcn)(const octave_value_list&, int);
122 60
123 extern void initialize_symbol_tables (void); 61 extern void initialize_symbol_tables (void);
194 extern void clear_global_error_variable (void *); 132 extern void clear_global_error_variable (void *);
195 133
196 extern void 134 extern void
197 bind_builtin_variable (const string&, const octave_value&, 135 bind_builtin_variable (const string&, const octave_value&,
198 bool protect = false, bool eternal = false, 136 bool protect = false, bool eternal = false,
199 sv_Function f = (sv_Function) 0, 137 symbol_record::sv_function f = 0,
200 const string& help = string ()); 138 const string& help = string ());
201 139
202 // Symbol table for symbols at the top level. 140 // Symbol table for symbols at the top level.
203 extern symbol_table *top_level_sym_tab; 141 extern symbol_table *top_level_sym_tab;
204 142