00001 /* 00002 00003 Copyright (C) 2010-2012 VZLU Prague 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 <iosfwd> 00028 00029 #include "ov-base.h" 00030 #include "ov-struct.h" 00031 #include "ov.h" 00032 00033 static void 00034 gripe_internal (void) 00035 { 00036 error ("onCleanup: internal error: cloning nonempty object"); 00037 } 00038 00039 class octave_oncleanup : public octave_base_value 00040 { 00041 public: 00042 octave_oncleanup (void) : fcn () { } 00043 00044 octave_oncleanup (const octave_value& fcn); 00045 00046 octave_base_value *clone (void) const 00047 { 00048 if (fcn.is_defined ()) 00049 gripe_internal (); 00050 00051 return empty_clone (); 00052 } 00053 00054 octave_base_value *empty_clone (void) const 00055 { 00056 return new octave_oncleanup (); 00057 } 00058 00059 ~octave_oncleanup (void); 00060 00061 bool is_defined (void) const { return true; } 00062 00063 bool is_object (void) const { return true; } // do we want this? 00064 00065 octave_map map_value (void) const { return scalar_map_value (); } 00066 00067 octave_scalar_map scalar_map_value (void) const; 00068 00069 dim_vector dims (void) const 00070 { 00071 static dim_vector dv (1, 1); 00072 return dv; 00073 } 00074 00075 bool save_ascii (std::ostream& os); 00076 00077 bool load_ascii (std::istream& is); 00078 00079 bool save_binary (std::ostream& os, bool& save_as_floats); 00080 00081 bool load_binary (std::istream& is, bool swap, 00082 oct_mach_info::float_format fmt); 00083 00084 #if defined (HAVE_HDF5) 00085 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); 00086 00087 bool load_hdf5 (hid_t loc_id, const char *name); 00088 #endif 00089 00090 void print (std::ostream& os, bool pr_as_read_syntax = false) const; 00091 00092 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; 00093 00094 private: 00095 00096 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA 00097 00098 protected: 00099 00100 octave_value fcn; 00101 };