1 /* 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 // This file is a supermacro 12 // (see http://wanderinghorse.net/computing/papers/supermacros_cpp.html) to 13 // expand a declaration of a late-binding symbol table class. 14 // 15 // Arguments: 16 // LATE_BINDING_SYMBOL_TABLE_CLASS_NAME: Name of the class to generate. 17 // LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST: List of symbols to load from the DLL, 18 // as an X-Macro list (see http://www.drdobbs.com/blogs/cpp/228700289). 19 // 20 // From a .h file, include the header(s) for the DLL to late-bind and the 21 // latebindingsymboltable.h header, and then call this supermacro (optionally 22 // from inside the namespace for the class to generate, if any). Example: 23 // 24 // #include <headerfordll.h> 25 // 26 // #include "webrtc/base/latebindingsymboltable.h" 27 // 28 // namespace foo { 29 // 30 // #define MY_CLASS_NAME DesiredClassName 31 // #define MY_SYMBOLS_LIST X(acos) X(sin) X(tan) 32 // 33 // #define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME MY_CLASS_NAME 34 // #define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST MY_SYMBOLS_LIST 35 // #include "webrtc/base/latebindingsymboltable.h.def" 36 // 37 // } 38 39 #ifndef WEBRTC_BASE_LATEBINDINGSYMBOLTABLE_H_ 40 #error You must first include latebindingsymboltable.h 41 #endif 42 43 #ifndef LATE_BINDING_SYMBOL_TABLE_CLASS_NAME 44 #error You must define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME 45 #endif 46 47 #ifndef LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST 48 #error You must define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST 49 #endif 50 51 class LATE_BINDING_SYMBOL_TABLE_CLASS_NAME : 52 public ::rtc::LateBindingSymbolTable { 53 public: 54 LATE_BINDING_SYMBOL_TABLE_CLASS_NAME(); 55 ~LATE_BINDING_SYMBOL_TABLE_CLASS_NAME(); 56 57 #define X(sym) \ 58 typeof(&::sym) sym() const { \ 59 ASSERT(::rtc::LateBindingSymbolTable::IsLoaded()); \ 60 return reinterpret_cast<typeof(&::sym)>(table_[SYMBOL_TABLE_INDEX_##sym]); \ 61 } 62 LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST 63 #undef X 64 65 private: 66 enum { 67 #define X(sym) \ 68 SYMBOL_TABLE_INDEX_##sym, 69 LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST 70 #undef X 71 SYMBOL_TABLE_SIZE 72 }; 73 74 static const ::rtc::LateBindingSymbolTable::TableInfo kTableInfo; 75 static const char *const kSymbolNames[]; 76 77 void *table_[SYMBOL_TABLE_SIZE]; 78 79 RTC_DISALLOW_COPY_AND_ASSIGN(LATE_BINDING_SYMBOL_TABLE_CLASS_NAME); 80 }; 81 82 #undef LATE_BINDING_SYMBOL_TABLE_CLASS_NAME 83 #undef LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST 84