Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / base / latebindingsymboltable.h.def
1 /*
2  * libjingle
3  * Copyright 2012, Google Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
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.
15  *
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.
26  */
27
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.
31 //
32 // Arguments:
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).
36 //
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:
40 //
41 // #include <headerfordll.h>
42 //
43 // #include "talk/base/latebindingsymboltable.h"
44 //
45 // namespace foo {
46 //
47 // #define MY_CLASS_NAME DesiredClassName
48 // #define MY_SYMBOLS_LIST X(acos) X(sin) X(tan)
49 //
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"
53 //
54 // }
55
56 #ifndef TALK_BASE_LATEBINDINGSYMBOLTABLE_H_
57 #error You must first include latebindingsymboltable.h
58 #endif
59
60 #ifndef LATE_BINDING_SYMBOL_TABLE_CLASS_NAME
61 #error You must define LATE_BINDING_SYMBOL_TABLE_CLASS_NAME
62 #endif
63
64 #ifndef LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST
65 #error You must define LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST
66 #endif
67
68 class LATE_BINDING_SYMBOL_TABLE_CLASS_NAME :
69     public ::talk_base::LateBindingSymbolTable {
70  public:
71   LATE_BINDING_SYMBOL_TABLE_CLASS_NAME();
72   ~LATE_BINDING_SYMBOL_TABLE_CLASS_NAME();
73
74 #define X(sym) \
75   typeof(&::sym) sym() const { \
76     ASSERT(::talk_base::LateBindingSymbolTable::IsLoaded()); \
77     return reinterpret_cast<typeof(&::sym)>(table_[SYMBOL_TABLE_INDEX_##sym]); \
78   }
79 LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST
80 #undef X
81
82  private:
83   enum {
84 #define X(sym) \
85     SYMBOL_TABLE_INDEX_##sym,
86 LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST
87 #undef X
88     SYMBOL_TABLE_SIZE
89   };
90
91   static const ::talk_base::LateBindingSymbolTable::TableInfo kTableInfo;
92   static const char *const kSymbolNames[];
93
94   void *table_[SYMBOL_TABLE_SIZE];
95
96   DISALLOW_COPY_AND_ASSIGN(LATE_BINDING_SYMBOL_TABLE_CLASS_NAME);
97 };
98
99 #undef LATE_BINDING_SYMBOL_TABLE_CLASS_NAME
100 #undef LATE_BINDING_SYMBOL_TABLE_SYMBOLS_LIST