blob: ae4dfb3d832f07277db777e794b4ad8504e854f4 [file] [log] [blame]
Wenzel Jakob38bd7112015-07-05 20:05:44 +02001/*
Wenzel Jakoba576e6a2015-07-29 17:51:54 +02002 example/example4.cpp -- global constants and functions, enumerations
Wenzel Jakob38bd7112015-07-05 20:05:44 +02003
4 Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
5
6 All rights reserved. Use of this source code is governed by a
7 BSD-style license that can be found in the LICENSE file.
8*/
9
10#include "example.h"
11
12enum EMyEnumeration {
13 EFirstEntry = 1,
14 ESecondEntry
15};
16
17class Example4 {
18public:
19 enum EMode {
20 EFirstMode = 1,
21 ESecondMode
22 };
23
24 static void test_function(EMode mode) {
25 std::cout << "Example4::test_function(enum=" << mode << ")" << std::endl;
26 }
27};
28
29bool test_function1() {
30 std::cout << "test_function()" << std::endl;
31 return false;
32}
33
Wenzel Jakob2cf192f2015-10-04 15:17:12 +020034void test_function2(EMyEnumeration k) {
35 std::cout << "test_function(enum=" << k << ")" << std::endl;
Wenzel Jakob38bd7112015-07-05 20:05:44 +020036}
37
Wenzel Jakob2cf192f2015-10-04 15:17:12 +020038float test_function3(int i) {
39 std::cout << "test_function(" << i << ")" << std::endl;
40 return i / 2.f;
Wenzel Jakob38bd7112015-07-05 20:05:44 +020041}
42
43void init_ex4(py::module &m) {
44 m.def("test_function", &test_function1);
45 m.def("test_function", &test_function2);
46 m.def("test_function", &test_function3);
47 m.attr("some_constant") = py::int_(14);
48
49 py::enum_<EMyEnumeration>(m, "EMyEnumeration")
50 .value("EFirstEntry", EFirstEntry)
51 .value("ESecondEntry", ESecondEntry)
52 .export_values();
53
54 py::class_<Example4> ex4_class(m, "Example4");
55 ex4_class.def_static("test_function", &Example4::test_function);
56 py::enum_<Example4::EMode>(ex4_class, "EMode")
57 .value("EFirstMode", Example4::EFirstMode)
58 .value("ESecondMode", Example4::ESecondMode)
59 .export_values();
60}