StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHyperCacheFactory.h
1 // StHyperCacheFactory.h
2 #ifndef __ST_HYPERCACHEFACTORY_H
3 #define __ST_HYPERCACHEFACTORY_H
4 
5 #include <map>
6 #include <string>
7 #include <sstream>
8 #include "StHyperCacheI.h"
9 #include "StHyperSingleton.h"
10 
11 typedef StHyperCacheI* (*StHyperCacheInstantiator)();
12 typedef std::map< std::string, StHyperCacheInstantiator > StHyperCacheInstantiatorMap;
13 
16 
18 {
19 
20 public:
22  virtual ~StHyperCacheFactory();
23 
24  StHyperCacheI* getStHyperCacheInstance( std::string id ) {
25  if (!m_InstantiatorMap) {
26  m_InstantiatorMap = new StHyperCacheInstantiatorMap();
27  }
28  StHyperCacheInstantiatorMap::iterator iter = (*m_InstantiatorMap).find(id);
29  if( iter != (*m_InstantiatorMap).end() ) {
30  return (iter->second)();
31  }
32  //LOG_DEBUG << "[ " << id << " ] cache type implementation was not found" << LOG_EOM;
33  return 0;
34  }
35 
36  static bool registerStHyperCacheInstantiator(std::string id, StHyperCacheInstantiator func) {
37  if (!m_InstantiatorMap) {
38  m_InstantiatorMap = new StHyperCacheInstantiatorMap();
39  }
40  (*m_InstantiatorMap).insert( std::make_pair( id, func ) );
41  return true;
42  }
43 
44 private:
45  static StHyperCacheInstantiatorMap* m_InstantiatorMap;
46 };
47 
48 #endif // __ST_HYPERCACHEFACTORY_H