Mercurial > octave
annotate liboctave/array/chMatrix.cc @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | 0a5b15007766 |
children | 597f3ee61a48 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
3 // Copyright (C) 1995-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
1573 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
27 # include "config.h" |
1573 | 28 #endif |
29 | |
7048 | 30 #include <cstring> |
31 | |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
32 #include <ostream> |
1728 | 33 #include <string> |
34 | |
1573 | 35 #include "lo-error.h" |
2349 | 36 #include "str-vec.h" |
1573 | 37 #include "mx-base.h" |
38 #include "mx-inlines.cc" | |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8750
diff
changeset
|
39 #include "mx-op-defs.h" |
1573 | 40 |
41 // charMatrix class. | |
42 | |
2384 | 43 bool |
1573 | 44 charMatrix::operator == (const charMatrix& a) const |
45 { | |
46 if (rows () != a.rows () || cols () != a.cols ()) | |
47 return 0; | |
48 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
49 return mx_inline_equal (numel (), data (), a.data ()); |
1573 | 50 } |
51 | |
2384 | 52 bool |
1573 | 53 charMatrix::operator != (const charMatrix& a) const |
54 { | |
55 return !(*this == a); | |
56 } | |
57 | |
58 charMatrix& | |
5275 | 59 charMatrix::insert (const char *s, octave_idx_type r, octave_idx_type c) |
1573 | 60 { |
61 if (s) | |
62 { | |
5275 | 63 octave_idx_type s_len = strlen (s); |
1573 | 64 |
65 if (r < 0 || r >= rows () || c < 0 || c + s_len - 1 > cols ()) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
66 (*current_liboctave_error_handler) ("range error for insert"); |
1573 | 67 |
5275 | 68 for (octave_idx_type i = 0; i < s_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10267
diff
changeset
|
69 elem (r, c+i) = s[i]; |
1573 | 70 } |
71 return *this; | |
72 } | |
73 | |
74 charMatrix& | |
5275 | 75 charMatrix::insert (const charMatrix& a, octave_idx_type r, octave_idx_type c) |
1573 | 76 { |
10351
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
77 Array<char>::insert (a, r, c); |
1573 | 78 return *this; |
79 } | |
80 | |
3504 | 81 std::string |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
82 charMatrix::row_as_string (octave_idx_type r, bool strip_ws) const |
1573 | 83 { |
3504 | 84 std::string retval; |
2613 | 85 |
5275 | 86 octave_idx_type nr = rows (); |
87 octave_idx_type nc = cols (); | |
2613 | 88 |
14012
4faef552363d
charMatrix::row_as_string: return early if r is 0 and either nr or nc is 0
John W. Eaton <jwe@octave.org>
parents:
12959
diff
changeset
|
89 if (r == 0 && (nr == 0 || nc == 0)) |
2613 | 90 return retval; |
91 | |
92 if (r < 0 || r >= nr) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
93 (*current_liboctave_error_handler) ("range error for row_as_string"); |
1573 | 94 |
2613 | 95 retval.resize (nc, '\0'); |
1573 | 96 |
5275 | 97 for (octave_idx_type i = 0; i < nc; i++) |
1573 | 98 retval[i] = elem (r, i); |
99 | |
11265
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
100 if (strip_ws) |
2493 | 101 { |
11265
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
102 while (--nc >= 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10267
diff
changeset
|
103 { |
11265
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
104 char c = retval[nc]; |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
105 if (c && c != ' ') |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
106 break; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10267
diff
changeset
|
107 } |
3836 | 108 |
109 retval.resize (nc+1); | |
2493 | 110 } |
1780 | 111 |
1573 | 112 return retval; |
113 } | |
114 | |
2255 | 115 charMatrix |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
116 charMatrix::extract (octave_idx_type r1, octave_idx_type c1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
117 octave_idx_type r2, octave_idx_type c2) const |
3189 | 118 { |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
119 if (r1 > r2) { std::swap (r1, r2); } |
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
120 if (c1 > c2) { std::swap (c1, c2); } |
3189 | 121 |
5275 | 122 octave_idx_type new_r = r2 - r1 + 1; |
123 octave_idx_type new_c = c2 - c1 + 1; | |
3189 | 124 |
125 charMatrix result (new_r, new_c); | |
126 | |
5275 | 127 for (octave_idx_type j = 0; j < new_c; j++) |
128 for (octave_idx_type i = 0; i < new_r; i++) | |
3189 | 129 result.elem (i, j) = elem (r1+i, c1+j); |
130 | |
131 return result; | |
132 } | |
133 | |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
134 MS_CMP_OPS (charMatrix, char) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
135 MS_BOOL_OPS (charMatrix, char) |
6456 | 136 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
137 SM_CMP_OPS (char, charMatrix) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
138 SM_BOOL_OPS (char, charMatrix) |
6456 | 139 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
140 MM_CMP_OPS (charMatrix, charMatrix) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
141 MM_BOOL_OPS (charMatrix, charMatrix) |