Commit 356f3cfb authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

In NumA++ :
- Implement Registry/Factory (as a draft) for Integrator.
parent 82f7b507
......@@ -8,6 +8,12 @@
* @version 1.0
*/
#include <SFML/System/Mutex.hpp>
#include <map>
#include <string>
#include "Integrator.h"
namespace NumA {
/**
......@@ -48,6 +54,13 @@ public:
Integrator* get(const std::string &className) const;
private:
/**
* Because NumA++ can be use in a multi-threading program we must ensure that only one object manipulates the registry at the same time to avoid memory access violation.
* It's performed by a mechanism called mutex or semaphore.
*/
mutable sf::Mutex m_mutex;
/**
* Private pointer of this class for a unique instance
*/
......
#include "../../../include/NumA/integration/IntegratorRegistry.h"
namespace NumA {
IntegratorRegistry* IntegratorRegistry::m_pInstance = 0;
IntegratorRegistry::IntegratorRegistry() {
}
IntegratorRegistry::~IntegratorRegistry() {
}
IntegratorRegistry* IntegratorRegistry::getInstance() {
if (!m_pInstance) {
m_pInstance = new IntegratorRegistry();
}
return m_pInstance;
}
unsigned int IntegratorRegistry::registerIntegrator(Integrator* pIntegrator) {
// sf::Lock lock(m_mutex); // mutex.lock()
//
// // Defined a temporary class identifier
// unsigned int classId = 0;
//
// // First check if a previous instance of this class has been registered
// // If not, store it.
// if (!isAvailable(pBaseObject->getClassName())) {
// // Retrieve the final class identifier
// classId = getUniqueClassId();
//
// // Registered the new instance of the class in both registry lists.
// m_translateList.insert(
// std::pair<std::string, BaseObject*>(pBaseObject->getClassName(),
// pBaseObject));
// m_baseObjectList.insert(
// std::pair<unsigned int, BaseObject*>(classId, pBaseObject));
// }
// // Else, throw an exception
// else {
// throw std::runtime_error(
// ElemUtils::Formatter()
// << "(BaseObjectRegistry::registerModule) Module class name is already in the registry - Please check your class name = "
// << pBaseObject->getClassName());
// }
//
// // Return the final class identifier to persist it into the static classId variable of the registered class.
// return classId;
} // mutex.unlock();
Integrator* IntegratorRegistry::get(unsigned int classId) const {
}
Integrator* IntegratorRegistry::get(const std::string& className) const {
}
} // namespace NumA
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment