add PITranslator
begin localization "ru"
This commit is contained in:
@@ -55,5 +55,6 @@
|
||||
#include "pilog.h"
|
||||
#include "pisingleapplication.h"
|
||||
#include "pisystemmonitor.h"
|
||||
#include "pitranslator.h"
|
||||
|
||||
#endif
|
||||
|
||||
101
libs/main/application/pitranslator.cpp
Normal file
101
libs/main/application/pitranslator.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Translation support
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pitranslator.h"
|
||||
|
||||
#include "pivaluetree_conversions.h"
|
||||
#include "tr/pip_all.h"
|
||||
|
||||
|
||||
//! \class PITranslator pitranslator.h
|
||||
//! \details
|
||||
//! \~english \section PITranslator_sec0 Synopsis
|
||||
//! \~russian \section PITranslator_sec0 Краткий обзор
|
||||
//! \~english
|
||||
//!
|
||||
//! \~russian
|
||||
//!
|
||||
|
||||
|
||||
PIString PITranslator::tr(const PIString & in, const PIString & context) {
|
||||
auto s = instance();
|
||||
auto c = s->contexts.value(context.hash());
|
||||
if (!c) return in;
|
||||
return c->strings.value(in.hash(), in);
|
||||
}
|
||||
|
||||
|
||||
void PITranslator::clear() {
|
||||
instance()->clearInternal();
|
||||
}
|
||||
|
||||
|
||||
void PITranslator::loadLang(const PIString & short_lang) {
|
||||
auto s = instance();
|
||||
auto vt = PIValueTreeConversions::fromText(getBuiltinConfig());
|
||||
auto lang = vt.child(short_lang.toLowerCase().trim());
|
||||
for (const auto & cn: lang.children()) {
|
||||
auto c = s->createContextInternal(cn.name());
|
||||
for (const auto & s: cn.children())
|
||||
c->add(s.name(), s.value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PITranslator::loadConfig(const PIString & content) {
|
||||
auto s = instance();
|
||||
auto lang = PIValueTreeConversions::fromText(content);
|
||||
for (const auto & cn: lang.children()) {
|
||||
auto c = s->createContextInternal(cn.name());
|
||||
for (const auto & s: cn.children())
|
||||
c->add(s.name(), s.value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PITranslator::PITranslator() {}
|
||||
|
||||
|
||||
PITranslator::~PITranslator() {
|
||||
clearInternal();
|
||||
}
|
||||
|
||||
|
||||
PITranslator * PITranslator::instance() {
|
||||
static PITranslator ret;
|
||||
return &ret;
|
||||
}
|
||||
|
||||
|
||||
void PITranslator::clearInternal() {
|
||||
piDeleteAll(contexts.values());
|
||||
contexts.clear();
|
||||
}
|
||||
|
||||
|
||||
PITranslator::Context * PITranslator::createContextInternal(const PIString & context) {
|
||||
auto & ret(contexts[context.hash()]);
|
||||
if (!ret) ret = new Context();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PITranslator::Context::add(const PIString & in, const PIString & out) {
|
||||
strings[in.hash()] = out;
|
||||
}
|
||||
64
libs/main/application/pitranslator.h
Normal file
64
libs/main/application/pitranslator.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*! \file pitranslator.h
|
||||
* \ingroup Application
|
||||
* \~\brief
|
||||
* \~english Translation support
|
||||
* \~russian Поддержка перевода
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Translation support
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef pitranslator_H
|
||||
#define pitranslator_H
|
||||
|
||||
#include "pifile.h"
|
||||
#include "piiostream.h"
|
||||
#include "pithread.h"
|
||||
|
||||
//! \ingroup Application
|
||||
//! \~\brief
|
||||
//! \~english Translation support
|
||||
//! \~russian Поддержка перевода
|
||||
class PIP_EXPORT PITranslator {
|
||||
public:
|
||||
static PIString tr(const PIString & in, const PIString & context = {});
|
||||
static PIString tr(const char * in, const PIString & context = {}) { return tr(PIString(in), context); }
|
||||
|
||||
static void clear();
|
||||
static void loadLang(const PIString & short_lang);
|
||||
static void loadConfig(const PIString & content);
|
||||
|
||||
private:
|
||||
PITranslator();
|
||||
~PITranslator();
|
||||
NO_COPY_CLASS(PITranslator)
|
||||
|
||||
struct Context {
|
||||
void add(const PIString & in, const PIString & out);
|
||||
PIMap<uint, PIString> strings;
|
||||
};
|
||||
|
||||
static PITranslator * instance();
|
||||
|
||||
void clearInternal();
|
||||
Context * createContextInternal(const PIString & context);
|
||||
|
||||
PIMap<uint, Context *> contexts;
|
||||
};
|
||||
|
||||
#endif
|
||||
16
libs/main/application/tr/pip_all.h
Normal file
16
libs/main/application/tr/pip_all.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef pitr_pip_all_H
|
||||
#define pitr_pip_all_H
|
||||
|
||||
#include "pip_ru.h"
|
||||
#include "pistring.h"
|
||||
|
||||
PIString getBuiltinConfig() {
|
||||
// clang-format off
|
||||
static const PIString ret =
|
||||
PIString::fromUTF8(config_ru)
|
||||
;
|
||||
// clang-format on
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
25
libs/main/application/tr/pip_ru.h
Normal file
25
libs/main/application/tr/pip_ru.h
Normal file
@@ -0,0 +1,25 @@
|
||||
constexpr char config_ru[] = "\
|
||||
[ru.PIString] \n\
|
||||
B = Б \n\
|
||||
KiB = KиБ \n\
|
||||
MiB = MиБ \n\
|
||||
GiB = ГиБ \n\
|
||||
TiB = ТиБ \n\
|
||||
PiB = ПиБ \n\
|
||||
EiB = ЭиБ \n\
|
||||
ZiB = ЗиБ \n\
|
||||
YiB = ЙиБ \n\
|
||||
\n\
|
||||
[ru.PIDiag] \n\
|
||||
/s = /сек \n\
|
||||
\n\
|
||||
[ru.PITime] \n\
|
||||
Hz = Гц \n\
|
||||
KHz = КГц \n\
|
||||
kHz = кГц \n\
|
||||
MHz = МГц \n\
|
||||
GHz = ГГц \n\
|
||||
THz = ТГц \n\
|
||||
PHz = ПГц \n\
|
||||
\n\
|
||||
";
|
||||
@@ -340,6 +340,13 @@ bool PIInit::isBuildOptionEnabled(PIInit::BuildOption o) {
|
||||
true;
|
||||
# else
|
||||
false;
|
||||
# endif
|
||||
case boConsole:
|
||||
return
|
||||
# ifdef PIP_CONSOLE
|
||||
true;
|
||||
# else
|
||||
false;
|
||||
# endif
|
||||
default: return false;
|
||||
}
|
||||
@@ -357,6 +364,7 @@ PIStringList PIInit::buildOptions() {
|
||||
if (isBuildOptionEnabled(boCompress)) ret << "Compress";
|
||||
if (isBuildOptionEnabled(boOpenCL)) ret << "OpenCL";
|
||||
if (isBuildOptionEnabled(boCloud)) ret << "Cloud";
|
||||
if (isBuildOptionEnabled(boConsole)) ret << "Console";
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
boCompress /*! \~english Zlib compression support \~russian Поддержка сжатия Zlib */ = 0x80,
|
||||
boOpenCL /*! \~english OpenCL support \~russian Поддержка OpenCL */ = 0x100,
|
||||
boCloud /*! \~english PICloud transport support \~russian Поддержка облачного транспорта PICloud */ = 0x200,
|
||||
boConsole /*! \~english Console graphics support \~russian Поддержка графики в консоли */ = 0x400,
|
||||
};
|
||||
static PIInit * instance() { return __PIInit_Initializer__::__instance__; }
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "pidiagnostics.h"
|
||||
|
||||
#include "piliterals_time.h"
|
||||
#include "pitranslator.h"
|
||||
|
||||
|
||||
/** \class PIDiagnostics
|
||||
@@ -40,7 +41,7 @@
|
||||
|
||||
|
||||
PIDiagnostics::State::State() {
|
||||
receive_speed = send_speed = PIString::readableSize(0) + "/s";
|
||||
receive_speed = send_speed = PIString::readableSize(0) + PITranslator::tr("/s", "PIDiag");
|
||||
}
|
||||
|
||||
|
||||
@@ -152,6 +153,7 @@ void PIDiagnostics::sended(int size) {
|
||||
|
||||
void PIDiagnostics::tick(int) {
|
||||
mutex_state.lock();
|
||||
auto speed_sec = PITranslator::tr("/s", "PIDiag");
|
||||
// piCoutObj << "lock";
|
||||
int tcnt_recv = 0;
|
||||
int tcnt_send = 0;
|
||||
@@ -176,8 +178,8 @@ void PIDiagnostics::tick(int) {
|
||||
cur_state.sended_bytes_per_sec = ullong(double(send.bytes_ok) / its);
|
||||
}
|
||||
// piCoutObj << "tick" << recv.cnt_ok << send.cnt_ok;
|
||||
cur_state.receive_speed = PIString::readableSize(cur_state.received_bytes_per_sec) + "/s";
|
||||
cur_state.send_speed = PIString::readableSize(cur_state.sended_bytes_per_sec) + "/s";
|
||||
cur_state.receive_speed = PIString::readableSize(cur_state.received_bytes_per_sec) + speed_sec;
|
||||
cur_state.send_speed = PIString::readableSize(cur_state.sended_bytes_per_sec) + speed_sec;
|
||||
int arc = recv.cnt_ok + recv.cnt_fail;
|
||||
float good_percents = 0.f;
|
||||
if (arc > 0) good_percents = (float)recv.cnt_ok / arc * 100.f;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "piliterals.h"
|
||||
#include "pimathbase.h"
|
||||
#include "pistringlist.h"
|
||||
#include "pitranslator.h"
|
||||
#ifdef PIP_ICU
|
||||
# define U_NOEXCEPT
|
||||
# include "unicode/ucnv.h"
|
||||
@@ -1732,43 +1733,32 @@ ldouble PIString::toLDouble() const {
|
||||
//! piCout << s; // 47.6 GiB
|
||||
//! \endcode
|
||||
PIString & PIString::setReadableSize(llong bytes) {
|
||||
static const PIString tr_c = "PIString"_a;
|
||||
clear();
|
||||
if (bytes < 1024) {
|
||||
*this += (PIString::fromNumber(bytes) + " B"_a);
|
||||
return *this;
|
||||
}
|
||||
double fres = bytes / 1024.;
|
||||
llong res = bytes / 1024;
|
||||
fres -= res;
|
||||
if (res < 1024) {
|
||||
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " KiB"_a);
|
||||
*this += (PIString::fromNumber(bytes) + " "_a + PITranslator::tr("B", tr_c));
|
||||
return *this;
|
||||
}
|
||||
double fres = bytes;
|
||||
llong res = bytes;
|
||||
auto checkRange = [this, &fres, &res](const PIString & unit, bool last = false) {
|
||||
fres = res / 1024.;
|
||||
res /= 1024;
|
||||
fres -= res;
|
||||
if (res < 1024) {
|
||||
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " MiB"_a);
|
||||
return *this;
|
||||
if (res < 1024 || last) {
|
||||
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " "_a + unit);
|
||||
return true;
|
||||
}
|
||||
fres = res / 1024.;
|
||||
res /= 1024;
|
||||
fres -= res;
|
||||
if (res < 1024) {
|
||||
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " GiB"_a);
|
||||
return *this;
|
||||
}
|
||||
fres = res / 1024.;
|
||||
res /= 1024;
|
||||
fres -= res;
|
||||
if (res < 1024) {
|
||||
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " TiB"_a);
|
||||
return *this;
|
||||
}
|
||||
fres = res / 1024.;
|
||||
res /= 1024;
|
||||
fres -= res;
|
||||
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " PiB"_a);
|
||||
return false;
|
||||
};
|
||||
if (checkRange(PITranslator::tr("KiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("MiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("GiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("TiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("PiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("EiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("ZiB", tr_c))) return *this;
|
||||
checkRange(PITranslator::tr("YiB", tr_c), true);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
401
main.cpp
401
main.cpp
@@ -8,375 +8,66 @@
|
||||
#include "pilog.h"
|
||||
#include "pimathbase.h"
|
||||
#include "pip.h"
|
||||
#include "pitranslator.h"
|
||||
#include "pivaluetree_conversions.h"
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
|
||||
enum MyEvent {
|
||||
meVoid,
|
||||
meInt,
|
||||
meString,
|
||||
meIntString,
|
||||
};
|
||||
|
||||
PIKbdListener kbd;
|
||||
|
||||
|
||||
class MyServerClient: public PIClientServer::ServerClient {
|
||||
public:
|
||||
~MyServerClient() { send_thread.stopAndWait(); }
|
||||
|
||||
protected:
|
||||
void readed(PIByteArray data) override { piCout << "readed" << (data.size()); }
|
||||
// void aboutDelete() override { piCout << "aboutDelete"; }
|
||||
// void disconnected() override { piCout << "disconnected"; }
|
||||
void connected() override {
|
||||
// piCout << "connected";
|
||||
send_thread.start(
|
||||
[this] {
|
||||
// write((PIString::fromNumber(++counter)).toUTF8());
|
||||
PIByteArray ba(64_KiB);
|
||||
write(ba);
|
||||
},
|
||||
2_Hz);
|
||||
template<typename Type>
|
||||
void foo() {
|
||||
static_assert(std::is_arithmetic<Type>::value || is_complex<Type>::value, "Type must be arithmetic");
|
||||
}
|
||||
PIThread send_thread;
|
||||
int counter = 0;
|
||||
};
|
||||
|
||||
|
||||
class MyClient: public PIClientServer::Client {
|
||||
public:
|
||||
~MyClient() { send_thread.stopAndWait(); }
|
||||
|
||||
protected:
|
||||
void readed(PIByteArray data) override { piCout << "readed" << (data.size()); }
|
||||
void disconnected() override { piCout << "disconnected"; }
|
||||
void connected() override {
|
||||
piCout << "connected";
|
||||
send_thread.start(
|
||||
[this] {
|
||||
// write((PIString::fromNumber(++counter)).toUTF8());
|
||||
write(PIByteArray(64_KiB));
|
||||
},
|
||||
2_Hz);
|
||||
}
|
||||
PIThread send_thread;
|
||||
int counter = 0;
|
||||
};
|
||||
|
||||
#include <iostream>
|
||||
int main(int argc, char * argv[]) {
|
||||
/*piCout << PIString("hello locale").entries("lo"); // 2
|
||||
piCout << PIString("hello locale").entries("lo lo"); // 1
|
||||
piCout << ("3hello4"_u8);
|
||||
piCout << ("3hello4"_u8).entries("hello1");
|
||||
piCout << ("3hello4"_u8).entries("hello");
|
||||
piCout << ("3hello4"_u8).entries("l");
|
||||
piCout << ("3hello4"_u8).entries("ello");
|
||||
piCout << ("3hello4"_u8).entries("hell");
|
||||
piCout << ("2hellohello1"_u8);
|
||||
piCout << ("2hellohello1"_u8).entries("hello1");
|
||||
piCout << ("2hellohello1"_u8).entries("hello");
|
||||
piCout << ("2hellohello1"_u8).entries("l");
|
||||
piCout << ("2hellohello1"_u8).entries("ello");
|
||||
piCout << ("2hellohello1"_u8).entries("hell");
|
||||
return 0;*/
|
||||
PITranslator::loadLang("ru");
|
||||
piCout << PIString::readableSize(50_KiB);
|
||||
piCout << PIString::readableSize(1_GB);
|
||||
PITranslator::clear();
|
||||
piCout << PIString::readableSize(50_KiB);
|
||||
piCout << PIString::readableSize(1_GB);
|
||||
// PICodeParser parser;
|
||||
// parser.parseFile("cmg_test.h");
|
||||
/*for (auto m: parser.macros) {
|
||||
piCout << "";
|
||||
piCout << m.name << m.args << m.value;
|
||||
piCout << m.expand({"hello"});
|
||||
}
|
||||
*/
|
||||
|
||||
PILog log;
|
||||
log.setColorConsole(false);
|
||||
log.setOutput(PILog::File, false);
|
||||
log.setLogName("test");
|
||||
log.setDir("logs");
|
||||
// log.setTimestampFormat("hh-mm-ss");
|
||||
// log.setLineFormat("[c] m (t)");
|
||||
log.start();
|
||||
|
||||
// log.enqueue("debug msg");
|
||||
// log.enqueue("warn msg with ${c}", PILog::Category::Warning);
|
||||
// log.enqueue("ERROR${m}${t}", PILog::Category::Error);
|
||||
log.setLevel(PILog::Level::Info);
|
||||
|
||||
log.debug() << "some msg";
|
||||
piMSleep(50);
|
||||
log.info() << "information";
|
||||
piMSleep(50);
|
||||
log.warning() << "another!";
|
||||
piMSleep(50);
|
||||
log.error(&log) << "critical!";
|
||||
|
||||
// log.stop();
|
||||
/*PISet<int> set;
|
||||
piCout << set << piSerialize(set) << piDeserialize<PISet<int>>(piSerialize(set));
|
||||
set << 1 << 2 << 3;
|
||||
piCout << set << piSerialize(set) << piDeserialize<PISet<int>>(piSerialize(set));
|
||||
set << 1 << -2 << 50 << -100;
|
||||
piCout << set << piSerialize(set) << piDeserialize<PISet<int>>(piSerialize(set));*/
|
||||
return 0;
|
||||
/*PIPeer p("123");
|
||||
|
||||
piCout << "start ...";
|
||||
p.start();
|
||||
piCout << "start ok";
|
||||
std::numeric_limits<complexf>::epsilon();
|
||||
using cmlp = complexf;
|
||||
PIMathMatrixT<3, 3, double> v0;
|
||||
PIMathMatrixT<3, 3, cmlp> v1;
|
||||
v0[0][1] = 1;
|
||||
v0[1][1] = 2;
|
||||
v0[2][1] = 3;
|
||||
v1[0][1] = cmlp(1., 0);
|
||||
v1[1][1] = cmlp(2., -1);
|
||||
v1[2][1] = cmlp(3., 2);
|
||||
piCout << v0 << v1;
|
||||
piCout << (v0 * 2.) << (v1 * cmlp(2., 2.));
|
||||
piCout << (v0 + 2.) << (v1 + cmlp(2.));
|
||||
piCout << (v0 - 2.) << (v1 - cmlp(2.));
|
||||
piCout << (v0 / 2.) << (v1 / cmlp(2., 1.));
|
||||
// piCout << (v0.length()) << (v1.length());
|
||||
// piCout << (v0.lengthSqr()) << (v1.lengthSqr());
|
||||
// piCout << (v0.manhattanLength()) << (v1.manhattanLength());
|
||||
|
||||
piSleep(1.);
|
||||
|
||||
piCout << "stop ...";
|
||||
p.stopAndWait();
|
||||
piCout << "stop ok";
|
||||
|
||||
piSleep(1.);
|
||||
|
||||
piCout << "exit";
|
||||
/*foo<int>();
|
||||
foo<double>();
|
||||
foo<complexf>();
|
||||
foo<complexd>();
|
||||
return 0;*/
|
||||
|
||||
if (argc > 1) {
|
||||
PIINTROSPECTION_START(server);
|
||||
} else {
|
||||
PIINTROSPECTION_START(client);
|
||||
}
|
||||
|
||||
kbd.enableExitCapture();
|
||||
|
||||
|
||||
PIClientServer::Server * s = nullptr;
|
||||
PIThread * s_thread = new PIThread();
|
||||
PIVector<PIClientServer::Client *> cv;
|
||||
|
||||
if (argc > 1) {
|
||||
piCout << "Server";
|
||||
s = new PIClientServer::Server();
|
||||
s->setClientFactory([] { return new MyServerClient(); });
|
||||
s->configuration().enableSymmetricEncryption("1122334455667788"_hex);
|
||||
s->listenAll(12345);
|
||||
s_thread->start(
|
||||
[s] {
|
||||
piCout << "*** clients" << s->clientsCount();
|
||||
int i = 0;
|
||||
s->forEachClient([&i](PIClientServer::ServerClient * c) {
|
||||
// piCout << "client" << ++i << c;
|
||||
c->write(PIByteArray(1_KiB));
|
||||
// c->close();
|
||||
// piMSleep(200);
|
||||
});
|
||||
},
|
||||
1._Hz);
|
||||
} else {
|
||||
piCout << "Client";
|
||||
piForTimes(2) {
|
||||
piMSleep(25);
|
||||
auto c = new MyClient();
|
||||
c->configuration().enableSymmetricEncryption("1122334455667788"_hex);
|
||||
c->connect(PINetworkAddress::resolve("127.0.0.1", 12345));
|
||||
cv << c;
|
||||
}
|
||||
}
|
||||
|
||||
WAIT_FOR_EXIT;
|
||||
|
||||
s_thread->stopAndWait();
|
||||
|
||||
piDeleteSafety(s);
|
||||
piDeleteAllAndClear(cv);
|
||||
|
||||
PIINTROSPECTION_STOP
|
||||
|
||||
return 0;
|
||||
/*PIPackedTCP * tcp_s =
|
||||
PIIODevice::createFromFullPath("ptcp://s::8000")->cast<PIPackedTCP>(); // new PIPackedTCP(PIPackedTCP::Server, {"0.0.0.0:8000"});
|
||||
PIPackedTCP * tcp_c = PIIODevice::createFromFullPath("ptcp://c:127.0.0.1:8000")
|
||||
->cast<PIPackedTCP>(); // new PIPackedTCP(PIPackedTCP::Client, {"127.0.0.1:8000"});
|
||||
piCout << tcp_s << tcp_c;
|
||||
// CONNECTL(&tcp_s, opened, []() { piCout << "Srv opened"; });
|
||||
// CONNECTL(&tcp_c, opened, []() { piCout << "Cli opened"; });
|
||||
// CONNECTL(&tcp_s, closed, []() { piCout << "Srv closed"; });
|
||||
// CONNECTL(&tcp_c, closed, []() { piCout << "Cli closed"; });
|
||||
CONNECTL(tcp_s, connected, []() { piCout << "Srv conn"; });
|
||||
CONNECTL(tcp_c, connected, []() { piCout << "Cli conn"; });
|
||||
CONNECTL(tcp_s, disconnected, []() { piCout << "Srv disconn"; });
|
||||
CONNECTL(tcp_c, disconnected, []() { piCout << "Cli disconn"; });
|
||||
CONNECTL(tcp_s, threadedReadEvent, [](const uchar * readed, ssize_t size) {
|
||||
PIByteArray d(readed, size);
|
||||
piCout << "Srv readed" << d;
|
||||
});
|
||||
CONNECTL(tcp_c, threadedReadEvent, [](const uchar * readed, ssize_t size) {
|
||||
PIByteArray d(readed, size);
|
||||
piCout << "Cli readed" << d;
|
||||
});
|
||||
// tcp_s->open();
|
||||
// tcp_c->open();
|
||||
tcp_s->startThreadedRead();
|
||||
tcp_c->startThreadedRead();
|
||||
piForTimes(5) {
|
||||
piCout << "\n1";
|
||||
piMSleep(200);
|
||||
piCout << "2";
|
||||
// tcp_c->close();
|
||||
piCout << "2+";
|
||||
// tcp_s->close();
|
||||
piCout << "3";
|
||||
// tcp_c->open();
|
||||
piCout << "3+";
|
||||
// tcp_s->open();
|
||||
piCout << "4";
|
||||
piMSleep(500);
|
||||
// piCout << "5";
|
||||
tcp_c->write("1234567890"_a.toByteArray());
|
||||
// piCout << "6";
|
||||
tcp_s->write("1234567890"_a.toByteArray());
|
||||
// piCout << "7";
|
||||
piMSleep(200);
|
||||
}
|
||||
// piCout << &tcp_s;
|
||||
// piCout << tcp_s->path();
|
||||
// piCout << tcp_s->constructFullPath();
|
||||
delete tcp_s;
|
||||
delete tcp_c;
|
||||
return 0;*/
|
||||
/*PITimer timer(tfunc);
|
||||
// timer.addDelimiter(2);
|
||||
timer.addDelimiter(40, tfunc4);
|
||||
|
||||
tm.reset();
|
||||
timer.start(0.5_Hz);
|
||||
piMSleep(2200);
|
||||
piCout << tm.elapsed_m() << cnt;
|
||||
|
||||
timer.stop();
|
||||
timer.waitForFinish();
|
||||
return 0;*/
|
||||
|
||||
|
||||
bool posted;
|
||||
PIStateMachine * root = new PIStateMachine("Machine");
|
||||
root->setOnFinish([] { piCout << "finish"; });
|
||||
|
||||
PIStateLambda * s1 = new PIStateLambda([] { piCout << "+ enter s1"; }, [] { piCout << "- exit s1"; }, "s1");
|
||||
PIStateLambda * s2 = new PIStateLambda([] { piCout << "+ enter s2"; }, [] { piCout << "- exit s2"; }, "s2");
|
||||
PIStateLambda * s3 = new PIStateLambda([] { piCout << "+ enter s3"; }, [] { piCout << "- exit s3"; }, "s3");
|
||||
PIStateLambda * s4 = new PIStateLambda([] { piCout << "+ enter s4"; }, [] { piCout << "- exit s4"; }, "s4");
|
||||
PIStateLambda * s11 = new PIStateLambda([] { piCout << " + enter s11"; }, [] { piCout << " - exit s11"; }, "s11");
|
||||
PIStateLambda * s12 = new PIStateLambda([] { piCout << " + enter s12"; }, [] { piCout << " - exit s12"; }, "s12");
|
||||
PIStateLambda * s13 = new PIStateLambda([] { piCout << " + enter s13"; }, [] { piCout << " - exit s13"; }, "s13");
|
||||
PIStateLambda * s21 = new PIStateLambda([] { piCout << " + enter s21"; }, [] { piCout << " - exit s21"; }, "s21");
|
||||
PIStateLambda * s22 = new PIStateLambda([] { piCout << " + enter s22"; }, [] { piCout << " - exit s22"; }, "s22");
|
||||
PIStateLambda * s23 = new PIStateLambda([] { piCout << " + enter s23"; }, [] { piCout << " - exit s23"; }, "s23");
|
||||
PIStateLambda * s211 = new PIStateLambda([] { piCout << " + enter s211"; }, [] { piCout << " - exit s211"; }, "s211");
|
||||
PIStateLambda * s212 = new PIStateLambda([] { piCout << " + enter s212"; }, [] { piCout << " - exit s212"; }, "s212");
|
||||
PIStateLambda * s213 = new PIStateLambda([] { piCout << " + enter s213"; }, [] { piCout << " - exit s213"; }, "s213");
|
||||
PIStateFinal * s214 = new PIStateFinal([] { piCout << " + enter s214 final"; }, "s214f");
|
||||
|
||||
root->addStates({s1, s2, s3, s4});
|
||||
// s1->addStates({s11, s12, s13});
|
||||
// s2->addStates({s21, s22, s23});
|
||||
// s21->addStates({s211, s212, s213});
|
||||
// root->addState(s214);
|
||||
|
||||
s2->setParallel(true);
|
||||
|
||||
root->setInitialState(s1);
|
||||
s1->setInitialState(s11);
|
||||
s2->setInitialState(s21);
|
||||
s21->setInitialState(s213);
|
||||
|
||||
// s213->addTransition(s13, meVoid)->addAction([] { piCout << "action transition s21 -> s22"; });
|
||||
// s3->addTransition(s212, meVoid)->addAction([] { piCout << "action transition s1 -> s213"; });
|
||||
s1->addTransition(s2, meVoid)->addAction([root] { root->postEvent(meInt, 1); });
|
||||
s2->addTransition(s3, meInt)->addGuard([](int i) { return i == 1; })->addAction([root] { root->postEvent(meInt, 2); });
|
||||
s3->addTransition(s4, meInt)->addGuard([](int i) { return i == 2; })->addAction([root] { root->postEvent(meInt, 3); });
|
||||
// s2->addTimeoutTransition(s3, .5_s);
|
||||
// s3->addTransition(s1, meIntString)->addGuard([](int i, PIString str) { return i == 2 && str == "hello"; });
|
||||
|
||||
root->start();
|
||||
piCout << "initial" << root->isRunning() << "\n";
|
||||
// piCout << "active atomics" << root->activeAtomics();
|
||||
root->print();
|
||||
|
||||
piCout << "\npost event";
|
||||
posted = root->postEvent(meVoid);
|
||||
piCout << "posted" << posted << "\n";
|
||||
// piCout << "active atomics" << root->activeAtomics();
|
||||
piSleep(1.);
|
||||
root->print();
|
||||
|
||||
// piCout << "\npost event";
|
||||
// posted = root->postEvent(meVoid);
|
||||
// piCout << "posted" << posted << "\n";
|
||||
// root->print();
|
||||
|
||||
/*root->addStates({s1, s2, s3});
|
||||
root->setInitialState(s1);
|
||||
root->start();
|
||||
|
||||
piCout << root->postEvent(meVoid);
|
||||
piCout << "";
|
||||
piCout << root->postEvent(meInt, 0.5f);
|
||||
piCout << "";
|
||||
piCout << root->postEvent(meInt, 0);
|
||||
piCout << "";
|
||||
piCout << root->postEvent(meInt, 1);
|
||||
piCout << "";
|
||||
piCout << root->postEvent(meIntString, 2, "hello");
|
||||
piCout << "";
|
||||
piCout << root->postEvent(meIntString, 2, PIString("hello"));
|
||||
piCout << "";*/
|
||||
delete root;
|
||||
|
||||
/*PISerial ser;
|
||||
ser.setSpeed(PISerial::S115200);
|
||||
piCout << ser.open("COM15", PIIODevice::ReadWrite);
|
||||
CONNECTL(&ser, threadedReadEvent, ([](const uchar * data, ssize_t size) { piCout << PIByteArray(data, size); }));
|
||||
ser.startThreadedRead();
|
||||
(2_s).sleep();
|
||||
ser.stopAndWait();*/
|
||||
|
||||
/*auto test = [](PISystemTime t) {
|
||||
piCout << "---------------";
|
||||
piCout << t << t.toString();
|
||||
piCout << PISystemTime::fromString(t.toString()) << PISystemTime::fromString(t.toString()).toString();
|
||||
piCout << PIVariant(t);
|
||||
piCout << PIVariant(t).toString();
|
||||
};
|
||||
auto test_str = [](PIString s) {
|
||||
piCout << "---------------";
|
||||
piCout << s;
|
||||
piCout << PISystemTime::fromString(s) << PISystemTime::fromString(s).toString();
|
||||
};
|
||||
|
||||
test(PISystemTime::current());
|
||||
test(1000.123_d);
|
||||
test(61_s);
|
||||
test(59_s);
|
||||
test(1234_us);
|
||||
test(5000001_ns);
|
||||
|
||||
test_str("");
|
||||
test_str("2020-05-04");
|
||||
test_str("2020-05-04 11:12:13");
|
||||
test_str("11:12:13");
|
||||
test_str("11:12:13.405");
|
||||
test_str("100");
|
||||
test_str("5 s");
|
||||
test_str("5s");
|
||||
test_str("1000 d 2 h 57 m 7 s 200 ms 2 ns");
|
||||
test_str("0.2 d");
|
||||
test_str(".5d");
|
||||
test_str("3E+2us");
|
||||
test_str("0.1d 200millis");
|
||||
test_str("2h 15 seconds");
|
||||
test_str("4secs 2hours 100 ns 3m 5ms 1 day 6 micros ");
|
||||
|
||||
test_str("1hz");
|
||||
test_str("5.123khz");
|
||||
test_str("5khz 123 hz");
|
||||
test_str("2mhz");
|
||||
test_str("1ghz");
|
||||
test_str("1hz 1hz");*/
|
||||
|
||||
// PIPair<int, PIString> p = createPIPair(0, "");
|
||||
/*PIConfig conf("model.conf");
|
||||
piCout << "****** config\n" << conf.allLeaves() << "******\n";
|
||||
|
||||
PIValueTree vt = PIValueTreeConversions::fromTextFile("model.conf");
|
||||
piCout << "****** tree";
|
||||
vt.forEachRecursive(
|
||||
[](const PIValueTree & v, const PIString & fn) { piCout << fn << "=" << v.value().toString() << "#" << v.comment(); });
|
||||
piCout << "******";*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ bool generate(const PIString & init_name, PIFile & file, const PIVector<ParserSe
|
||||
PIString descname = "_pirc_" + fcname + "_desc_";
|
||||
PIString funcname = "_pirc_" + init_name + "_init_";
|
||||
PIVector<PIResourcesStorage::__RCEntry> fv;
|
||||
piForeachC(ParserSection & s, files) {
|
||||
piForeachC(ParserEntry & p, s.files) {
|
||||
for (const auto & s: files) {
|
||||
for (const auto & p: s.files) {
|
||||
PIFile f;
|
||||
if (!f.open(p.path, PIIODevice::ReadOnly)) continue;
|
||||
// piCout << "gen" << p.name << p.alias << p.path;
|
||||
@@ -31,7 +31,7 @@ bool generate(const PIString & init_name, PIFile & file, const PIVector<ParserSe
|
||||
bool first = true;
|
||||
int rcnt = -1;
|
||||
llong curoff = 0, curfile = 0;
|
||||
piForeach(PIResourcesStorage::__RCEntry & e, fv) {
|
||||
for (auto & e: fv) {
|
||||
e.offset = curoff;
|
||||
PIFile f;
|
||||
f.open(e.file, PIIODevice::ReadOnly);
|
||||
|
||||
@@ -60,8 +60,8 @@ int main(int argc, char * argv[]) {
|
||||
return 0;
|
||||
}
|
||||
if (cli.hasArgument("list")) {
|
||||
piForeachC(ParserSection & s, files) {
|
||||
piForeachC(ParserEntry & e, s.files) {
|
||||
for (const auto & s: files) {
|
||||
for (const auto & e: s.files) {
|
||||
piCout << e.path;
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ int main(int argc, char * argv[]) {
|
||||
PIIOTextStream ts(&outf);
|
||||
ts << "// Generated by \"PIP Resources Compiler\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n");
|
||||
ts << "// Execute command:\n";
|
||||
piForeachC(PIString & _a, cli.rawArguments())
|
||||
for (const auto & _a: cli.rawArguments())
|
||||
ts << "// \"" << _a << "\"\n";
|
||||
ts << "\n";
|
||||
if (!generate(init_name, outf, files)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "parser.h"
|
||||
|
||||
#include "piconfig.h"
|
||||
#include "pidir.h"
|
||||
#include "piiostream.h"
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef PIRC_PARSER_H
|
||||
#define PIRC_PARSER_H
|
||||
|
||||
#include "pidir.h"
|
||||
#include "pifile.h"
|
||||
|
||||
struct ParserEntry {
|
||||
|
||||
Reference in New Issue
Block a user