OgreStringInterface.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __StringInterface_H__
#define __StringInterface_H__
#include "OgrePrerequisites.h"
#include "OgreString.h"
#include "OgreCommon.h"
#include "Threading/OgreThreadHeaders.h"
#include "OgreHeaderPrefix.h"
namespace Ogre {
enum ParameterType
{
PT_BOOL,
PT_REAL,
PT_INT,
PT_UNSIGNED_INT,
PT_SHORT,
PT_UNSIGNED_SHORT,
PT_LONG,
PT_UNSIGNED_LONG,
PT_STRING,
PT_VECTOR3,
PT_MATRIX3,
PT_MATRIX4,
PT_QUATERNION,
PT_COLOURVALUE
};
class _OgreExport ParameterDef
{
public:
String name;
String description;
ParameterType paramType;
ParameterDef(const String& newName, const String& newDescription, ParameterType newType)
: name(newName), description(newDescription), paramType(newType) {}
};
typedef vector<ParameterDef>::type ParameterList;
class _OgreExport ParamCommand
{
public:
virtual String doGet(const void* target) const = 0;
virtual void doSet(void* target, const String& val) = 0;
virtual ~ParamCommand() { }
};
typedef map<String, ParamCommand* >::type ParamCommandMap;
class _OgreExport ParamDictionary
{
friend class StringInterface;
protected:
ParameterList mParamDefs;
ParamCommandMap mParamCommands;
ParamCommand* getParamCommand(const String& name)
{
ParamCommandMap::iterator i = mParamCommands.find(name);
if (i != mParamCommands.end())
{
return i->second;
}
else
{
return 0;
}
}
const ParamCommand* getParamCommand(const String& name) const
{
ParamCommandMap::const_iterator i = mParamCommands.find(name);
if (i != mParamCommands.end())
{
return i->second;
}
else
{
return 0;
}
}
public:
ParamDictionary() {}
void addParameter(const ParameterDef& paramDef, ParamCommand* paramCmd)
{
mParamDefs.push_back(paramDef);
mParamCommands[paramDef.name] = paramCmd;
}
const ParameterList& getParameters(void) const
{
return mParamDefs;
}
};
typedef map<String, ParamDictionary>::type ParamDictionaryMap;
class _OgreExport StringInterface
{
private:
OGRE_STATIC_MUTEX( msDictionaryMutex );
static ParamDictionaryMap msDictionary;
String mParamDictName;
ParamDictionary* mParamDict;
protected:
bool createParamDictionary(const String& className)
{
OGRE_LOCK_MUTEX( msDictionaryMutex );
ParamDictionaryMap::iterator it = msDictionary.find(className);
if ( it == msDictionary.end() )
{
mParamDict = &msDictionary.insert( std::make_pair( className, ParamDictionary() ) ).first->second;
mParamDictName = className;
return true;
}
else
{
mParamDict = &it->second;
mParamDictName = className;
return false;
}
}
public:
StringInterface() : mParamDict(NULL) { }
virtual ~StringInterface() {}
ParamDictionary* getParamDictionary(void)
{
return mParamDict;
}
const ParamDictionary* getParamDictionary(void) const
{
return mParamDict;
}
const ParameterList& getParameters(void) const;
virtual bool setParameter(const String& name, const String& value);
virtual void setParameterList(const NameValuePairList& paramList);
virtual String getParameter(const String& name) const
{
// Get dictionary
const ParamDictionary* dict = getParamDictionary();
if (dict)
{
// Look up command object
const ParamCommand* cmd = dict->getParamCommand(name);
if (cmd)
{
return cmd->doGet(this);
}
}
// Fallback
return "";
}
virtual void copyParametersTo(StringInterface* dest) const
{
// Get dictionary
const ParamDictionary* dict = getParamDictionary();
if (dict)
{
// Iterate through own parameters
ParameterList::const_iterator i;
for (i = dict->mParamDefs.begin();
i != dict->mParamDefs.end(); ++i)
{
dest->setParameter(i->name, getParameter(i->name));
}
}
}
static void cleanupDictionary () ;
};
}
#include "OgreHeaderSuffix.h"
#endif
Ogre::ParamDictionary::ParamDictionary
ParamDictionary()
Definition: OgreStringInterface.h:127
Ogre::ParameterDef::description
String description
Definition: OgreStringInterface.h:71
Ogre::ParameterType
ParameterType
List of parameter types available.
Definition: OgreStringInterface.h:48
Ogre::ParameterDef::ParameterDef
ParameterDef(const String &newName, const String &newDescription, ParameterType newType)
Definition: OgreStringInterface.h:73
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
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::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::PT_STRING
Definition: OgreStringInterface.h:58
Ogre::PT_MATRIX3
Definition: OgreStringInterface.h:60
Ogre::ParamCommand::doGet
virtual String doGet(const void *target) const =0
Ogre::ParamDictionary::getParameters
const ParameterList & getParameters(void) const
Retrieves a list of parameters valid for this object.
Definition: OgreStringInterface.h:144
Ogre::PT_LONG
Definition: OgreStringInterface.h:56
Ogre::ParamDictionary::getParamCommand
const ParamCommand * getParamCommand(const String &name) const
Definition: OgreStringInterface.h:114
Ogre::StringInterface::setParameter
virtual bool setParameter(const String &name, const String &value)
Generic parameter setting method.
OgreString.h
Ogre::PT_MATRIX4
Definition: OgreStringInterface.h:61
OGRE_LOCK_MUTEX
#define OGRE_LOCK_MUTEX(name)
Definition: OgreThreadDefinesBoost.h:34
Ogre::ParamDictionary
Class to hold a dictionary of parameters for a single class.
Definition: OgreStringInterface.h:90
Ogre::PT_UNSIGNED_SHORT
Definition: OgreStringInterface.h:55
Ogre::ParamDictionary::addParameter
void addParameter(const ParameterDef &paramDef, ParamCommand *paramCmd)
Method for adding a parameter definition for this class.
Definition: OgreStringInterface.h:134
Ogre::ParamDictionary::getParamCommand
ParamCommand * getParamCommand(const String &name)
Retrieves the parameter command object for a named parameter.
Definition: OgreStringInterface.h:101
Ogre::ParamDictionaryMap
map< String, ParamDictionary >::type ParamDictionaryMap
Definition: OgreStringInterface.h:152
OgreCommon.h
Ogre::PT_COLOURVALUE
Definition: OgreStringInterface.h:63
Ogre::ParamCommand::~ParamCommand
virtual ~ParamCommand()
Definition: OgreStringInterface.h:85
Ogre::PT_UNSIGNED_INT
Definition: OgreStringInterface.h:53
OgrePrerequisites.h
Ogre::map::type
std::map< K, V, P, A > type
Definition: OgrePrerequisites.h:536
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::getParamDictionary
const ParamDictionary * getParamDictionary(void) const
Definition: OgreStringInterface.h:224
Ogre::NameValuePairList
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:550
Ogre::StringInterface
Class defining the common interface which classes can use to present a reflection-style, self-defining parameter set to callers.
Definition: OgreStringInterface.h:163
Ogre::ParameterList
vector< ParameterDef >::type ParameterList
Definition: OgreStringInterface.h:76
Ogre::PT_VECTOR3
Definition: OgreStringInterface.h:59
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::ParamDictionary::mParamCommands
ParamCommandMap mParamCommands
Command objects to get/set.
Definition: OgreStringInterface.h:98
Ogre::StringInterface::~StringInterface
virtual ~StringInterface()
Virtual destructor, see Effective C++.
Definition: OgreStringInterface.h:210
OgreHeaderSuffix.h
Ogre::PT_QUATERNION
Definition: OgreStringInterface.h:62
OgreThreadHeaders.h
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::StringInterface::mParamDict
ParamDictionary * mParamDict
Definition: OgreStringInterface.h:173
OGRE_STATIC_MUTEX
#define OGRE_STATIC_MUTEX(name)
Definition: OgreThreadDefinesBoost.h:48
Ogre::ParameterDef::paramType
ParameterType paramType
Definition: OgreStringInterface.h:72
Ogre::PT_SHORT
Definition: OgreStringInterface.h:54
Ogre::ParameterDef::name
String name
Definition: OgreStringInterface.h:70
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::StringInterface::StringInterface
StringInterface()
Definition: OgreStringInterface.h:207
Ogre::ParamCommandMap
map< String, ParamCommand *>::type ParamCommandMap
Definition: OgreStringInterface.h:87
OgreHeaderPrefix.h
Ogre::PT_INT
Definition: OgreStringInterface.h:52
Ogre::PT_UNSIGNED_LONG
Definition: OgreStringInterface.h:57
Ogre::PT_REAL
Definition: OgreStringInterface.h:51
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::ParamCommand
Abstract class which is command object which gets/sets parameters.
Definition: OgreStringInterface.h:79
Ogre::ParameterDef
Definition of a parameter supported by a StringInterface class, for introspection.
Definition: OgreStringInterface.h:67
Ogre::StringInterface::copyParametersTo
virtual void copyParametersTo(StringInterface *dest) const
Method for copying this object&#39;s parameters to another object.
Definition: OgreStringInterface.h:303
Ogre::PT_BOOL
Definition: OgreStringInterface.h:50
Ogre::ParamDictionary::mParamDefs
ParameterList mParamDefs
Definitions of parameters.
Definition: OgreStringInterface.h:95
Ogre::StringInterface::getParameter
virtual String getParameter(const String &name) const
Generic parameter retrieval method.
Definition: OgreStringInterface.h:272

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