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 interface for library containing functions.
22 *//*--------------------------------------------------------------------*/
23
24 #include "tcuFunctionLibrary.hpp"
25
26 namespace tcu
27 {
28
29 // FunctionLibrary
30
FunctionLibrary(void)31 FunctionLibrary::FunctionLibrary(void)
32 {
33 }
34
~FunctionLibrary(void)35 FunctionLibrary::~FunctionLibrary(void)
36 {
37 }
38
39 // StaticFunctionLibrary
40
StaticFunctionLibrary(const Entry * entries,int numEntries)41 StaticFunctionLibrary::StaticFunctionLibrary(const Entry *entries, int numEntries)
42 {
43 for (int entryNdx = 0; entryNdx < numEntries; entryNdx++)
44 m_functions.insert(std::make_pair(std::string(entries[entryNdx].name), entries[entryNdx].ptr));
45 }
46
~StaticFunctionLibrary(void)47 StaticFunctionLibrary::~StaticFunctionLibrary(void)
48 {
49 }
50
getFunction(const char * funcName) const51 deFunctionPtr StaticFunctionLibrary::getFunction(const char *funcName) const
52 {
53 std::map<std::string, deFunctionPtr>::const_iterator iter = m_functions.find(funcName);
54
55 if (iter == m_functions.end())
56 return DE_NULL;
57 else
58 return iter->second;
59 }
60
61 // DynamicFunctionLibrary
62
DynamicFunctionLibrary(const char * fileName)63 DynamicFunctionLibrary::DynamicFunctionLibrary(const char *fileName) : m_dynamicLibrary(fileName)
64 {
65 }
66
~DynamicFunctionLibrary(void)67 DynamicFunctionLibrary::~DynamicFunctionLibrary(void)
68 {
69 }
70
getFunction(const char * funcName) const71 deFunctionPtr DynamicFunctionLibrary::getFunction(const char *funcName) const
72 {
73 return m_dynamicLibrary.getFunction(funcName);
74 }
75
76 // CompositeFunctionLibrary
77
CompositeFunctionLibrary(const FunctionLibrary * libraries,int numLibraries)78 CompositeFunctionLibrary::CompositeFunctionLibrary(const FunctionLibrary *libraries, int numLibraries)
79 : m_libraries(libraries)
80 , m_numLibraries(numLibraries)
81 {
82 }
83
~CompositeFunctionLibrary(void)84 CompositeFunctionLibrary::~CompositeFunctionLibrary(void)
85 {
86 }
87
getFunction(const char * name) const88 deFunctionPtr CompositeFunctionLibrary::getFunction(const char *name) const
89 {
90 for (int ndx = 0; ndx < m_numLibraries; ndx++)
91 {
92 const deFunctionPtr ptr = m_libraries[ndx].getFunction(name);
93 if (ptr)
94 return ptr;
95 }
96 return DE_NULL;
97 }
98
99 } // namespace tcu
100