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 (c) 2000-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 00029 #ifndef __StringInterface_H__ 00030 #define __StringInterface_H__ 00031 00032 #include "OgrePrerequisites.h" 00033 #include "OgreString.h" 00034 #include "OgreCommon.h" 00035 #include "Threading/OgreThreadHeaders.h" 00036 #include "OgreHeaderPrefix.h" 00037 00038 namespace Ogre { 00039 00047 00048 enum ParameterType 00049 { 00050 PT_BOOL, 00051 PT_REAL, 00052 PT_INT, 00053 PT_UNSIGNED_INT, 00054 PT_SHORT, 00055 PT_UNSIGNED_SHORT, 00056 PT_LONG, 00057 PT_UNSIGNED_LONG, 00058 PT_STRING, 00059 PT_VECTOR3, 00060 PT_MATRIX3, 00061 PT_MATRIX4, 00062 PT_QUATERNION, 00063 PT_COLOURVALUE 00064 }; 00065 00067 class _OgreExport ParameterDef 00068 { 00069 public: 00070 String name; 00071 String description; 00072 ParameterType paramType; 00073 ParameterDef(const String& newName, const String& newDescription, ParameterType newType) 00074 : name(newName), description(newDescription), paramType(newType) {} 00075 }; 00076 typedef vector<ParameterDef>::type ParameterList; 00077 00079 class _OgreExport ParamCommand 00080 { 00081 public: 00082 virtual String doGet(const void* target) const = 0; 00083 virtual void doSet(void* target, const String& val) = 0; 00084 00085 virtual ~ParamCommand() { } 00086 }; 00087 typedef map<String, ParamCommand* >::type ParamCommandMap; 00088 00090 class _OgreExport ParamDictionary 00091 { 00092 friend class StringInterface; 00093 protected: 00095 ParameterList mParamDefs; 00096 00098 ParamCommandMap mParamCommands; 00099 00101 ParamCommand* getParamCommand(const String& name) 00102 { 00103 ParamCommandMap::iterator i = mParamCommands.find(name); 00104 if (i != mParamCommands.end()) 00105 { 00106 return i->second; 00107 } 00108 else 00109 { 00110 return 0; 00111 } 00112 } 00113 00114 const ParamCommand* getParamCommand(const String& name) const 00115 { 00116 ParamCommandMap::const_iterator i = mParamCommands.find(name); 00117 if (i != mParamCommands.end()) 00118 { 00119 return i->second; 00120 } 00121 else 00122 { 00123 return 0; 00124 } 00125 } 00126 public: 00127 ParamDictionary() {} 00134 void addParameter(const ParameterDef& paramDef, ParamCommand* paramCmd) 00135 { 00136 mParamDefs.push_back(paramDef); 00137 mParamCommands[paramDef.name] = paramCmd; 00138 } 00144 const ParameterList& getParameters(void) const 00145 { 00146 return mParamDefs; 00147 } 00148 00149 00150 00151 }; 00152 typedef map<String, ParamDictionary>::type ParamDictionaryMap; 00153 00163 class _OgreExport StringInterface 00164 { 00165 private: 00166 OGRE_STATIC_MUTEX( msDictionaryMutex ); 00167 00169 static ParamDictionaryMap msDictionary; 00170 00172 String mParamDictName; 00173 ParamDictionary* mParamDict; 00174 00175 protected: 00186 bool createParamDictionary(const String& className) 00187 { 00188 OGRE_LOCK_MUTEX( msDictionaryMutex ); 00189 00190 ParamDictionaryMap::iterator it = msDictionary.find(className); 00191 00192 if ( it == msDictionary.end() ) 00193 { 00194 mParamDict = &msDictionary.insert( std::make_pair( className, ParamDictionary() ) ).first->second; 00195 mParamDictName = className; 00196 return true; 00197 } 00198 else 00199 { 00200 mParamDict = &it->second; 00201 mParamDictName = className; 00202 return false; 00203 } 00204 } 00205 00206 public: 00207 StringInterface() : mParamDict(NULL) { } 00208 00210 virtual ~StringInterface() {} 00211 00219 ParamDictionary* getParamDictionary(void) 00220 { 00221 return mParamDict; 00222 } 00223 00224 const ParamDictionary* getParamDictionary(void) const 00225 { 00226 return mParamDict; 00227 } 00228 00234 const ParameterList& getParameters(void) const; 00235 00250 virtual bool setParameter(const String& name, const String& value); 00260 virtual void setParameterList(const NameValuePairList& paramList); 00272 virtual String getParameter(const String& name) const 00273 { 00274 // Get dictionary 00275 const ParamDictionary* dict = getParamDictionary(); 00276 00277 if (dict) 00278 { 00279 // Look up command object 00280 const ParamCommand* cmd = dict->getParamCommand(name); 00281 00282 if (cmd) 00283 { 00284 return cmd->doGet(this); 00285 } 00286 } 00287 00288 // Fallback 00289 return ""; 00290 } 00303 virtual void copyParametersTo(StringInterface* dest) const 00304 { 00305 // Get dictionary 00306 const ParamDictionary* dict = getParamDictionary(); 00307 00308 if (dict) 00309 { 00310 // Iterate through own parameters 00311 ParameterList::const_iterator i; 00312 00313 for (i = dict->mParamDefs.begin(); 00314 i != dict->mParamDefs.end(); ++i) 00315 { 00316 dest->setParameter(i->name, getParameter(i->name)); 00317 } 00318 } 00319 00320 00321 } 00322 00326 static void cleanupDictionary () ; 00327 00328 }; 00329 00334 } 00335 00336 #include "OgreHeaderSuffix.h" 00337 00338 #endif 00339
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48