WPathHelper.h 5.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WPATHHELPER_H
#define WPATHHELPER_H

#include <vector>

30 31 32 33
// Use filesystem version 2 for compatibility with newer boost versions.
#ifndef BOOST_FILESYSTEM_VERSION
    #define BOOST_FILESYSTEM_VERSION 2
#endif
34 35 36
#include <boost/filesystem.hpp>
#include <boost/shared_ptr.hpp>

37
#include "WExportCommon.h"
38 39 40 41
/**
 * 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.
 * It contains global paths only. Modules have their OWN local paths.
 */
42
class OWCOMMON_EXPORT WPathHelper // NOLINT
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
{
public:

    /**
     * Destructor.
     */
    virtual ~WPathHelper();

    /**
     * Returns instance of the path helper. If it does not exists, it will be created.
     *
     * \return the running path helper instance.
     */
    static boost::shared_ptr< WPathHelper > getPathHelper();

    /**
     * Set the current application path. This should be called only once.
     *
     * \param appPath the application path
     */
    void setAppPath( boost::filesystem::path appPath );

    /**
     * The path where the binary file resides in. This is for example /usr/bin.
     *
     * \return the application path.
     */
    static boost::filesystem::path getAppPath();

    /**
     * The path where font files reside in.
     *
     * \return the font path.
     */
    static boost::filesystem::path getFontPath();

    /**
     * Paths to all known fonts.
     */
    typedef struct
    {
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
84 85 86
        /**
         * The default font to use in most cases.
         */
87
        boost::filesystem::path Default;
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
88 89 90 91

        /**
         * The Regular font (not bold, not italic)
         */
92
        boost::filesystem::path Regular;
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
93 94 95 96

        /**
         * Italic font.
         */
97
        boost::filesystem::path Italic;
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
98 99 100 101

        /**
         * Bold font.
         */
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
        boost::filesystem::path Bold;
    }
    Fonts;

    /**
     * The paths to all fonts supported.
     *
     * \return the file paths to all fonts
     */
    static Fonts getAllFonts();

    /**
     * The path to the global shaders. Modules usually have their own local shader directory.
     *
     * \return global shader path.
     */
    static boost::filesystem::path getShaderPath();

    /**
     * The path to the globally installed modules. This does not respect any environment variables or config options! Use this only to search
     * global modules. To get a list of all module search paths, including user defined ones, use getAllModulePaths().
     *
     * \return path to globally installed modules.
     */
    static boost::filesystem::path getModulePath();

    /**
129
     * This returns a list of search paths for modules. This list is defined by the environment variable "OW_MODULE_PATH". All of these
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
     * directories CAN contain modules. On startup, they get searched in the specified order.
     *
     * \return list of search paths for modules
     */
    static std::vector< boost::filesystem::path > getAllModulePaths();

    /**
     * The path to the OW libs. You normally should not need this.
     *
     * \return the path to the libs.
     */
    static boost::filesystem::path getLibPath();

    /**
     * The path where shared files reside in.
     *
     * \return the shared files path.
     */
    static boost::filesystem::path getSharePath();

150 151 152 153 154 155 156
    /**
     * The path where the doc files reside in.
     *
     * \return the doc file path.
     */
    static boost::filesystem::path getDocPath();

157 158 159 160 161 162 163
    /**
     * The path where the config files reside in.
     *
     * \return the config file path.
     */
    static boost::filesystem::path getConfigPath();

164 165
protected:

166 167 168 169 170
    /**
     * Constructors are protected because this is a Singleton.
     */
    WPathHelper();

171 172 173
private:

    /**
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
174 175
     * Application path. NOT the path of the binary. The application path is the directory in which the binary is placed.
     * The binary path is m_appPath+"/openwalnut".
176 177 178 179 180 181 182 183
     */
    boost::filesystem::path m_appPath;

    /**
     * The path where all the shared files reside in.
     */
    boost::filesystem::path m_sharePath;

184 185 186 187 188
    /**
     * The path where all the documentation files reside in.
     */
    boost::filesystem::path m_docPath;

189 190 191 192 193
    /**
     * The path where all the config files reside in.
     */
    boost::filesystem::path m_configPath;

194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    /**
     * The path to the globally installed modules.
     */
    boost::filesystem::path m_modulePath;

    /**
     * The path to the OW libs.
     */
    boost::filesystem::path m_libPath;

    /**
     * Singleton instance of WPathHelper.
     */
    static boost::shared_ptr< WPathHelper > m_instance;
};

#endif  // WPATHHELPER_H