# HG changeset patch
# User Carnë Draug <carandraug@octave.org>
# Date 1413765292 -3600
#      Mon Oct 20 01:34:52 2014 +0100
# Node ID 1918edd05fe8398c44ccb338140fe9797d9d5c33
# Parent  238522618904afe1cfe9844a05f805e9e53dc308
Change boolMatrix to subclass boolNDArray rather than be another Array<bool>.

* boolMatrix.h: both boolMatrix and boolNDArray are Array<bool>, the first
being simply 2 dimensional. We change this so that boolMatrix inherits from
boolNDArray instead.
* boolNDArray.cc, boolNDArray.h (boolNDArray::matrix_value): remove method
since boolMatrix can be constructed from its parent.
(boolNDArray::boolNDArray): remove constructor from boolMatrix
* pr-output.cc, octave-value/ov-bool-mat.cc, octave-value/ov-bool-mat.h:
replace calls to boolNDArray::matrix_value () with the boolMatrix constructor.

diff -r 238522618904 -r 1918edd05fe8 libinterp/corefcn/pr-output.cc
--- a/libinterp/corefcn/pr-output.cc	Wed Oct 29 08:21:24 2014 -0700
+++ b/libinterp/corefcn/pr-output.cc	Mon Oct 20 01:34:52 2014 +0100
@@ -2775,7 +2775,7 @@
     {
     case 1:
     case 2:
-      octave_print_internal (os, nda.matrix_value (),
+      octave_print_internal (os, boolMatrix (nda),
                              pr_as_read_syntax, extra_indent);
       break;
 
diff -r 238522618904 -r 1918edd05fe8 libinterp/octave-value/ov-bool-mat.cc
--- a/libinterp/octave-value/ov-bool-mat.cc	Wed Oct 29 08:21:24 2014 -0700
+++ b/libinterp/octave-value/ov-bool-mat.cc	Mon Oct 20 01:34:52 2014 +0100
@@ -79,7 +79,7 @@
 
   if (matrix.ndims () == 2)
     {
-      boolMatrix bm = matrix.matrix_value ();
+      boolMatrix bm (matrix);
 
       octave_idx_type nr = bm.rows ();
       octave_idx_type nc = bm.cols ();
diff -r 238522618904 -r 1918edd05fe8 libinterp/octave-value/ov-bool-mat.h
--- a/libinterp/octave-value/ov-bool-mat.h	Wed Oct 29 08:21:24 2014 -0700
+++ b/libinterp/octave-value/ov-bool-mat.h	Mon Oct 20 01:34:52 2014 +0100
@@ -135,10 +135,10 @@
   { return double_value (frc_str_conv); }
 
   Matrix matrix_value (bool = false) const
-  { return Matrix (matrix.matrix_value ()); }
+  { return Matrix (boolMatrix (matrix)); }
 
   FloatMatrix float_matrix_value (bool = false) const
-  { return FloatMatrix (matrix.matrix_value ()); }
+  { return FloatMatrix (boolMatrix (matrix)); }
 
   NDArray array_value (bool = false) const
   { return NDArray (matrix); }
@@ -151,10 +151,10 @@
   FloatComplex float_complex_value (bool = false) const;
 
   ComplexMatrix complex_matrix_value (bool = false) const
-  { return ComplexMatrix (matrix.matrix_value ()); }
+  { return ComplexMatrix (boolMatrix (matrix)); }
 
   FloatComplexMatrix float_complex_matrix_value (bool = false) const
-  { return FloatComplexMatrix (matrix.matrix_value ()); }
+  { return FloatComplexMatrix (boolMatrix (matrix)); }
 
   ComplexNDArray complex_array_value (bool = false) const
   { return ComplexNDArray (matrix); }
@@ -176,19 +176,19 @@
   }
 
   boolMatrix bool_matrix_value (bool = false) const
-  { return matrix.matrix_value (); }
+  { return boolMatrix (matrix); }
 
   boolNDArray bool_array_value (bool = false) const
   { return matrix; }
 
   SparseMatrix sparse_matrix_value (bool = false) const
-  { return SparseMatrix (Matrix (matrix.matrix_value ())); }
+  { return SparseMatrix (Matrix (boolMatrix (matrix))); }
 
   SparseComplexMatrix sparse_complex_matrix_value (bool = false) const
-  { return SparseComplexMatrix (ComplexMatrix (matrix.matrix_value ())); }
+  { return SparseComplexMatrix (ComplexMatrix (boolMatrix (matrix))); }
 
   SparseBoolMatrix sparse_bool_matrix_value (bool = false) const
-  { return SparseBoolMatrix (matrix.matrix_value ()); }
+  { return SparseBoolMatrix (boolMatrix (matrix)); }
 
   octave_value convert_to_str_internal (bool pad, bool force, char type) const;
 
diff -r 238522618904 -r 1918edd05fe8 liboctave/array/boolMatrix.h
--- a/liboctave/array/boolMatrix.h	Wed Oct 29 08:21:24 2014 -0700
+++ b/liboctave/array/boolMatrix.h	Mon Oct 20 01:34:52 2014 +0100
@@ -25,31 +25,32 @@
 #define octave_boolMatrix_h 1
 
 #include "Array.h"
+#include "boolNDArray.h"
 
 #include "mx-defs.h"
 #include "mx-op-decl.h"
 
 class
 OCTAVE_API
-boolMatrix : public Array<bool>
+boolMatrix : public boolNDArray
 {
 public:
 
-  boolMatrix (void) : Array<bool> () { }
+  boolMatrix (void) : boolNDArray () { }
 
   boolMatrix (octave_idx_type r, octave_idx_type c)
-    : Array<bool> (dim_vector (r, c)) { }
+    : boolNDArray (dim_vector (r, c)) { }
 
   boolMatrix (octave_idx_type r, octave_idx_type c, bool val)
-    : Array<bool> (dim_vector (r, c), val) { }
+    : boolNDArray (dim_vector (r, c), val) { }
 
-  boolMatrix (const dim_vector& dv) : Array<bool> (dv) { }
+  boolMatrix (const dim_vector& dv) : boolNDArray (dv) { }
 
-  boolMatrix (const dim_vector& dv, bool val) : Array<bool> (dv, val) { }
+  boolMatrix (const dim_vector& dv, bool val) : boolNDArray (dv, val) { }
 
-  boolMatrix (const Array<bool>& a) : Array<bool> (a.as_matrix ()) { }
+  boolMatrix (const Array<bool>& a) : boolNDArray (a.as_matrix ()) { }
 
-  boolMatrix (const boolMatrix& a) : Array<bool> (a) { }
+  boolMatrix (const boolMatrix& a) : boolNDArray (a) { }
 
   boolMatrix& operator = (const boolMatrix& a)
   {
diff -r 238522618904 -r 1918edd05fe8 liboctave/array/boolNDArray.cc
--- a/liboctave/array/boolNDArray.cc	Wed Oct 29 08:21:24 2014 -0700
+++ b/liboctave/array/boolNDArray.cc	Mon Oct 20 01:34:52 2014 +0100
@@ -107,14 +107,6 @@
   return *this;
 }
 
-
-
-boolMatrix
-boolNDArray::matrix_value (void) const
-{
-  return *this;
-}
-
 void
 boolNDArray::increment_index (Array<octave_idx_type>& ra_idx,
                               const dim_vector& dimensions,
diff -r 238522618904 -r 1918edd05fe8 liboctave/array/boolNDArray.h
--- a/liboctave/array/boolNDArray.h	Wed Oct 29 08:21:24 2014 -0700
+++ b/liboctave/array/boolNDArray.h	Mon Oct 20 01:34:52 2014 +0100
@@ -29,9 +29,6 @@
 #include "mx-op-decl.h"
 #include "bsxfun-decl.h"
 
-#include "boolMatrix.h"
-
-
 class
 OCTAVE_API
 boolNDArray : public Array<bool>
@@ -49,8 +46,6 @@
 
   boolNDArray (const boolNDArray& a) : Array<bool> (a) { }
 
-  boolNDArray (const boolMatrix& a) : Array<bool> (a) { }
-
   boolNDArray (const Array<bool>& a) : Array<bool> (a) { }
 
   boolNDArray& operator = (const boolNDArray& a)
@@ -83,8 +78,6 @@
   boolNDArray& insert (const boolNDArray& a,
                        const Array<octave_idx_type>& ra_idx);
 
-  boolMatrix matrix_value (void) const;
-
   boolNDArray squeeze (void) const { return Array<bool>::squeeze (); }
 
   static void increment_index (Array<octave_idx_type>& ra_idx,
# HG changeset patch
# User Carnë Draug <carandraug@octave.org>
# Date 1414110713 -3600
#      Fri Oct 24 01:31:53 2014 +0100
# Node ID 84876e78e7ce71cdb2aacbd501823614399cfcaa
# Parent  1918edd05fe8398c44ccb338140fe9797d9d5c33
Change charMatrix to subclass charNDArray rather than be another Array<char>.

* chMatrix.h: both charMatrix and charNDArray are Array<char>, 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 1918edd05fe8 -r 84876e78e7ce 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 1918edd05fe8 -r 84876e78e7ce 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 1918edd05fe8 -r 84876e78e7ce 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 1918edd05fe8 -r 84876e78e7ce 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<char> ()
-{
-  octave_idx_type nc = 1;
-  octave_idx_type nr = 1;
-
-  resize (nr, nc);
-
-  elem (0, 0) = c;
-}
-
-charMatrix::charMatrix (const char *s)
-  : Array<char> ()
-{
-  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<char> ()
-{
-  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<char> (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 1918edd05fe8 -r 84876e78e7ce 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 <string>
 
 #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<char>
+charMatrix : public charNDArray
 {
   friend class ComplexMatrix;
 
 public:
 
-  charMatrix (void) : Array<char> () { }
+  charMatrix (void) : charNDArray () { }
 
   charMatrix (octave_idx_type r, octave_idx_type c)
-    : Array<char> (dim_vector (r, c)) { }
+    : charNDArray (dim_vector (r, c)) { }
 
   charMatrix (octave_idx_type r, octave_idx_type c, char val)
-    : Array<char> (dim_vector (r, c), val) { }
+    : charNDArray (dim_vector (r, c), val) { }
 
-  charMatrix (const dim_vector& dv) : Array<char> (dv) { }
+  charMatrix (const dim_vector& dv) : charNDArray (dv) { }
 
-  charMatrix (const dim_vector& dv, char val) : Array<char> (dv, val) { }
+  charMatrix (const dim_vector& dv, char val) : charNDArray (dv, val) { }
 
-  charMatrix (const Array<char>& a) : Array<char> (a.as_matrix ()) { }
+  charMatrix (const Array<char>& a) : charNDArray (a.as_matrix ()) { }
 
-  charMatrix (const charMatrix& a) : Array<char> (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 1918edd05fe8 -r 84876e78e7ce 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 <config.h>
 #endif
 
+#include <string>
+
 #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<char> ()
+{
+  octave_idx_type nc = 1;
+  octave_idx_type nr = 1;
+
+  resize (nr, nc);
+
+  elem (0, 0) = c;
+}
+
+charNDArray::charNDArray (const char *s)
+  : Array<char> ()
+{
+  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<char> ()
+{
+  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<char> (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<octave_idx_type>& ra_idx,
                               const dim_vector& dimensions,
diff -r 1918edd05fe8 -r 84876e78e7ce 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 <string>
+
 #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<char> (a) { }
 
-  charNDArray (const charMatrix& a) : Array<char> (a) { }
+  charNDArray (const Array<char>& a) : Array<char> (a) { }
 
-  charNDArray (char c) : Array<char> (charMatrix (c)) { }
+  charNDArray (char c);
 
-  charNDArray (const char *s) : Array<char> (charMatrix (s)) { }
+  charNDArray (const char *s);
 
-  charNDArray (const std::string& s) : Array<char> (charMatrix (s)) { }
+  charNDArray (const std::string& s);
 
-  charNDArray (const string_vector& s) : Array<char> (charMatrix (s)) { }
-
-  charNDArray (const Array<char>& a) : Array<char> (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<octave_idx_type>& ra_idx);
 
-  charMatrix matrix_value (void) const;
-
   charNDArray squeeze (void) const { return Array<char>::squeeze (); }
 
   static void increment_index (Array<octave_idx_type>& ra_idx,
