1 #ifndef _TCUFUNCTIONLIBRARY_HPP 2 #define _TCUFUNCTIONLIBRARY_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program Tester Core 5 * ---------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 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 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 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. 20 * 21 *//*! 22 * \file 23 * \brief Generic interface for library containing functions. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 #include "deDynamicLibrary.hpp" 28 29 #include <string> 30 #include <vector> 31 #include <map> 32 33 namespace tcu 34 { 35 36 // \note Returned function pointers have same lifetime as the library. 37 class FunctionLibrary 38 { 39 protected: 40 FunctionLibrary(void); 41 42 public: 43 virtual ~FunctionLibrary(void); 44 virtual deFunctionPtr getFunction(const char *funcName) const = 0; 45 46 private: 47 FunctionLibrary(const FunctionLibrary &); 48 FunctionLibrary &operator=(const FunctionLibrary &); 49 }; 50 51 class StaticFunctionLibrary : public FunctionLibrary 52 { 53 public: 54 struct Entry 55 { 56 const char *name; 57 deFunctionPtr ptr; 58 }; 59 60 StaticFunctionLibrary(const Entry *entries, int numEntries); 61 ~StaticFunctionLibrary(void); 62 63 deFunctionPtr getFunction(const char *funcName) const; 64 65 private: 66 StaticFunctionLibrary(const StaticFunctionLibrary &); 67 StaticFunctionLibrary &operator=(const StaticFunctionLibrary &); 68 69 // \todo [2014-03-11 pyry] This could be implemented with const char* pointers and custom compare. 70 std::map<std::string, deFunctionPtr> m_functions; 71 }; 72 73 class DynamicFunctionLibrary : public FunctionLibrary 74 { 75 public: 76 DynamicFunctionLibrary(const char *fileName); 77 ~DynamicFunctionLibrary(void); 78 79 deFunctionPtr getFunction(const char *funcName) const; 80 81 private: 82 DynamicFunctionLibrary(const DynamicFunctionLibrary &); 83 DynamicFunctionLibrary &operator=(const DynamicFunctionLibrary &); 84 85 de::DynamicLibrary m_dynamicLibrary; 86 }; 87 88 class CompositeFunctionLibrary : public FunctionLibrary 89 { 90 public: 91 CompositeFunctionLibrary(const FunctionLibrary *libraries, int numLibraries); 92 ~CompositeFunctionLibrary(void); 93 94 deFunctionPtr getFunction(const char *funcName) const; 95 96 private: 97 const FunctionLibrary *const m_libraries; 98 const int m_numLibraries; 99 }; 100 101 } // namespace tcu 102 103 #endif // _TCUFUNCTIONLIBRARY_HPP 104