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 |
6323
|
53 octave_shlib (void) : relative (false), rep (make_shlib ()) { } |
3326
|
54 |
6323
|
55 octave_shlib (const std::string& f) |
|
56 : relative (false), rep (make_shlib ()) { open (f); } |
3326
|
57 |
|
58 virtual ~octave_shlib (void) |
|
59 { |
|
60 if (rep && --rep->count == 0) |
|
61 { |
|
62 delete rep; |
|
63 rep = 0; |
|
64 } |
|
65 } |
|
66 |
|
67 octave_shlib (const octave_shlib& sl) |
|
68 { |
|
69 rep = sl.rep; |
|
70 rep->count++; |
|
71 } |
|
72 |
|
73 octave_shlib& operator = (const octave_shlib& sl) |
|
74 { |
|
75 if (rep != sl.rep) |
|
76 { |
|
77 if (--rep->count == 0) |
|
78 delete rep; |
|
79 |
|
80 rep = sl.rep; |
|
81 rep->count++; |
|
82 } |
|
83 |
|
84 return *this; |
|
85 } |
|
86 |
|
87 bool operator == (const octave_shlib& sl) const |
|
88 { return (rep == sl.rep); } |
|
89 |
|
90 operator bool () const { return is_open (); } |
|
91 |
5781
|
92 virtual void open (const std::string& f) { rep->open (f); } |
3326
|
93 |
3504
|
94 virtual void *search (const std::string& nm, name_mangler mangler = 0) |
3326
|
95 { return rep->search (nm, mangler); } |
|
96 |
|
97 virtual void close (close_hook cl_hook = 0) |
|
98 { rep->close (cl_hook); } |
|
99 |
3504
|
100 virtual bool remove (const std::string& fcn_name) |
3326
|
101 { return rep->remove (fcn_name); } |
|
102 |
|
103 virtual bool is_out_of_date (void) const |
|
104 { return rep->is_out_of_date (); } |
|
105 |
6323
|
106 void mark_relative (void) { relative = true; } |
|
107 |
|
108 bool is_relative (void) const { return relative; } |
|
109 |
3326
|
110 virtual int number_of_functions_loaded (void) const |
|
111 { return rep->number_of_functions_loaded (); } |
|
112 |
3504
|
113 virtual std::string file_name (void) const |
3326
|
114 { return rep->file_name (); } |
|
115 |
|
116 virtual octave_time time_loaded (void) const |
|
117 { return rep->time_loaded (); } |
|
118 |
|
119 protected: |
|
120 |
|
121 octave_shlib (const octave_xshlib&) : rep (0) { } |
|
122 |
|
123 virtual bool is_open (void) const { return rep->is_open (); } |
|
124 |
|
125 static octave_shlib *make_shlib (void); |
|
126 |
6323
|
127 // TRUE if this function was found from a relative path element. |
|
128 bool relative; |
|
129 |
3326
|
130 union |
|
131 { |
|
132 octave_shlib *rep; |
|
133 int count; |
|
134 }; |
|
135 }; |
|
136 |
|
137 #endif |
|
138 |
|
139 /* |
|
140 ;;; Local Variables: *** |
|
141 ;;; mode: C++ *** |
|
142 ;;; End: *** |
|
143 */ |