00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_base_scalar_h)
00025 #define octave_base_scalar_h 1
00026
00027 #include <cstdlib>
00028
00029 #include <iosfwd>
00030 #include <string>
00031
00032 #include "lo-mappers.h"
00033 #include "lo-utils.h"
00034 #include "oct-alloc.h"
00035 #include "str-vec.h"
00036 #include "MatrixType.h"
00037
00038 #include "ov-base.h"
00039 #include "ov-typeinfo.h"
00040
00041
00042
00043 template <class ST>
00044 class
00045 octave_base_scalar : public octave_base_value
00046 {
00047 public:
00048
00049 octave_base_scalar (void)
00050 : octave_base_value () { }
00051
00052 octave_base_scalar (const ST& s)
00053 : octave_base_value (), scalar (s) { }
00054
00055 octave_base_scalar (const octave_base_scalar& s)
00056 : octave_base_value (), scalar (s.scalar) { }
00057
00058 ~octave_base_scalar (void) { }
00059
00060 octave_base_value *clone (void) const { return new octave_base_scalar (*this); }
00061 octave_base_value *empty_clone (void) const { return new octave_base_scalar (); }
00062
00063 octave_value squeeze (void) const { return scalar; }
00064
00065 octave_value full_value (void) const { return scalar; }
00066
00067 octave_value subsref (const std::string& type,
00068 const std::list<octave_value_list>& idx);
00069
00070 octave_value_list subsref (const std::string& type,
00071 const std::list<octave_value_list>& idx, int)
00072 { return subsref (type, idx); }
00073
00074 octave_value subsasgn (const std::string& type,
00075 const std::list<octave_value_list>& idx,
00076 const octave_value& rhs);
00077
00078 bool is_constant (void) const { return true; }
00079
00080 bool is_defined (void) const { return true; }
00081
00082 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; }
00083
00084 octave_idx_type nnz (void) const { return (scalar != ST ()) ? 1 : 0; }
00085
00086 octave_value permute (const Array<int>&, bool = false) const
00087 { return scalar; }
00088
00089 octave_value reshape (const dim_vector& new_dims) const
00090 { return array_value ().reshape (new_dims); }
00091
00092 size_t byte_size (void) const { return sizeof (ST); }
00093
00094 octave_value all (int = 0) const { return (scalar != ST ()); }
00095
00096 octave_value any (int = 0) const { return (scalar != ST ()); }
00097
00098 octave_value diag (octave_idx_type k = 0) const
00099 { return octave_value (matrix_value (). diag (k)); }
00100
00101 octave_value sort (octave_idx_type, sortmode) const
00102 { return octave_value (scalar); }
00103 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type,
00104 sortmode) const
00105 {
00106 sidx.resize (dim_vector (1, 1));
00107 sidx(0) = 0;
00108 return octave_value (scalar);
00109 }
00110
00111 sortmode is_sorted (sortmode mode = UNSORTED) const
00112 { return mode ? mode : ASCENDING; }
00113
00114 Array<octave_idx_type> sort_rows_idx (sortmode) const
00115 { return Array<octave_idx_type> (1, 0); }
00116
00117 sortmode is_sorted_rows (sortmode mode = UNSORTED) const
00118 { return mode ? mode : ASCENDING; }
00119
00120 MatrixType matrix_type (void) const { return MatrixType::Diagonal; }
00121 MatrixType matrix_type (const MatrixType&) const
00122 { return matrix_type (); }
00123
00124 bool is_scalar_type (void) const { return true; }
00125
00126 bool is_numeric_type (void) const { return true; }
00127
00128 bool is_true (void) const;
00129
00130 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
00131
00132 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00133
00134 bool print_name_tag (std::ostream& os, const std::string& name) const;
00135
00136
00137
00138 void *mex_get_data (void) const { return const_cast<ST *> (&scalar); }
00139
00140 protected:
00141
00142
00143 ST scalar;
00144 };
00145
00146 #endif
00147
00148
00149
00150
00151
00152