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 31 FunctionLibrary::FunctionLibrary (void) 32 { 33 } 34 35 FunctionLibrary::~FunctionLibrary (void) 36 { 37 } 38 39 // StaticFunctionLibrary 40 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 47 StaticFunctionLibrary::~StaticFunctionLibrary (void) 48 { 49 } 50 51 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 63 DynamicFunctionLibrary::DynamicFunctionLibrary (const char* fileName) 64 : m_dynamicLibrary(fileName) 65 { 66 } 67 68 DynamicFunctionLibrary::~DynamicFunctionLibrary (void) 69 { 70 } 71 72 deFunctionPtr DynamicFunctionLibrary::getFunction (const char* funcName) const 73 { 74 return m_dynamicLibrary.getFunction(funcName); 75 } 76 77 // CompositeFunctionLibrary 78 79 CompositeFunctionLibrary::CompositeFunctionLibrary (const FunctionLibrary* libraries, int numLibraries) 80 : m_libraries (libraries) 81 , m_numLibraries (numLibraries) 82 { 83 } 84 85 CompositeFunctionLibrary::~CompositeFunctionLibrary (void) 86 { 87 } 88 89 deFunctionPtr CompositeFunctionLibrary::getFunction (const char* name) const 90 { 91 for (int ndx = 0; ndx < m_numLibraries; ndx++) 92 { 93 const deFunctionPtr ptr = m_libraries[ndx].getFunction(name); 94 if (ptr) 95 return ptr; 96 } 97 return DE_NULL; 98 } 99 100 } // tcu 101