GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
chMatrix.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1995-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <cstring>
31
32#include <ostream>
33#include <string>
34
35#include "lo-error.h"
36#include "str-vec.h"
37#include "mx-base.h"
38#include "mx-inlines.cc"
39#include "mx-op-defs.h"
40
41// charMatrix class.
42
43bool
45{
46 if (rows () != a.rows () || cols () != a.cols ())
47 return 0;
48
49 return mx_inline_equal (numel (), data (), a.data ());
50}
51
52bool
54{
55 return !(*this == a);
56}
57
60{
61 if (s)
62 {
63 octave_idx_type s_len = strlen (s);
64
65 if (r < 0 || r >= rows () || c < 0 || c + s_len - 1 > cols ())
66 (*current_liboctave_error_handler) ("range error for insert");
67
68 for (octave_idx_type i = 0; i < s_len; i++)
69 elem (r, c+i) = s[i];
70 }
71 return *this;
72}
73
76{
77 Array<char>::insert (a, r, c);
78 return *this;
79}
80
81std::string
83{
84 std::string retval;
85
86 octave_idx_type nr = rows ();
87 octave_idx_type nc = cols ();
88
89 if (r == 0 && (nr == 0 || nc == 0))
90 return retval;
91
92 if (r < 0 || r >= nr)
93 (*current_liboctave_error_handler) ("range error for row_as_string");
94
95 retval.resize (nc, '\0');
96
97 for (octave_idx_type i = 0; i < nc; i++)
98 retval[i] = elem (r, i);
99
100 if (strip_ws)
101 {
102 while (--nc >= 0)
103 {
104 char c = retval[nc];
105 if (c && c != ' ')
106 break;
107 }
108
109 retval.resize (nc+1);
110 }
111
112 return retval;
113}
114
117 octave_idx_type r2, octave_idx_type c2) const
118{
119 if (r1 > r2) { std::swap (r1, r2); }
120 if (c1 > c2) { std::swap (c1, c2); }
121
122 octave_idx_type new_r = r2 - r1 + 1;
123 octave_idx_type new_c = c2 - c1 + 1;
124
125 charMatrix result (new_r, new_c);
126
127 for (octave_idx_type j = 0; j < new_c; j++)
128 for (octave_idx_type i = 0; i < new_r; i++)
129 result.elem (i, j) = elem (r1+i, c1+j);
130
131 return result;
132}
133
136
139
char & elem(octave_idx_type n)
Definition Array.h:563
octave_idx_type rows() const
Definition Array.h:463
Array< T, Alloc > & insert(const Array< T, Alloc > &a, const Array< octave_idx_type > &idx)
Insert an array into another at a specified position.
octave_idx_type cols() const
Definition Array.h:473
const char * data() const
Definition Array.h:665
octave_idx_type numel() const
Number of elements in the array.
Definition Array.h:418
charMatrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
Definition chMatrix.cc:116
bool operator==(const charMatrix &a) const
Definition chMatrix.cc:44
charMatrix & insert(const char *s, octave_idx_type r, octave_idx_type c)
Definition chMatrix.cc:59
std::string row_as_string(octave_idx_type, bool strip_ws=false) const
Definition chMatrix.cc:82
bool operator!=(const charMatrix &a) const
Definition chMatrix.cc:53
bool mx_inline_equal(std::size_t n, const T1 *x, const T2 *y)
#define MM_BOOL_OPS(M1, M2)
Definition mx-op-defs.h:213
#define MM_CMP_OPS(M1, M2)
Definition mx-op-defs.h:196
#define MS_CMP_OPS(M, S)
Definition mx-op-defs.h:110
#define SM_CMP_OPS(S, M)
Definition mx-op-defs.h:153
#define SM_BOOL_OPS(S, M)
Definition mx-op-defs.h:170
#define MS_BOOL_OPS(M, S)
Definition mx-op-defs.h:127
T::size_type strlen(const typename T::value_type *str)
Definition oct-string.cc:88