00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 00026 #ifndef __StringInterface_H__ 00027 #define __StringInterface_H__ 00028 00029 #include "OgrePrerequisites.h" 00030 #include "OgreString.h" 00031 00032 namespace Ogre { 00033 00034 00036 enum ParameterType 00037 { 00038 PT_BOOL, 00039 PT_REAL, 00040 PT_INT, 00041 PT_UNSIGNED_INT, 00042 PT_SHORT, 00043 PT_UNSIGNED_SHORT, 00044 PT_LONG, 00045 PT_UNSIGNED_LONG, 00046 PT_STRING, 00047 PT_VECTOR3, 00048 PT_MATRIX3, 00049 PT_MATRIX4, 00050 PT_QUATERNION, 00051 PT_COLOURVALUE 00052 }; 00053 00055 class _OgreExport ParameterDef 00056 { 00057 public: 00058 String name; 00059 String description; 00060 ParameterType paramType; 00061 ParameterDef(const String& newName, const String& newDescription, ParameterType newType) 00062 : name(newName), description(newDescription), paramType(newType) {} 00063 }; 00064 typedef std::vector<ParameterDef> ParameterList; 00065 00067 class _OgreExport ParamCommand 00068 { 00069 public: 00070 virtual String doGet(const void* target) const = 0; 00071 virtual void doSet(void* target, const String& val) = 0; 00072 }; 00073 typedef std::map<String, ParamCommand* > ParamCommandMap; 00074 00076 class _OgreExport ParamDictionary 00077 { 00078 friend class StringInterface; 00079 protected: 00081 ParameterList mParamDefs; 00082 00084 ParamCommandMap mParamCommands; 00085 00087 ParamCommand* getParamCommand(const String& name) 00088 { 00089 ParamCommandMap::iterator i = mParamCommands.find(name); 00090 if (i != mParamCommands.end()) 00091 { 00092 return i->second; 00093 } 00094 else 00095 { 00096 return 0; 00097 } 00098 } 00099 00100 const ParamCommand* getParamCommand(const String& name) const 00101 { 00102 ParamCommandMap::const_iterator i = mParamCommands.find(name); 00103 if (i != mParamCommands.end()) 00104 { 00105 return i->second; 00106 } 00107 else 00108 { 00109 return 0; 00110 } 00111 } 00112 public: 00113 ParamDictionary() {} 00120 void addParameter(const ParameterDef& paramDef, ParamCommand* paramCmd) 00121 { 00122 mParamDefs.push_back(paramDef); 00123 mParamCommands[paramDef.name] = paramCmd; 00124 } 00130 const ParameterList& getParameters(void) const 00131 { 00132 return mParamDefs; 00133 } 00134 00135 00136 00137 }; 00138 typedef std::map<String, ParamDictionary> ParamDictionaryMap; 00139 00149 class _OgreExport StringInterface 00150 { 00151 protected: 00152 00154 static ParamDictionaryMap msDictionary; 00155 00157 String mParamDictName; 00158 00169 bool createParamDictionary(const String& className) 00170 { 00171 mParamDictName = className; 00172 if (msDictionary.find(className) == msDictionary.end()) 00173 { 00174 msDictionary[className] = ParamDictionary(); 00175 return true; 00176 } 00177 return false; 00178 00179 } 00180 00181 public: 00182 00184 virtual ~StringInterface() {} 00185 00193 ParamDictionary* getParamDictionary(void) 00194 { 00195 ParamDictionaryMap::iterator i = msDictionary.find(mParamDictName); 00196 if (i != msDictionary.end()) 00197 { 00198 return &(i->second); 00199 } 00200 else 00201 { 00202 return 0; 00203 } 00204 } 00205 00206 const ParamDictionary* getParamDictionary(void) const 00207 { 00208 ParamDictionaryMap::const_iterator i = msDictionary.find(mParamDictName); 00209 if (i != msDictionary.end()) 00210 { 00211 return &(i->second); 00212 } 00213 else 00214 { 00215 return 0; 00216 } 00217 } 00218 00224 const ParameterList& getParameters(void) const 00225 { 00226 static ParameterList emptyList; 00227 00228 const ParamDictionary* dict = getParamDictionary(); 00229 if (dict) 00230 return dict->getParameters(); 00231 else 00232 return emptyList; 00233 00234 }; 00235 00250 virtual bool setParameter(const String& name, const String& value); 00262 virtual String getParameter(const String& name) const 00263 { 00264 // Get dictionary 00265 const ParamDictionary* dict = getParamDictionary(); 00266 00267 if (dict) 00268 { 00269 // Look up command object 00270 const ParamCommand* cmd = dict->getParamCommand(name); 00271 00272 if (cmd) 00273 { 00274 return cmd->doGet(this); 00275 } 00276 } 00277 00278 // Fallback 00279 return ""; 00280 } 00293 virtual void copyParametersTo(StringInterface* dest) const 00294 { 00295 // Get dictionary 00296 const ParamDictionary* dict = getParamDictionary(); 00297 00298 if (dict) 00299 { 00300 // Iterate through own parameters 00301 ParameterList::const_iterator i; 00302 00303 for (i = dict->mParamDefs.begin(); 00304 i != dict->mParamDefs.end(); ++i) 00305 { 00306 dest->setParameter(i->name, getParameter(i->name)); 00307 } 00308 } 00309 00310 00311 } 00312 00316 static void cleanupDictionary () ; 00317 00318 }; 00319 00320 00321 00322 } 00323 00324 #endif 00325
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:47 2004