ov-null-mat.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2008-2012 Jaroslav Hajek
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "ov-null-mat.h"
00028 #include "ops.h"
00029 #include "defun.h"
00030 
00031 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_null_matrix, "null_matrix", "double");
00032 
00033 const octave_value octave_null_matrix::instance (new octave_null_matrix ());
00034 
00035 static octave_base_value *
00036 default_null_matrix_numeric_conversion_function (const octave_base_value& a)
00037 {
00038   // The cast is not necessary?
00039   // CAST_CONV_ARG (const octave_null_matrix&);
00040 
00041   return a.empty_clone ();
00042 }
00043 
00044 octave_base_value::type_conv_info
00045 octave_null_matrix::numeric_conversion_function (void) const
00046 {
00047   return octave_base_value::type_conv_info (default_null_matrix_numeric_conversion_function,
00048                                             octave_matrix::static_type_id ());
00049 }
00050 
00051 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_null_str, "null_string", "char");
00052 
00053 const octave_value octave_null_str::instance (new octave_null_str ());
00054 
00055 static octave_base_value *
00056 default_null_str_numeric_conversion_function (const octave_base_value& a)
00057 {
00058   // The cast is not necessary?
00059   // CAST_CONV_ARG (const octave_null_str&);
00060 
00061   return a.empty_clone ();
00062 }
00063 
00064 octave_base_value::type_conv_info
00065 octave_null_str::numeric_conversion_function (void) const
00066 {
00067   return octave_base_value::type_conv_info (default_null_str_numeric_conversion_function,
00068                                             octave_char_matrix_str::static_type_id ());
00069 }
00070 
00071 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_null_sq_str, "null_sq_string", "char");
00072 
00073 const octave_value octave_null_sq_str::instance (new octave_null_sq_str ());
00074 
00075 static octave_base_value *
00076 default_null_sq_str_numeric_conversion_function (const octave_base_value& a)
00077 {
00078   // The cast is not necessary?
00079   // CAST_CONV_ARG (const octave_null_sq_str&);
00080 
00081   return a.empty_clone ();
00082 }
00083 
00084 octave_base_value::type_conv_info
00085 octave_null_sq_str::numeric_conversion_function (void) const
00086 {
00087   return octave_base_value::type_conv_info (default_null_sq_str_numeric_conversion_function,
00088                                             octave_char_matrix_sq_str::static_type_id ());
00089 }
00090 
00091 DEFUN (isnull, args, ,
00092   "-*- texinfo -*-\n\
00093 @deftypefn {Built-in Function} {} isnull (@var{x})\n\
00094 Return true if @var{x} is a special null matrix, string, or single quoted\n\
00095 string.  Indexed assignment with such a value on the right-hand side should\n\
00096 delete array elements.  This function should be used when overloading\n\
00097 indexed assignment for user-defined classes instead of @code{isempty}, to\n\
00098 distinguish the cases:\n\
00099 @table @asis\n\
00100 @item @code{A(I) = []}\n\
00101 This should delete elements if @code{I} is nonempty.\n\
00102 \n\
00103 @item @code{X = []; A(I) = X}\n\
00104 This should give an error if @code{I} is nonempty.\n\
00105 @end table\n\
00106 @seealso{isempty, isindex}\n\
00107 @end deftypefn")
00108 {
00109   octave_value retval;
00110 
00111   int nargin = args.length ();
00112 
00113   if (nargin == 1 && args(0).is_defined ())
00114     retval = args(0).is_null_value ();
00115   else
00116     print_usage ();
00117 
00118   return retval;
00119 }
00120 
00121 /*
00122 
00123 %!assert (isnull ([]), true)
00124 %!assert (isnull ([1]), false)
00125 %!assert (isnull (zeros (0,3)), false)
00126 %!assert (isnull (""), true)
00127 %!assert (isnull ("A"), false)
00128 %!assert (isnull (''), true)
00129 %!assert (isnull ('A'), false)
00130 %!test
00131 %! x = [];
00132 %! assert (isnull (x), false);
00133 
00134 */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines