summaryrefslogtreecommitdiff
path: root/orkbasecxx
diff options
context:
space:
mode:
Diffstat (limited to 'orkbasecxx')
-rw-r--r--orkbasecxx/ObjectFactory.cpp12
-rw-r--r--orkbasecxx/ObjectFactory.h4
2 files changed, 13 insertions, 3 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));
}
diff --git a/orkbasecxx/ObjectFactory.h b/orkbasecxx/ObjectFactory.h
index 0c5cd31..fcfba11 100644
--- a/orkbasecxx/ObjectFactory.h
+++ b/orkbasecxx/ObjectFactory.h
@@ -14,6 +14,7 @@
#ifndef __OBJECTFACTORY_H__
#define __OBJECTFACTORY_H__
+#include "ace/Thread_Mutex.h"
#include "ace/Singleton.h"
#include <map>
#include "StdString.h"
@@ -37,9 +38,8 @@ private:
ObjectFactory();
static ObjectFactory* m_singleton;
std::map<CStdString, ObjectRef> m_classes;
+ ACE_Thread_Mutex m_mutex;
};
-//typedef ACE_Singleton<ObjectFactory, ACE_Thread_Mutex> ObjectFactorySingleton;
-
#endif