# HG changeset patch # User Carnë Draug # Date 1414110713 -3600 # Node ID 6c9ea5be96bfd0772723aac7db4ef2abfecd9cef # Parent 25f535b90e5295ad0d84f0550f06fd18f542c536 Change charMatrix to subclass charNDArray rather than be another Array. * chMatrix.h: both charMatrix and charNDArray are Array, the first being simply 2 dimensional. We change this so that charMatrix inherits from charNDArray instead. * chMatrix.cc: remove all constructors which are now inherited from charNDArray. * chNDArray.h, chNDArray.cc: implement all constructors here rather than calling charMatrix. Remove matrix_value() since a charMatrix constructor is now enough. * pr-output.cc, octave-value/ov-ch-mat.h, octave-value/ov-str-mat.cc: replace calls to charNDArray::matrix_value () with the charMatrix constructor. diff -r 25f535b90e52 -r 6c9ea5be96bf libinterp/corefcn/pr-output.cc --- a/libinterp/corefcn/pr-output.cc Mon Oct 20 01:34:52 2014 +0100 +++ b/libinterp/corefcn/pr-output.cc Fri Oct 24 01:31:53 2014 +0100 @@ -2842,7 +2842,7 @@ { case 1: case 2: - octave_print_internal (os, nda.matrix_value (), + octave_print_internal (os, charMatrix (nda), pr_as_read_syntax, extra_indent, pr_as_string); break; diff -r 25f535b90e52 -r 6c9ea5be96bf libinterp/octave-value/ov-ch-mat.h --- a/libinterp/octave-value/ov-ch-mat.h Mon Oct 20 01:34:52 2014 +0100 +++ b/libinterp/octave-value/ov-ch-mat.h Fri Oct 24 01:31:53 2014 +0100 @@ -107,10 +107,10 @@ { return float_value (frc_str_conv); } Matrix matrix_value (bool = false) const - { return Matrix (matrix.matrix_value ()); } + { return Matrix (charMatrix (matrix)); } FloatMatrix float_matrix_value (bool = false) const - { return FloatMatrix (matrix.matrix_value ()); } + { return FloatMatrix (charMatrix (matrix)); } NDArray array_value (bool = false) const { return NDArray (matrix); } @@ -123,10 +123,10 @@ FloatComplex float_complex_value (bool = false) const; ComplexMatrix complex_matrix_value (bool = false) const - { return ComplexMatrix (matrix.matrix_value ()); } + { return ComplexMatrix (charMatrix (matrix)); } FloatComplexMatrix float_complex_matrix_value (bool = false) const - { return FloatComplexMatrix (matrix.matrix_value ()); } + { return FloatComplexMatrix (charMatrix (matrix)); } ComplexNDArray complex_array_value (bool = false) const { return ComplexNDArray (matrix); } @@ -135,7 +135,7 @@ { return FloatComplexNDArray (matrix); } charMatrix char_matrix_value (bool = false) const - { return matrix.matrix_value (); } + { return charMatrix (matrix); } charNDArray char_array_value (bool = false) const { return matrix; } diff -r 25f535b90e52 -r 6c9ea5be96bf libinterp/octave-value/ov-str-mat.cc --- a/libinterp/octave-value/ov-str-mat.cc Mon Oct 20 01:34:52 2014 +0100 +++ b/libinterp/octave-value/ov-str-mat.cc Fri Oct 24 01:31:53 2014 +0100 @@ -211,7 +211,7 @@ if (matrix.ndims () == 2) { - charMatrix chm = matrix.matrix_value (); + charMatrix chm (matrix); octave_idx_type n = chm.rows (); @@ -233,7 +233,7 @@ if (matrix.ndims () == 2) { - charMatrix chm = matrix.matrix_value (); + charMatrix chm (matrix); retval = chm.row_as_string (0); // FIXME? } @@ -250,7 +250,7 @@ if (matrix.ndims () == 2) { - const charMatrix chm = matrix.matrix_value (); + const charMatrix chm (matrix); octave_idx_type nr = chm.rows (); retval.clear (nr, 1); for (octave_idx_type i = 0; i < nr; i++) diff -r 25f535b90e52 -r 6c9ea5be96bf liboctave/array/chMatrix.cc --- a/liboctave/array/chMatrix.cc Mon Oct 20 01:34:52 2014 +0100 +++ b/liboctave/array/chMatrix.cc Fri Oct 24 01:31:53 2014 +0100 @@ -39,55 +39,6 @@ // charMatrix class. -charMatrix::charMatrix (char c) - : Array () -{ - octave_idx_type nc = 1; - octave_idx_type nr = 1; - - resize (nr, nc); - - elem (0, 0) = c; -} - -charMatrix::charMatrix (const char *s) - : Array () -{ - octave_idx_type nc = s ? strlen (s) : 0; - octave_idx_type nr = s && nc > 0 ? 1 : 0; - - resize (nr, nc); - - for (octave_idx_type i = 0; i < nc; i++) - elem (0, i) = s[i]; -} - -charMatrix::charMatrix (const std::string& s) - : Array () -{ - octave_idx_type nc = s.length (); - octave_idx_type nr = nc > 0 ? 1 : 0; - - resize (nr, nc); - - for (octave_idx_type i = 0; i < nc; i++) - elem (0, i) = s[i]; -} - -charMatrix::charMatrix (const string_vector& s, char fill_value) - : Array (dim_vector (s.length (), s.max_length ()), fill_value) -{ - octave_idx_type nr = rows (); - - for (octave_idx_type i = 0; i < nr; i++) - { - const std::string si = s(i); - octave_idx_type nc = si.length (); - for (octave_idx_type j = 0; j < nc; j++) - elem (i, j) = si[j]; - } -} - bool charMatrix::operator == (const charMatrix& a) const { diff -r 25f535b90e52 -r 6c9ea5be96bf liboctave/array/chMatrix.h --- a/liboctave/array/chMatrix.h Mon Oct 20 01:34:52 2014 +0100 +++ b/liboctave/array/chMatrix.h Fri Oct 24 01:31:53 2014 +0100 @@ -27,6 +27,7 @@ #include #include "Array.h" +#include "chNDArray.h" #include "mx-defs.h" #include "mx-op-decl.h" @@ -34,35 +35,36 @@ class OCTAVE_API -charMatrix : public Array +charMatrix : public charNDArray { friend class ComplexMatrix; public: - charMatrix (void) : Array () { } + charMatrix (void) : charNDArray () { } charMatrix (octave_idx_type r, octave_idx_type c) - : Array (dim_vector (r, c)) { } + : charNDArray (dim_vector (r, c)) { } charMatrix (octave_idx_type r, octave_idx_type c, char val) - : Array (dim_vector (r, c), val) { } + : charNDArray (dim_vector (r, c), val) { } - charMatrix (const dim_vector& dv) : Array (dv) { } + charMatrix (const dim_vector& dv) : charNDArray (dv) { } - charMatrix (const dim_vector& dv, char val) : Array (dv, val) { } + charMatrix (const dim_vector& dv, char val) : charNDArray (dv, val) { } - charMatrix (const Array& a) : Array (a.as_matrix ()) { } + charMatrix (const Array& a) : charNDArray (a.as_matrix ()) { } - charMatrix (const charMatrix& a) : Array (a) { } + charMatrix (const charMatrix& a) : charNDArray (a) { } - charMatrix (char c); + charMatrix (char c) : charNDArray (c) {} - charMatrix (const char *s); + charMatrix (const char *s) : charNDArray (s) {} - charMatrix (const std::string& s); + charMatrix (const std::string& s) : charNDArray (s) {} - charMatrix (const string_vector& s, char fill_value = '\0'); + charMatrix (const string_vector& s, char fill_value = '\0') + : charNDArray (s, fill_value) {} charMatrix& operator = (const charMatrix& a) { diff -r 25f535b90e52 -r 6c9ea5be96bf liboctave/array/chNDArray.cc --- a/liboctave/array/chNDArray.cc Mon Oct 20 01:34:52 2014 +0100 +++ b/liboctave/array/chNDArray.cc Fri Oct 24 01:31:53 2014 +0100 @@ -25,15 +25,67 @@ #include #endif +#include + #include "Array-util.h" #include "chNDArray.h" #include "mx-base.h" #include "lo-ieee.h" #include "lo-mappers.h" #include "mx-op-defs.h" +#include "str-vec.h" #include "bsxfun-defs.cc" +charNDArray::charNDArray (char c) + : Array () +{ + octave_idx_type nc = 1; + octave_idx_type nr = 1; + + resize (nr, nc); + + elem (0, 0) = c; +} + +charNDArray::charNDArray (const char *s) + : Array () +{ + octave_idx_type nc = s ? strlen (s) : 0; + octave_idx_type nr = s && nc > 0 ? 1 : 0; + + resize (nr, nc); + + for (octave_idx_type i = 0; i < nc; i++) + elem (0, i) = s[i]; +} + +charNDArray::charNDArray (const std::string& s) + : Array () +{ + octave_idx_type nc = s.length (); + octave_idx_type nr = nc > 0 ? 1 : 0; + + resize (nr, nc); + + for (octave_idx_type i = 0; i < nc; i++) + elem (0, i) = s[i]; +} + +charNDArray::charNDArray (const string_vector& s, char fill_value) + : Array (dim_vector (s.length (), s.max_length ()), fill_value) +{ + octave_idx_type nr = rows (); + + for (octave_idx_type i = 0; i < nr; i++) + { + const std::string si = s(i); + octave_idx_type nc = si.length (); + for (octave_idx_type j = 0; j < nc; j++) + elem (i, j) = si[j]; + } +} + // FIXME: this is not quite the right thing. boolNDArray @@ -130,12 +182,6 @@ return *this; } -charMatrix -charNDArray::matrix_value (void) const -{ - return *this; -} - void charNDArray::increment_index (Array& ra_idx, const dim_vector& dimensions, diff -r 25f535b90e52 -r 6c9ea5be96bf liboctave/array/chNDArray.h --- a/liboctave/array/chNDArray.h Mon Oct 20 01:34:52 2014 +0100 +++ b/liboctave/array/chNDArray.h Fri Oct 24 01:31:53 2014 +0100 @@ -23,12 +23,14 @@ #if !defined (octave_chNDArray_h) #define octave_chNDArray_h 1 +#include + #include "Array.h" -#include "chMatrix.h" #include "mx-defs.h" #include "mx-op-decl.h" #include "bsxfun-decl.h" +#include "str-vec.h" class OCTAVE_API @@ -46,17 +48,15 @@ charNDArray (const charNDArray& a) : Array (a) { } - charNDArray (const charMatrix& a) : Array (a) { } + charNDArray (const Array& a) : Array (a) { } - charNDArray (char c) : Array (charMatrix (c)) { } - - charNDArray (const char *s) : Array (charMatrix (s)) { } + charNDArray (char c); - charNDArray (const std::string& s) : Array (charMatrix (s)) { } + charNDArray (const char *s); - charNDArray (const string_vector& s) : Array (charMatrix (s)) { } + charNDArray (const std::string& s); - charNDArray (const Array& a) : Array (a) { } + charNDArray (const string_vector& s, char fill_value = '\0'); charNDArray& operator = (const charNDArray& a) { @@ -84,8 +84,6 @@ charNDArray& insert (const charNDArray& a, const Array& ra_idx); - charMatrix matrix_value (void) const; - charNDArray squeeze (void) const { return Array::squeeze (); } static void increment_index (Array& ra_idx,