1*35238bceSAndroid Build Coastguard Worker /*------------------------------------------------------------------------- 2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program Tester Core 3*35238bceSAndroid Build Coastguard Worker * ---------------------------------------- 4*35238bceSAndroid Build Coastguard Worker * 5*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project 6*35238bceSAndroid Build Coastguard Worker * 7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at 10*35238bceSAndroid Build Coastguard Worker * 11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 12*35238bceSAndroid Build Coastguard Worker * 13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 17*35238bceSAndroid Build Coastguard Worker * limitations under the License. 18*35238bceSAndroid Build Coastguard Worker * 19*35238bceSAndroid Build Coastguard Worker *//*! 20*35238bceSAndroid Build Coastguard Worker * \file 21*35238bceSAndroid Build Coastguard Worker * \brief Generic registry class for factories 22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/ 23*35238bceSAndroid Build Coastguard Worker 24*35238bceSAndroid Build Coastguard Worker #include "tcuFactoryRegistry.hpp" 25*35238bceSAndroid Build Coastguard Worker 26*35238bceSAndroid Build Coastguard Worker namespace tcu 27*35238bceSAndroid Build Coastguard Worker { 28*35238bceSAndroid Build Coastguard Worker 29*35238bceSAndroid Build Coastguard Worker // AbstractFactory 30*35238bceSAndroid Build Coastguard Worker AbstractFactory(void)31*35238bceSAndroid Build Coastguard WorkerAbstractFactory::AbstractFactory(void) 32*35238bceSAndroid Build Coastguard Worker { 33*35238bceSAndroid Build Coastguard Worker } 34*35238bceSAndroid Build Coastguard Worker ~AbstractFactory(void)35*35238bceSAndroid Build Coastguard WorkerAbstractFactory::~AbstractFactory(void) 36*35238bceSAndroid Build Coastguard Worker { 37*35238bceSAndroid Build Coastguard Worker } 38*35238bceSAndroid Build Coastguard Worker 39*35238bceSAndroid Build Coastguard Worker // GenericFactoryRegistry 40*35238bceSAndroid Build Coastguard Worker GenericFactoryRegistry(void)41*35238bceSAndroid Build Coastguard WorkerGenericFactoryRegistry::GenericFactoryRegistry(void) 42*35238bceSAndroid Build Coastguard Worker { 43*35238bceSAndroid Build Coastguard Worker } 44*35238bceSAndroid Build Coastguard Worker ~GenericFactoryRegistry(void)45*35238bceSAndroid Build Coastguard WorkerGenericFactoryRegistry::~GenericFactoryRegistry(void) 46*35238bceSAndroid Build Coastguard Worker { 47*35238bceSAndroid Build Coastguard Worker for (std::vector<AbstractFactory *>::const_iterator i = m_factories.begin(); i != m_factories.end(); ++i) 48*35238bceSAndroid Build Coastguard Worker delete *i; 49*35238bceSAndroid Build Coastguard Worker } 50*35238bceSAndroid Build Coastguard Worker getFactoryByIndex(size_t index)51*35238bceSAndroid Build Coastguard WorkerAbstractFactory *GenericFactoryRegistry::getFactoryByIndex(size_t index) 52*35238bceSAndroid Build Coastguard Worker { 53*35238bceSAndroid Build Coastguard Worker DE_ASSERT(index < m_factories.size()); 54*35238bceSAndroid Build Coastguard Worker return m_factories[index]; 55*35238bceSAndroid Build Coastguard Worker } 56*35238bceSAndroid Build Coastguard Worker getFactoryByIndex(size_t index) const57*35238bceSAndroid Build Coastguard Workerconst AbstractFactory *GenericFactoryRegistry::getFactoryByIndex(size_t index) const 58*35238bceSAndroid Build Coastguard Worker { 59*35238bceSAndroid Build Coastguard Worker DE_ASSERT(index < m_factories.size()); 60*35238bceSAndroid Build Coastguard Worker return m_factories[index]; 61*35238bceSAndroid Build Coastguard Worker } 62*35238bceSAndroid Build Coastguard Worker getFactoryByName(const std::string & name)63*35238bceSAndroid Build Coastguard WorkerAbstractFactory *GenericFactoryRegistry::getFactoryByName(const std::string &name) 64*35238bceSAndroid Build Coastguard Worker { 65*35238bceSAndroid Build Coastguard Worker for (size_t index = 0; index < m_factories.size(); index++) 66*35238bceSAndroid Build Coastguard Worker { 67*35238bceSAndroid Build Coastguard Worker if (name == m_factories[index]->getName()) 68*35238bceSAndroid Build Coastguard Worker return m_factories[index]; 69*35238bceSAndroid Build Coastguard Worker } 70*35238bceSAndroid Build Coastguard Worker 71*35238bceSAndroid Build Coastguard Worker return DE_NULL; 72*35238bceSAndroid Build Coastguard Worker } 73*35238bceSAndroid Build Coastguard Worker getFactoryByName(const std::string & name) const74*35238bceSAndroid Build Coastguard Workerconst AbstractFactory *GenericFactoryRegistry::getFactoryByName(const std::string &name) const 75*35238bceSAndroid Build Coastguard Worker { 76*35238bceSAndroid Build Coastguard Worker for (size_t index = 0; index < m_factories.size(); index++) 77*35238bceSAndroid Build Coastguard Worker { 78*35238bceSAndroid Build Coastguard Worker if (name == m_factories[index]->getName()) 79*35238bceSAndroid Build Coastguard Worker return m_factories[index]; 80*35238bceSAndroid Build Coastguard Worker } 81*35238bceSAndroid Build Coastguard Worker 82*35238bceSAndroid Build Coastguard Worker return DE_NULL; 83*35238bceSAndroid Build Coastguard Worker } 84*35238bceSAndroid Build Coastguard Worker registerFactory(AbstractFactory * factory)85*35238bceSAndroid Build Coastguard Workervoid GenericFactoryRegistry::registerFactory(AbstractFactory *factory) 86*35238bceSAndroid Build Coastguard Worker { 87*35238bceSAndroid Build Coastguard Worker DE_ASSERT(!getFactoryByName(factory->getName())); 88*35238bceSAndroid Build Coastguard Worker m_factories.push_back(factory); 89*35238bceSAndroid Build Coastguard Worker } 90*35238bceSAndroid Build Coastguard Worker 91*35238bceSAndroid Build Coastguard Worker // FactoryBase 92*35238bceSAndroid Build Coastguard Worker FactoryBase(const std::string & name,const std::string & description)93*35238bceSAndroid Build Coastguard WorkerFactoryBase::FactoryBase(const std::string &name, const std::string &description) 94*35238bceSAndroid Build Coastguard Worker : m_name(name) 95*35238bceSAndroid Build Coastguard Worker , m_description(description) 96*35238bceSAndroid Build Coastguard Worker { 97*35238bceSAndroid Build Coastguard Worker } 98*35238bceSAndroid Build Coastguard Worker ~FactoryBase(void)99*35238bceSAndroid Build Coastguard WorkerFactoryBase::~FactoryBase(void) 100*35238bceSAndroid Build Coastguard Worker { 101*35238bceSAndroid Build Coastguard Worker } 102*35238bceSAndroid Build Coastguard Worker getName(void) const103*35238bceSAndroid Build Coastguard Workerconst char *FactoryBase::getName(void) const 104*35238bceSAndroid Build Coastguard Worker { 105*35238bceSAndroid Build Coastguard Worker return m_name.c_str(); 106*35238bceSAndroid Build Coastguard Worker } 107*35238bceSAndroid Build Coastguard Worker getDescription(void) const108*35238bceSAndroid Build Coastguard Workerconst char *FactoryBase::getDescription(void) const 109*35238bceSAndroid Build Coastguard Worker { 110*35238bceSAndroid Build Coastguard Worker return m_description.c_str(); 111*35238bceSAndroid Build Coastguard Worker } 112*35238bceSAndroid Build Coastguard Worker 113*35238bceSAndroid Build Coastguard Worker } // namespace tcu 114