IntegratorRegistry.h 2 KB
Newer Older
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
1
2
3
4
5
6
7
8
9
10
#ifndef INTEGRATOR_REGISTRY_H
#define INTEGRATOR_REGISTRY_H

/**
 * @file IntegratorRegistry.h
 * @author Bryan BERTHOU (SPhN / CEA Saclay)
 * @date June 29, 2016
 * @version 1.0
 */

Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
11
12
13
14
15
16
#include <SFML/System/Mutex.hpp>
#include <map>
#include <string>

#include "Integrator.h"

Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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:
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
57
58
59
60
61
62
63

    /**
     * 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;

Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    /**
     * 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 */