ConsoleRule.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #if !defined(AFX_ConsoleRULE_H__7A8C972C_069D_44F7_A604_A8A8D1B4773A__INCLUDED_)
00022 #define AFX_ConsoleRULE_H__7A8C972C_069D_44F7_A604_A8A8D1B4773A__INCLUDED_
00023 
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 
00028 enum ConsoleRuleType
00029 {
00030         ConsoleRuleTypeNone = 0,
00031         ConsoleRuleTypeBoolean,
00032         ConsoleRuleTypeNumber,
00033         ConsoleRuleTypeString
00034 };
00035 
00036 struct ConsoleRuleValue
00037 {
00038         int position;
00039 
00040         std::string valueString;
00041         bool valueBool;
00042         float valueNumber;
00043 
00044         ConsoleRuleType type;
00045 };
00046 
00047 class ConsoleRuleParam
00048 {
00049 public:
00050         ConsoleRuleParam(const std::string &constant);
00051         ConsoleRuleParam(const std::string &name, ConsoleRuleType type);
00052 
00053         const char *getName() { return name_.c_str(); }
00054         ConsoleRuleType getType() { return type_; }
00055 
00056 private:
00057         std::string name_;
00058         ConsoleRuleType type_;
00059 };
00060 
00061 class Console;
00062 class ConsoleRule
00063 {
00064 public:
00065         ConsoleRule(const char *name, 
00066                 const std::vector<ConsoleRuleParam> &params,
00067                 unsigned int userData = 0);
00068         virtual ~ConsoleRule();
00069 
00070         virtual void runRule(
00071                 Console *console,
00072                 const char *wholeLine,
00073                 std::vector<ConsoleRuleValue> &values) = 0;
00074 
00075         std::string toString();
00076         std::string toString(std::vector<ConsoleRuleValue> &values);
00077         static std::string valuesToString(std::vector<ConsoleRuleValue> &values);
00078 
00079         const char *getName() { return name_.c_str(); }
00080         std::vector<ConsoleRuleParam> &getParams() { return params_; }
00081         unsigned int getUserData() { return userData_; }
00082 
00083         bool matchesPartialParams(std::vector<ConsoleRuleValue> &values);
00084         bool matchesExactParams(std::vector<ConsoleRuleValue> &values);
00085 protected:
00086         std::string name_;
00087         std::vector<ConsoleRuleParam> params_;
00088         unsigned int userData_;
00089 
00090 };
00091 
00092 class ConsoleUtil
00093 {
00094 public:
00095         static std::vector<ConsoleRuleParam> formParams(
00096                 const ConsoleRuleParam &param1);
00097         static std::vector<ConsoleRuleParam> formParams(
00098                 const ConsoleRuleParam &param1, 
00099                 const ConsoleRuleParam &param2);
00100         static std::vector<ConsoleRuleParam> formParams(
00101                 const ConsoleRuleParam &param1, 
00102                 const ConsoleRuleParam &param2, 
00103                 const ConsoleRuleParam &param3);
00104         static std::vector<ConsoleRuleParam> formParams(
00105                 const ConsoleRuleParam &param1, 
00106                 const ConsoleRuleParam &param2, 
00107                 const ConsoleRuleParam &param3, 
00108                 const ConsoleRuleParam &param4);
00109         static std::vector<ConsoleRuleParam> formParams(
00110                 const ConsoleRuleParam &param1, 
00111                 const ConsoleRuleParam &param2, 
00112                 const ConsoleRuleParam &param3, 
00113                 const ConsoleRuleParam &param4, 
00114                 const ConsoleRuleParam &param5);
00115 };
00116 
00117 #endif // !defined(AFX_ConsoleRULE_H__7A8C972C_069D_44F7_A604_A8A8D1B4773A__INCLUDED_)

Generated on Mon Feb 16 15:14:37 2009 for Scorched3D by  doxygen 1.5.3