3 * Copyright 2012, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 // This file is a supermacro
29 // (see http://wanderinghorse.net/computing/papers/supermacros_cpp.html) to
30 // expand a declaration of a late-binding symbol table class.
33 // LATE_BINDING_SYMBOL_TABLE_CLASS_NAME: Name of the class to generate.
34 // LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST: List of symbols to load from the DLL,
35 // as an X-Macro list (see http://www.drdobbs.com/blogs/cpp/228700289).
37 // From a .h file, include the header(s) for the DLL to late-bind and the
38 // latebindingsymboltable.h header, and then call this supermacro (optionally
39 // from inside the namespace for the class to generate, if any). Example:
41 // #include <headerfordll.h>
43 // #include "talk/base/latebindingsymboltable.h"
47 // #define MY_CLASS_NAME DesiredClassName
48 // #define MY_SYMBOLS_LIST X(acos) X(sin) X(tan)
50 // #define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME MY_CLASS_NAME
51 // #define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST MY_SYMBOLS_LIST
52 // #include "talk/base/latebindingsymboltable.h.def"
56 #ifndef TALK_BASE_LATEBINDINGSYMBOLTABLE_H_
57 #error You must first include latebindingsymboltable.h
60 #ifndef LATE_BINDING_SYMBOL_TABLE_CLASS_NAME
61 #error You must define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME
64 #ifndef LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST
65 #error You must define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST
68 class LATE_BINDING_SYMBOL_TABLE_CLASS_NAME :
69 public ::talk_base::LateBindingSymbolTable {
71 LATE_BINDING_SYMBOL_TABLE_CLASS_NAME();
72 ~LATE_BINDING_SYMBOL_TABLE_CLASS_NAME();
75 typeof(&::sym) sym() const { \
76 ASSERT(::talk_base::LateBindingSymbolTable::IsLoaded()); \
77 return reinterpret_cast<typeof(&::sym)>(table_[SYMBOL_TABLE_INDEX_##sym]); \
79 LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST
85 SYMBOL_TABLE_INDEX_##sym,
86 LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST
91 static const ::talk_base::LateBindingSymbolTable::TableInfo kTableInfo;
92 static const char *const kSymbolNames[];
94 void *table_[SYMBOL_TABLE_SIZE];
96 DISALLOW_COPY_AND_ASSIGN(LATE_BINDING_SYMBOL_TABLE_CLASS_NAME);
99 #undef LATE_BINDING_SYMBOL_TABLE_CLASS_NAME
100 #undef LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST