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