Salome HOME
IDM : Batch sur CCRT
[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 using namespace std;
16
17 namespace Batch {
18
19   pthread_mutex_t BatchManagerCatalog::_mutex = PTHREAD_MUTEX_INITIALIZER;
20   std::map<string, FactBatchManager *> * BatchManagerCatalog::_p_catalog = 0;
21
22   // Constructeur
23   BatchManagerCatalog::BatchManagerCatalog()
24   {
25     // Nothing to do
26   }
27
28   // Destructeur
29   BatchManagerCatalog::~BatchManagerCatalog()
30   {
31     // Nothing to do
32   }
33
34   // Functor
35   FactBatchManager * BatchManagerCatalog::getFactBatchManager(const char * type)
36   {
37     return (* BatchManagerCatalog::_p_catalog)[type];
38   }
39
40   void BatchManagerCatalog::addFactBatchManager(const char * type, FactBatchManager * pFBM)
41   {
42     if (pFBM) { // *** section critique ***
43       pthread_mutex_lock(&_mutex);
44
45       if (! BatchManagerCatalog::_p_catalog) BatchManagerCatalog::_p_catalog = new std::map<string, FactBatchManager *>;
46       (*BatchManagerCatalog::_p_catalog)[type] = pFBM;
47
48       pthread_mutex_unlock(&_mutex);
49     }
50   }
51
52   FactBatchManager * BatchManagerCatalog::operator() (const char * type) const
53   {
54     return BatchManagerCatalog::getFactBatchManager(type);
55   }
56
57   std::map<string, FactBatchManager *> * BatchManagerCatalog::dict() const
58   {
59     return _p_catalog;
60   }
61
62   string BatchManagerCatalog::__repr__() const
63   {
64     ostringstream oss;
65     oss << "<BatchManagerCatalog contains {";
66     string sep;
67     for(std::map<string, FactBatchManager *>::const_iterator it = (*_p_catalog).begin(); it != (*_p_catalog).end(); it++, sep=", ") {
68       oss << sep << "'" << (*it).first << "' : '" << (*it).second->__repr__() << "'";
69     }
70     oss << "}>";
71     return oss.str();
72   }
73
74 }