OgreStringInterface.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE 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 
38 namespace Ogre {
39 
47  enum ParameterType
49  {
64  };
65 
68  {
69  public:
73  ParameterDef(const String& newName, const String& newDescription, ParameterType newType)
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:
134  void addParameter(const ParameterDef& paramDef, ParamCommand* paramCmd)
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:
166  OGRE_STATIC_MUTEX( msDictionaryMutex );
167 
170 
174 
175  protected:
186  bool createParamDictionary(const String& className)
187  {
188  OGRE_LOCK_MUTEX( msDictionaryMutex );
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);
260  virtual void setParameterList(const NameValuePairList& paramList);
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  }
303  virtual void copyParametersTo(StringInterface* dest) const
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 
OgreHeaderSuffix.h
Ogre::ParameterType
ParameterType
List of parameter types available.
Definition: OgreStringInterface.h:49
OGRE_LOCK_MUTEX
#define OGRE_LOCK_MUTEX(name)
Definition: OgreThreadDefinesBoost.h:34
Ogre::PT_UNSIGNED_SHORT
@ PT_UNSIGNED_SHORT
Definition: OgreStringInterface.h:55
Ogre::StringInterface::setParameter
virtual bool setParameter(const String &name, const String &value)
Generic parameter setting method.
Ogre::PT_VECTOR3
@ PT_VECTOR3
Definition: OgreStringInterface.h:59
Ogre
Definition: OgreAndroidLogListener.h:35
Ogre::ParamDictionary::addParameter
void addParameter(const ParameterDef &paramDef, ParamCommand *paramCmd)
Method for adding a parameter definition for this class.
Definition: OgreStringInterface.h:134
Ogre::PT_COLOURVALUE
@ PT_COLOURVALUE
Definition: OgreStringInterface.h:63
Ogre::StringInterface::cleanupDictionary
static void cleanupDictionary()
Cleans up the static 'msDictionary' required to reset Ogre, otherwise the containers are left with in...
Ogre::ParamDictionary::mParamDefs
ParameterList mParamDefs
Definitions of parameters.
Definition: OgreStringInterface.h:95
Ogre::map
Definition: OgrePrerequisites.h:534
Ogre::PT_REAL
@ PT_REAL
Definition: OgreStringInterface.h:51
Ogre::StringInterface::getParameters
const ParameterList & getParameters(void) const
Retrieves a list of parameters valid for this object.
Ogre::StringInterface::copyParametersTo
virtual void copyParametersTo(StringInterface *dest) const
Method for copying this object's parameters to another object.
Definition: OgreStringInterface.h:303
Ogre::ParamDictionaryMap
map< String, ParamDictionary >::type ParamDictionaryMap
Definition: OgreStringInterface.h:152
Ogre::ParamDictionary::ParamDictionary
ParamDictionary()
Definition: OgreStringInterface.h:127
Ogre::ParamDictionary::getParamCommand
ParamCommand * getParamCommand(const String &name)
Retrieves the parameter command object for a named parameter.
Definition: OgreStringInterface.h:101
Ogre::ParameterDef::paramType
ParameterType paramType
Definition: OgreStringInterface.h:72
Ogre::ParamCommand::~ParamCommand
virtual ~ParamCommand()
Definition: OgreStringInterface.h:85
Ogre::ParameterDef::description
String description
Definition: OgreStringInterface.h:71
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::PT_STRING
@ PT_STRING
Definition: OgreStringInterface.h:58
Ogre::ParamCommand::doSet
virtual void doSet(void *target, const String &val)=0
Ogre::NameValuePairList
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:550
Ogre::ParameterDef
Definition of a parameter supported by a StringInterface class, for introspection.
Definition: OgreStringInterface.h:68
Ogre::StringInterface::~StringInterface
virtual ~StringInterface()
Virtual destructor, see Effective C++.
Definition: OgreStringInterface.h:210
Ogre::ParamCommand::doGet
virtual String doGet(const void *target) const =0
Ogre::ParamCommand
Abstract class which is command object which gets/sets parameters.
Definition: OgreStringInterface.h:80
Ogre::StringInterface::setParameterList
virtual void setParameterList(const NameValuePairList &paramList)
Generic multiple parameter setting method.
OgreHeaderPrefix.h
OgrePrerequisites.h
OgreThreadHeaders.h
Ogre::PT_MATRIX4
@ PT_MATRIX4
Definition: OgreStringInterface.h:61
Ogre::PT_UNSIGNED_INT
@ PT_UNSIGNED_INT
Definition: OgreStringInterface.h:53
Ogre::ParameterDef::ParameterDef
ParameterDef(const String &newName, const String &newDescription, ParameterType newType)
Definition: OgreStringInterface.h:73
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
OgreCommon.h
Ogre::PT_QUATERNION
@ PT_QUATERNION
Definition: OgreStringInterface.h:62
Ogre::PT_UNSIGNED_LONG
@ PT_UNSIGNED_LONG
Definition: OgreStringInterface.h:57
Ogre::StringInterface::StringInterface
StringInterface()
Definition: OgreStringInterface.h:207
Ogre::StringInterface
Class defining the common interface which classes can use to present a reflection-style,...
Definition: OgreStringInterface.h:164
Ogre::StringInterface::getParamDictionary
const ParamDictionary * getParamDictionary(void) const
Definition: OgreStringInterface.h:224
Ogre::PT_MATRIX3
@ PT_MATRIX3
Definition: OgreStringInterface.h:60
Ogre::map::type
std::map< K, V, P, A > type
Definition: OgrePrerequisites.h:536
Ogre::ParamCommandMap
map< String, ParamCommand * >::type ParamCommandMap
Definition: OgreStringInterface.h:87
Ogre::ParameterList
vector< ParameterDef >::type ParameterList
Definition: OgreStringInterface.h:76
Ogre::StringInterface::msDictionary
static ParamDictionaryMap msDictionary
Dictionary of parameters.
Definition: OgreStringInterface.h:169
Ogre::StringInterface::getParamDictionary
ParamDictionary * getParamDictionary(void)
Retrieves the parameter dictionary for this class.
Definition: OgreStringInterface.h:219
Ogre::StringInterface::getParameter
virtual String getParameter(const String &name) const
Generic parameter retrieval method.
Definition: OgreStringInterface.h:272
Ogre::ParameterDef::name
String name
Definition: OgreStringInterface.h:70
Ogre::StringInterface::mParamDictName
String mParamDictName
Class name for this instance to be used as a lookup (must be initialised by subclasses)
Definition: OgreStringInterface.h:172
Ogre::PT_LONG
@ PT_LONG
Definition: OgreStringInterface.h:56
Ogre::StringInterface::createParamDictionary
bool createParamDictionary(const String &className)
Internal method for creating a parameter dictionary for the class, if it does not already exist.
Definition: OgreStringInterface.h:186
Ogre::ParamDictionary::mParamCommands
ParamCommandMap mParamCommands
Command objects to get/set.
Definition: OgreStringInterface.h:98
Ogre::PT_BOOL
@ PT_BOOL
Definition: OgreStringInterface.h:50
OgreString.h
Ogre::StringInterface::mParamDict
ParamDictionary * mParamDict
Definition: OgreStringInterface.h:173
Ogre::vector
Definition: OgrePrerequisites.h:492
Ogre::ParamDictionary::getParamCommand
const ParamCommand * getParamCommand(const String &name) const
Definition: OgreStringInterface.h:114
Ogre::PT_SHORT
@ PT_SHORT
Definition: OgreStringInterface.h:54
Ogre::PT_INT
@ PT_INT
Definition: OgreStringInterface.h:52
Ogre::ParamDictionary::getParameters
const ParameterList & getParameters(void) const
Retrieves a list of parameters valid for this object.
Definition: OgreStringInterface.h:144
Ogre::StringInterface::OGRE_STATIC_MUTEX
OGRE_STATIC_MUTEX(msDictionaryMutex)
Ogre::ParamDictionary
Class to hold a dictionary of parameters for a single class.
Definition: OgreStringInterface.h:91

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.