1 #ifndef _TCUFACTORYREGISTRY_HPP
2 #define _TCUFACTORYREGISTRY_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Generic registry class for factories
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
37 AbstractFactory (void);
38 virtual ~AbstractFactory (void);
40 virtual const char* getName (void) const = 0;
43 class GenericFactoryRegistry
46 GenericFactoryRegistry (void);
47 ~GenericFactoryRegistry (void);
49 size_t size (void) const { return m_factories.size(); }
50 bool empty (void) const { return m_factories.empty(); }
52 void registerFactory (AbstractFactory* factory);
54 AbstractFactory* getFactoryByName (const std::string& name);
55 const AbstractFactory* getFactoryByName (const std::string& name) const;
57 AbstractFactory* getFactoryByIndex (size_t index);
58 const AbstractFactory* getFactoryByIndex (size_t index) const;
61 GenericFactoryRegistry (const GenericFactoryRegistry&);
62 GenericFactoryRegistry& operator= (const GenericFactoryRegistry&);
64 std::vector<AbstractFactory*> m_factories;
67 class FactoryBase : public AbstractFactory
70 FactoryBase (const std::string& name, const std::string& description);
73 const char* getName (void) const;
74 const char* getDescription (void) const;
77 const std::string m_name;
78 const std::string m_description;
81 template<class Factory>
85 FactoryRegistry (void) {}
86 ~FactoryRegistry (void) {}
88 bool empty (void) const { return m_registry.empty(); }
89 size_t size (void) const { return m_registry.size(); }
90 size_t getFactoryCount (void) const { return m_registry.size(); }
92 void registerFactory (Factory* factory) { m_registry.registerFactory(factory); }
94 Factory* getFactoryByName (const std::string& name);
95 const Factory* getFactoryByName (const std::string& name) const;
97 Factory* getFactoryByIndex (size_t index);
98 const Factory* getFactoryByIndex (size_t index) const;
100 Factory* getDefaultFactory (void) { return getFactoryByIndex(0); }
101 const Factory* getDefaultFactory (void) const { return getFactoryByIndex(0); }
104 GenericFactoryRegistry m_registry;
107 template<class Factory>
108 inline Factory* FactoryRegistry<Factory>::getFactoryByName (const std::string& name)
110 return static_cast<Factory*>(m_registry.getFactoryByName(name));
113 template<class Factory>
114 inline const Factory* FactoryRegistry<Factory>::getFactoryByName (const std::string& name) const
116 return static_cast<const Factory*>(m_registry.getFactoryByName(name));
119 template<class Factory>
120 inline Factory* FactoryRegistry<Factory>::getFactoryByIndex (size_t index)
122 return static_cast<Factory*>(m_registry.getFactoryByIndex(index));
125 template<class Factory>
126 inline const Factory* FactoryRegistry<Factory>::getFactoryByIndex (size_t index) const
128 return static_cast<const Factory*>(m_registry.getFactoryByIndex(index));
133 #endif // _TCUFACTORYREGISTRY_HPP