OGRE  1.9.0
OgreStringInterface.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28
29#ifndef __StringInterface_H__
30#define __StringInterface_H__
31
32#include "OgrePrerequisites.h"
33#include "OgreString.h"
34#include "OgreCommon.h"
36#include "OgreHeaderPrefix.h"
37
38namespace Ogre {
39
49 {
64 };
65
68 {
69 public:
74 : name(newName), description(newDescription), paramType(newType) {}
75 };
77
80 {
81 public:
82 virtual String doGet(const void* target) const = 0;
83 virtual void doSet(void* target, const String& val) = 0;
84
85 virtual ~ParamCommand() { }
86 };
88
91 {
92 friend class StringInterface;
93 protected:
96
99
102 {
103 ParamCommandMap::iterator i = mParamCommands.find(name);
104 if (i != mParamCommands.end())
105 {
106 return i->second;
107 }
108 else
109 {
110 return 0;
111 }
112 }
113
114 const ParamCommand* getParamCommand(const String& name) const
115 {
116 ParamCommandMap::const_iterator i = mParamCommands.find(name);
117 if (i != mParamCommands.end())
118 {
119 return i->second;
120 }
121 else
122 {
123 return 0;
124 }
125 }
126 public:
135 {
136 mParamDefs.push_back(paramDef);
137 mParamCommands[paramDef.name] = paramCmd;
138 }
144 const ParameterList& getParameters(void) const
145 {
146 return mParamDefs;
147 }
148
149
150
151 };
153
164 {
165 private:
167
170
174
175 protected:
187 {
189
190 ParamDictionaryMap::iterator it = msDictionary.find(className);
191
192 if ( it == msDictionary.end() )
193 {
194 mParamDict = &msDictionary.insert( std::make_pair( className, ParamDictionary() ) ).first->second;
195 mParamDictName = className;
196 return true;
197 }
198 else
199 {
200 mParamDict = &it->second;
201 mParamDictName = className;
202 return false;
203 }
204 }
205
206 public:
207 StringInterface() : mParamDict(NULL) { }
208
210 virtual ~StringInterface() {}
211
220 {
221 return mParamDict;
222 }
223
225 {
226 return mParamDict;
227 }
228
234 const ParameterList& getParameters(void) const;
235
250 virtual bool setParameter(const String& name, const String& value);
272 virtual String getParameter(const String& name) const
273 {
274 // Get dictionary
275 const ParamDictionary* dict = getParamDictionary();
276
277 if (dict)
278 {
279 // Look up command object
280 const ParamCommand* cmd = dict->getParamCommand(name);
281
282 if (cmd)
283 {
284 return cmd->doGet(this);
285 }
286 }
287
288 // Fallback
289 return "";
290 }
304 {
305 // Get dictionary
306 const ParamDictionary* dict = getParamDictionary();
307
308 if (dict)
309 {
310 // Iterate through own parameters
311 ParameterList::const_iterator i;
312
313 for (i = dict->mParamDefs.begin();
314 i != dict->mParamDefs.end(); ++i)
315 {
316 dest->setParameter(i->name, getParameter(i->name));
317 }
318 }
319
320
321 }
322
326 static void cleanupDictionary () ;
327
328 };
329
334}
335
336#include "OgreHeaderSuffix.h"
337
338#endif
339
#define _OgreExport
#define OGRE_LOCK_MUTEX(name)
Abstract class which is command object which gets/sets parameters.
virtual void doSet(void *target, const String &val)=0
virtual String doGet(const void *target) const =0
Class to hold a dictionary of parameters for a single class.
ParamCommandMap mParamCommands
Command objects to get/set.
ParameterList mParamDefs
Definitions of parameters.
void addParameter(const ParameterDef &paramDef, ParamCommand *paramCmd)
Method for adding a parameter definition for this class.
const ParameterList & getParameters(void) const
Retrieves a list of parameters valid for this object.
const ParamCommand * getParamCommand(const String &name) const
ParamCommand * getParamCommand(const String &name)
Retrieves the parameter command object for a named parameter.
Definition of a parameter supported by a StringInterface class, for introspection.
ParameterDef(const String &newName, const String &newDescription, ParameterType newType)
Reference-counted shared pointer, used for objects where implicit destruction is required.
Class defining the common interface which classes can use to present a reflection-style,...
virtual String getParameter(const String &name) const
Generic parameter retrieval method.
static void cleanupDictionary()
Cleans up the static 'msDictionary' required to reset Ogre, otherwise the containers are left with in...
OGRE_STATIC_MUTEX(msDictionaryMutex)
virtual void copyParametersTo(StringInterface *dest) const
Method for copying this object's parameters to another object.
const ParamDictionary * getParamDictionary(void) const
ParamDictionary * mParamDict
static ParamDictionaryMap msDictionary
Dictionary of parameters.
bool createParamDictionary(const String &className)
Internal method for creating a parameter dictionary for the class, if it does not already exist.
ParamDictionary * getParamDictionary(void)
Retrieves the parameter dictionary for this class.
virtual ~StringInterface()
Virtual destructor, see Effective C++.
String mParamDictName
Class name for this instance to be used as a lookup (must be initialised by subclasses)
const ParameterList & getParameters(void) const
Retrieves a list of parameters valid for this object.
virtual bool setParameter(const String &name, const String &value)
Generic parameter setting method.
virtual void setParameterList(const NameValuePairList &paramList)
Generic multiple parameter setting method.
ParameterType
List of parameter types available.
map< String, ParamCommand * >::type ParamCommandMap
map< String, ParamDictionary >::type ParamDictionaryMap
vector< ParameterDef >::type ParameterList
_StringBase String
std::map< K, V, P, A > type
std::vector< T, A > type