Commit 0f9da999 authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

In NumA++ create trunk.
parents f025c9df 5db7090c
......@@ -4,6 +4,9 @@ cmake_minimum_required(VERSION 2.6)
project(NumA++ CXX)
# Force C++98
add_definitions(-std=c++98)
# placez vos exécutables dans des dossiers portant le nom du type de compilation (Release, Debug...). Ce dernier est défini par la variable CMAKE_BUILD_TYPE (qui n'a d'effet seulement si le générateur choisi est basé sur Make)
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
......
class Integrator {
public:
Integrator();
virtual ~Integrator();
};
#ifndef INTEGRATOR_REGISTRY_H
#define INTEGRATOR_REGISTRY_H
/**
* @file IntegratorRegistry.h
* @author Bryan BERTHOU (SPhN / CEA Saclay)
* @date June 29, 2016
* @version 1.0
*/
#include <SFML/System/Mutex.hpp>
#include <map>
#include <string>
#include "Integrator.h"
namespace NumA {
/**
* @class IntegratorRegistry
*
* @brief
*/
class IntegratorRegistry {
public:
/**
* Static function to be able to retrieve a unique instance pointer of this class anywhere in the code.
*
* @return a unique instance of this class
*/
static IntegratorRegistry* getInstance();
/**
* Default destructor
*/
virtual ~IntegratorRegistry();
unsigned int registerIntegrator(Integrator * pIntegrator);
/**
* Try to find stored object identified by its unique class identifier.
*
* @param classId
* @return reference to object in memory or throw an exception
*/
Integrator* get(unsigned int classId) const;
/**
* Try to find stored object identified by its class name.
*
* @param className
* @return reference to object in memory or throw an exception
*/
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
*/
static IntegratorRegistry* m_pInstance;
/**
* Private default constructor for a unique instance
*/
IntegratorRegistry();
std::map<unsigned int, Integrator*> m_baseObjectList; ///< list of registered objects identified by their unique integer identifier
std::map<std::string, Integrator*> m_translateList; ///< list of registered objects identified by their class name.
};
} // namespace NumA
#endif /* INTEGRATOR_REGISTRY_H */
#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