• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
67 								StaticFunctionLibrary	(const StaticFunctionLibrary&);
68 	StaticFunctionLibrary&		operator=				(const StaticFunctionLibrary&);
69 
70 	// \todo [2014-03-11 pyry] This could be implemented with const char* pointers and custom compare.
71 	std::map<std::string, deFunctionPtr>				m_functions;
72 };
73 
74 class DynamicFunctionLibrary : public FunctionLibrary
75 {
76 public:
77 								DynamicFunctionLibrary	(const char* fileName);
78 								~DynamicFunctionLibrary	(void);
79 
80 	deFunctionPtr				getFunction				(const char* funcName) const;
81 
82 private:
83 								DynamicFunctionLibrary	(const DynamicFunctionLibrary&);
84 	DynamicFunctionLibrary&		operator=				(const DynamicFunctionLibrary&);
85 
86 	de::DynamicLibrary			m_dynamicLibrary;
87 };
88 
89 class CompositeFunctionLibrary : public FunctionLibrary
90 {
91 public:
92 									CompositeFunctionLibrary	(const FunctionLibrary* libraries, int numLibraries);
93 									~CompositeFunctionLibrary	(void);
94 
95 	deFunctionPtr					getFunction					(const char* funcName) const;
96 
97 private:
98 	const FunctionLibrary* const	m_libraries;
99 	const int						m_numLibraries;
100 };
101 
102 } // tcu
103 
104 #endif // _TCUFUNCTIONLIBRARY_HPP
105