Salome HOME
437be93fb7d6cd0fb89ecfa93b5dda0ec4b2fbaf
[modules/kernel.git] / src / Batch / Batch_BatchManagerCatalog.cxx
1 /*
2  * BatchManagerCatalog.cxx : 
3  *
4  * Auteur : Ivan DUTKA-MALEN - EDF R&D
5  * Date   : Septembre 2004
6  * Projet : SALOME 2
7  *
8  */
9
10 #include <string>
11 #include <sstream>
12 #include <map>
13 #include "Batch_BatchManagerCatalog.hxx"
14 #include "Batch_FactBatchManager.hxx"
15
16 namespace Batch {
17
18   pthread_mutex_t BatchManagerCatalog::_mutex = PTHREAD_MUTEX_INITIALIZER;
19   map<string, FactBatchManager *> * BatchManagerCatalog::_p_catalog = 0;
20
21   // Constructeur
22   BatchManagerCatalog::BatchManagerCatalog()
23   {
24     // Nothing to do
25   }
26
27   // Destructeur
28   BatchManagerCatalog::~BatchManagerCatalog()
29   {
30     // Nothing to do
31   }
32
33   // Functor
34   FactBatchManager * BatchManagerCatalog::getFactBatchManager(const char * type)
35   {
36     return (* BatchManagerCatalog::_p_catalog)[type];
37   }
38
39   void BatchManagerCatalog::addFactBatchManager(const char * type, FactBatchManager * pFBM)
40   {
41     if (pFBM) { // *** section critique ***
42       pthread_mutex_lock(&_mutex);
43
44       if (! BatchManagerCatalog::_p_catalog) BatchManagerCatalog::_p_catalog = new map<string, FactBatchManager *>;
45       (*BatchManagerCatalog::_p_catalog)[type] = pFBM;
46
47       pthread_mutex_unlock(&_mutex);
48     }
49   }
50
51   FactBatchManager * BatchManagerCatalog::operator() (const char * type) const
52   {
53     return BatchManagerCatalog::getFactBatchManager(type);
54   }
55
56   map<string, FactBatchManager *> * BatchManagerCatalog::dict() const
57   {
58     return _p_catalog;
59   }
60
61   string BatchManagerCatalog::__repr__() const
62   {
63     ostringstream oss;
64     oss << "<BatchManagerCatalog contains {";
65     string sep;
66     for(map<string, FactBatchManager *>::const_iterator it = (*_p_catalog).begin(); it != (*_p_catalog).end(); it++, sep=", ") {
67       oss << sep << "'" << (*it).first << "' : '" << (*it).second->__repr__() << "'";
68     }
69     oss << "}>";
70     return oss.str();
71   }
72
73 }