1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<title>Mangled Import</title> 6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="../boost_dll.html" title="Chapter 14. Boost.DLL"> 10<link rel="prev" href="tutorial.html" title="Tutorial"> 11<link rel="next" href="missuses.html" title="Missuses"> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td> 16<td align="center"><a href="../../../index.html">Home</a></td> 17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<a accesskey="p" href="tutorial.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_dll.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="missuses.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="section"> 27<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 28<a name="boost_dll.mangled_import"></a><a class="link" href="mangled_import.html" title="Mangled Import">Mangled Import</a> 29</h2></div></div></div> 30<div class="toc"><dl class="toc"> 31<dt><span class="section"><a href="mangled_import.html#boost_dll.mangled_import.support___requirements">Support 32 & Requirements</a></span></dt> 33<dt><span class="section"><a href="mangled_import.html#boost_dll.mangled_import.mangled_import_example">Mangled 34 Import Example</a></span></dt> 35<dt><span class="section"><a href="mangled_import.html#boost_dll.mangled_import.class_import">Class Import</a></span></dt> 36<dt><span class="section"><a href="mangled_import.html#boost_dll.mangled_import.overloading_qualifiers">Overloading 37 qualifiers</a></span></dt> 38</dl></div> 39<p> 40 This section describes the experimental feature of allowing the import of mangled 41 symbols from an dll. While this feature is unique to this library and looks 42 quite promising, it is not throroughly tested and thus not considered stable. 43 </p> 44<p> 45 As a short example we can import the following functions quite easily: 46 </p> 47<p> 48</p> 49<pre class="programlisting"><span class="comment">//library.dll</span> 50<span class="keyword">namespace</span> <span class="identifier">foo</span> <span class="special">{</span> 51<span class="keyword">int</span> <span class="identifier">bar</span><span class="special">(</span><span class="keyword">int</span><span class="special">);</span> 52<span class="keyword">double</span> <span class="identifier">bar</span><span class="special">(</span><span class="keyword">double</span><span class="special">);</span> 53<span class="special">}</span> 54</pre> 55<p> 56 </p> 57<p> 58 And the import looks like this: 59 </p> 60<p> 61</p> 62<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">f1</span> <span class="special">=</span> <span class="identifier">import_mangled</span><span class="special"><</span><span class="keyword">int</span><span class="special">(</span><span class="keyword">int</span><span class="special">)>(</span><span class="string">"library.dll"</span><span class="special">,</span> <span class="string">"foo::bar"</span><span class="special">);</span> 63<span class="keyword">auto</span> <span class="identifier">f2</span> <span class="special">=</span> <span class="identifier">import_mangled</span><span class="special"><</span><span class="keyword">double</span><span class="special">(</span><span class="keyword">double</span><span class="special">)>(</span><span class="string">"library.dll"</span><span class="special">,</span> <span class="string">"foo::bar"</span><span class="special">);</span> 64<span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">f1</span><span class="special">(</span><span class="number">42</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">endl</span><span class="special">;</span> 65<span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">f2</span><span class="special">(</span><span class="number">3.2</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">endl</span><span class="special">;</span> 66</pre> 67<p> 68 </p> 69<div class="section"> 70<div class="titlepage"><div><div><h3 class="title"> 71<a name="boost_dll.mangled_import.support___requirements"></a><a class="link" href="mangled_import.html#boost_dll.mangled_import.support___requirements" title="Support & Requirements">Support 72 & Requirements</a> 73</h3></div></div></div> 74<p> 75 Currently, the Itanium ABI and the MSVC ABI are implemented. The MSVC ABI 76 requires boost.spirit.x3 support, allowing only the usage of MSVC 2015. The 77 Itanium API requires C++11. 78 </p> 79<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 80<li class="listitem"> 81 Gcc 82 </li> 83<li class="listitem"> 84 Clang 85 </li> 86<li class="listitem"> 87 MSVC 2015 88 </li> 89<li class="listitem"> 90 Intel C++ 91 </li> 92</ul></div> 93<p> 94 The Itanium API does not import the return type of functions, nor the type 95 of global variables. 96 </p> 97</div> 98<div class="section"> 99<div class="titlepage"><div><div><h3 class="title"> 100<a name="boost_dll.mangled_import.mangled_import_example"></a><a class="link" href="mangled_import.html#boost_dll.mangled_import.mangled_import_example" title="Mangled Import Example">Mangled 101 Import Example</a> 102</h3></div></div></div> 103<p> 104 The core of the mangled import is the <code class="computeroutput">smart_library</code> 105 class. It can import functions and variables in their mangled form; to do 106 this, the smart_library reads the entire outline of the library and demangles 107 every entry point in it. That also means, that this class should only be 108 constructed once. 109 </p> 110<p> 111 In order to import all the methods in the following library, we will use 112 the <code class="computeroutput">smart_library</code> . 113 </p> 114<p> 115 The first thing to do when creating your own plugins is define the plugin 116 interface. There is an example of an abstract class that will be our plugin 117 API: 118 </p> 119<p> 120</p> 121<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">string</span><span class="special">></span> 122 123<span class="keyword">namespace</span> <span class="identifier">space</span> <span class="special">{</span> 124 125<span class="keyword">class</span> <span class="identifier">BOOST_SYMBOL_EXPORT</span> <span class="identifier">my_plugin</span> 126<span class="special">{</span> 127 <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">_name</span><span class="special">;</span> 128<span class="keyword">public</span><span class="special">:</span> 129 <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">name</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> 130 <span class="keyword">float</span> <span class="identifier">calculate</span><span class="special">(</span><span class="keyword">float</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">float</span> <span class="identifier">y</span><span class="special">);</span> 131 <span class="keyword">int</span> <span class="identifier">calculate</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">y</span><span class="special">);</span> 132 <span class="keyword">static</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span><span class="special">();</span> 133 <span class="identifier">my_plugin</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&</span> <span class="identifier">name</span><span class="special">);</span> 134 <span class="identifier">my_plugin</span><span class="special">();</span> 135 <span class="special">~</span><span class="identifier">my_plugin_api</span><span class="special">();</span> 136 <span class="keyword">static</span> <span class="keyword">int</span> <span class="identifier">value</span><span class="special">;</span> 137<span class="special">};</span> 138 139<span class="special">}</span> 140</pre> 141<p> 142 </p> 143<p> 144 Alright, now we have the definition for the plugin, so we use it in the following 145 full-fleshed example. Mind that there is a more convenient solution to import 146 member-functions which will be discussed later on. This example shows however 147 what the <code class="computeroutput">smart_lib</code> provides as features. 148 </p> 149<p> 150 At first we setup the smart library. Mind that the alias class is needed 151 to provide a type-alias for the my_plugin. 152 </p> 153<p> 154</p> 155<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">dll</span><span class="special">/</span><span class="identifier">smart_library</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> <span class="comment">// for import_alias</span> 156<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 157<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">memory</span><span class="special">></span> 158 159<span class="keyword">namespace</span> <span class="identifier">dll</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">dll</span><span class="special">;</span> 160 161<span class="keyword">struct</span> <span class="identifier">alias</span><span class="special">;</span> 162 163<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">argv</span><span class="special">[])</span> <span class="special">{</span> 164 165 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">dll</span><span class="special">::</span><span class="identifier">fs</span><span class="special">::</span><span class="identifier">path</span> <span class="identifier">lib_path</span><span class="special">(</span><span class="identifier">argv</span><span class="special">[</span><span class="number">1</span><span class="special">]);</span> <span class="comment">// argv[1] contains path to directory with our plugin library</span> 166 <span class="identifier">dll</span><span class="special">::</span><span class="identifier">smart_lib</span> <span class="identifier">lib</span><span class="special">(</span><span class="identifier">lib_path</span><span class="special">);</span> <span class="comment">// smart library instance</span> 167</pre> 168<p> 169 </p> 170<p> 171 In order to create the class, we will need to allocate memory. That of course 172 means, that we need to know the size; unfortunately it is not exported into 173 the dll, so we added the static size function for export. Static are used 174 as plain functions. 175 </p> 176<p> 177 So we import it, call it and allocate memory. 178 </p> 179<p> 180</p> 181<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">size_f</span> <span class="special">=</span> <span class="identifier">lib</span><span class="special">.</span><span class="identifier">get_function</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">()>(</span><span class="string">"space::my_plugin::size"</span><span class="special">);</span> <span class="comment">//get the size function</span> 182 183<span class="keyword">auto</span> <span class="identifier">size</span> <span class="special">=</span> <span class="identifier">size_f</span><span class="special">();</span> <span class="comment">// get the size of the class</span> 184<span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="keyword">char</span><span class="special">[],</span> <span class="identifier">size</span><span class="special">></span> <span class="identifier">buffer</span><span class="special">(</span><span class="keyword">new</span> <span class="keyword">char</span><span class="special">[</span><span class="identifier">size</span><span class="special">]);</span> <span class="comment">//allocate a buffer for the import</span> 185<span class="identifier">alias</span> <span class="special">&</span> <span class="identifier">inst</span> <span class="special">=</span> <span class="special">*</span><span class="keyword">reinterpret_cast</span><span class="special"><</span><span class="identifier">alias</span><span class="special">*>(</span><span class="identifier">buffer</span><span class="special">.</span><span class="identifier">get</span><span class="special">());</span> <span class="comment">//cast it to our alias type.</span> 186</pre> 187<p> 188 </p> 189<p> 190 Now, we have the memory size and a reference with our alias type. In order 191 to use it, we need to register the type as an alias. That will allow the 192 smart library to resolve the type name. 193 </p> 194<p> 195</p> 196<pre class="programlisting"><span class="identifier">lib</span><span class="special">.</span><span class="identifier">add_type_alias</span><span class="special">(</span><span class="string">"space::my_plugin"</span><span class="special">);</span> <span class="comment">//add an alias, so i can import a class that is not declared here</span> 197</pre> 198<p> 199 </p> 200<p> 201 In order to use the class, we of course need to initialize it, i.e. call 202 the constructor. The Itanium ABI may also implement an allocating constructor. 203 That is why a constructor may have two functions; since we already have allocated 204 the memory we use the standard constructor version, of the constructor from 205 string. So we select the constructor by passing the signature. 206 </p> 207<p> 208</p> 209<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">ctor</span> <span class="special">=</span> <span class="identifier">lib</span><span class="special">.</span><span class="identifier">get_constructor</span><span class="special"><</span><span class="identifier">alias</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&)>();</span> <span class="comment">//get the constructor</span> 210<span class="identifier">ctor</span><span class="special">.</span><span class="identifier">call_standard</span><span class="special">(&</span><span class="identifier">inst</span><span class="special">,</span> <span class="string">"MyName"</span><span class="special">);</span> <span class="comment">//call the non-allocating constructor. The allocating-constructor is a non-portable feature</span> 211</pre> 212<p> 213 </p> 214<p> 215 So since the class is now initialized, we can call the name method. If the 216 function is const and/or volatile the type parameter passed as type must 217 have the same qualifiers. 218 </p> 219<p> 220</p> 221<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">name_f</span> <span class="special">=</span> <span class="identifier">lib</span><span class="special">.</span><span class="identifier">get_mem_fn</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">alias</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">()>(</span><span class="string">"name"</span><span class="special">);//</span><span class="identifier">import</span> <span class="identifier">the</span> <span class="identifier">name</span> <span class="identifier">function</span> 222<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Name Call: "</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">inst</span><span class="special">.*</span><span class="identifier">name_f</span><span class="special">)()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 223</pre> 224<p> 225 </p> 226<p> 227 Overloaded functions can only be imported separately. 228 </p> 229<p> 230</p> 231<pre class="programlisting"><span class="comment">//import both calculate functions</span> 232<span class="keyword">auto</span> <span class="identifier">calc_f</span> <span class="special">=</span> <span class="identifier">lib</span><span class="special">.</span><span class="identifier">get_mem_fn</span><span class="special"><</span><span class="identifier">alias</span><span class="special">,</span> <span class="keyword">float</span><span class="special">(</span><span class="keyword">float</span><span class="special">,</span> <span class="keyword">float</span><span class="special">)>(</span><span class="string">"calculate"</span><span class="special">);</span> 233<span class="keyword">auto</span> <span class="identifier">calc_i</span> <span class="special">=</span> <span class="identifier">lib</span><span class="special">.</span><span class="identifier">get_mem_fn</span><span class="special"><</span><span class="identifier">alias</span><span class="special">,</span> <span class="keyword">int</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)></span> <span class="special">(</span><span class="string">"calculate"</span><span class="special">);</span> 234 235<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"calc(float): "</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">inst</span><span class="special">.*</span><span class="identifier">calc_f</span><span class="special">)(</span><span class="number">5.</span><span class="special">,</span> <span class="number">2.</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 236<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"calc(int) : "</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">inst</span><span class="special">.*</span><span class="identifier">calc_f</span><span class="special">)(</span><span class="number">5</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 237</pre> 238<p> 239 </p> 240<p> 241 Import of static variable is done like with plain variable. 242 </p> 243<p> 244</p> 245<pre class="programlisting"><span class="keyword">auto</span> <span class="special">&</span> <span class="identifier">var</span> <span class="special">=</span> <span class="identifier">lib</span><span class="special">.</span><span class="identifier">get_variable</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(</span><span class="string">"space::my_plugin::value"</span><span class="special">);</span> 246<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"value "</span> <span class="special"><<</span> <span class="identifier">var</span> <span class="special"><<</span> <span class="identifier">endl</span><span class="special">;</span> 247</pre> 248<p> 249 </p> 250<p> 251 Since we are finished, we call the destructor of the class. 252 </p> 253<p> 254</p> 255<pre class="programlisting"> <span class="keyword">auto</span> <span class="identifier">dtor</span> <span class="special">=</span> <span class="identifier">lib</span><span class="special">.</span><span class="identifier">get_destructor</span><span class="special"><</span><span class="identifier">alias</span><span class="special">>();</span> <span class="comment">//get the destructor</span> 256 <span class="identifier">dtor</span><span class="special">.</span><span class="identifier">call_standard</span><span class="special">(&</span><span class="identifier">inst</span><span class="special">);</span> 257 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"plugin->calculate(1.5, 1.5) call: "</span> <span class="special"><<</span> <span class="identifier">plugin</span><span class="special">-></span><span class="identifier">calculate</span><span class="special">(</span><span class="number">1.5</span><span class="special">,</span> <span class="number">1.5</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 258<span class="special">}</span> 259</pre> 260<p> 261 </p> 262<p> 263 <a class="link" href="mangled_import.html" title="Mangled Import">Back to the Top</a> 264 </p> 265</div> 266<div class="section"> 267<div class="titlepage"><div><div><h3 class="title"> 268<a name="boost_dll.mangled_import.class_import"></a><a class="link" href="mangled_import.html#boost_dll.mangled_import.class_import" title="Class Import">Class Import</a> 269</h3></div></div></div> 270<p> 271 Now it is demonstrated, how mangled and methods may be imported. This is 272 however a rather versatile way, so an easier interface is provided, which 273 also allows access to the type_info of an object. 274 </p> 275<p> 276 We will take the same class and import the same methods, but do it with the 277 import features. 278 </p> 279<p> 280 We put the library into a shared_pointer, because every import will hold 281 such a pointer to it. That is, we do not want to copy it. 282 </p> 283<p> 284</p> 285<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">dll</span><span class="special">/</span><span class="identifier">smart_library</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 286<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">dll</span><span class="special">/</span><span class="identifier">import_mangled</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 287<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">dll</span><span class="special">/</span><span class="identifier">import_class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 288 289 290 291<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">argv</span><span class="special">[])</span> <span class="special">{</span> 292 293 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">dll</span><span class="special">::</span><span class="identifier">fs</span><span class="special">::</span><span class="identifier">path</span> <span class="identifier">lib_path</span><span class="special">(</span><span class="identifier">argv</span><span class="special">[</span><span class="number">1</span><span class="special">]);</span> <span class="comment">// argv[1] contains path to directory with our plugin library</span> 294 <span class="identifier">smart_library</span> <span class="identifier">lib</span><span class="special">(</span><span class="identifier">lib_path</span><span class="special">);//</span> <span class="identifier">smart</span> <span class="identifier">library</span> <span class="identifier">instance</span> 295</pre> 296<p> 297 </p> 298<p> 299 Similar to the previous example, we need the size of the class. 300 </p> 301<p> 302</p> 303<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">size_f</span> <span class="special">=</span> <span class="identifier">import_mangled</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">()>(</span><span class="string">"space::my_plugin::size"</span><span class="special">);</span> <span class="comment">//get the size function</span> 304 305<span class="keyword">auto</span> <span class="identifier">size</span> <span class="special">=</span> <span class="special">(*</span><span class="identifier">size_f</span><span class="special">)();</span> <span class="comment">// get the size of the class</span> 306</pre> 307<p> 308 </p> 309<p> 310 On a side note, we can also import variable easily with that function. 311 </p> 312<p> 313</p> 314<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">value</span> <span class="special">=</span> <span class="identifier">import_mangled</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(</span><span class="identifier">lib</span><span class="special">,</span> <span class="string">"space::my_plugin::value"</span><span class="special">);</span> 315</pre> 316<p> 317 </p> 318<p> 319 We do the forward declaration on the first call, and invoke the constructor 320 directly. This is quite simple and allows to invoke the constructor directly. 321 The destructor will be invoked automatically. 322 </p> 323<p> 324</p> 325<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">cl</span> <span class="special">=</span> <span class="identifier">import_class</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">alias</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&>(</span><span class="identifier">lib</span><span class="special">,</span> <span class="string">"space::my_plugin::some_class"</span><span class="special">,</span> <span class="identifier">size</span><span class="special">,</span> <span class="string">"MyName"</span><span class="special">);</span> 326</pre> 327<p> 328 </p> 329<p> 330 Invoking a function will still require to import it first. 331 </p> 332<p> 333</p> 334<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">name</span> <span class="special">=</span> <span class="identifier">import_mangled</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">alias</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">()>(</span><span class="identifier">lib</span><span class="special">,</span> <span class="string">"name"</span><span class="special">);</span> 335<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Name: "</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">cl</span><span class="special">->*</span><span class="identifier">name</span><span class="special">)()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 336</pre> 337<p> 338 </p> 339<p> 340 For overloaded functions, we can import them as groups, which will give us 341 an object containing the overloads. 342 </p> 343<p> 344</p> 345<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">calc</span> <span class="special">=</span> <span class="identifier">import_mangled</span><span class="special"><</span><span class="identifier">alias</span><span class="special">,</span> <span class="keyword">float</span><span class="special">(</span><span class="keyword">float</span><span class="special">,</span> <span class="keyword">float</span><span class="special">),</span> <span class="keyword">int</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)>(</span><span class="identifier">lib</span><span class="special">,</span> <span class="string">"calculate"</span><span class="special">);</span> 346<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Calc(float): "</span> <span class="special">(</span><span class="identifier">cl</span><span class="special">->*</span><span class="identifier">calc</span><span class="special">)(</span><span class="number">5.f</span><span class="special">,</span> <span class="number">2.f</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 347<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Calc(int): "</span> <span class="special">(</span><span class="identifier">cl</span><span class="special">->*</span><span class="identifier">calc</span><span class="special">)(</span><span class="number">5</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 348</pre> 349<p> 350 </p> 351<p> 352 Additionally, we can access the typeinfo like this. 353 </p> 354<p> 355</p> 356<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span> <span class="special">&</span><span class="identifier">ti</span> <span class="special">=</span> <span class="identifier">cl</span><span class="special">.</span><span class="identifier">get_type_info</span><span class="special">();</span> 357</pre> 358<p> 359 </p> 360<p> 361 <a class="link" href="mangled_import.html" title="Mangled Import">Back to the Top</a> 362 </p> 363</div> 364<div class="section"> 365<div class="titlepage"><div><div><h3 class="title"> 366<a name="boost_dll.mangled_import.overloading_qualifiers"></a><a class="link" href="mangled_import.html#boost_dll.mangled_import.overloading_qualifiers" title="Overloading qualifiers">Overloading 367 qualifiers</a> 368</h3></div></div></div> 369<p> 370 Not handled in the example was the question, of how it is handled if the 371 qualification differs for an overloaded function. This can be done, by passing 372 the class again with another qualification - a function signature will always 373 pick the last one provided. 374 </p> 375<p> 376 If we have this in our plugin: 377</p> 378<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">plugin</span> 379<span class="special">{</span> 380 <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">);</span> 381 <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">double</span><span class="special">);</span> 382 <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 383 <span class="keyword">void</span> <span class="identifier">f</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> 384 <span class="keyword">void</span> <span class="identifier">f</span><span class="special">()</span> <span class="keyword">volatile</span><span class="special">;</span> 385 <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">)</span> <span class="keyword">volatile</span><span class="special">;</span> 386 <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">double</span><span class="special">);</span> <span class="keyword">const</span> <span class="keyword">volatile</span><span class="special">;</span> 387<span class="special">};</span> 388</pre> 389<p> 390 </p> 391<p> 392 we can import them all at once, with the following command: 393 </p> 394<p> 395</p> 396<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">import_class</span><span class="special"><</span> 397 <span class="identifier">alias</span><span class="special">,</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">),</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">double</span><span class="special">),</span> <span class="comment">//not qualified</span> 398 <span class="keyword">const</span> <span class="identifier">alias</span><span class="special">,</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">),</span> <span class="identifier">f</span><span class="special">(),</span> <span class="comment">//const</span> 399 <span class="keyword">volatile</span> <span class="identifier">alias</span><span class="special">,</span> <span class="identifier">f</span><span class="special">(),</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">int</span><span class="special">),</span> <span class="comment">//volatile</span> 400 <span class="keyword">const</span> <span class="keyword">volatile</span> <span class="identifier">alias</span><span class="special">,</span> <span class="identifier">f</span><span class="special">(</span><span class="keyword">double</span><span class="special">)//</span><span class="keyword">const</span> <span class="keyword">volatile</span> 401 <span class="special">>(</span><span class="identifier">lib</span><span class="special">,</span> <span class="string">"f"</span><span class="special">);</span> 402</pre> 403<p> 404 </p> 405</div> 406</div> 407<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 408<td align="left"></td> 409<td align="right"><div class="copyright-footer">Copyright © 2014 Renato Tegon Forti, Antony Polukhin<br>Copyright © 2015 Antony Polukhin<br>Copyright © 2016 Antony Polukhin, Klemens Morgenstern<br>Copyright © 2017-2019 Antony Polukhin<p> 410 Distributed under the Boost Software License, Version 1.0. (See accompanying 411 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 412 </p> 413</div></td> 414</tr></table> 415<hr> 416<div class="spirit-nav"> 417<a accesskey="p" href="tutorial.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_dll.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="missuses.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 418</div> 419</body> 420</html> 421