Changeset View
Changeset View
Standalone View
Standalone View
src/backends/julia/juliaextensions.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | This program is free software; you can redistribute it and/or | ||||
3 | modify it under the terms of the GNU General Public License | ||||
4 | as published by the Free Software Foundation; either version 2 | ||||
5 | of the License, or (at your option) any later version. | ||||
6 | | ||||
7 | This program is distributed in the hope that it will be useful, | ||||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
10 | GNU General Public License for more details. | ||||
11 | | ||||
12 | You should have received a copy of the GNU General Public License | ||||
13 | along with this program; if not, write to the Free Software | ||||
14 | Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
15 | Boston, MA 02110-1301, USA. | ||||
16 | | ||||
17 | --- | ||||
18 | Copyright (C) 2016 Ivan Lakhtanov <ivan.lakhtanov@gmail.com> | ||||
19 | */ | ||||
20 | #include "juliaextensions.h" | ||||
21 | | ||||
22 | #include <QDebug> | ||||
23 | #include <KLocalizedString> | ||||
24 | | ||||
25 | #include "juliascriptloading.h" | ||||
26 | | ||||
27 | #define JULIA_EXT_CDTOR(name) Julia##name##Extension::Julia##name##Extension(QObject *parent) : name##Extension(parent) {} \ | ||||
28 | Julia##name##Extension::~Julia##name##Extension() {} | ||||
29 | | ||||
30 | | ||||
31 | JULIA_EXT_CDTOR(VariableManagement) | ||||
32 | | ||||
33 | const QString JuliaVariableManagementExtension::REMOVED_VARIABLE_MARKER = | ||||
34 | QLatin1String("__REM__"); | ||||
35 | | ||||
36 | QString JuliaVariableManagementExtension::addVariable( | ||||
37 | const QString &name, | ||||
38 | const QString &value) | ||||
39 | { | ||||
40 | return setValue(name, value); | ||||
41 | } | ||||
42 | | ||||
43 | QString JuliaVariableManagementExtension::setValue( | ||||
44 | const QString &name, | ||||
45 | const QString &value) | ||||
46 | { | ||||
47 | return QString::fromLatin1("%1 = %2").arg(name).arg(value); | ||||
48 | } | ||||
49 | | ||||
50 | QString JuliaVariableManagementExtension::removeVariable(const QString &name) | ||||
51 | { | ||||
52 | // There is no way to completely delete object from scope: | ||||
53 | // http://docs.julialang.org/en/release-0.4/manual/faq/#how-do-i-delete-an-object-in-memory | ||||
54 | return QString::fromLatin1("%1 = \"%2\"") | ||||
55 | .arg(name).arg(REMOVED_VARIABLE_MARKER); | ||||
56 | } | ||||
57 | | ||||
58 | QString JuliaVariableManagementExtension::clearVariables() | ||||
59 | { | ||||
60 | return loadScript(QLatin1String("variables_cleaner")) | ||||
61 | .arg(REMOVED_VARIABLE_MARKER); | ||||
62 | } | ||||
63 | | ||||
64 | QString JuliaVariableManagementExtension::saveVariables(const QString &fileName) | ||||
65 | { | ||||
66 | return loadScript(QLatin1String("variables_saver")).arg(fileName); | ||||
67 | } | ||||
68 | | ||||
69 | QString JuliaVariableManagementExtension::loadVariables(const QString &fileName) | ||||
70 | { | ||||
71 | return loadScript(QLatin1String("variables_loader")).arg(fileName); | ||||
72 | } |