PixelLightAPI  .
ApplicationContext.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: ApplicationContext.h                           *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_APPLICATIONCONTEXT_H__
00024 #define __PLCORE_APPLICATIONCONTEXT_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/Base/Object.h"
00032 #include "PLCore/Core/AbstractContext.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLCore {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Classes                                               ]
00043 //[-------------------------------------------------------]
00044 /**
00045 *  @brief
00046 *    Application context
00047 *
00048 *  @remarks
00049 *    The application context stores data and information for an application,
00050 *    such as startup information (what was the current directory when the
00051 *    application started) or paths to needed resources.
00052 */
00053 class ApplicationContext : public Object, public AbstractContext {
00054 
00055 
00056     //[-------------------------------------------------------]
00057     //[ RTTI interface                                        ]
00058     //[-------------------------------------------------------]
00059     pl_class(PLCORE_RTTI_EXPORT, ApplicationContext, "PLCore", PLCore::Object, "Application context")
00060         #ifdef PLCORE_EXPORTS   // The following is only required when compiling PLCore
00061             // Methods
00062             pl_method_0(GetExecutableFilename,  pl_ret_type(String),    "Get absolute path of application executable (native path style, e.g. on Windows: 'C:\MyApplication\x86\Test.exe').",               "")
00063             pl_method_0(GetExecutableDirectory, pl_ret_type(String),    "Get directory of executable (native path style, e.g. on Windows: 'C:\MyApplication\x86').",                                        "")
00064             pl_method_0(GetAppDirectory,        pl_ret_type(String),    "Get directory of application (native path style, e.g. on Windows: 'C:\MyApplication').",                                           "")
00065             pl_method_0(GetStartupDirectory,    pl_ret_type(String),    "Get current directory when the application constructor was called (native path style, e.g. on Windows: 'C:\MyApplication\x86').",  "")
00066             pl_method_0(GetLogFilename,         pl_ret_type(String),    "Get absolute path to log file, empty if log has not been opened (native path style).",                                             "")
00067             pl_method_0(GetConfigFilename,      pl_ret_type(String),    "Get absolute path to config file, empty if no config is used (native path style).",                                                "")
00068         #endif
00069     pl_class_end
00070 
00071 
00072     //[-------------------------------------------------------]
00073     //[ Public functions                                      ]
00074     //[-------------------------------------------------------]
00075     public:
00076         /**
00077         *  @brief
00078         *    Constructor
00079         */
00080         PLCORE_API ApplicationContext();
00081 
00082         /**
00083         *  @brief
00084         *    Destructor
00085         */
00086         PLCORE_API virtual ~ApplicationContext();
00087 
00088 
00089         //[-------------------------------------------------------]
00090         //[ Options and data                                      ]
00091         //[-------------------------------------------------------]
00092         /**
00093         *  @brief
00094         *    Get absolute path of application executable
00095         *
00096         *  @return
00097         *    Path to executable (native path style, e.g. on Windows: 'C:\MyApplication\x86\Test.exe')
00098         */
00099         inline String GetExecutableFilename() const;
00100 
00101         /**
00102         *  @brief
00103         *    Set absolute path of application executable
00104         *
00105         *  @param[in] sExecutableFilename
00106         *    Path to executable (e.g. on Windows: 'C:\MyApplication\x86\Test.exe', automatically converted internally to native path style)
00107         */
00108         PLCORE_API void SetExecutableFilename(const String &sExecutableFilename);
00109 
00110         /**
00111         *  @brief
00112         *    Get command line arguments
00113         *
00114         *  @return
00115         *    List of command line arguments that were passed to the program
00116         */
00117         inline const Array<String> &GetArguments() const;
00118 
00119         /**
00120         *  @brief
00121         *    Set command line arguments
00122         *
00123         *  @param[in] lstArguments
00124         *    List of command line arguments that were passed to the program
00125         */
00126         inline void SetArguments(const Array<String> &lstArguments);
00127 
00128         /**
00129         *  @brief
00130         *    Get directory of application executable
00131         *
00132         *  @return
00133         *    Directory in which the application executable is (native path style, e.g. on Windows: 'C:\MyApplication\x86')
00134         *
00135         *  @remarks
00136         *    This is just a convenience function and is the same as using
00137         *      Url(Url(GetExecutableFile()).CutFilename()).Collapse().GetNativePath()
00138         */
00139         inline String GetExecutableDirectory() const;
00140 
00141         /**
00142         *  @brief
00143         *    Get directory of application
00144         *
00145         *  @return
00146         *    Directory in which the application is (native path style, e.g. on Windows: 'C:\MyApplication')
00147         *
00148         *  @remarks
00149         *    This is just a convenience function and is the same as using
00150         *      Url(Url(GetExecutableFile()).CutFilename() + "../").Collapse().GetNativePath()
00151         */
00152         inline String GetAppDirectory() const;
00153 
00154         /**
00155         *  @brief
00156         *    Get current directory when the application constructor was called
00157         *
00158         *  @return
00159         *    Current directory that was set when the application constructor was called (native path style, e.g. on Windows: 'C:\MyApplication\x86')
00160         */
00161         inline String GetStartupDirectory() const;
00162 
00163         /**
00164         *  @brief
00165         *    Set current directory when the application constructor was called
00166         *
00167         *  @param[in] sStartupDirectory
00168         *    Current directory that was set when the application constructor was called (automatically converted internally to native path style)
00169         */
00170         PLCORE_API void SetStartupDirectory(const String &sStartupDirectory);
00171 
00172         /**
00173         *  @brief
00174         *    Get log filename
00175         *
00176         *  @return
00177         *    Absolute path to log file, empty if log has not been opened (native path style)
00178         */
00179         inline String GetLogFilename() const;
00180 
00181         /**
00182         *  @brief
00183         *    Set log filename
00184         *
00185         *  @param[in] sLog
00186         *    Absolute path to log file, empty if log has not been opened (automatically converted internally to native path style)
00187         */
00188         PLCORE_API void SetLogFilename(const String &sLog);
00189 
00190         /**
00191         *  @brief
00192         *    Get config filename
00193         *
00194         *  @return
00195         *    Absolute path to config file, empty if no config is used (native path style)
00196         */
00197         inline String GetConfigFilename() const;
00198 
00199         /**
00200         *  @brief
00201         *    Set config filename
00202         *
00203         *  @param[in] sConfig
00204         *    Absolute path to config file, empty if no config is used (automatically converted internally to native path style)
00205         */
00206         PLCORE_API void SetConfigFilename(const String &sConfig);
00207 
00208 
00209         //[-------------------------------------------------------]
00210         //[ Tool functions                                        ]
00211         //[-------------------------------------------------------]
00212         /**
00213         *  @brief
00214         *    Sets the current directory to the path of the application executable
00215         *
00216         *  @note
00217         *    - Whenever possible, do not manipulate the current directory, this may backfire when you don't expect it
00218         *    - Because the executable filename is used, which is set within "CoreApplication::Run()",
00219         *      calling this method from inside a application constructor is not recommended
00220         */
00221         PLCORE_API void ChangeIntoAppDirectory() const;
00222 
00223 
00224     //[-------------------------------------------------------]
00225     //[ Protected data                                        ]
00226     //[-------------------------------------------------------]
00227     protected:
00228         String          m_sExecutableFilename;  /**< Absolute executable filename of the application */
00229         Array<String>   m_lstArguments;         /**< Argument list */
00230         String          m_sExecutableDirectory; /**< Application directory (derived from "m_sExecutableFilename") */
00231         String          m_sAppDirectory;        /**< Application directory (derived from "m_sExecutableFilename") */
00232         String          m_sStartupDirectory;    /**< The current directory when the application constructor was called */
00233         String          m_sLog;                 /**< Absolute path to log file, empty if log has not been opened */
00234         String          m_sConfig;              /**< Absolute path to config file, empty if no config is used */
00235 
00236 
00237 };
00238 
00239 
00240 //[-------------------------------------------------------]
00241 //[ Namespace                                             ]
00242 //[-------------------------------------------------------]
00243 } // PLCore
00244 
00245 
00246 //[-------------------------------------------------------]
00247 //[ Implementation                                        ]
00248 //[-------------------------------------------------------]
00249 #include "PLCore/Application/ApplicationContext.inl"
00250 
00251 
00252 #endif // __PLCORE_APPLICATIONCONTEXT_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:52
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported