Mercurial > hg > octave-nkf
diff liboctave/oct-shlib.h @ 3326:c19f4b9484af
[project @ 1999-10-29 21:52:12 by jwe]
author | jwe |
---|---|
date | Fri, 29 Oct 1999 21:52:30 +0000 |
parents | |
children | 5eef8a2294bd |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/liboctave/oct-shlib.h @@ -0,0 +1,137 @@ +/* + +Copyright (C) 1999 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_shlib_h) +#define octave_shlib_h 1 + +#include <string> + +#include <oct-time.h> + +// This just provides a way to avoid infinite recursion when building +// octave_shlib objects. + +class +octave_xshlib +{ +public: + + octave_xshlib (void) { } +}; + +class +octave_shlib +{ +public: + + typedef string (*name_mangler) (const string&); + + typedef void (*close_hook) (const string&); + + octave_shlib (void) : rep (make_shlib ()) { } + + octave_shlib::octave_shlib (const string& f, bool warn_future) + : rep (make_shlib ()) + { + open (f, warn_future); + } + + virtual ~octave_shlib (void) + { + if (rep && --rep->count == 0) + { + delete rep; + rep = 0; + } + } + + octave_shlib (const octave_shlib& sl) + { + rep = sl.rep; + rep->count++; + } + + octave_shlib& operator = (const octave_shlib& sl) + { + if (rep != sl.rep) + { + if (--rep->count == 0) + delete rep; + + rep = sl.rep; + rep->count++; + } + + return *this; + } + + bool operator == (const octave_shlib& sl) const + { return (rep == sl.rep); } + + operator bool () const { return is_open (); } + + virtual void open (const string& f, bool warn_future = false) + { rep->open (f, warn_future); } + + virtual void *search (const string& nm, name_mangler mangler = 0) + { return rep->search (nm, mangler); } + + virtual void close (close_hook cl_hook = 0) + { rep->close (cl_hook); } + + virtual bool remove (const string& fcn_name) + { return rep->remove (fcn_name); } + + virtual bool is_out_of_date (void) const + { return rep->is_out_of_date (); } + + virtual int number_of_functions_loaded (void) const + { return rep->number_of_functions_loaded (); } + + virtual string file_name (void) const + { return rep->file_name (); } + + virtual octave_time time_loaded (void) const + { return rep->time_loaded (); } + +protected: + + octave_shlib (const octave_xshlib&) : rep (0) { } + + virtual bool is_open (void) const { return rep->is_open (); } + + static octave_shlib *make_shlib (void); + + union + { + octave_shlib *rep; + int count; + }; +}; + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/