GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
libinterp
octave-value
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
31
DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA
(
octave_null_matrix
,
"null_matrix"
,
32
"double"
);
33
34
const
octave_value
octave_null_matrix::instance
(
new
octave_null_matrix
());
35
36
static
octave_base_value
*
37
default_null_matrix_numeric_conversion_function
(
const
octave_base_value
& a)
38
{
39
// The cast is not necessary?
40
// CAST_CONV_ARG (const octave_null_matrix&);
41
42
return
a.
empty_clone
();
43
}
44
45
octave_base_value::type_conv_info
46
octave_null_matrix::numeric_conversion_function
(
void
)
const
47
{
48
return
octave_base_value::type_conv_info
49
(
default_null_matrix_numeric_conversion_function
,
50
octave_matrix::static_type_id
());
51
}
52
53
DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA
(
octave_null_str
,
"null_string"
,
"char"
);
54
55
const
octave_value
octave_null_str::instance
(
new
octave_null_str
());
56
57
static
octave_base_value
*
58
default_null_str_numeric_conversion_function
(
const
octave_base_value
& a)
59
{
60
// The cast is not necessary?
61
// CAST_CONV_ARG (const octave_null_str&);
62
63
return
a.
empty_clone
();
64
}
65
66
octave_base_value::type_conv_info
67
octave_null_str::numeric_conversion_function
(
void
)
const
68
{
69
return
octave_base_value::type_conv_info
70
(
default_null_str_numeric_conversion_function
,
71
octave_char_matrix_str::static_type_id
());
72
}
73
74
DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA
(
octave_null_sq_str
,
"null_sq_string"
,
75
"char"
);
76
77
const
octave_value
octave_null_sq_str::instance
(
new
octave_null_sq_str
());
78
79
static
octave_base_value
*
80
default_null_sq_str_numeric_conversion_function
(
const
octave_base_value
& a)
81
{
82
// The cast is not necessary?
83
// CAST_CONV_ARG (const octave_null_sq_str&);
84
85
return
a.
empty_clone
();
86
}
87
88
octave_base_value::type_conv_info
89
octave_null_sq_str::numeric_conversion_function
(
void
)
const
90
{
91
return
octave_base_value::type_conv_info
92
(
default_null_sq_str_numeric_conversion_function
,
93
octave_char_matrix_sq_str::static_type_id
());
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
*/
Generated on Mon Dec 30 2013 03:04:33 for GNU Octave by
1.8.1.2