mirror of
https://github.com/alkoleft/yaxunit-addin.git
synced 2026-06-16 07:35:40 +02:00
Консоль
This commit is contained in:
+2
-2
@@ -16,8 +16,8 @@ list(APPEND SOURCES
|
||||
src/exports.cpp
|
||||
src/Component.cpp
|
||||
src/Component.h
|
||||
src/YaxUnitAddIn.cpp
|
||||
src/YaxUnitAddIn.h)
|
||||
src/CommonAddIn.cpp
|
||||
src/CommonAddIn.h)
|
||||
|
||||
if (ANDROID)
|
||||
list(APPEND SOURCES
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Modern Native AddIn
|
||||
* Copyright (C) 2018 Infactum
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
#include "CommonAddIn.h"
|
||||
|
||||
std::string CommonAddIn::extensionName() {
|
||||
return "Common";
|
||||
}
|
||||
|
||||
CommonAddIn::CommonAddIn() {
|
||||
|
||||
// Full featured property registration example
|
||||
AddProperty(L"Version", L"ВерсияКомпоненты", [&]() {
|
||||
auto s = std::string(Version);
|
||||
return std::make_shared<variant_t>(std::move(s));
|
||||
});
|
||||
|
||||
AddMethod(L"Sleep", L"Ожидать", this, &CommonAddIn::sleep, {{0, 5}});
|
||||
AddMethod(L"Print", L"Напечатать", this, &CommonAddIn::print);
|
||||
}
|
||||
|
||||
void CommonAddIn::sleep(const variant_t &delay) {
|
||||
using namespace std;
|
||||
// It safe to get any type from variant.
|
||||
// Exceptions are handled by component API.
|
||||
this_thread::sleep_for(chrono::milliseconds(get<int32_t>(delay)));
|
||||
}
|
||||
|
||||
|
||||
std::string variant_present(const variant_t &msg){
|
||||
|
||||
using namespace std;
|
||||
string result;
|
||||
|
||||
visit(overloaded{
|
||||
[&](const string &v) {
|
||||
result = v;
|
||||
},
|
||||
[&](const int32_t &v) {
|
||||
result = to_string(static_cast<int>(v));
|
||||
},
|
||||
[&](const double &v) {
|
||||
result = to_string(v);
|
||||
},
|
||||
[&](const bool &v) {
|
||||
result = string(v ? u8"Истина" : u8"Ложь");
|
||||
},
|
||||
[&](const std::tm &v) {
|
||||
ostringstream oss;
|
||||
oss.imbue(std::locale("ru_RU.utf8"));
|
||||
oss << put_time(&v, "%c");
|
||||
result = oss.str();
|
||||
},
|
||||
[&](const vector<char> &v) {
|
||||
result = string(v.begin(), v.end());
|
||||
},
|
||||
[&](const monostate &) { }
|
||||
}, msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void print_time() {
|
||||
std::time_t t = std::time(nullptr);
|
||||
std::cout << "[" << std::put_time(std::localtime(&t), "%F %T %Z") << "] ";
|
||||
}
|
||||
|
||||
void CommonAddIn::print(const variant_t &msg) {
|
||||
std::string present = variant_present(msg);
|
||||
|
||||
if(!present.empty()){
|
||||
std::cout << present << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -17,21 +17,22 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef YAXUNITADDIN_H
|
||||
#define YAXUNITADDIN_H
|
||||
#ifndef COMMONADDIN_H
|
||||
#define COMMONADDIN_H
|
||||
|
||||
#include "Component.h"
|
||||
|
||||
class YaxUnitAddIn final : public Component {
|
||||
class CommonAddIn final : public Component {
|
||||
public:
|
||||
const char *Version = u8"1.0.0";
|
||||
const char *Version = u8"1.0.1";
|
||||
|
||||
YaxUnitAddIn();
|
||||
CommonAddIn();
|
||||
|
||||
private:
|
||||
std::string extensionName() override;
|
||||
|
||||
void sleep(const variant_t &delay);
|
||||
void print(const variant_t &msg);
|
||||
};
|
||||
|
||||
#endif //YAXUNITADDIN_H
|
||||
#endif //COMMONADDIN_H
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Modern Native AddIn
|
||||
* Copyright (C) 2018 Infactum
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "YaxUnitAddIn.h"
|
||||
|
||||
std::string YaxUnitAddIn::extensionName() {
|
||||
return "Sleep";
|
||||
}
|
||||
|
||||
YaxUnitAddIn::YaxUnitAddIn() {
|
||||
|
||||
// Full featured property registration example
|
||||
AddProperty(L"Version", L"ВерсияКомпоненты", [&]() {
|
||||
auto s = std::string(Version);
|
||||
return std::make_shared<variant_t>(std::move(s));
|
||||
});
|
||||
|
||||
AddMethod(L"Sleep", L"Ожидать", this, &YaxUnitAddIn::sleep, {{0, 5}});
|
||||
}
|
||||
|
||||
|
||||
void YaxUnitAddIn::sleep(const variant_t &delay) {
|
||||
using namespace std;
|
||||
// It safe to get any type from variant.
|
||||
// Exceptions are handled by component API.
|
||||
this_thread::sleep_for(chrono::milliseconds(get<int32_t>(delay)));
|
||||
}
|
||||
+4
-4
@@ -20,7 +20,7 @@
|
||||
#include <ComponentBase.h>
|
||||
#include <types.h>
|
||||
|
||||
#include "YaxUnitAddIn.h"
|
||||
#include "CommonAddIn.h"
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#pragma warning (disable : 4311 4302)
|
||||
@@ -28,15 +28,15 @@
|
||||
|
||||
const WCHAR_T *GetClassNames() {
|
||||
// Might contain multiple class names seperated by |
|
||||
static char16_t cls_names[] = u"Sleep";
|
||||
static char16_t cls_names[] = u"Common";
|
||||
return reinterpret_cast<WCHAR_T *>(cls_names);
|
||||
}
|
||||
|
||||
long GetClassObject(const WCHAR_T *clsName, IComponentBase **pInterface) {
|
||||
if (!*pInterface) {
|
||||
auto cls_name = std::u16string(reinterpret_cast<const char16_t *>(clsName));
|
||||
if (cls_name == u"Sleep") {
|
||||
*pInterface = new YaxUnitAddIn;
|
||||
if (cls_name == u"Common") {
|
||||
*pInterface = new CommonAddIn;
|
||||
}
|
||||
return (long) *pInterface;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user