PixelLightAPI  .
ApplicationContext.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: ApplicationContext.h                           *
00003  *
00004  *  Copyright (C) 2002-2011 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 (e.g. on Windows: 'C:\MyApplication\Test.exe').",              "")
00063             pl_method_0(GetAppDirectory,        pl_ret_type(String),    "Get directory of application executable (e.g. on Windows: 'C:\MyApplication').",                           "")
00064             pl_method_0(GetStartupDirectory,    pl_ret_type(String),    "Get current directory when the application constructor was called (e.g. on Windows: 'C:\MyApplication').", "")
00065             pl_method_0(GetLogFilename,         pl_ret_type(String),    "Get absolute path to log file, empty if log has not been opened.",                                         "")
00066             pl_method_0(GetConfigFilename,      pl_ret_type(String),    "Get absolute path to config file, empty if no config is used.",                                            "")
00067         #endif
00068     pl_class_end
00069 
00070 
00071     //[-------------------------------------------------------]
00072     //[ Public functions                                      ]
00073     //[-------------------------------------------------------]
00074     public:
00075         /**
00076         *  @brief
00077         *    Constructor
00078         */
00079         PLCORE_API ApplicationContext();
00080 
00081         /**
00082         *  @brief
00083         *    Destructor
00084         */
00085         PLCORE_API virtual ~ApplicationContext();
00086 
00087 
00088         //[-------------------------------------------------------]
00089         //[ Options and data                                      ]
00090         //[-------------------------------------------------------]
00091         /**
00092         *  @brief
00093         *    Get absolute path of application executable
00094         *
00095         *  @return
00096         *    Path to executable (e.g. on Windows: 'C:\MyApplication\Test.exe')
00097         */
00098         inline String GetExecutableFilename() const;
00099 
00100         /**
00101         *  @brief
00102         *    Set absolute path of application executable
00103         *
00104         *  @param[in] sExecutableFilename
00105         *    Path to executable (e.g. on Windows: 'C:\MyApplication\Test.exe')
00106         */
00107         PLCORE_API void SetExecutableFilename(const String &sExecutableFilename);
00108 
00109         /**
00110         *  @brief
00111         *    Get command line arguments
00112         *
00113         *  @return
00114         *    List of command line arguments that were passed to the program
00115         */
00116         inline const Array<String> &GetArguments() const;
00117 
00118         /**
00119         *  @brief
00120         *    Set command line arguments
00121         *
00122         *  @param[in] lstArguments
00123         *    List of command line arguments that were passed to the program
00124         */
00125         inline void SetArguments(const Array<String> &lstArguments);
00126 
00127         /**
00128         *  @brief
00129         *    Get directory of application executable
00130         *
00131         *  @return
00132         *    Directory in which the application executable is (e.g. on Windows: 'C:\MyApplication')
00133         *
00134         *  @remarks
00135         *    This is just a convenience function and is the same as using
00136         *      Url(Url(GetExecutableFile()).CutFilename() + "../").Collapse().GetUrl()
00137         */
00138         inline String GetAppDirectory() const;
00139 
00140         /**
00141         *  @brief
00142         *    Get current directory when the application constructor was called
00143         *
00144         *  @return
00145         *    Current directory that was set when the application constructor was called (e.g. on Windows: 'C:\MyApplication')
00146         */
00147         inline String GetStartupDirectory() const;
00148 
00149         /**
00150         *  @brief
00151         *    Set current directory when the application constructor was called
00152         *
00153         *  @param[in] sStartupDirectory
00154         *    Current directory that was set when the application constructor was called
00155         */
00156         inline void SetStartupDirectory(const String &sStartupDirectory);
00157 
00158         /**
00159         *  @brief
00160         *    Get log filename
00161         *
00162         *  @return
00163         *    Absolute path to log file, empty if log has not been opened
00164         */
00165         inline String GetLogFilename() const;
00166 
00167         /**
00168         *  @brief
00169         *    Set log filename
00170         *
00171         *  @param[in] sLog
00172         *    Absolute path to log file, empty if log has not been opened
00173         */
00174         inline void SetLogFilename(const String &sLog);
00175 
00176         /**
00177         *  @brief
00178         *    Get config filename
00179         *
00180         *  @return
00181         *    Absolute path to config file, empty if no config is used
00182         */
00183         inline String GetConfigFilename() const;
00184 
00185         /**
00186         *  @brief
00187         *    Set config filename
00188         *
00189         *  @param[in] sConfig
00190         *    Absolute path to config file, empty if no config is used
00191         */
00192         inline void SetConfigFilename(const String &sConfig);
00193 
00194 
00195         //[-------------------------------------------------------]
00196         //[ Tool functions                                        ]
00197         //[-------------------------------------------------------]
00198         /**
00199         *  @brief
00200         *    Sets the current directory to the path of the application executable
00201         *
00202         *  @note
00203         *    - Whenever possible, do not manipulate the current directory, this may backfire when you don't expect it
00204         *    - Because the executable filename is used, which is set within "CoreApplication::Run()",
00205         *      calling this method from inside a application constructor is not recommended
00206         */
00207         PLCORE_API void ChangeIntoAppDirectory() const;
00208 
00209 
00210     //[-------------------------------------------------------]
00211     //[ Protected data                                        ]
00212     //[-------------------------------------------------------]
00213     protected:
00214         String          m_sExecutableFilename;  /**< Absolute executable filename of the application */
00215         Array<String>   m_lstArguments;         /**< Argument list */
00216         String          m_sAppDirectory;        /**< Application directory */
00217         String          m_sStartupDirectory;    /**< The current directory when the application constructor was called */
00218         String          m_sLog;                 /**< Absolute path to log file, empty if log has not been opened */
00219         String          m_sConfig;              /**< Absolute path to config file, empty if no config is used */
00220 
00221 
00222 };
00223 
00224 
00225 //[-------------------------------------------------------]
00226 //[ Namespace                                             ]
00227 //[-------------------------------------------------------]
00228 } // PLCore
00229 
00230 
00231 //[-------------------------------------------------------]
00232 //[ Implementation                                        ]
00233 //[-------------------------------------------------------]
00234 #include "PLCore/Application/ApplicationContext.inl"
00235 
00236 
00237 #endif // __PLCORE_APPLICATIONCONTEXT_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:51
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported