GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-shlib.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1999-2017 John W. Eaton
4 Copyright (C) 2009 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_oct_shlib_h)
25 #define octave_oct_shlib_h 1
26 
27 #include "octave-config.h"
28 
29 #include <string>
30 #include <map>
31 
32 #include "oct-time.h"
33 #include "oct-refcount.h"
34 
35 namespace octave
36 {
37  class
38  OCTAVE_API
40  {
41  public: // FIXME: make this class private?
42 
43  typedef std::string (*name_mangler) (const std::string&);
44  typedef void (*close_hook) (const std::string&);
45 
46  class dynlib_rep
47  {
48  public:
49 
50  dynlib_rep (void)
51  : count (1), file (), tm_loaded (time_t ()), fcn_names () { }
52 
53  protected:
54 
55  dynlib_rep (const std::string& f);
56 
57  public:
58 
59  virtual ~dynlib_rep (void)
60  {
61  instances.erase (file);
62  }
63 
64  virtual bool is_open (void) const
65  { return false; }
66 
67  virtual void *search (const std::string&, name_mangler = 0)
68  { return 0; }
69 
70  bool is_out_of_date (void) const;
71 
72  // This method will be overridden conditionally.
73  static dynlib_rep *new_instance (const std::string& f);
74 
75  static dynlib_rep *get_instance (const std::string& f, bool fake);
76 
78  { return tm_loaded; }
79 
80  std::string file_name (void) const
81  { return file; }
82 
83  size_t num_fcn_names (void) const { return fcn_names.size (); }
84 
85  void add_fcn_name (const std::string&);
86 
87  bool remove_fcn_name (const std::string&);
88 
89  void do_close_hook (close_hook cl_hook);
90 
91  public:
92 
94 
95  protected:
96 
97  void fake_reload (void);
98 
101 
102  // Set of hooked function names.
103  typedef std::map<std::string, size_t>::iterator fcn_names_iterator;
104  typedef std::map<std::string, size_t>::const_iterator fcn_names_const_iterator;
105 
106  std::map<std::string, size_t> fcn_names;
107 
108  static std::map<std::string, dynlib_rep *> instances;
109  };
110 
111  private:
112 
114 
115  public:
116 
117  dynamic_library (void) : rep (&nil_rep) { rep->count++; }
118 
119  dynamic_library (const std::string& f, bool fake = true)
120  : rep (dynlib_rep::get_instance (f, fake)) { }
121 
123  {
124  if (--rep->count == 0)
125  delete rep;
126  }
127 
129  : rep (sl.rep)
130  {
131  rep->count++;
132  }
133 
134  dynamic_library& operator = (const dynamic_library& sl)
135  {
136  if (rep != sl.rep)
137  {
138  if (--rep->count == 0)
139  delete rep;
140 
141  rep = sl.rep;
142  rep->count++;
143  }
144 
145  return *this;
146  }
147 
148  bool operator == (const dynamic_library& sl) const
149  { return (rep == sl.rep); }
150 
151  operator bool () const { return rep->is_open (); }
152 
153  void open (const std::string& f)
154  { *this = dynamic_library (f); }
155 
156  void close (close_hook cl_hook = 0)
157  {
158  if (cl_hook)
159  rep->do_close_hook (cl_hook);
160 
161  *this = dynamic_library ();
162  }
163 
164  void *search (const std::string& nm, name_mangler mangler = 0) const
165  {
166  void *f = rep->search (nm, mangler);
167  if (f)
168  rep->add_fcn_name (nm);
169 
170  return f;
171  }
172 
173  void add (const std::string& name)
174  { rep->add_fcn_name (name); }
175 
176  bool remove (const std::string& name)
177  { return rep->remove_fcn_name (name); }
178 
179  size_t number_of_functions_loaded (void) const
180  { return rep->num_fcn_names (); }
181 
182  bool is_out_of_date (void) const
183  { return rep->is_out_of_date (); }
184 
185  std::string file_name (void) const
186  { return rep->file_name (); }
187 
189  { return rep->time_loaded (); }
190 
191  private:
192 
194  };
195 }
196 
197 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
198 
199 OCTAVE_DEPRECATED ("use 'octave::dynamic_library' instead")
200 typedef octave::dynamic_library octave_shlib;
201 
202 #endif
203 
204 #endif
virtual bool is_open(void) const
Definition: oct-shlib.h:64
virtual void * search(const std::string &, name_mangler=0)
Definition: oct-shlib.h:67
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
void * search(const std::string &nm, name_mangler mangler=0) const
Definition: oct-shlib.h:164
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
std::map< std::string, size_t >::const_iterator fcn_names_const_iterator
Definition: oct-shlib.h:104
static std::map< std::string, dynlib_rep * > instances
Definition: oct-shlib.h:108
size_t num_fcn_names(void) const
Definition: oct-shlib.h:83
bool is_out_of_date(void) const
Definition: oct-shlib.h:182
std::map< std::string, size_t > fcn_names
Definition: oct-shlib.h:106
dynamic_library(const std::string &f, bool fake=true)
Definition: oct-shlib.h:119
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
std::string file_name(void) const
Definition: oct-shlib.h:80
octave_refcount< int > count
Definition: oct-shlib.h:93
bool operator==(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:538
static dynlib_rep nil_rep
Definition: oct-shlib.h:113
size_t number_of_functions_loaded(void) const
Definition: oct-shlib.h:179
octave::sys::time time_loaded(void) const
Definition: oct-shlib.h:188
void add(const std::string &name)
Definition: oct-shlib.h:173
dynamic_library(const dynamic_library &sl)
Definition: oct-shlib.h:128
void open(const std::string &f)
Definition: oct-shlib.h:153
octave::sys::time time_loaded(void) const
Definition: oct-shlib.h:77
std::string file_name(void) const
Definition: oct-shlib.h:185
void close(close_hook cl_hook=0)
Definition: oct-shlib.h:156
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
std::map< std::string, size_t >::iterator fcn_names_iterator
Definition: oct-shlib.h:103