Hybrid Query Processing Engine for Coprocessing in Database Systems
HyPE
factory.hpp
Go to the documentation of this file.
00001 /***********************************************************************************************************
00002 Copyright (c) 2012, Sebastian Breß, Otto-von-Guericke University of Magdeburg, Germany. All rights reserved.
00003 
00004 This program and accompanying materials are made available under the terms of the 
00005 GNU LESSER GENERAL PUBLIC LICENSE - Version 3, http://www.gnu.org/licenses/lgpl-3.0.txt
00006 ***********************************************************************************************************/
00007 #pragma once
00008 
00009 #include <map>
00010 
00011 namespace hype{
00012    namespace core{
00013 
00014             template<class AbstractProduct, typename IdentifierType, typename ProductCreator = AbstractProduct* (*)()>
00015              class Factory{
00016                        private:
00017                              typedef std::map<IdentifierType, ProductCreator> AssocMap;
00018                              AssocMap associations_;
00019        
00020                        public:
00021 
00022                               Factory(): associations_(){}
00023 ~Factory(){
00024 associations_.erase(associations_.begin(), associations_.end());
00025 }
00026 
00027                               bool Register(const IdentifierType& id, ProductCreator creator){
00028                                     return associations_.insert(typename AssocMap::value_type(id,creator)).second;
00029                               }
00030 
00031                               bool Unregister(const IdentifierType& id){
00032                                     return associations_.erase(id)==1;
00033                               } 
00034                               AbstractProduct* CreateObject(const IdentifierType& id){
00035                                     typename AssocMap::const_iterator i = associations_.find(id);
00036                                     if(i!=associations_.end()){
00037                                          return i->second();
00038                                     }
00039                                     return NULL;
00040                               }
00041            };
00042 
00043    }; //end namespace core
00044 }; //end namespace hype
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines