forked from opencor/libopencor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.cpp
More file actions
78 lines (63 loc) · 3.39 KB
/
file.cpp
File metadata and controls
78 lines (63 loc) · 3.39 KB
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
/*
Copyright libOpenCOR contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <libopencor>
void fileApi()
{
// File API.
emscripten::enum_<libOpenCOR::File::Type>("File.Type")
.value("UNKNOWN_FILE", libOpenCOR::File::Type::UNKNOWN_FILE)
.value("CELLML_FILE", libOpenCOR::File::Type::CELLML_FILE)
.value("SEDML_FILE", libOpenCOR::File::Type::SEDML_FILE)
.value("COMBINE_ARCHIVE", libOpenCOR::File::Type::COMBINE_ARCHIVE);
emscripten::class_<libOpenCOR::File, emscripten::base<libOpenCOR::Logger>>("File")
.smart_ptr_constructor("File", &libOpenCOR::File::create)
.property("type", &libOpenCOR::File::type)
.property("fileName", &libOpenCOR::File::fileName)
.property("url", &libOpenCOR::File::url)
.property("path", &libOpenCOR::File::path)
.function("contents", emscripten::optional_override([](const libOpenCOR::FilePtr &pThis) {
auto contents {pThis->contents()};
auto view {emscripten::typed_memory_view(contents.size(), contents.data())};
auto res {emscripten::val::global("Uint8Array").new_(contents.size())};
res.call<void>("set", view);
return res;
}))
.function("setContents", emscripten::optional_override([](const libOpenCOR::FilePtr &pThis, emscripten::val pContents) {
if (pContents.isNull() || pContents.isUndefined()) {
pThis->setContents(libOpenCOR::UnsignedChars {});
return;
}
pThis->setContents(emscripten::vecFromJSArray<unsigned char>(pContents));
}))
.property("hasChildFiles", &libOpenCOR::File::hasChildFiles)
.property("childFileCount", &libOpenCOR::File::childFileCount)
.property("childFileNames", &libOpenCOR::File::childFileNames)
.property("childFiles", &libOpenCOR::File::childFiles)
.function("childFile", &libOpenCOR::File::childFile)
.function("childFileFromFileName", &libOpenCOR::File::childFileFromFileName);
EM_ASM({
Module["File"]["Type"] = Module["File.Type"];
delete Module["File.Type"];
});
// FileManager API.
emscripten::class_<libOpenCOR::FileManager>("FileManager")
.class_function("instance", &libOpenCOR::FileManager::instance)
.function("manage", &libOpenCOR::FileManager::manage)
.function("unmanage", &libOpenCOR::FileManager::unmanage)
.function("reset", &libOpenCOR::FileManager::reset)
.property("hasFiles", &libOpenCOR::FileManager::hasFiles)
.property("fileCount", &libOpenCOR::FileManager::fileCount)
.property("files", &libOpenCOR::FileManager::files)
.function("file", &libOpenCOR::FileManager::file)
.function("fileFromFileNameOrUrl", &libOpenCOR::FileManager::fileFromFileNameOrUrl);
}