File: cpp_import_test.cpp

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (76 lines) | stat: -rw-r--r-- 2,009 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2016 Klemens Morgenstern
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

// For more information, see http://www.boost.org

#include <boost/config.hpp>

#include "../example/b2_workarounds.hpp"

#include <boost/dll/smart_library.hpp>
#include <boost/dll/import_mangled.hpp>

#include <boost/core/lightweight_test.hpp>
#include <boost/filesystem.hpp>
#include <boost/variant.hpp>

#include <functional>
#include <iostream>

struct override_class
{
    int arr[32];
};


int main(int argc, char* argv[])
{   
     using namespace boost::dll;
    using namespace boost::dll::experimental;
    boost::dll::fs::path pt = b2_workarounds::first_lib_from_argv(argc, argv);

    BOOST_TEST(!pt.empty());
    std::cout << "Library: " << pt << std::endl;

    smart_library sm(pt);

    auto sp_variable = import_mangled<double>(sm, "some_space::variable");

    auto unscoped_var = import_mangled<int>(sm, "unscoped_var");


    auto ovl = import_mangled<void(int), void(double)>(sm, "overloaded");

    ovl(12);
    BOOST_TEST(*unscoped_var == 12);
    ovl(5.0);
    BOOST_TEST(*sp_variable == 5.0);

    std::function<void(int)> f_test = ovl;//test if it binds
    f_test(-2);
    BOOST_TEST(*unscoped_var == -2);

    sm.add_type_alias<override_class>("some_space::some_class");

    auto func = import_mangled<
            override_class, double(double, double), int(int, int),
            volatile override_class, int(int, int),
            const volatile override_class, double(double, double)>(sm, "func");

    override_class override_class_varible{};

    override_class *ov = &override_class_varible;
    volatile override_class *ovv = ov;
    const volatile override_class *ovcv = ov;

    BOOST_TEST(func(ov, 3.,2.) == 6.);
    BOOST_TEST(func(ov, 1,2  ) == 3 );
    BOOST_TEST(func(ovv, 10,2) == 8 );
    BOOST_TEST(func(ovcv, 9,2) == 4.5 );

    return boost::report_errors();
}