changeset 19350:6c9ea5be96bf

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.
author Carnë Draug <carandraug@octave.org>
date Fri, 24 Oct 2014 01:31:53 +0100
parents 25f535b90e52
children 8b4a24081e47
files libinterp/corefcn/pr-output.cc libinterp/octave-value/ov-ch-mat.h libinterp/octave-value/ov-str-mat.cc liboctave/array/chMatrix.cc liboctave/array/chMatrix.h liboctave/array/chNDArray.cc liboctave/array/chNDArray.h
diffstat 7 files changed, 83 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- 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;
 
--- 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; }
--- 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++)
--- 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
 {
--- 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)
   {
--- 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,
--- 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 (const char *s) : Array<char> (charMatrix (s)) { }
+  charNDArray (char c);
 
-  charNDArray (const std::string& s) : Array<char> (charMatrix (s)) { }
+  charNDArray (const char *s);
 
-  charNDArray (const string_vector& s) : Array<char> (charMatrix (s)) { }
+  charNDArray (const std::string& 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,