2 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #ifndef _GLIBMM_MODULE_H
4 #define _GLIBMM_MODULE_H
7 /* $Id: module.hg,v 1.5 2004/04/09 14:49:44 murrayc Exp $ */
9 /* Copyright (C) 2002 The gtkmm Development Team
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free
23 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <glibmmconfig.h>
30 GLIBMM_USING_STD(string)
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 extern "C" { typedef struct _GModule GModule; }
40 /** @addtogroup glibmmEnums Enums and Flags */
43 * @ingroup glibmmEnums
44 * @par Bitwise operators:
45 * <tt>%ModuleFlags operator|(ModuleFlags, ModuleFlags)</tt><br>
46 * <tt>%ModuleFlags operator&(ModuleFlags, ModuleFlags)</tt><br>
47 * <tt>%ModuleFlags operator^(ModuleFlags, ModuleFlags)</tt><br>
48 * <tt>%ModuleFlags operator~(ModuleFlags)</tt><br>
49 * <tt>%ModuleFlags& operator|=(ModuleFlags&, ModuleFlags)</tt><br>
50 * <tt>%ModuleFlags& operator&=(ModuleFlags&, ModuleFlags)</tt><br>
51 * <tt>%ModuleFlags& operator^=(ModuleFlags&, ModuleFlags)</tt><br>
55 MODULE_BIND_LAZY = 1 << 0,
56 MODULE_BIND_LOCAL = 1 << 1,
57 MODULE_BIND_MASK = 0x03
60 /** @ingroup glibmmEnums */
61 inline ModuleFlags operator|(ModuleFlags lhs, ModuleFlags rhs)
62 { return static_cast<ModuleFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
64 /** @ingroup glibmmEnums */
65 inline ModuleFlags operator&(ModuleFlags lhs, ModuleFlags rhs)
66 { return static_cast<ModuleFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
68 /** @ingroup glibmmEnums */
69 inline ModuleFlags operator^(ModuleFlags lhs, ModuleFlags rhs)
70 { return static_cast<ModuleFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
72 /** @ingroup glibmmEnums */
73 inline ModuleFlags operator~(ModuleFlags flags)
74 { return static_cast<ModuleFlags>(~static_cast<unsigned>(flags)); }
76 /** @ingroup glibmmEnums */
77 inline ModuleFlags& operator|=(ModuleFlags& lhs, ModuleFlags rhs)
78 { return (lhs = static_cast<ModuleFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
80 /** @ingroup glibmmEnums */
81 inline ModuleFlags& operator&=(ModuleFlags& lhs, ModuleFlags rhs)
82 { return (lhs = static_cast<ModuleFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
84 /** @ingroup glibmmEnums */
85 inline ModuleFlags& operator^=(ModuleFlags& lhs, ModuleFlags rhs)
86 { return (lhs = static_cast<ModuleFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
89 //TODO: Replace get_last_error() with exceptions?
92 /** Dynamic Loading of Modules
93 * These functions provide a portable way to dynamically load object
94 * files (commonly known as 'plug-ins'). The current implementation
95 * supports all systems that provide an implementation of dlopen()
96 * (e.g. Linux/Sun), as well as HP-UX via its shl_load() mechanism,
97 * and Windows platforms via DLLs.
102 #ifndef DOXYGEN_SHOULD_SKIP_THIS
103 typedef Module CppObjectType;
104 typedef GModule BaseObjectType;
105 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
114 * First of all it tries to open file_name as a module. If that
115 * fails and file_name has the ".la"-suffix (and is a libtool
116 * archive) it tries to open the corresponding module. If that fails
117 * and it doesn't have the proper module suffix for the platform
118 * (G_MODULE_SUFFIX), this suffix will be appended and the
119 * corresponding module will be opended. If that fails and file_name
120 * doesn't have the ".la"-suffix, this suffix is appended and
121 * it tries to open the corresponding module.
123 * Use operator bool() to see whether the operation succeeded. For instance,
125 * Glib::Module module("plugins/helloworld");
129 * bool found = get_symbol("some_function", func);
133 * @param file_name The library filename to open
134 * @param flags Flags to configure the load process
136 explicit Module(const std::string& file_name, ModuleFlags flags = ModuleFlags(0));
138 /** Close a module. The module will be removed from memory, unless
139 * <tt>make_resident</tt> has been called.
143 /** Check whether the module was found.
145 operator bool() const;
147 /** Checks if modules are supported on the current platform.
148 * @returns true if available, false otherwise
151 static bool get_supported();
153 /** Ensures that a module will never be unloaded. Any calls to the
154 * Glib::Module destructor will not unload the module.
157 void make_resident();
159 /** Gets a string describing the last module error.
160 * @returns The error string
163 static std::string get_last_error();
165 /** Gets a symbol pointer from the module.
166 * @param symbol_name The name of the symbol to lookup
167 * @param symbol A pointer to set to the symbol
168 * @returns True if the symbol was found, false otherwise.
171 bool get_symbol(const std::string& symbol_name, void*& symbol) const;
173 /** Get the name of the module.
174 * @returns The name of the module
177 std::string get_name() const;
179 /** A portable way to build the filename of a module. The
180 * platform-specific prefix and suffix are added to the filename, if
181 * needed, and the result is added to the directory, using the
182 * correct separator character.
184 * The directory should specify the directory where the module can
185 * be found. It can be an empty string to indicate that the
186 * module is in a standard platform-specific directory, though this
187 * is not recommended since the wrong module may be found.
189 * For example, calling <tt>g_module_build_path()</tt> on a Linux
190 * system with a directory of <tt>/lib</tt> and a module_name of
191 * "mylibrary" will return <tt>/lib/libmylibrary.so</tt>. On a
192 * Windows system, using <tt>\\Windows</tt> as the directory it will
193 * return <tt>\\Windows\\mylibrary.dll</tt>.
195 * @param directory The directory the module is in
196 * @param module_name The name of the module
197 * @returns The system-specific filename of the module
199 // TODO: add an override which doesn't take a directory
200 // TODO: check what happens when directory is ""
202 static std::string build_path(const std::string& directory, const std::string& module_name);
204 GModule* gobj() { return gobject_; }
205 const GModule* gobj() const { return gobject_; }
212 Module(const Module&);
213 Module& operator=(const Module&);
221 #endif /* _GLIBMM_MODULE_H */