• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011-2012 Renato Tegon Forti
2 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
3 // Copyright 2015-2020 Antony Polukhin.
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt
7 // or copy at http://www.boost.org/LICENSE_1_0.txt)
8 
9 // For more information, see http://www.boost.org
10 
11 // MinGW related workaround
12 #define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
13 
14 #include <boost/dll/config.hpp>
15 #include <boost/dll/alias.hpp>
16 #include <iostream>
17 #include <vector>
18 
19 #include <boost/shared_ptr.hpp>
20 #include <boost/make_shared.hpp>
21 #include <boost/fusion/container.hpp>
22 
23 #define LIBRARY_API BOOST_SYMBOL_EXPORT
24 
25 extern "C" void LIBRARY_API say_hello(void);
26 extern "C" float LIBRARY_API lib_version(void);
27 extern "C" int LIBRARY_API increment(int);
28 
29 extern "C" int LIBRARY_API integer_g;
30 extern "C" const int LIBRARY_API const_integer_g = 777;
31 
32 namespace foo {
bar(const std::vector<int> & v)33     std::size_t bar(const std::vector<int>& v) {
34         return v.size();
35     }
36 
37     std::size_t variable = 42;
38 }
39 
40 
41 
42 // Make sure that aliases have no problems with memory allocations and different types of input parameters
43 namespace namespace1 { namespace namespace2 { namespace namespace3 {
44     typedef
45         boost::fusion::vector<std::vector<int>, std::vector<int>, std::vector<int>, const std::vector<int>*, std::vector<int>* >
46     do_share_res_t;
47 
do_share(std::vector<int> v1,std::vector<int> & v2,const std::vector<int> & v3,const std::vector<int> * v4,std::vector<int> * v5)48     boost::shared_ptr<do_share_res_t> do_share(
49             std::vector<int> v1,
50             std::vector<int>& v2,
51             const std::vector<int>& v3,
52             const std::vector<int>* v4,
53             std::vector<int>* v5
54         )
55     {
56         v2.back() = 777;
57         v5->back() = 9990;
58         return boost::make_shared<do_share_res_t>(v1, v2, v3, v4, v5);
59     }
60 
61     std::string info("I am a std::string from the test_library (Think of me as of 'Hello world'. Long 'Hello world').");
62 
ref_returning_function()63     int& ref_returning_function() {
64         static int i = 0;
65         return i;
66     }
67 }}}
68 
69 
70 
71 BOOST_DLL_ALIAS(foo::bar, foo_bar)
72 BOOST_DLL_ALIAS(foo::variable, foo_variable)
73 BOOST_DLL_ALIAS(namespace1::namespace2::namespace3::do_share, do_share)
74 BOOST_DLL_ALIAS(namespace1::namespace2::namespace3::info, info)
75 BOOST_DLL_ALIAS(const_integer_g, const_integer_g_alias)
76 BOOST_DLL_ALIAS(namespace1::namespace2::namespace3::ref_returning_function, ref_returning_function)
77 
78 
79 
80 int integer_g = 100;
81 
say_hello(void)82 void say_hello(void)
83 {
84    std::cout << "Hello, Boost.Application!" << std::endl;
85 }
86 
lib_version(void)87 float lib_version(void)
88 {
89    return 1.0;
90 }
91 
increment(int n)92 int increment(int n)
93 {
94    return ++n;
95 }
96 
97 #include <boost/dll/runtime_symbol_info.hpp>
98 
this_module_location_from_itself()99 boost::dll::fs::path this_module_location_from_itself() {
100     return boost::dll::this_line_location();
101 }
102 
103 BOOST_DLL_ALIAS(this_module_location_from_itself, module_location_from_itself)
104 
105 
106 
107 int internal_integer_i = 0xFF0000;
108 extern "C" LIBRARY_API int& reference_to_internal_integer;
109 int& reference_to_internal_integer = internal_integer_i;
110 
111 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
112 extern "C" LIBRARY_API int&& rvalue_reference_to_internal_integer;
113 int&& rvalue_reference_to_internal_integer = static_cast<int&&>(internal_integer_i);
114 #endif
115 
116