13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _TCUFACTORYREGISTRY_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _TCUFACTORYREGISTRY_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Generic registry class for factories 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuDefs.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass AbstractFactory 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AbstractFactory (void); 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~AbstractFactory (void); 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual const char* getName (void) const = 0; 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass GenericFactoryRegistry 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GenericFactoryRegistry (void); 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~GenericFactoryRegistry (void); 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t size (void) const { return m_factories.size(); } 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool empty (void) const { return m_factories.empty(); } 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void registerFactory (AbstractFactory* factory); 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AbstractFactory* getFactoryByName (const std::string& name); 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const AbstractFactory* getFactoryByName (const std::string& name) const; 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AbstractFactory* getFactoryByIndex (size_t index); 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const AbstractFactory* getFactoryByIndex (size_t index) const; 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GenericFactoryRegistry (const GenericFactoryRegistry&); 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GenericFactoryRegistry& operator= (const GenericFactoryRegistry&); 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<AbstractFactory*> m_factories; 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FactoryBase : public AbstractFactory 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FactoryBase (const std::string& name, const std::string& description); 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~FactoryBase (void); 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* getName (void) const; 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* getDescription (void) const; 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string m_name; 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string m_description; 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<class Factory> 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FactoryRegistry 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FactoryRegistry (void) {} 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~FactoryRegistry (void) {} 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool empty (void) const { return m_registry.empty(); } 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t size (void) const { return m_registry.size(); } 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t getFactoryCount (void) const { return m_registry.size(); } 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void registerFactory (Factory* factory) { m_registry.registerFactory(factory); } 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Factory* getFactoryByName (const std::string& name); 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Factory* getFactoryByName (const std::string& name) const; 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Factory* getFactoryByIndex (size_t index); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Factory* getFactoryByIndex (size_t index) const; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Factory* getDefaultFactory (void) { return getFactoryByIndex(0); } 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Factory* getDefaultFactory (void) const { return getFactoryByIndex(0); } 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GenericFactoryRegistry m_registry; 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<class Factory> 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Factory* FactoryRegistry<Factory>::getFactoryByName (const std::string& name) 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return static_cast<Factory*>(m_registry.getFactoryByName(name)); 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<class Factory> 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline const Factory* FactoryRegistry<Factory>::getFactoryByName (const std::string& name) const 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return static_cast<const Factory*>(m_registry.getFactoryByName(name)); 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<class Factory> 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Factory* FactoryRegistry<Factory>::getFactoryByIndex (size_t index) 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return static_cast<Factory*>(m_registry.getFactoryByIndex(index)); 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<class Factory> 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline const Factory* FactoryRegistry<Factory>::getFactoryByIndex (size_t index) const 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return static_cast<const Factory*>(m_registry.getFactoryByIndex(index)); 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _TCUFACTORYREGISTRY_HPP 134