3326
|
1 /* |
|
2 |
|
3 Copyright (C) 1999 John W. Eaton |
|
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 2, or (at your option) any |
|
10 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, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3326
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_shlib_h) |
|
25 #define octave_shlib_h 1 |
|
26 |
|
27 #include <string> |
|
28 |
4848
|
29 #include "oct-time.h" |
3326
|
30 |
|
31 // This just provides a way to avoid infinite recursion when building |
|
32 // octave_shlib objects. |
|
33 |
|
34 class |
6108
|
35 OCTAVE_API |
3326
|
36 octave_xshlib |
|
37 { |
|
38 public: |
|
39 |
|
40 octave_xshlib (void) { } |
|
41 }; |
|
42 |
|
43 class |
6108
|
44 OCTAVE_API |
3326
|
45 octave_shlib |
|
46 { |
|
47 public: |
|
48 |
3504
|
49 typedef std::string (*name_mangler) (const std::string&); |
3326
|
50 |
3504
|
51 typedef void (*close_hook) (const std::string&); |
3326
|
52 |
|
53 octave_shlib (void) : rep (make_shlib ()) { } |
|
54 |
5781
|
55 octave_shlib (const std::string& f) : rep (make_shlib ()) { open (f); } |
3326
|
56 |
|
57 virtual ~octave_shlib (void) |
|
58 { |
|
59 if (rep && --rep->count == 0) |
|
60 { |
|
61 delete rep; |
|
62 rep = 0; |
|
63 } |
|
64 } |
|
65 |
|
66 octave_shlib (const octave_shlib& sl) |
|
67 { |
|
68 rep = sl.rep; |
|
69 rep->count++; |
|
70 } |
|
71 |
|
72 octave_shlib& operator = (const octave_shlib& sl) |
|
73 { |
|
74 if (rep != sl.rep) |
|
75 { |
|
76 if (--rep->count == 0) |
|
77 delete rep; |
|
78 |
|
79 rep = sl.rep; |
|
80 rep->count++; |
|
81 } |
|
82 |
|
83 return *this; |
|
84 } |
|
85 |
|
86 bool operator == (const octave_shlib& sl) const |
|
87 { return (rep == sl.rep); } |
|
88 |
|
89 operator bool () const { return is_open (); } |
|
90 |
5781
|
91 virtual void open (const std::string& f) { rep->open (f); } |
3326
|
92 |
3504
|
93 virtual void *search (const std::string& nm, name_mangler mangler = 0) |
3326
|
94 { return rep->search (nm, mangler); } |
|
95 |
|
96 virtual void close (close_hook cl_hook = 0) |
|
97 { rep->close (cl_hook); } |
|
98 |
3504
|
99 virtual bool remove (const std::string& fcn_name) |
3326
|
100 { return rep->remove (fcn_name); } |
|
101 |
|
102 virtual bool is_out_of_date (void) const |
|
103 { return rep->is_out_of_date (); } |
|
104 |
|
105 virtual int number_of_functions_loaded (void) const |
|
106 { return rep->number_of_functions_loaded (); } |
|
107 |
3504
|
108 virtual std::string file_name (void) const |
3326
|
109 { return rep->file_name (); } |
|
110 |
|
111 virtual octave_time time_loaded (void) const |
|
112 { return rep->time_loaded (); } |
|
113 |
|
114 protected: |
|
115 |
|
116 octave_shlib (const octave_xshlib&) : rep (0) { } |
|
117 |
|
118 virtual bool is_open (void) const { return rep->is_open (); } |
|
119 |
|
120 static octave_shlib *make_shlib (void); |
|
121 |
|
122 union |
|
123 { |
|
124 octave_shlib *rep; |
|
125 int count; |
|
126 }; |
|
127 }; |
|
128 |
|
129 #endif |
|
130 |
|
131 /* |
|
132 ;;; Local Variables: *** |
|
133 ;;; mode: C++ *** |
|
134 ;;; End: *** |
|
135 */ |