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 #ifndef WPATHHELPER_H 00026 #define WPATHHELPER_H 00027 00028 #include <vector> 00029 00030 // Use filesystem version 2 for compatibility with newer boost versions. 00031 #ifndef BOOST_FILESYSTEM_VERSION 00032 #define BOOST_FILESYSTEM_VERSION 2 00033 #endif 00034 #include <boost/filesystem.hpp> 00035 #include <boost/shared_ptr.hpp> 00036 00037 #include "WExportCommon.h" 00038 00039 /** 00040 * Singleton class helping to find files and paths. It is a useful to to search for resources and the central place to "hardcode" relative paths. 00041 * It contains global paths only. Modules have their OWN local paths. 00042 */ 00043 class OWCOMMON_EXPORT WPathHelper // NOLINT 00044 { 00045 public: 00046 00047 /** 00048 * Destructor. 00049 */ 00050 virtual ~WPathHelper(); 00051 00052 /** 00053 * Returns instance of the path helper. If it does not exists, it will be created. 00054 * 00055 * \return the running path helper instance. 00056 */ 00057 static boost::shared_ptr< WPathHelper > getPathHelper(); 00058 00059 /** 00060 * Set the current application path. This should be called only once. 00061 * 00062 * \param appPath the application path 00063 */ 00064 void setAppPath( boost::filesystem::path appPath ); 00065 00066 /** 00067 * The path where the binary file resides in. This is for example /usr/bin. 00068 * 00069 * \return the application path. 00070 */ 00071 static boost::filesystem::path getAppPath(); 00072 00073 /** 00074 * The path where font files reside in. 00075 * 00076 * \return the font path. 00077 */ 00078 static boost::filesystem::path getFontPath(); 00079 00080 /** 00081 * Paths to all known fonts. 00082 */ 00083 typedef struct 00084 { 00085 /** 00086 * The default font to use in most cases. 00087 */ 00088 boost::filesystem::path Default; 00089 00090 /** 00091 * The Regular font (not bold, not italic) 00092 */ 00093 boost::filesystem::path Regular; 00094 00095 /** 00096 * Italic font. 00097 */ 00098 boost::filesystem::path Italic; 00099 00100 /** 00101 * Bold font. 00102 */ 00103 boost::filesystem::path Bold; 00104 } 00105 Fonts; 00106 00107 /** 00108 * The paths to all fonts supported. 00109 * 00110 * \return the file paths to all fonts 00111 */ 00112 static Fonts getAllFonts(); 00113 00114 /** 00115 * The path to the global shaders. Modules usually have their own local shader directory. 00116 * 00117 * \return global shader path. 00118 */ 00119 static boost::filesystem::path getShaderPath(); 00120 00121 /** 00122 * The path to the globally installed modules. This does not respect any environment variables or config options! Use this only to search 00123 * global modules. To get a list of all module search paths, including user defined ones, use getAllModulePaths(). 00124 * 00125 * \return path to globally installed modules. 00126 */ 00127 static boost::filesystem::path getModulePath(); 00128 00129 /** 00130 * This returns a list of search paths for modules. This list is defined by the environment variable "OW_MODULE_PATH". All of these 00131 * directories CAN contain modules. On startup, they get searched in the specified order. 00132 * 00133 * \return list of search paths for modules 00134 */ 00135 static std::vector< boost::filesystem::path > getAllModulePaths(); 00136 00137 /** 00138 * The path to the OW libs. You normally should not need this. 00139 * 00140 * \return the path to the libs. 00141 */ 00142 static boost::filesystem::path getLibPath(); 00143 00144 /** 00145 * The path where shared files reside in. 00146 * 00147 * \return the shared files path. 00148 */ 00149 static boost::filesystem::path getSharePath(); 00150 00151 /** 00152 * The path where the doc files reside in. 00153 * 00154 * \return the doc file path. 00155 */ 00156 static boost::filesystem::path getDocPath(); 00157 00158 /** 00159 * The path where the config files reside in. 00160 * 00161 * \return the config file path. 00162 */ 00163 static boost::filesystem::path getConfigPath(); 00164 00165 protected: 00166 00167 /** 00168 * Constructors are protected because this is a Singleton. 00169 */ 00170 WPathHelper(); 00171 00172 private: 00173 00174 /** 00175 * Application path. NOT the path of the binary. The application path is the directory in which the binary is placed. 00176 * The binary path is m_appPath+"/openwalnut". 00177 */ 00178 boost::filesystem::path m_appPath; 00179 00180 /** 00181 * The path where all the shared files reside in. 00182 */ 00183 boost::filesystem::path m_sharePath; 00184 00185 /** 00186 * The path where all the documentation files reside in. 00187 */ 00188 boost::filesystem::path m_docPath; 00189 00190 /** 00191 * The path where all the config files reside in. 00192 */ 00193 boost::filesystem::path m_configPath; 00194 00195 /** 00196 * The path to the globally installed modules. 00197 */ 00198 boost::filesystem::path m_modulePath; 00199 00200 /** 00201 * The path to the OW libs. 00202 */ 00203 boost::filesystem::path m_libPath; 00204 00205 /** 00206 * Singleton instance of WPathHelper. 00207 */ 00208 static boost::shared_ptr< WPathHelper > m_instance; 00209 }; 00210 00211 #endif // WPATHHELPER_H 00212