loom

Форк
0
192 строки · 6.6 Кб
1
/*
2
MIT License
3

4
Copyright (c) 2021 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
5

6
https://bmstu.codes/lsx/simodo/loom
7
*/
8

9
#include "simodo/variable/Module_interface.h"
10
#include "simodo/variable/VariableSetWrapper.h"
11
#include "simodo/interpret/Interpret_interface.h"
12

13
#include <memory>
14
#include <exception>
15
#include <cassert>
16

17
#ifdef CROSS_WIN
18
// MinGW related workaround
19
#define BOOST_DLL_FORCE_ALIAS_INSTANTIATION
20
#endif
21

22
#include <boost/dll/alias.hpp>
23

24
using namespace simodo;
25

26
namespace
27
{
28
    variable::Value createOutput(variable::Module_interface * host, const variable::VariableSetWrapper & args);
29
    variable::Value openOutput(variable::Module_interface * host, const variable::VariableSetWrapper & args);
30
    variable::Value openInput(variable::Module_interface * host, const variable::VariableSetWrapper & args);
31
    variable::Value output(variable::Module_interface * host, const variable::VariableSetWrapper & args);
32
    variable::Value outputLine(variable::Module_interface * host, const variable::VariableSetWrapper & args);
33
    variable::Value inputLine(variable::Module_interface * host, const variable::VariableSetWrapper & args);
34
    variable::Value _close(variable::Module_interface * host, const variable::VariableSetWrapper & args);
35
    variable::Value _read(variable::Module_interface * host, const variable::VariableSetWrapper & args);
36
    variable::Value _write(variable::Module_interface * host, const variable::VariableSetWrapper & args);
37
}
38

39
class Io_module : public variable::Module_interface
40
{
41
public:
42
    virtual version_t version() const override { return lib_version(); }
43

44
    virtual variable::Value instantiate(std::shared_ptr<Module_interface> module_object) override 
45
    {
46
        return {{
47
            {u"createOutput", {variable::ValueType::Function, variable::Object {{
48
                {u"@", variable::ExternalFunction {module_object, ::createOutput}},
49
                {{}, variable::ValueType::Int},
50
                {u"file_name", variable::ValueType::String},
51
            }}}},
52
            {u"openOutput", {variable::ValueType::Function, variable::Object {{
53
                {u"@", variable::ExternalFunction {module_object, ::openOutput}},
54
                {{}, variable::ValueType::Int},
55
                {u"file_name", variable::ValueType::String},
56
            }}}},
57
            {u"openInput", {variable::ValueType::Function, variable::Object {{
58
                {u"@", variable::ExternalFunction {module_object, ::openInput}},
59
                {{}, variable::ValueType::Int},
60
                {u"file_name", variable::ValueType::String},
61
            }}}},
62
            {u"output", {variable::ValueType::Function, variable::Object {{
63
                {u"@", variable::ExternalFunction {module_object, ::output}},
64
                {{}, variable::ValueType::Bool},
65
                {u"file_id", variable::ValueType::Int},
66
                {u"value_string", variable::ValueType::String},
67
            }}}},
68
            {u"outputLine", {variable::ValueType::Function, variable::Object {{
69
                {u"@", variable::ExternalFunction {module_object, ::outputLine}},
70
                {{}, variable::ValueType::Bool},
71
                {u"file_id", variable::ValueType::Int},
72
                {u"value_string", variable::ValueType::String},
73
            }}}},
74
            {u"inputLine", {variable::ValueType::Function, variable::Object {{
75
                {u"@", variable::ExternalFunction {module_object, ::inputLine}},
76
                {{}, variable::ValueType::Object},
77
                {u"file_id", variable::ValueType::Int},
78
            }}}},
79
            {u"close", {variable::ValueType::Function, variable::Object {{
80
                {u"@", variable::ExternalFunction {module_object, ::_close}},
81
                {{}, variable::ValueType::Bool},
82
                {u"file_id", variable::ValueType::Int},
83
            }}}},
84
            {u"read", {variable::ValueType::Function, variable::Object {{
85
                {u"@", variable::ExternalFunction {module_object, ::_read}},
86
                {{}, variable::ValueType::Object},
87
                {u"file_name", variable::ValueType::String},
88
            }}}},
89
            {u"write", {variable::ValueType::Function, variable::Object {{
90
                {u"@", variable::ExternalFunction {module_object, ::_write}},
91
                {{}, variable::ValueType::Bool},
92
                {u"file_name", variable::ValueType::String},
93
                {u"text_string", variable::ValueType::String},
94
            }}}},
95
        }};
96
    }
97

98
    // Factory method
99
    static std::shared_ptr<Module_interface> create(interpret::Interpret_interface * ) {
100
        return std::make_shared<Io_module>();
101
    }
102
};
103

104
BOOST_DLL_ALIAS(
105
    Io_module::create,    // <-- this function is exported with...
106
    create_simodo_module        // <-- ...this alias name
107
)
108

109
namespace
110
{
111
    variable::Value createOutput(variable::Module_interface * , const variable::VariableSetWrapper & args)
112
    {
113
        assert(args.size() == 1);
114

115
        const variable::Value & file_name_value = args[0].origin().value();
116

117
        assert(file_name_value.isString());
118

119
        // code...
120

121
        return -1;
122
    }
123

124
    variable::Value openOutput(variable::Module_interface * , const variable::VariableSetWrapper & args)
125
    {
126
        assert(args.size() == 1);
127

128
        const variable::Value & file_name_value = args[0].origin().value();
129

130
        assert(file_name_value.isString());
131

132
        // code...
133

134
        return -1;
135
    }
136

137
    variable::Value openInput(variable::Module_interface * , const variable::VariableSetWrapper & args)
138
    {
139
        assert(args.size() == 1);
140

141
        const variable::Value & file_name_value = args[0].origin().value();
142

143
        assert(file_name_value.isString());
144

145
        // code...
146

147
        return -1;
148
    }
149

150
    variable::Value output(variable::Module_interface * , const variable::VariableSetWrapper & /*args*/)
151
    {
152
        // code...
153

154
        return {};
155
    }
156

157
    variable::Value outputLine(variable::Module_interface * , const variable::VariableSetWrapper & /*args*/)
158
    {
159
        // code...
160

161
        return {};
162
    }
163

164
    variable::Value inputLine(variable::Module_interface * /*host*/, const variable::VariableSetWrapper & /*args*/)
165
    {
166
        // code...
167

168
        return {};
169
    }
170

171
    variable::Value _close(variable::Module_interface * /*host*/, const variable::VariableSetWrapper & /*args*/)
172
    {
173
        // code...
174

175
        return {};
176
    }
177

178
    variable::Value _read(variable::Module_interface * /*host*/, const variable::VariableSetWrapper & /*args*/)
179
    {
180
        // code...
181

182
        return {};
183
    }
184

185
    variable::Value _write(variable::Module_interface * /*host*/, const variable::VariableSetWrapper & /*args*/)
186
    {
187
        // code...
188

189
        return {};
190
    }
191

192
}
193

194

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.