GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
chMatrix.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1995-2018 John W. Eaton
4 Copyright (C) 2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include <cstring>
29 
30 #include <iostream>
31 #include <string>
32 
33 #include "lo-error.h"
34 #include "str-vec.h"
35 #include "mx-base.h"
36 #include "mx-inlines.cc"
37 #include "mx-op-defs.h"
38 
39 // charMatrix class.
40 
41 bool
43 {
44  if (rows () != a.rows () || cols () != a.cols ())
45  return 0;
46 
47  return mx_inline_equal (numel (), data (), a.data ());
48 }
49 
50 bool
52 {
53  return !(*this == a);
54 }
55 
58 {
59  if (s)
60  {
61  octave_idx_type s_len = strlen (s);
62 
63  if (r < 0 || r >= rows () || c < 0 || c + s_len - 1 > cols ())
64  (*current_liboctave_error_handler) ("range error for insert");
65 
66  for (octave_idx_type i = 0; i < s_len; i++)
67  elem (r, c+i) = s[i];
68  }
69  return *this;
70 }
71 
74 {
75  Array<char>::insert (a, r, c);
76  return *this;
77 }
78 
81 {
83 
84  octave_idx_type nr = rows ();
85  octave_idx_type nc = cols ();
86 
87  if (r == 0 && (nr == 0 || nc == 0))
88  return retval;
89 
90  if (r < 0 || r >= nr)
91  (*current_liboctave_error_handler) ("range error for row_as_string");
92 
93  retval.resize (nc, '\0');
94 
95  for (octave_idx_type i = 0; i < nc; i++)
96  retval[i] = elem (r, i);
97 
98  if (strip_ws)
99  {
100  while (--nc >= 0)
101  {
102  char c = retval[nc];
103  if (c && c != ' ')
104  break;
105  }
106 
107  retval.resize (nc+1);
108  }
109 
110  return retval;
111 }
112 
115  octave_idx_type r2, octave_idx_type c2) const
116 {
117  if (r1 > r2) { std::swap (r1, r2); }
118  if (c1 > c2) { std::swap (c1, c2); }
119 
120  octave_idx_type new_r = r2 - r1 + 1;
121  octave_idx_type new_c = c2 - c1 + 1;
122 
123  charMatrix result (new_r, new_c);
124 
125  for (octave_idx_type j = 0; j < new_c; j++)
126  for (octave_idx_type i = 0; i < new_r; i++)
127  result.elem (i, j) = elem (r1+i, c1+j);
128 
129  return result;
130 }
131 
134 
137 
octave_idx_type rows(void) const
Definition: Array.h:404
#define MM_BOOL_OPS(M1, M2)
Definition: mx-op-defs.h:212
const char * data(void) const
Definition: Array.h:582
bool operator==(const charMatrix &a) const
Definition: chMatrix.cc:42
#define SM_BOOL_OPS(S, M)
Definition: mx-op-defs.h:169
char & elem(octave_idx_type n)
Definition: Array.h:488
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
s
Definition: file-io.cc:2729
#define MS_CMP_OPS(M, S)
Definition: mx-op-defs.h:109
octave_idx_type cols(void) const
Definition: Array.h:412
Array< T > & insert(const Array< T > &a, const Array< octave_idx_type > &idx)
Insert an array into another at a specified position.
Definition: Array.cc:1583
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:511
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
bool swap
Definition: load-save.cc:738
charMatrix & insert(const char *s, octave_idx_type r, octave_idx_type c)
Definition: chMatrix.cc:57
octave_value retval
Definition: data.cc:6246
T::size_type strlen(const typename T::value_type *str)
Definition: oct-string.cc:75
With real return the complex result
Definition: data.cc:3260
bool operator!=(const charMatrix &a) const
Definition: chMatrix.cc:51
std::string row_as_string(octave_idx_type, bool strip_ws=false) const
Definition: chMatrix.cc:80
#define MS_BOOL_OPS(M, S)
Definition: mx-op-defs.h:126
#define MM_CMP_OPS(M1, M2)
Definition: mx-op-defs.h:195
for i
Definition: data.cc:5264
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
bool mx_inline_equal(size_t n, const T1 *x, const T2 *y)
Definition: mx-inlines.cc:569
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
charMatrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
Definition: chMatrix.cc:114
#define SM_CMP_OPS(S, M)
Definition: mx-op-defs.h:152