LoadConfig.h
Go to the documentation of this file.
00001 /* 00002 * Copyright 2006-2009 Savarese Software Research Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * https://www.savarese.com/software/ApacheLicense-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00022 #ifndef __SSRC_WSPR_LUA_LOAD_CONFIG_H 00023 #define __SSRC_WSPR_LUA_LOAD_CONFIG_H 00024 00025 #include <boost/filesystem/path.hpp> 00026 00027 #include <ssrc/wispers/utility/DynamicLibrary.h> 00028 #include <ssrc/wispers/lua/Properties.h> 00029 00030 __BEGIN_NS_SSRC_WSPR_LUA 00031 00032 extern "C" typedef properties_ptr fun_type(const std::string &); 00033 extern "C" typedef fun_type* fun_ptr; 00034 00041 class LoadConfig { 00042 NS_SSRC_WSPR_UTILITY::DynamicLibrary _lib; 00043 const fun_ptr _load; 00044 const fun_ptr _load_str; 00045 00046 public: 00047 00048 LoadConfig(const boost::filesystem::path & module_dir) 00049 SSRC_DECL_THROW(NS_SSRC_WSPR_UTILITY::LoadError) : 00050 _lib((module_dir / "wspr.dso.load_config.so").string()), 00051 _load(_lib.symbol<fun_ptr>("ssrc_wispers_load_config")), 00052 _load_str(_lib.symbol<fun_ptr>("ssrc_wispers_load_string_config")) 00053 { } 00054 00055 inline properties_ptr operator()(const std::string & filename) const 00056 SSRC_DECL_THROW(LuaCallError) 00057 { 00058 try { 00059 return _load(filename); 00060 } catch(const LuaCallError & lce) { 00061 // Re-throw a copy to avoid possible segfault if library is unloaded 00062 // before next catch.. 00063 throw LuaCallError(lce); 00064 } 00065 } 00066 00067 inline properties_ptr load_from_string(const std::string & code_str) const 00068 SSRC_DECL_THROW(LuaCallError) 00069 { 00070 try { 00071 return _load_str(code_str); 00072 } catch(const LuaCallError & lce) { 00073 // Re-throw a copy to avoid possible segfault if library is unloaded 00074 // before next catch.. 00075 throw LuaCallError(lce); 00076 } 00077 } 00078 }; 00079 00080 __END_NS_SSRC_WSPR_LUA 00081 00082 #endif
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.