OpenWalnut 1.2.5
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #include <string> 00026 #include <vector> 00027 #include <cstdlib> 00028 00029 #include <boost/tokenizer.hpp> 00030 00031 #include "WPathHelper.h" 00032 00033 // path helper instance as singleton 00034 boost::shared_ptr< WPathHelper > WPathHelper::m_instance = boost::shared_ptr< WPathHelper >(); 00035 00036 WPathHelper::WPathHelper() 00037 { 00038 // initialize members 00039 } 00040 00041 WPathHelper::~WPathHelper() 00042 { 00043 // cleanup 00044 } 00045 00046 boost::shared_ptr< WPathHelper > WPathHelper::getPathHelper() 00047 { 00048 if( !m_instance ) 00049 { 00050 m_instance = boost::shared_ptr< WPathHelper >( new WPathHelper() ); 00051 } 00052 00053 return m_instance; 00054 } 00055 00056 void WPathHelper::setAppPath( boost::filesystem::path appPath ) 00057 { 00058 m_appPath = appPath; 00059 m_sharePath = m_appPath / "../share/openwalnut"; 00060 m_docPath = m_appPath / "../share/doc"; 00061 m_configPath = m_appPath / "../share/openwalnut"; 00062 m_libPath = m_appPath / "../lib"; 00063 m_modulePath = m_libPath / "openwalnut"; 00064 } 00065 00066 boost::filesystem::path WPathHelper::getAppPath() 00067 { 00068 return getPathHelper()->m_appPath; 00069 } 00070 00071 boost::filesystem::path WPathHelper::getFontPath() 00072 { 00073 return getPathHelper()->m_sharePath / "fonts"; 00074 } 00075 00076 boost::filesystem::path WPathHelper::getShaderPath() 00077 { 00078 return getPathHelper()->m_sharePath / "shaders"; 00079 } 00080 00081 WPathHelper::Fonts WPathHelper::getAllFonts() 00082 { 00083 Fonts fonts; 00084 fonts.Regular = getFontPath() / "Regular.ttf"; 00085 fonts.Bold = getFontPath() / "Bold.ttf"; 00086 fonts.Italic = getFontPath() / "Italic.ttf"; 00087 fonts.Default = fonts.Bold; 00088 00089 return fonts; 00090 } 00091 00092 boost::filesystem::path WPathHelper::getModulePath() 00093 { 00094 return getPathHelper()->m_modulePath; 00095 } 00096 00097 boost::filesystem::path WPathHelper::getLibPath() 00098 { 00099 return getPathHelper()->m_libPath; 00100 } 00101 00102 boost::filesystem::path WPathHelper::getSharePath() 00103 { 00104 return getPathHelper()->m_sharePath; 00105 } 00106 00107 boost::filesystem::path WPathHelper::getDocPath() 00108 { 00109 return getPathHelper()->m_docPath; 00110 } 00111 00112 boost::filesystem::path WPathHelper::getConfigPath() 00113 { 00114 return getPathHelper()->m_configPath; 00115 } 00116 00117 std::vector< boost::filesystem::path > WPathHelper::getAllModulePaths() 00118 { 00119 // the list of paths 00120 std::vector< boost::filesystem::path > paths; 00121 // the first element always is the global search path 00122 paths.push_back( getModulePath() ); 00123 00124 // the environment variable stores the additional paths 00125 std::string additionalPaths( getenv( "OW_MODULE_PATH" ) ? getenv( "OW_MODULE_PATH" ) : "" ); 00126 00127 // separate list of additional paths: 00128 typedef boost::tokenizer< boost::char_separator< char > > tokenizer; 00129 boost::char_separator< char > sep( ";" ); 00130 tokenizer tok( additionalPaths, sep ); 00131 for( tokenizer::iterator it = tok.begin(); it != tok.end(); ++it ) 00132 { 00133 paths.push_back( boost::filesystem::path( *it ) ); 00134 } 00135 00136 return paths; 00137 } 00138