Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 1 | /* |
Wenzel Jakob | a576e6a | 2015-07-29 17:51:54 +0200 | [diff] [blame] | 2 | example/example4.cpp -- global constants and functions, enumerations |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 3 | |
| 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 | |
| 12 | enum EMyEnumeration { |
| 13 | EFirstEntry = 1, |
| 14 | ESecondEntry |
| 15 | }; |
| 16 | |
| 17 | class Example4 { |
| 18 | public: |
| 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 | |
| 29 | bool test_function1() { |
| 30 | std::cout << "test_function()" << std::endl; |
| 31 | return false; |
| 32 | } |
| 33 | |
Wenzel Jakob | 2cf192f | 2015-10-04 15:17:12 +0200 | [diff] [blame] | 34 | void test_function2(EMyEnumeration k) { |
| 35 | std::cout << "test_function(enum=" << k << ")" << std::endl; |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 36 | } |
| 37 | |
Wenzel Jakob | 2cf192f | 2015-10-04 15:17:12 +0200 | [diff] [blame] | 38 | float test_function3(int i) { |
| 39 | std::cout << "test_function(" << i << ")" << std::endl; |
| 40 | return i / 2.f; |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void 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 | } |