comparison liboctave/array/chNDArray.cc @ 19508: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 49a5a4be04a1
children 1f4455ff2329
comparison
equal deleted inserted replaced
19507:25f535b90e52 19508:6c9ea5be96bf
22 */ 22 */
23 23
24 #ifdef HAVE_CONFIG_H 24 #ifdef HAVE_CONFIG_H
25 #include <config.h> 25 #include <config.h>
26 #endif 26 #endif
27
28 #include <string>
27 29
28 #include "Array-util.h" 30 #include "Array-util.h"
29 #include "chNDArray.h" 31 #include "chNDArray.h"
30 #include "mx-base.h" 32 #include "mx-base.h"
31 #include "lo-ieee.h" 33 #include "lo-ieee.h"
32 #include "lo-mappers.h" 34 #include "lo-mappers.h"
33 #include "mx-op-defs.h" 35 #include "mx-op-defs.h"
36 #include "str-vec.h"
34 37
35 #include "bsxfun-defs.cc" 38 #include "bsxfun-defs.cc"
39
40 charNDArray::charNDArray (char c)
41 : Array<char> ()
42 {
43 octave_idx_type nc = 1;
44 octave_idx_type nr = 1;
45
46 resize (nr, nc);
47
48 elem (0, 0) = c;
49 }
50
51 charNDArray::charNDArray (const char *s)
52 : Array<char> ()
53 {
54 octave_idx_type nc = s ? strlen (s) : 0;
55 octave_idx_type nr = s && nc > 0 ? 1 : 0;
56
57 resize (nr, nc);
58
59 for (octave_idx_type i = 0; i < nc; i++)
60 elem (0, i) = s[i];
61 }
62
63 charNDArray::charNDArray (const std::string& s)
64 : Array<char> ()
65 {
66 octave_idx_type nc = s.length ();
67 octave_idx_type nr = nc > 0 ? 1 : 0;
68
69 resize (nr, nc);
70
71 for (octave_idx_type i = 0; i < nc; i++)
72 elem (0, i) = s[i];
73 }
74
75 charNDArray::charNDArray (const string_vector& s, char fill_value)
76 : Array<char> (dim_vector (s.length (), s.max_length ()), fill_value)
77 {
78 octave_idx_type nr = rows ();
79
80 for (octave_idx_type i = 0; i < nr; i++)
81 {
82 const std::string si = s(i);
83 octave_idx_type nc = si.length ();
84 for (octave_idx_type j = 0; j < nc; j++)
85 elem (i, j) = si[j];
86 }
87 }
36 88
37 // FIXME: this is not quite the right thing. 89 // FIXME: this is not quite the right thing.
38 90
39 boolNDArray 91 boolNDArray
40 charNDArray::all (int dim) const 92 charNDArray::all (int dim) const
128 { 180 {
129 Array<char>::insert (a, ra_idx); 181 Array<char>::insert (a, ra_idx);
130 return *this; 182 return *this;
131 } 183 }
132 184
133 charMatrix
134 charNDArray::matrix_value (void) const
135 {
136 return *this;
137 }
138
139 void 185 void
140 charNDArray::increment_index (Array<octave_idx_type>& ra_idx, 186 charNDArray::increment_index (Array<octave_idx_type>& ra_idx,
141 const dim_vector& dimensions, 187 const dim_vector& dimensions,
142 int start_dimension) 188 int start_dimension)
143 { 189 {