GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-null-mat.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2013 Jaroslav Hajek
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "ov-null-mat.h"
28 #include "ops.h"
29 #include "defun.h"
30 
32  "double");
33 
35 
36 static octave_base_value *
38 {
39  // The cast is not necessary?
40  // CAST_CONV_ARG (const octave_null_matrix&);
41 
42  return a.empty_clone ();
43 }
44 
47 {
51 }
52 
54 
56 
57 static octave_base_value *
59 {
60  // The cast is not necessary?
61  // CAST_CONV_ARG (const octave_null_str&);
62 
63  return a.empty_clone ();
64 }
65 
68 {
72 }
73 
75  "char");
76 
78 
79 static octave_base_value *
81 {
82  // The cast is not necessary?
83  // CAST_CONV_ARG (const octave_null_sq_str&);
84 
85  return a.empty_clone ();
86 }
87 
90 {
94 }
95 
96 DEFUN (isnull, args, ,
97  "-*- texinfo -*-\n\
98 @deftypefn {Built-in Function} {} isnull (@var{x})\n\
99 Return true if @var{x} is a special null matrix, string, or single quoted\n\
100 string. Indexed assignment with such a value on the right-hand side should\n\
101 delete array elements. This function should be used when overloading\n\
102 indexed assignment for user-defined classes instead of @code{isempty}, to\n\
103 distinguish the cases:\n\
104 \n\
105 @table @asis\n\
106 @item @code{A(I) = []}\n\
107 This should delete elements if @code{I} is nonempty.\n\
108 \n\
109 @item @code{X = []; A(I) = X}\n\
110 This should give an error if @code{I} is nonempty.\n\
111 @end table\n\
112 @seealso{isempty, isindex}\n\
113 @end deftypefn")
114 {
115  octave_value retval;
116 
117  int nargin = args.length ();
118 
119  if (nargin == 1 && args(0).is_defined ())
120  retval = args(0).is_null_value ();
121  else
122  print_usage ();
123 
124  return retval;
125 }
126 
127 /*
128 %!assert (isnull ([]), true)
129 %!assert (isnull ([1]), false)
130 %!assert (isnull (zeros (0,3)), false)
131 %!assert (isnull (""), true)
132 %!assert (isnull ("A"), false)
133 %!assert (isnull (''), true)
134 %!assert (isnull ('A'), false)
135 %!test
136 %! x = [];
137 %! assert (isnull (x), false);
138 */