Mercurial > hg > octave-nkf
diff src/ov-fcn-handle.h @ 4654:a9b22513b7a6
[project @ 2003-11-24 18:56:35 by jwe]
author | jwe |
---|---|
date | Mon, 24 Nov 2003 18:56:35 +0000 |
parents | f7ce581b27fb |
children | c8829691db47 |
line wrap: on
line diff
--- a/src/ov-fcn-handle.h +++ b/src/ov-fcn-handle.h @@ -33,48 +33,39 @@ #include "oct-alloc.h" #include "ov-base.h" +#include "ov-base-mat.h" #include "ov-fcn.h" +#include "ov-typeinfo.h" #include "symtab.h" // Function handles. -class -octave_fcn_handle : public octave_base_value +class fcn_handle_elt { public: - octave_fcn_handle (void) : fcn (0), nm ("[]") { } + fcn_handle_elt (void) : fcn (0), nm ("@[]") { } - octave_fcn_handle (octave_function *f, const std::string& n) + fcn_handle_elt (octave_function *f, const std::string& n) : fcn (f), nm (std::string ("@") + n) { } - octave_fcn_handle (const octave_fcn_handle& fh) - : fcn (fh.fcn), nm (fh.nm) { } + fcn_handle_elt (const fcn_handle_elt& fhe) + : fcn (fhe.fcn), nm (fhe.nm) { } - octave_fcn_handle& operator = (const octave_fcn_handle& fh) + fcn_handle_elt& operator = (const fcn_handle_elt& fhe) { - if (this != &fh) + if (this != &fhe) { - fcn = fh.fcn; - nm = fh.nm; + fcn = fhe.fcn; + nm = fhe.nm; } return *this; } - ~octave_fcn_handle (void) { } - - bool is_defined (void) const { return fcn; } - - octave_function *function_value (bool) { return fcn; } + ~fcn_handle_elt (void) { } - octave_fcn_handle *fcn_handle_value (bool) { return this; } - - bool print_as_scalar (void) const { return true; } - - void print (std::ostream& os, bool pr_as_read_syntax = false) const; - - void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; + octave_function *function_value (void) { return fcn; } std::string name (void) const { return nm; } @@ -85,6 +76,99 @@ // The name of the handle, including the "@". std::string nm; +}; + +class fcn_handle_array : public ArrayN<fcn_handle_elt> +{ +public: + + fcn_handle_array (void) : ArrayN<fcn_handle_elt> () { } + + fcn_handle_array (const dim_vector& dv, + const fcn_handle_elt& val = resize_fill_value ()) + : ArrayN<fcn_handle_elt> (dv, val) { } + + fcn_handle_array (octave_function *f, const std::string& nm) + : ArrayN<fcn_handle_elt> (dim_vector (1, 1), fcn_handle_elt (f, nm)) { } + + fcn_handle_array (const ArrayN<fcn_handle_elt>& fa) + : ArrayN<fcn_handle_elt> (fa) { } + + fcn_handle_array (const fcn_handle_array& fa) + : ArrayN<fcn_handle_elt> (fa) { } + + ~fcn_handle_array (void) { } + + fcn_handle_array& operator = (const fcn_handle_array& fa) + { + if (this != &fa) + ArrayN<fcn_handle_elt>::operator = (fa); + + return *this; + } + + fcn_handle_array squeeze (void) const + { return ArrayN<fcn_handle_elt>::squeeze (); } + + boolNDArray all (int dim = -1) const; + boolNDArray any (int dim = -1) const; + + ArrayN<std::string> names (void) const; + + static int compute_index (Array<int>& ra_idx, + const dim_vector& dimensions); + + static fcn_handle_elt resize_fill_value (void) + { + static fcn_handle_elt nil_handle = fcn_handle_elt (); + return nil_handle; + } +}; + +class +octave_fcn_handle : public octave_base_matrix<fcn_handle_array> +{ +public: + + octave_fcn_handle (void) + : octave_base_matrix<fcn_handle_array> () { } + + octave_fcn_handle (octave_function *f, const std::string& n) + : octave_base_matrix<fcn_handle_array> + (fcn_handle_array (dim_vector (1, 1), fcn_handle_elt (f, n))) { } + + octave_fcn_handle (const fcn_handle_array& fha) + : octave_base_matrix<fcn_handle_array> (fha) { } + + octave_fcn_handle (const octave_fcn_handle& fh) + : octave_base_matrix<fcn_handle_array> (fh) { } + + ~octave_fcn_handle (void) { } + + octave_value *clone (void) const { return new octave_fcn_handle (*this); } + octave_value *empty_clone (void) const { return new octave_fcn_handle (); } + + bool is_defined (void) const { return true; } + + bool is_function_handle (void) const { return true; } + + octave_function *function_value (bool = false); + + std::string name (void) const; + + octave_fcn_handle *fcn_handle_value (bool = false) { return this; } + + fcn_handle_array fcn_handle_array_value (void) const { return matrix; } + + ArrayN<std::string> name_array (void) const { return matrix.names (); } + + bool print_as_scalar (void) const { return true; } + + void print (std::ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; + +private: DECLARE_OCTAVE_ALLOCATOR