summaryrefslogtreecommitdiff
path: root/orkbasecxx/ObjectFactory.cpp
diff options
context:
space:
mode:
authorHenri Herscher <henri@oreka.org>2007-02-09 02:17:03 +0000
committerHenri Herscher <henri@oreka.org>2007-02-09 02:17:03 +0000
commit6e895bf3e556be3d30d85d4329b4bd79891faf79 (patch)
tree2d295cce32ca2d8b4f0fb0b790e7df985c906c0d /orkbasecxx/ObjectFactory.cpp
parente660a409b15c382ca3ea98ffc9d7a73ee3e08d5d (diff)
ObjectFactory now protected by a mutex. It is also now possible to override an OrkObject class by reregistering a new class under the same name.
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@407 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkbasecxx/ObjectFactory.cpp')
-rw-r--r--orkbasecxx/ObjectFactory.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/orkbasecxx/ObjectFactory.cpp b/orkbasecxx/ObjectFactory.cpp
index 97536e9..724bbfd 100644
--- a/orkbasecxx/ObjectFactory.cpp
+++ b/orkbasecxx/ObjectFactory.cpp
@@ -10,9 +10,11 @@
* Please refer to http://www.gnu.org/copyleft/gpl.html
*
*/
+#pragma warning( disable: 4786 )
#define _WINSOCKAPI_ // prevents the inclusion of winsock.h
+#include "Utils.h"
#include "ObjectFactory.h"
ObjectFactory* ObjectFactory::m_singleton = NULL;
@@ -34,6 +36,7 @@ ObjectFactory* ObjectFactory::GetSingleton()
ObjectRef ObjectFactory::NewInstance(CStdString& className)
{
+ MutexSentinel mutexSentinel(m_mutex);
std::map<CStdString, ObjectRef>::iterator pair;
pair = m_classes.find(className);
@@ -43,12 +46,19 @@ ObjectRef ObjectFactory::NewInstance(CStdString& className)
}
else
{
- return pair->second;
+ ObjectRef ref = pair->second;
+ return ref->NewInstance();
}
}
void ObjectFactory::RegisterObject(ObjectRef& objRef)
{
+ MutexSentinel mutexSentinel(m_mutex);
+ std::map<CStdString, ObjectRef>::iterator pair = m_classes.find(objRef->GetClassName());
+ if(pair != m_classes.end())
+ {
+ m_classes.erase(pair);
+ }
m_classes.insert(std::make_pair(objRef->GetClassName(), objRef));
}