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