-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
106 lines (82 loc) · 4.33 KB
/
main.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <phpcpp.h>
#include "schema-parser.h"
#include "parsed-schema.h"
#include "flat-array-message-reader.h"
#include "struct-schema.h"
#include "dynamic-struct-reader.h"
#include "dynamic-list-reader.h"
#include "dynamic-struct-builder.h"
#include "dynamic-list-builder.h"
#include "malloc-message-builder.h"
/**
* tell the compiler that the get_module is a pure C function
*/
extern "C" {
/**
* Function that is called by PHP right after the PHP process
* has started, and that returns an address of an internal PHP
* strucure with all the details and features of your extension
*
* @return void* a pointer to an address that is understood by PHP
*/
PHPCPP_EXPORT void *get_module()
{
// static(!) Php::Extension object that should stay in memory
// for the entire duration of the process (that's why it's static)
static Php::Extension extension("capnp-php", "0.1");
// @todo add your own functions, classes, namespaces to the extension
Php::Namespace extNamespace("CAPNP");
Php::Class<capnp_php::SchemaParser> schemaParser("SchemaParser");
schemaParser.method("parseDiskFile", &capnp_php::SchemaParser::parseDiskFile, {
Php::ByVal("displayName", Php::Type::String, true),
Php::ByVal("fileName", Php::Type::String, true),
Php::ByVal("importPaths", Php::Type::Array, false)
});
Php::Class<capnp_php::ParsedSchema> parsedSchema("ParsedSchema");
parsedSchema.method("getProto", &capnp_php::ParsedSchema::getProto);
parsedSchema.method("getNested", &capnp_php::ParsedSchema::getNested, {
Php::ByVal("name", Php::Type::String, true)
});
parsedSchema.method("asStruct", &capnp_php::ParsedSchema::asStruct);
Php::Class<capnp_php::FlatArrayMessageReader> flatArrayMessageReader("FlatArrayMessageReader");
flatArrayMessageReader.method("__construct", &capnp_php::FlatArrayMessageReader::__construct, {
Php::ByVal("data", Php::Type::String, true),
});
flatArrayMessageReader.method("getRoot", &capnp_php::FlatArrayMessageReader::getRoot, {
Php::ByVal("data", "\\CAPNP\\StructSchema", true),
});
Php::Class<capnp_php::StructSchema> structSchema("StructSchema");
structSchema.method("getFieldNames", &capnp_php::StructSchema::getFieldNames);
Php::Class<capnp_php::DynamicStructReader> dynamicStructReader("DynamicStructReader");
dynamicStructReader.method("which", &capnp_php::DynamicStructReader::which);
Php::Class<capnp_php::DynamicListReader> dynamicListReader("DynamicListReader");
Php::Class<capnp_php::DynamicStructBuilder> dynamicStructBuilder("DynamicStructBuilder");
dynamicStructBuilder.method("init", &capnp_php::DynamicStructBuilder::init);
dynamicStructBuilder.method("which", &capnp_php::DynamicStructBuilder::which);
Php::Class<capnp_php::DynamicListBuilder> dynamicListBuilder("DynamicListBuilder");
Php::Interface messageBuilder("MessageBuilder");
messageBuilder.method("initRoot", {
Php::ByVal("schema", "\\CAPNP\\StructSchema", true)
});
messageBuilder.method("toFlatArray");
Php::Class<capnp_php::MallocMessageBuilder> mallocMessageBuilder("MallocMessageBuilder");
mallocMessageBuilder.implements(messageBuilder);
mallocMessageBuilder.method("initRoot", &capnp_php::MallocMessageBuilder::initRoot, {
Php::ByVal("schema", "\\CAPNP\\StructSchema", true)
});
mallocMessageBuilder.method("toFlatArray", &capnp_php::MallocMessageBuilder::toFlatArray);
extNamespace.add(std::move(schemaParser));
extNamespace.add(std::move(parsedSchema));
extNamespace.add(std::move(flatArrayMessageReader));
extNamespace.add(std::move(structSchema));
extNamespace.add(std::move(dynamicStructReader));
extNamespace.add(std::move(dynamicListReader));
extNamespace.add(std::move(dynamicStructBuilder));
extNamespace.add(std::move(dynamicListBuilder));
extNamespace.add(std::move(messageBuilder));
extNamespace.add(std::move(mallocMessageBuilder));
extension.add(std::move(extNamespace));
// return the extension
return extension;
}
}