1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 // File: vogl_dynamic_module.h
29 // TODO: Add Linux support!
33 #include "vogl_core.h"
37 typedef void *dynamic_module_handle_t;
39 dynamic_module_handle_t load_dynamic_module(const char *pModule_filename);
40 void unload_dynamic_module(dynamic_module_handle_t handle);
41 void *get_dynamic_module_proc_address(dynamic_module_handle_t handle, const char *pFunc_name);
42 void *lookup_dynamic_module_func(const char *pModule_filename, const char *pFunc_name);
44 class dynamic_module_cache
47 dynamic_module_cache();
48 ~dynamic_module_cache();
52 bool is_module_loaded(const char *pModule_filename);
53 dynamic_module_handle_t get_module(const char *pModule_filename);
55 static dynamic_module_cache &get_global()
57 static dynamic_module_cache s_module_cache;
58 return s_module_cache;
64 dynamic_string m_filename;
65 dynamic_module_handle_t m_handle;
68 vogl::vector<loaded_module> m_modules;
71 template <typename dynamic_func_def_t>
72 class dynamic_function
79 dynamic_function(const char *pModule_filename, const char *pFunc_name)
82 lookup(pModule_filename, pFunc_name);
90 inline dynamic_func_def_t get_ptr() const
94 inline operator dynamic_func_def_t() const
99 inline void set(dynamic_func_def_t ptr)
104 inline operator bool() const
106 return m_pFunc != NULL;
108 inline bool operator!() const
110 return m_pFunc == NULL;
113 inline bool lookup(const char *pModule_filename, const char *pFunc_name)
116 m_pFunc = (dynamic_func_def_t)lookup_dynamic_module_func(pModule_filename, pFunc_name);
117 return m_pFunc != NULL;
121 dynamic_func_def_t m_pFunc;