Debian Codegraph @

experimental/tskit/bindings/core.cpp

raw
1 /*
2 * Copyright 2021 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include <string>
8
9 #include "experimental/tskit/bindings/bindings.h"
10
11 class Something {
12 public:
13 Something(std::string n): fName(n) {}
14
15 const std::string getName() {
16 return fName;
17 }
18
19 void setName(std::string name) {
20 fName = name;
21 }
22
23 private:
24 std::string fName;
25 };
26
27 EMSCRIPTEN_BINDINGS(Core) {
28 TS_PRIVATE_EXPORT("_privateFunction(x: number, y: number): number")
29 function("_privateFunction", optional_override([](int x, int y)->size_t {
30 return x * y;
31 }));
32
33 /**
34 * This function does a public thing.
35 * @param input an ice cream flavor
36 */
37 TS_EXPORT("publicFunction(input: string): void")
38 function("publicFunction", optional_override([](std::string s)->void {
39 printf("Hello %s\n", s.c_str());
40 }));
41
42 /**
43 * The Something class is quite something. See SkSomething.h for more.
44 */
45 class_<Something>("Something")
46 /**
47 * Returns a Something with the provided name.
48 * @param name
49 */
50 TS_EXPORT("new(name: string): Something")
51 .constructor<std::string>()
52 /**
53 * Returns the associated name.
54 */
55 TS_EXPORT("getName(): string")
56 .function("getName", &Something::getName)
57 TS_PRIVATE_EXPORT("setName(name: string): void")
58 .function("_setName", &Something::setName);
59 }