diff --git a/libs/main/application/piapplicationmodule.h b/libs/main/application/piapplicationmodule.h index 09c12990..024b4061 100644 --- a/libs/main/application/piapplicationmodule.h +++ b/libs/main/application/piapplicationmodule.h @@ -55,5 +55,6 @@ #include "pilog.h" #include "pisingleapplication.h" #include "pisystemmonitor.h" +#include "pitranslator.h" #endif diff --git a/libs/main/application/pitranslator.cpp b/libs/main/application/pitranslator.cpp new file mode 100644 index 00000000..874c9a45 --- /dev/null +++ b/libs/main/application/pitranslator.cpp @@ -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 . +*/ + +#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; +} diff --git a/libs/main/application/pitranslator.h b/libs/main/application/pitranslator.h new file mode 100644 index 00000000..60eea97e --- /dev/null +++ b/libs/main/application/pitranslator.h @@ -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 . +*/ + +#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 strings; + }; + + static PITranslator * instance(); + + void clearInternal(); + Context * createContextInternal(const PIString & context); + + PIMap contexts; +}; + +#endif diff --git a/libs/main/application/tr/pip_all.h b/libs/main/application/tr/pip_all.h new file mode 100644 index 00000000..476ffadb --- /dev/null +++ b/libs/main/application/tr/pip_all.h @@ -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 diff --git a/libs/main/application/tr/pip_ru.h b/libs/main/application/tr/pip_ru.h new file mode 100644 index 00000000..acc1ae56 --- /dev/null +++ b/libs/main/application/tr/pip_ru.h @@ -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\ +"; diff --git a/libs/main/core/piinit.cpp b/libs/main/core/piinit.cpp index dd8fcb53..72a65808 100644 --- a/libs/main/core/piinit.cpp +++ b/libs/main/core/piinit.cpp @@ -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; } diff --git a/libs/main/core/piinit.h b/libs/main/core/piinit.h index b1ba9c2e..87e31489 100644 --- a/libs/main/core/piinit.h +++ b/libs/main/core/piinit.h @@ -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__; } diff --git a/libs/main/io_utils/pidiagnostics.cpp b/libs/main/io_utils/pidiagnostics.cpp index 9cfe5964..dba39105 100644 --- a/libs/main/io_utils/pidiagnostics.cpp +++ b/libs/main/io_utils/pidiagnostics.cpp @@ -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,14 +153,15 @@ 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; - Entry send = calcHistory(history_send, tcnt_send); - Entry recv = calcHistory(history_rec, tcnt_recv); - float itr = disconn_.toSeconds() * (float(tcnt_recv) / history_rec.size()); - float its = disconn_.toSeconds() * (float(tcnt_send) / history_send.size()); - float hz = 1. / interval().toSeconds(); + int tcnt_recv = 0; + int tcnt_send = 0; + Entry send = calcHistory(history_send, tcnt_send); + Entry recv = calcHistory(history_rec, tcnt_recv); + float itr = disconn_.toSeconds() * (float(tcnt_recv) / history_rec.size()); + float its = disconn_.toSeconds() * (float(tcnt_send) / history_send.size()); + float hz = 1. / interval().toSeconds(); if (tcnt_recv == 0) { cur_state.integral_freq = cur_state.immediate_freq = 0; cur_state.received_packets_per_sec = cur_state.received_bytes_per_sec = 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; diff --git a/libs/main/text/pistring.cpp b/libs/main/text/pistring.cpp index 8707b0d5..dc719ff6 100644 --- a/libs/main/text/pistring.cpp +++ b/libs/main/text/pistring.cpp @@ -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); + *this += (PIString::fromNumber(bytes) + " "_a + PITranslator::tr("B", tr_c)); 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); - return *this; - } - 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; - } - 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); + 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 || last) { + *this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " "_a + unit); + return true; + } + 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; } diff --git a/main.cpp b/main.cpp index 21450986..a3a8adb5 100644 --- a/main.cpp +++ b/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; +template +void foo() { + static_assert(std::is_arithmetic::value || is_complex::value, "Type must be arithmetic"); +} -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); - } - 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 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 set; + piCout << set << piSerialize(set) << piDeserialize>(piSerialize(set)); + set << 1 << 2 << 3; + piCout << set << piSerialize(set) << piDeserialize>(piSerialize(set)); + set << 1 << -2 << 50 << -100; + piCout << set << piSerialize(set) << piDeserialize>(piSerialize(set));*/ return 0; - /*PIPeer p("123"); - piCout << "start ..."; - p.start(); - piCout << "start ok"; + std::numeric_limits::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(); + foo(); + foo(); + foo(); return 0;*/ - if (argc > 1) { - PIINTROSPECTION_START(server); - } else { - PIINTROSPECTION_START(client); - } - - kbd.enableExitCapture(); - - - PIClientServer::Server * s = nullptr; - PIThread * s_thread = new PIThread(); - PIVector 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(); // new PIPackedTCP(PIPackedTCP::Server, {"0.0.0.0:8000"}); - PIPackedTCP * tcp_c = PIIODevice::createFromFullPath("ptcp://c:127.0.0.1:8000") - ->cast(); // 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 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; } diff --git a/utils/resources_compiler/generator.cpp b/utils/resources_compiler/generator.cpp index 5a11b2bb..9a79a6b4 100644 --- a/utils/resources_compiler/generator.cpp +++ b/utils/resources_compiler/generator.cpp @@ -17,8 +17,8 @@ bool generate(const PIString & init_name, PIFile & file, const PIVector 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