Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

# OgreStringInterface.h

Go to the documentation of this file.

    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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029
    00030 #ifndef __StringInterface_H__
    00031 #define __StringInterface_H__
    00032
    00033 #include "OgrePrerequisites.h"
    00034 #include "OgreString.h"
    00035 #include "OgreCommon.h"
    00036
    00037 namespace Ogre {
    00038
    00039
    00041     enum ParameterType
    00042     {
    00043         PT_BOOL,
    00044         PT_REAL,
    00045         PT_INT,
    00046         PT_UNSIGNED_INT,
    00047         PT_SHORT,
    00048         PT_UNSIGNED_SHORT,
    00049         PT_LONG,
    00050         PT_UNSIGNED_LONG,
    00051         PT_STRING,
    00052         PT_VECTOR3,
    00053         PT_MATRIX3,
    00054         PT_MATRIX4,
    00055         PT_QUATERNION,
    00056         PT_COLOURVALUE
    00057     };
    00058
    00060     class _OgreExport ParameterDef
    00061     {
    00062     public:
    00063         String name;
    00064         String description;
    00065         ParameterType paramType;
    00066         ParameterDef(const String& newName, const String& newDescription, ParameterType newType)
    00067             : name(newName), description(newDescription), paramType(newType) {}
    00068     };
    00069     typedef std::vector<ParameterDef> ParameterList;
    00070
    00072     class _OgreExport ParamCommand
    00073     {
    00074     public:
    00075         virtual String doGet(const void* target) const = 0;
    00076         virtual void doSet(void* target, const String& val) = 0;
    00077
    00078         virtual ~ParamCommand() { }
    00079     };
    00080     typedef std::map<String, ParamCommand* > ParamCommandMap;
    00081
    00083     class _OgreExport ParamDictionary
    00084     {
    00085         friend class StringInterface;
    00086     protected:
    00088         ParameterList mParamDefs;
    00089
    00091         ParamCommandMap mParamCommands;
    00092
    00094         ParamCommand* getParamCommand(const String& name)
    00095         {
    00096             ParamCommandMap::iterator i = mParamCommands.find(name);
    00097             if (i != mParamCommands.end())
    00098             {
    00099                 return i->second;
    00100             }
    00101             else
    00102             {
    00103                 return 0;
    00104             }
    00105         }
    00106
    00107         const ParamCommand* getParamCommand(const String& name) const
    00108         {
    00109             ParamCommandMap::const_iterator i = mParamCommands.find(name);
    00110             if (i != mParamCommands.end())
    00111             {
    00112                 return i->second;
    00113             }
    00114             else
    00115             {
    00116                 return 0;
    00117             }
    00118         }
    00119     public:
    00120         ParamDictionary()  {}
    00127         void addParameter(const ParameterDef& paramDef, ParamCommand* paramCmd)
    00128         {
    00129             mParamDefs.push_back(paramDef);
    00130             mParamCommands[paramDef.name] = paramCmd;
    00131         }
    00137         const ParameterList& getParameters(void) const
    00138         {
    00139             return mParamDefs;
    00140         }
    00141
    00142
    00143
    00144     };
    00145     typedef std::map<String, ParamDictionary> ParamDictionaryMap;
    00146
    00156     class _OgreExport StringInterface
    00157     {
    00158     protected:
    00159
    00161         static ParamDictionaryMap msDictionary;
    00162
    00164         String mParamDictName;
    00165
    00176         bool createParamDictionary(const String& className)
    00177         {
    00178             mParamDictName = className;
    00179             if (msDictionary.find(className) == msDictionary.end())
    00180             {
    00181                 msDictionary[className] = ParamDictionary();
    00182                 return true;
    00183             }
    00184             return false;
    00185
    00186         }
    00187
    00188     public:
    00189
    00191         virtual ~StringInterface() {}
    00192
    00200         ParamDictionary* getParamDictionary(void)
    00201         {
    00202             ParamDictionaryMap::iterator i = msDictionary.find(mParamDictName);
    00203             if (i != msDictionary.end())
    00204             {
    00205                 return &(i->second);
    00206             }
    00207             else
    00208             {
    00209                 return 0;
    00210             }
    00211         }
    00212
    00213         const ParamDictionary* getParamDictionary(void) const
    00214         {
    00215             ParamDictionaryMap::const_iterator i = msDictionary.find(mParamDictName);
    00216             if (i != msDictionary.end())
    00217             {
    00218                 return &(i->second);
    00219             }
    00220             else
    00221             {
    00222                 return 0;
    00223             }
    00224         }
    00225
    00231         const ParameterList& getParameters(void) const;
    00232
    00247         virtual bool setParameter(const String& name, const String& value);
    00257         virtual void setParameterList(const NameValuePairList& paramList);
    00269         virtual String getParameter(const String& name) const
    00270         {
    00271             // Get dictionary
    00272             const ParamDictionary* dict = getParamDictionary();
    00273
    00274             if (dict)
    00275             {
    00276                 // Look up command object
    00277                 const ParamCommand* cmd = dict->getParamCommand(name);
    00278
    00279                 if (cmd)
    00280                 {
    00281                     return cmd->doGet(this);
    00282                 }
    00283             }
    00284
    00285             // Fallback
    00286             return "";
    00287         }
    00300         virtual void copyParametersTo(StringInterface* dest) const
    00301         {
    00302             // Get dictionary
    00303             const ParamDictionary* dict = getParamDictionary();
    00304
    00305             if (dict)
    00306             {
    00307                 // Iterate through own parameters
    00308                 ParameterList::const_iterator i;
    00309
    00310                 for (i = dict->mParamDefs.begin();
    00311                 i != dict->mParamDefs.end(); ++i)
    00312                 {
    00313                     dest->setParameter(i->name, getParameter(i->name));
    00314                 }
    00315             }
    00316
    00317
    00318         }
    00319
    00323         static void cleanupDictionary () ;
    00324
    00325     };
    00326
    00327
    00328
    00329 }
    00330
    00331 #endif
    00332

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Mar 6 09:46:26 2008