PixelLightAPI  .
ConsoleCommand.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: ConsoleCommand.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 __PLENGINE_COMPOSITING_CONSOLECOMMAND_H__
00024 #define __PLENGINE_COMPOSITING_CONSOLECOMMAND_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLCore/Container/Array.h>
00032 #include <PLCore/Base/Func/Functor.h>
00033 #include "PLEngine/PLEngine.h"
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLEngine {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Forward declarations                                  ]
00044 //[-------------------------------------------------------]
00045 class SNConsoleBase;
00046 
00047 
00048 //[-------------------------------------------------------]
00049 //[ Classes                                               ]
00050 //[-------------------------------------------------------]
00051 /**
00052 *  @brief
00053 *    Console command
00054 */
00055 class ConsoleCommand {
00056 
00057 
00058     //[-------------------------------------------------------]
00059     //[ Friends                                               ]
00060     //[-------------------------------------------------------]
00061     friend class SNConsoleBase;
00062 
00063 
00064     //[-------------------------------------------------------]
00065     //[ Public definitions                                    ]
00066     //[-------------------------------------------------------]
00067     public:
00068         /**
00069         *  @brief
00070         *     Console message parameter types
00071         *
00072         *  @remarks
00073         *  @verbatim
00074         *     A paramCode of "FFBIS" would mean:
00075         *     Param Type
00076         *     0     ParamUnknown
00077         *     1     ParamFloat
00078         *     2     ParamInt
00079         *     3     ParamString
00080         *     4     ParamBool
00081         *  @endverbatim
00082         */
00083         enum EMsgParamID {
00084             ParamUnknown,   /**< May not occur! */
00085             ParamFloat,     /**< 'F' */
00086             ParamInt,       /**< 'I' */
00087             ParamString,    /**< 'S' */
00088             ParamBool       /**< 'B' */
00089         };
00090 
00091 
00092     //[-------------------------------------------------------]
00093     //[ Public classes                                        ]
00094     //[-------------------------------------------------------]
00095     public:
00096         /**
00097         *  @brief
00098         *    Console variable
00099         */
00100         class Variable {
00101 
00102 
00103             //[-------------------------------------------------------]
00104             //[ Public data                                           ]
00105             //[-------------------------------------------------------]
00106             public:
00107                 float          f;
00108                 bool           b;
00109                 int            i;
00110                 PLCore::String s;
00111 
00112 
00113             //[-------------------------------------------------------]
00114             //[ Public functions                                      ]
00115             //[-------------------------------------------------------]
00116             public:
00117                 Variable() :
00118                     f(0.0f), b(false), i(0)
00119                 {
00120                 }
00121 
00122                 // [TODO] Implement this?
00123                 Variable &operator =(const Variable &cSource)
00124                 {
00125                     return *this;
00126                 }
00127                 bool operator ==(const Variable &cVar) const
00128                 {
00129                     return false;
00130                 }
00131 
00132 
00133         };
00134 
00135 
00136     //[-------------------------------------------------------]
00137     //[ Public functions                                      ]
00138     //[-------------------------------------------------------]
00139     public:
00140         /**
00141         *  @brief
00142         *    Constructor
00143         *
00144         *  @param[in] bDebug
00145         *    'true' if it is a debug command, else 'false'
00146         *  @param[in] sCommand
00147         *    Command string
00148         *  @param[in] sParameters
00149         *    Parameter string
00150         *  @param[in] sHelp
00151         *    Help string
00152         *  @param[in] cFunctor
00153         *    Execution functor
00154         */
00155         PL_API ConsoleCommand(bool bDebug, const PLCore::String &sCommand, const PLCore::String &sParameters,
00156                               const PLCore::String &sHelp, const PLCore::Functor<void, ConsoleCommand &> &cFunctor);
00157 
00158         /**
00159         *  @brief
00160         *    Copy constructor
00161         *
00162         *  @param[in] cSource
00163         *    Source to copy from
00164         */
00165         PL_API ConsoleCommand(const ConsoleCommand &cSource);
00166 
00167         /**
00168         *  @brief
00169         *    Destructor
00170         */
00171         PL_API ~ConsoleCommand();
00172 
00173         /**
00174         *  @brief
00175         *    Returns the owner console
00176         *
00177         *  @return
00178         *    Owner console, can be a null pointer
00179         */
00180         PL_API SNConsoleBase *GetConsole() const;
00181 
00182         /**
00183         *  @brief
00184         *    Returns whether this is a debug command or not
00185         *
00186         *  @return
00187         *    'true' if it is a debug command, else 'false'
00188         */
00189         PL_API bool IsDebug() const;
00190 
00191         /**
00192         *  @brief
00193         *    Returns the command string
00194         *
00195         *  @return
00196         *    Command string
00197         */
00198         PL_API PLCore::String GetCommand() const;
00199 
00200         /**
00201         *  @brief
00202         *    Returns the parameter string
00203         *
00204         *  @return
00205         *    Parameter string
00206         */
00207         PL_API PLCore::String GetParameters() const;
00208 
00209         /**
00210         *  @brief
00211         *    Returns the help string
00212         *
00213         *  @return
00214         *    Help string
00215         */
00216         PL_API PLCore::String GetHelp() const;
00217 
00218         /**
00219         *  @brief
00220         *    Returns the execution functor
00221         *
00222         *  @return
00223         *    Command execution functor
00224         */
00225         PL_API PLCore::Functor<void, ConsoleCommand &> &GetFunctor();
00226 
00227         /**
00228         *  @brief
00229         *    Check if the params are valid
00230         *
00231         *  @return
00232         *    'true' if the parameters are valid, else 'false'
00233         */
00234         PL_API bool HasValidParams() const;
00235 
00236         /**
00237         *  @brief
00238         *    Returns the number of parameters
00239         *
00240         *  @return
00241         *    Number of command parameters
00242         */
00243         PL_API PLCore::uint32 GetNumOfParams() const;
00244 
00245         /**
00246         *  @brief
00247         *    Returns the parameter type of parameter <nr>
00248         *
00249         *  @param[in] nNr
00250         *    Vars index (must be in range from 0..GetNumOfParams())
00251         *
00252         *  @return
00253         *    The parameter type of parameter
00254         */
00255         PL_API EMsgParamID GetParamType(PLCore::uint32 nNr) const;
00256 
00257         /**
00258         *  @brief
00259         *    Create vars from params (convert string into vars)
00260         *
00261         *  @param[in] sParameters
00262         *    Parameter string
00263         */
00264         PL_API void CreateVarsFromString(const PLCore::String &sParameters);
00265 
00266         /**
00267         *  @brief
00268         *    Returns the vars at the given index
00269         *
00270         *  @param[in] nNr
00271         *    Vars index
00272         *
00273         *  @return
00274         *    The vars at the given index
00275         *
00276         *  @note
00277         *    - CreateVarsFromString() must have been called before this function...
00278         */
00279         PL_API Variable &GetVar(PLCore::uint32 nNr) const;
00280 
00281         /**
00282         *  @brief
00283         *    Copy operator
00284         *
00285         *  @param[in] cSource
00286         *    Source to copy from
00287         *
00288         *  @return
00289         *    This instance
00290         */
00291         PL_API ConsoleCommand &operator =(const ConsoleCommand &cSource);
00292 
00293         /**
00294         *  @brief
00295         *    Compare operator
00296         *
00297         *  @param[in] cCommand
00298         *    Command to compare with
00299         */
00300         PL_API bool operator ==(const ConsoleCommand &cCommand) const;
00301 
00302 
00303     //[-------------------------------------------------------]
00304     //[ Private data                                          ]
00305     //[-------------------------------------------------------]
00306     private:
00307         SNConsoleBase                           *m_pConsole;    /**< Owner console, can be a null pointer */
00308         bool                                     m_bDebug;      /**< Is this a debug command? */
00309         PLCore::String                           m_sCommand;    /**< For example "/fogcolor" */
00310         PLCore::String                           m_sParameters; /**< For example "III" in case you want R G B values (3 integers) */
00311         PLCore::String                           m_sHelp;       /**< For example "<r> <g> <n>" if you want to display "Usage: /fogcolor <r> <g> <b>" as help */
00312         PLCore::Functor<void, ConsoleCommand &>  m_cFunctor;    /**< The console functor which executes this command, always valid! */
00313         PLCore::Array<Variable>                  m_lstVars;     /**< Values for the parameters, which the user entered */
00314 
00315 
00316 };
00317 
00318 
00319 //[-------------------------------------------------------]
00320 //[ Namespace                                             ]
00321 //[-------------------------------------------------------]
00322 } // PLEngine
00323 
00324 
00325 #endif // __PLENGINE_COMPOSITING_CONSOLECOMMAND_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