first release of translation facility

* runtime - loading and translating
 * design-time - works with *.ts file (pip_tr utility)
 * compile-time - CMake macro for compile *.ts
This commit is contained in:
2024-11-05 13:49:00 +03:00
parent 73ed51e3d4
commit 57f8c1313e
52 changed files with 1571 additions and 480 deletions

View File

@@ -20,6 +20,7 @@
#include "picli.h"
#include "pisysteminfo.h"
#include "pitranslator.h"
//! \class PICLI picli.h
@@ -116,7 +117,7 @@ void PICLI::parse() {
_args_opt << cra;
continue;
}
piCoutObj << "Arguments overflow, \"" << cra << "\" ignored";
piCoutObj << "Arguments overflow, \"%1\" ignored"_tr("PICLI").arg(cra);
}
if (last == 0 ? false : last->has_value) {
last->value = cra;

View File

@@ -108,14 +108,14 @@ bool PISystemMonitor::startOnProcess(int pID, PISystemTime interval) {
PRIVATE->file.open(PRIVATE->proc_dir + "stat", PIIODevice::ReadOnly);
PRIVATE->filem.open(PRIVATE->proc_dir + "statm", PIIODevice::ReadOnly);
if (!PRIVATE->file.isOpened()) {
piCoutObj << "Can`t find process with ID = " << pID_ << "!";
piCoutObj << "Can`t find process with ID = %1!"_tr("PISystemMonitor").arg(pID_);
return false;
}
# endif
# else
PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
if (PRIVATE->hProc == 0) {
piCoutObj << "Can`t open process with ID = "_tr << pID_ << "," << errorString();
piCoutObj << "Can`t open process with ID = %1, %2!"_tr("PISystemMonitor").arg(pID_).arg(errorString());
return false;
}
PRIVATE->tm.reset();
@@ -377,12 +377,12 @@ void PISystemMonitor::gatherThread(llong id) {
FILETIME times[4];
HANDLE thdl = OpenThread(THREAD_QUERY_INFORMATION, FALSE, DWORD(id));
if (!thdl) {
piCout << "[PISystemMonitor] gatherThread(" << id << "):: OpenThread() error:" << errorString();
piCoutObj << "GatherThread(" << id << "):: OpenThread() error:" << errorString();
return;
}
if (GetThreadTimes(thdl, &(times[0]), &(times[1]), &(times[2]), &(times[3])) == 0) {
CloseHandle(thdl);
piCout << "[PISystemMonitor] gatherThread(" << id << "):: GetThreadTimes() error:" << errorString();
piCoutObj << "GatherThread(" << id << "):: GetThreadTimes() error:" << errorString();
return;
}
CloseHandle(thdl);

View File

@@ -19,8 +19,11 @@
#include "pitranslator.h"
#include "pidir.h"
#include "pifile.h"
#include "piliterals_string.h"
#include "pitranslator_p.h"
#include "pivaluetree_conversions.h"
#include "tr/pip_all.h"
//! \class PITranslator pitranslator.h
@@ -33,28 +36,38 @@
//!
PRIVATE_DEFINITION_START(PITranslator)
PITranslatorPrivate::Translation content;
PRIVATE_DEFINITION_END(PITranslator)
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);
return instance()->PRIVATEWB->content.translate(in, context);
}
void PITranslator::clear() {
instance()->clearInternal();
instance()->PRIVATEWB->content.clear();
}
void PITranslator::loadLang(const PIString & short_lang) {
auto s = instance();
void PITranslator::loadLang(const PIString & short_lang, PIString dir) {
if (dir.isEmpty()) dir = PIDir::current().absolute("lang");
clear();
auto files = PIDir(dir).entries();
for (const auto & f: files) {
if (!f.baseName().endsWith(short_lang)) continue;
loadFile(f.path);
}
piCout << "Loaded %1 string for lang \"%2\""_a.arg(instance()->PRIVATEWB->content.count()).arg(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());
auto c = s->PRIVATEWB->content.createContext(cn.name());
for (const auto & s: cn.children())
c->add(s.name(), s.value().toString());
}
}*/
}
@@ -62,11 +75,11 @@ 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());
auto c = s->PRIVATEWB->content.createContext(cn.name());
for (const auto & s: cn.children())
c->add(s.name(), s.value().toString());
}
auto c = s->createContextInternal("");
auto c = s->PRIVATEWB->content.createContext("");
for (const auto & s: lang.children()) {
if (s.hasChildren()) continue;
c->add(s.name(), s.value().toString());
@@ -74,11 +87,26 @@ void PITranslator::loadConfig(const PIString & content) {
}
bool PITranslator::load(const PIByteArray & content) {
return instance()->PRIVATEWB->content.load(content);
}
bool PITranslator::loadFile(const PIString & path) {
PIFile f(path, PIIODevice::ReadOnly);
if (f.isClosed()) return false;
if (!PITranslatorPrivate::checkHeader(&f)) return false;
auto data = f.readAll();
data.remove(0, PITranslatorPrivate::headerSize());
return load(data);
}
PITranslator::PITranslator() {}
PITranslator::~PITranslator() {
clearInternal();
PRIVATE->content.clear();
}
@@ -86,21 +114,3 @@ 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;
}

View File

@@ -29,7 +29,8 @@
#include "pistring.h"
#define piTr PITranslator::tr
#define piTr PITranslator::tr
#define piTrNoOp PITranslator::trNoOp
//! \ingroup Application
//! \~\brief
@@ -39,34 +40,59 @@ 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::fromUTF8(in), context); }
static PIString trNoOp(const PIString & in, const PIString & context = {}) { return in; }
static PIString trNoOp(const char * in, const PIString & context = {}) { return trNoOp(PIString::fromUTF8(in), context); }
static void clear();
static void loadLang(const PIString & short_lang);
static void loadLang(const PIString & short_lang, PIString dir = {});
static void loadConfig(const PIString & content);
static bool load(const PIByteArray & content);
static bool loadFile(const PIString & path);
private:
PITranslator();
~PITranslator();
NO_COPY_CLASS(PITranslator)
struct Context {
void add(const PIString & in, const PIString & out);
PIMap<uint, PIString> strings;
};
PRIVATE_DECLARATION(PIP_EXPORT)
static PITranslator * instance();
void clearInternal();
Context * createContextInternal(const PIString & context);
PIMap<uint, Context *> contexts;
};
class PIStringContextTr {
public:
PIStringContextTr(PIString && s): _s(s) {}
operator PIString() const { return PITranslator::tr(_s); }
PIString operator()(const PIString & ctx = {}) const { return PITranslator::tr(_s, ctx); }
private:
PIString _s;
};
class PIStringContextTrNoOp {
public:
PIStringContextTrNoOp(PIString && s): _s(s) {}
operator PIString() const { return _s; }
PIString operator()(const PIString & ctx = {}) const { return _s; }
private:
PIString _s;
};
//! \~\brief
//! \~english PIString from UTF-8
//! \~russian PIString из UTF-8
inline PIString operator""_tr(const char * v, size_t sz) {
return PITranslator::tr(PIString::fromUTF8(v, sz));
//! \~english Translate string with \a PITranslator::tr()
//! \~russian Перевести строку с помощью \a PITranslator::tr()
inline PIStringContextTr operator""_tr(const char * v, size_t sz) {
return PIStringContextTr(PIString::fromUTF8(v, sz));
}
//! \~\brief
//! \~english Translate string with \a PITranslator::tr()
//! \~russian Перевести строку с помощью \a PITranslator::tr()
inline PIStringContextTrNoOp operator""_trNoOp(const char * v, size_t sz) {
return PIStringContextTrNoOp(PIString::fromUTF8(v, sz));
}
#endif

View File

@@ -0,0 +1,124 @@
/*
PIP - Platform Independent Primitives
Translation private
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_p.h"
#include "pichunkstream.h"
#include "piiodevice.h"
constexpr int currentVersion = 1;
const PIByteArray fileHeader("PIPBTF", 6);
void PITranslatorPrivate::Context::add(const PIMap<uint, PIString> & sm) {
auto it = sm.makeIterator();
while (it.next())
strings[it.key()] = it.value();
}
void PITranslatorPrivate::Translation::clear() {
piDeleteAll(contexts.values());
contexts.clear();
lang.clear();
}
PITranslatorPrivate::Context * PITranslatorPrivate::Translation::createContext(const PIString & context) {
return createContext(context.hash());
}
PITranslatorPrivate::Context * PITranslatorPrivate::Translation::createContext(uint hash) {
auto & ret(contexts[hash]);
if (!ret) ret = new Context();
return ret;
}
PIString PITranslatorPrivate::Translation::translate(const PIString & in, const PIString & context) {
auto c = contexts.value(context.hash());
if (!c) return in;
return c->strings.value(in.hash(), in);
}
bool PITranslatorPrivate::Translation::load(const PIByteArray & data) {
if (data.size_s() <= 4) return false;
PIChunkStream cs(data);
Context * ctx = nullptr;
PIMap<uint, PIString> strings;
while (!cs.atEnd()) {
switch (cs.read()) {
case 1: {
int version = cs.getData<int>();
if (version != currentVersion) {
piCout << "Invalid translation version!";
return false;
}
} break;
case 3: {
uint ctx_hash = cs.getData<uint>();
ctx = createContext(ctx_hash);
} break;
case 4: {
cs.get(strings);
if (ctx) ctx->add(strings);
} break;
}
}
return true;
}
int PITranslatorPrivate::Translation::count() const {
int ret = 0;
auto cit = contexts.makeIterator();
while (cit.next())
ret += cit.value()->strings.size_s();
return ret;
}
PIByteArray PITranslatorPrivate::Translation::save() {
PIChunkStream cs;
cs.add(1, currentVersion).add(2, lang);
auto cit = contexts.makeIterator();
while (cit.next()) {
cs.add(3, cit.key()).add(4, cit.value()->strings);
}
return cs.data();
}
int PITranslatorPrivate::headerSize() {
return fileHeader.size_s();
}
bool PITranslatorPrivate::checkHeader(PIIODevice * d) {
if (!d) return false;
return d->read(fileHeader.size_s()) == fileHeader;
}
void PITranslatorPrivate::writeHeader(PIIODevice * d) {
if (!d) return;
d->write(fileHeader);
}

View File

@@ -0,0 +1,53 @@
/*
PIP - Platform Independent Primitives
Translation private
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_p_H
#define pitranslator_p_H
#include "pistring.h"
class PIIODevice;
namespace PITranslatorPrivate {
struct PIP_EXPORT Context {
void add(const PIString & in, const PIString & out) { strings[in.hash()] = out; }
void add(const PIMap<uint, PIString> & sm);
PIMap<uint, PIString> strings;
};
struct PIP_EXPORT Translation {
void clear();
Context * createContext(const PIString & context);
Context * createContext(uint hash);
PIString translate(const PIString & in, const PIString & context);
bool load(const PIByteArray & data);
int count() const;
PIByteArray save();
PIString lang;
PIMap<uint, Context *> contexts;
};
PIP_EXPORT int headerSize();
PIP_EXPORT bool checkHeader(PIIODevice * d);
PIP_EXPORT void writeHeader(PIIODevice * d);
} // namespace PITranslatorPrivate
#endif

View File

@@ -1,16 +0,0 @@
#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

View File

@@ -1,25 +0,0 @@
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\
";

View File

@@ -24,6 +24,7 @@
#include "piliterals_time.h"
#include "pipropertystorage.h"
#include "pitime.h"
#include "pitranslator.h"
#define PIBINARYLOG_VERSION_OLD 0x31
@@ -100,7 +101,7 @@ bool PIBinaryLog::openDevice() {
index.clear();
log_size = 0;
if (mode_ == ReadWrite) {
piCoutObj << "Error: ReadWrite mode not supported, use WriteOnly or ReadOnly";
piCoutObj << "Error: ReadWrite mode not supported, use WriteOnly or ReadOnly"_tr("PIBinLog");
return false;
}
if (path().isEmpty() && mode_ == WriteOnly) {
@@ -122,21 +123,21 @@ bool PIBinaryLog::openDevice() {
}
}
if (!file.open(path(), mode_)) {
piCoutObj << "Error: Can't open file" << path();
piCoutObj << "Error: Can't open file \"%1\": %2"_tr("PIBinLog").arg(path()).arg(errorString());
return false;
}
setName(path());
if (mode_ == WriteOnly) {
file.clear();
if (!writeFileHeader()) {
piCoutObj << "Error: Can't write binlog file header" << path();
piCoutObj << "Error: Can't write binlog file header \"%1\""_tr("PIBinLog").arg(path());
return false;
}
is_started = true;
}
if (mode_ == ReadOnly) {
if (file.isEmpty()) {
piCoutObj << "Error: File is null" << path();
piCoutObj << "Error: File is null \"%1\""_tr("PIBinLog").arg(path());
fileError();
return false;
}
@@ -145,7 +146,7 @@ bool PIBinaryLog::openDevice() {
return false;
}
if (isEmpty()) {
piCoutObj << "Warning: Empty BinLog file" << path();
piCoutObj << "Warning: Empty BinLog file \"%1\""_tr("PIBinLog").arg(path());
fileEnd();
}
play_time = 0;
@@ -175,7 +176,7 @@ bool PIBinaryLog::closeDevice() {
bool PIBinaryLog::threadedRead(const uchar * readed, ssize_t size) {
// piCout << "binlog threaded read";
// piCout << "binlog threaded read";
if (!canRead() || isEnd()) return PIIODevice::threadedRead(readed, size);
is_thread_ok = false;
logmutex.lock();
@@ -258,7 +259,7 @@ PIString PIBinaryLog::getLogfilePath(const PIString & log_dir, const PIString &
dir.setDir(dir.absolutePath());
if (!dir.isExists()) {
piCout << "[PIBinaryLog]"
<< "Creating directory" << dir.path();
<< "Creating directory \"%1\""_tr("PIBinLog").arg(dir.path());
dir.make(true);
}
const PIString npath = log_dir + PIDir::separator + prefix + PIDateTime::current().toString("yyyy_MM_dd__hh_mm_ss");
@@ -282,7 +283,7 @@ PIString PIBinaryLog::createNewFile() {
newFile(file.path());
return file.path();
}
piCoutObj << "Can't create new file, maybe LogDir" << ("\"" + logDir() + "\"") << "is invalid.";
piCoutObj << "Can't create new file, maybe LogDir \"%1\" is invalid"_tr("PIBinLog").arg(logDir());
return PIString();
}
@@ -291,7 +292,7 @@ void PIBinaryLog::createNewFile(const PIString & path) {
if (open(path, PIIODevice::WriteOnly)) {
newFile(file.path());
} else
piCoutObj << "Can't create new file, maybe path" << ("\"" + path + "\"") << "is invalid.";
piCoutObj << "Can't create new file, maybe path \"%1\" is invalid"_tr("PIBinLog").arg(path);
}
@@ -315,7 +316,7 @@ void PIBinaryLog::setPause(bool pause) {
int PIBinaryLog::writeBinLog(int id, const void * data, int size) {
if (size <= 0 || !canWrite()) return -1;
if (id == 0) {
piCoutObj << "Error: can`t write with id = 0! Id must be > 0";
piCoutObj << "Error: can`t write with id = 0! ID must be > 0"_tr("PIBinLog");
return -1;
}
if (is_pause) return 0;
@@ -359,7 +360,7 @@ PIByteArray PIBinaryLog::readBinLog(int id, PISystemTime * time, int * readed_id
Record br = readRecord();
logmutex.unlock();
if (br.id == -1) {
piCoutObj << "End of BinLog file";
piCoutObj << "End of BinLog file"_tr("PIBinLog");
fileEnd();
return PIByteArray();
}
@@ -373,7 +374,7 @@ PIByteArray PIBinaryLog::readBinLog(int id, PISystemTime * time, int * readed_id
br = readRecord();
logmutex.unlock();
if (br.id == -1) {
piCoutObj << "End of BinLog file";
piCoutObj << "End of BinLog file"_tr("PIBinLog");
fileEnd();
return PIByteArray();
}
@@ -382,7 +383,7 @@ PIByteArray PIBinaryLog::readBinLog(int id, PISystemTime * time, int * readed_id
if (readed_id) *readed_id = br.id;
return br.data;
}
piCoutObj << "Can't find record with id =" << id;
piCoutObj << "Can't find record with id = %1"_tr("PIBinLog").arg(id);
return PIByteArray();
}
@@ -428,15 +429,15 @@ ssize_t PIBinaryLog::readDevice(void * read_to, ssize_t max_size) {
}
if (br.id == -1) {
fileEnd();
piCoutObj << "End of BinLog file";
piCoutObj << "End of BinLog file"_tr("PIBinLog");
return 0;
}
if (br.id == 0) {
piCoutObj << "Read record error";
piCoutObj << "Read record error"_tr("PIBinLog");
return -1;
}
const ssize_t sz = piMini(max_size, br.data.size());
if (sz < br.data.size_s()) piCoutObj << "too small read buffer:" << max_size << ", data size:" << br.data.size();
if (sz < br.data.size_s()) piCoutObj << "too small read buffer: %1, data size: %2"_tr("PIBinLog").arg(max_size).arg(br.data.size());
memcpy(read_to, br.data.data(), sz);
return sz;
}
@@ -491,7 +492,7 @@ bool PIBinaryLog::checkFileHeader() {
for (uint i = 0; i < PIBINARYLOG_SIGNATURE_SIZE; i++)
if (read_sig[i] != binlog_sig[i]) correct = false;
if (!correct) {
piCoutObj << "BinLogFile signature is corrupted or invalid file";
piCoutObj << "BinLogFile signature is corrupted or invalid file"_tr("PIBinLog");
return false;
}
uchar read_version = 0;
@@ -509,9 +510,9 @@ bool PIBinaryLog::checkFileHeader() {
}
return true;
}
if (read_version == 0) piCoutObj << "BinLogFile has invalid version";
if (read_version < PIBINARYLOG_VERSION) piCoutObj << "BinLogFile has too old verion";
if (read_version > PIBINARYLOG_VERSION) piCoutObj << "BinLogFile has too newest version";
if (read_version == 0) piCoutObj << "BinLogFile has invalid version"_tr("PIBinLog");
if (read_version < PIBINARYLOG_VERSION) piCoutObj << "BinLogFile has too old verion"_tr("PIBinLog");
if (read_version > PIBINARYLOG_VERSION) piCoutObj << "BinLogFile has too new version"_tr("PIBinLog");
return false;
}
@@ -545,7 +546,7 @@ PIBinaryLog::Record PIBinaryLog::readRecord() {
if (br.id == 0) fileError();
moveIndex(index.index_pos.value(file.pos(), -1));
logmutex.unlock();
// piCoutObj << "readRecord done";
// piCoutObj << "readRecord done";
return br;
}
@@ -721,7 +722,7 @@ bool PIBinaryLog::cutBinLog(const PIBinaryLog::BinLogInfo & src, const PIString
PIBinaryLog slog;
if (!slog.open(src.path, PIIODevice::ReadOnly)) {
piCout << "[PIBinaryLog]"
<< "Error, can't open" << src.path;
<< "Error, can't open \"%1\""_tr("PIBinLog").arg(src.path);
return false;
}
const PIVector<int> ids = src.records.keys();
@@ -730,7 +731,7 @@ bool PIBinaryLog::cutBinLog(const PIBinaryLog::BinLogInfo & src, const PIString
dlog.createNewFile(dst);
if (!dlog.isOpened()) {
piCout << "[PIBinaryLog]"
<< "Error, can't create" << dst;
<< "Error, can't create \"%1\""_tr("PIBinLog").arg(dst);
return false;
}
bool first = true;
@@ -746,7 +747,7 @@ bool PIBinaryLog::cutBinLog(const PIBinaryLog::BinLogInfo & src, const PIString
if (ids.contains(br.id)) {
if (dlog.writeBinLog_raw(br.id, br.timestamp - st, br.data) <= 0) {
piCout << "[PIBinaryLog]"
<< "Error, can't write to file" << dst;
<< "Error, can't write to file \"%1\""_tr("PIBinLog").arg(dst);
return false;
}
}
@@ -772,7 +773,7 @@ bool PIBinaryLog::joinBinLogsSerial(const PIStringList & src,
for (const PIString & fn: src) {
if (!slog.open(fn, PIIODevice::ReadOnly)) {
piCout << "[PIBinaryLog]"
<< "Error, can't open" << fn;
<< "Error, can't open \"%1\""_tr("PIBinLog").arg(fn);
return false;
}
if (first) {
@@ -781,11 +782,11 @@ bool PIBinaryLog::joinBinLogsSerial(const PIStringList & src,
dlog.createNewFile(dst);
if (!dlog.isOpened()) {
piCout << "[PIBinaryLog]"
<< "Error, can't create" << dst;
<< "Error, can't create \"%1\""_tr("PIBinLog").arg(dst);
return false;
}
piCout << "[PIBinaryLog]"
<< "Start join binlogs to" << dst;
<< "Start join binlogs to \"%1\""_tr("PIBinLog").arg(dst);
} else {
dtime = lt;
}
@@ -799,7 +800,7 @@ bool PIBinaryLog::joinBinLogsSerial(const PIStringList & src,
lt = dtime + br.timestamp;
if (dlog.writeBinLog_raw(br.id, lt, br.data) <= 0) {
piCout << "[PIBinaryLog]"
<< "Error, can't write to file" << dst;
<< "Error, can't write to file \"%1\""_tr("PIBinLog").arg(dst);
return false;
}
if (tm.elapsed_s() > 0.1) {
@@ -821,7 +822,7 @@ bool PIBinaryLog::joinBinLogsSerial(const PIStringList & src,
// piCout << "[PIBinaryLog]" << "complete" << fn;
}
piCout << "[PIBinaryLog]"
<< "Finish join binlogs, total time" << PITime::fromSystemTime(lt).toString();
<< "Finish join binlogs, total time %1"_tr("PIBinLog").arg(PITime::fromSystemTime(lt).toString());
return true;
}
@@ -853,7 +854,7 @@ int PIBinaryLog::posForTime(const PISystemTime & time) {
void PIBinaryLog::seekTo(int rindex) {
// piCoutObj << "seekTo";
// piCoutObj << "seekTo";
logmutex.lock();
pausemutex.lock();
if (rindex < index.index.size_s() && rindex >= 0) {
@@ -866,7 +867,7 @@ void PIBinaryLog::seekTo(int rindex) {
startlogtime = PISystemTime::current() - lastrecord.timestamp;
}
}
// piCoutObj << "seekTo done";
// piCoutObj << "seekTo done";
pausemutex.unlock();
logmutex.unlock();
}
@@ -947,7 +948,7 @@ void PIBinaryLog::configureFromFullPathDevice(const PIString & full_path) {
break;
}
}
// piCoutObj << "configured";
// piCoutObj << "configured";
}
@@ -989,7 +990,7 @@ void PIBinaryLog::propertyChanged(const char * s) {
split_time = property("splitTime").toSystemTime();
split_size = property("splitFileSize").toLLong();
split_count = property("splitRecordCount").toInt();
// piCoutObj << "propertyChanged" << s << play_mode;
// piCoutObj << "propertyChanged" << s << play_mode;
}

View File

@@ -24,6 +24,7 @@
#include "piliterals.h"
#include "pipropertystorage.h"
#include "pisysteminfo.h"
#include "pitranslator.h"
// clang-format off
#ifdef QNX
# include <arpa/inet.h>
@@ -897,7 +898,9 @@ void PIEthernet::server_func(void * eth) {
piMSleep(10);
return;
}
if (ce->debug()) piCout << "[PIEthernet] Can`t accept new connection," << ethErrorString();
if (ce->debug())
piCout << "[PIEthernet]"
<< "Can`t accept new connection, %1"_tr("PIEthernet").arg(ethErrorString());
piMSleep(50);
return;
}
@@ -1081,14 +1084,16 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
ulong ulOutBufLen = sizeof(IP_ADAPTER_INFO);
PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
if (!pAdapterInfo) {
piCout << "[PIEthernet] Error allocating memory needed to call GetAdaptersInfo";
piCout << "[PIEthernet]"
<< "Error allocating memory needed to call GetAdaptersInfo"_tr("PIEthernet");
return il;
}
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
HeapFree(GetProcessHeap(), 0, pAdapterInfo);
pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, ulOutBufLen);
if (!pAdapterInfo) {
piCout << "[PIEthernet] Error allocating memory needed to call GetAdaptersInfo";
piCout << "[PIEthernet]"
<< "Error allocating memory needed to call GetAdaptersInfo"_tr("PIEthernet");
return il;
}
}
@@ -1134,7 +1139,8 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
ifc.ifc_len = 256;
ifc.ifc_buf = new char[ifc.ifc_len];
if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
piCout << "[PIEthernet] Can`t get interfaces:" << errorString();
piCout << "[PIEthernet]"
<< "Can`t get interfaces: %1"_tr("PIEthernet").arg(errorString());
delete[] ifc.ifc_buf;
return il;
}
@@ -1223,7 +1229,8 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
}
freeifaddrs(ret);
} else
piCout << "[PIEthernet] Can`t get interfaces:" << errorString();
piCout << "[PIEthernet]"
<< "Can`t get interfaces: %1"_tr("PIEthernet").arg(errorString());
if (s != -1) ::close(s);
# endif
# endif

View File

@@ -23,6 +23,7 @@
#include "piincludes_p.h"
#include "piiostream.h"
#include "pitime_win.h"
#include "pitranslator.h"
#ifdef WINDOWS
# undef S_IFDIR
# undef S_IFREG
@@ -295,7 +296,7 @@ void PIFile::resize(llong new_size, uchar fill_) {
clear();
return;
}
piCoutObj << "Downsize is not supported yet :-(";
piCoutObj << "Downsize is not supported yet :-("_tr("PIFile");
}

View File

@@ -56,12 +56,12 @@ bool PIIOByteArray::open(const PIByteArray & buffer) {
ssize_t PIIOByteArray::readDevice(void * read_to, ssize_t size) {
// piCout << "PIIOByteArray::read" << data_ << size << canRead();
// piCout << "PIIOByteArray::read" << data_ << size << canRead();
if (!canRead() || !data_) return -1;
int ret = piMini(size, data_->size_s() - pos);
if (ret <= 0) return -1;
memcpy(read_to, data_->data(pos), ret);
// piCout << "readed" << ret;
// piCout << "readed" << ret;
pos += size;
if (pos > data_->size_s()) pos = data_->size_s();
return ret;
@@ -69,12 +69,12 @@ ssize_t PIIOByteArray::readDevice(void * read_to, ssize_t size) {
ssize_t PIIOByteArray::writeDevice(const void * data, ssize_t size) {
// piCout << "PIIOByteArray::write" << data << size << canWrite();
// piCout << "PIIOByteArray::write" << data << size << canWrite();
if (!canWrite() || !data) return -1;
// piCout << "write" << data;
if (pos > data_->size_s()) pos = data_->size_s();
PIByteArray rs = PIByteArray(data, size);
// piCoutObj << rs;
// piCoutObj << rs;
data_->insert(pos, rs);
pos += rs.size_s();
return rs.size_s();

View File

@@ -25,6 +25,7 @@
#include "piliterals_time.h"
#include "pipropertystorage.h"
#include "pitime.h"
#include "pitranslator.h"
//! \class PIIODevice piiodevice.h
@@ -222,7 +223,7 @@ void PIIODevice::stopThreadedRead() {
if (!destroying) {
interrupt();
} else {
piCoutObj << "Error: Device is running after destructor!";
piCoutObj << "Error: Device is running after destructor!"_tr("PIIODevice");
}
#endif
}
@@ -535,7 +536,7 @@ void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode *
if (fpwm.find('(') > 0 && fpwm.find(')') > 0) {
PIString dms(fpwm.right(fpwm.length() - fpwm.findLast('(')).takeRange('(', ')').trim().toLowerCase().removeAll(' '));
PIStringList opts(dms.split(","));
piForeachC(PIString & o, opts) {
for (const auto & o: opts) {
// piCout << dms;
if (o == "r"_a || o == "ro"_a || o == "read"_a || o == "readonly"_a) dm |= ReadOnly;
if (o == "w"_a || o == "wo"_a || o == "write"_a || o == "writeonly"_a) dm |= WriteOnly;
@@ -666,7 +667,7 @@ PIMap<PIConstChars, PIIODevice::FabricInfo> & PIIODevice::fabrics() {
bool PIIODevice::threadedRead(const uchar * readed, ssize_t size) {
// piCout << "iodevice threaded read";
// piCout << "iodevice threaded read";
if (func_read) return func_read(readed, size, ret_data_);
return true;
}

View File

@@ -19,6 +19,8 @@
#include "piiostring.h"
#include "pitranslator.h"
//! \class PIIOString piiostring.h
//! \details
@@ -49,7 +51,7 @@ void PIIOString::clear() {
bool PIIOString::open(PIString * string, PIIODevice::DeviceMode mode) {
if (mode == PIIODevice::ReadWrite) {
piCoutObj << "Error: ReadWrite mode not supported, use WriteOnly or ReadOnly";
piCoutObj << "Error: ReadWrite mode not supported, use WriteOnly or ReadOnly"_tr("PIIOString");
str = nullptr;
return false;
}

View File

@@ -24,6 +24,7 @@
#include "piincludes_p.h"
#include "pipropertystorage.h"
#include "pitime.h"
#include "pitranslator.h"
#include "piwaitevent_p.h"
#include <errno.h>
@@ -463,10 +464,10 @@ int PISerial::convertSpeed(PISerial::Speed speed) {
default: break;
}
#ifdef WINDOWS
piCoutObj << "Warning: Custom speed" << (int)speed;
piCoutObj << "Warning: Custom speed %1"_tr("PISerial").arg((int)speed);
return (int)speed;
#else
piCoutObj << "Warning: Unknown speed" << (int)speed << ", using 115200";
piCoutObj << "Warning: Unknown speed %1, using 115200"_tr("PISerial").arg((int)speed);
return B115200;
#endif
}
@@ -691,7 +692,7 @@ bool PISerial::openDevice() {
}
}
if (p.isEmpty()) {
piCoutObj << "Unable to find device \"" << pl << "\"";
piCoutObj << "Unable to find device \"%1\""_tr("PISerial").arg(pl);
}
}
if (p.isEmpty()) return false;
@@ -708,7 +709,7 @@ bool PISerial::openDevice() {
PIString wp = "//./" + p;
PRIVATE->hCom = CreateFileA(wp.dataAscii(), ds, sm, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);
if (PRIVATE->hCom == INVALID_HANDLE_VALUE) {
piCoutObj << "Unable to open \"" << p << "\"" << errorString();
piCoutObj << "Unable to open \"%1\": %2"_tr("PISerial").arg(p).arg(errorString());
fd = -1;
return false;
}
@@ -722,7 +723,7 @@ bool PISerial::openDevice() {
}
fd = ::open(p.data(), O_NOCTTY | om);
if (fd == -1) {
piCoutObj << "Unable to open \"" << p << "\"";
piCoutObj << "Unable to open \"%1\": %2"_tr("PISerial").arg(p).arg(errorString());
return false;
}
tcgetattr(fd, &PRIVATE->desc);
@@ -747,7 +748,7 @@ bool PISerial::closeDevice() {
#ifdef WINDOWS
SetCommState(PRIVATE->hCom, &PRIVATE->sdesc);
SetCommMask(PRIVATE->hCom, PRIVATE->mask);
// piCoutObj << "close" <<
// piCoutObj << "close" <<
CloseHandle(PRIVATE->hCom);
PRIVATE->hCom = 0;
#else
@@ -788,7 +789,7 @@ void PISerial::applySettings() {
}
PRIVATE->desc.StopBits = params[PISerial::TwoStopBits] ? TWOSTOPBITS : ONESTOPBIT;
if (SetCommState(PRIVATE->hCom, &PRIVATE->desc) == -1) {
piCoutObj << "Unable to set comm state for \"" << path() << "\"";
piCoutObj << "Unable to set comm state for \"%1\""_tr("PISerial").arg(path());
return;
}
#else
@@ -822,7 +823,7 @@ void PISerial::applySettings() {
setTimeouts();
if (tcsetattr(fd, TCSANOW, &PRIVATE->desc) < 0) {
piCoutObj << "Can`t set attributes for \"" << path() << "\"";
piCoutObj << "Can`t set attributes for \"%1\""_tr("PISerial").arg(path());
return;
}
#endif
@@ -871,7 +872,7 @@ ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) {
// piCoutObj << "read ..." << PRIVATE->hCom << max_size;
DWORD mask = 0;
if (GetCommMask(PRIVATE->hCom, &mask) == FALSE) {
piCoutObj << "read error" << errorString();
piCoutObj << "Read error: %1"_tr("PISerial").arg(errorString());
stop();
close();
return 0;
@@ -883,7 +884,7 @@ ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) {
DWORD err = GetLastError();
// piCoutObj << "read" << err;
if (err == ERROR_BAD_COMMAND || err == ERROR_ACCESS_DENIED) {
piCoutObj << "read error" << errorString();
piCoutObj << "Read error: %1"_tr("PISerial").arg(errorString());
stop();
close();
return 0;

View File

@@ -21,9 +21,12 @@
#include "piliterals_time.h"
#include "pitime.h"
#include "pitranslator.h"
const uint PIBaseTransfer::signature = 0x54424950;
PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) {
header.sig = signature;
crc_enabled = true;
@@ -96,7 +99,7 @@ void PIBaseTransfer::received(PIByteArray data) {
data >> h;
PacketType pt = (PacketType)h.type;
if (!h.check_sig()) {
piCoutObj << "invalid packet signature";
piCoutObj << "invalid packet signature"_tr("PIBaseTransfer");
diag.received(data.size(), false);
return;
} else
@@ -119,7 +122,7 @@ void PIBaseTransfer::received(PIByteArray data) {
ccrc = 0;
if (rcrc != ccrc) {
header.id = h.id;
piCoutObj << "invalid CRC";
piCoutObj << "invalid CRC"_tr("PIBaseTransfer");
sendReply(pt_ReplyInvalid);
} else {
mutex_session.lock();
@@ -170,9 +173,9 @@ void PIBaseTransfer::received(PIByteArray data) {
if (send_up > 20 && send_up > packets_count * 2) packets_count += piMaxi(packets_count / 10, 1);
// piCoutObj << packets_count;
} else
piCoutObj << "invalid reply id";
piCoutObj << "invalid reply id"_tr("PIBaseTransfer");
mutex_session.unlock();
// piCoutObj << "Done Packet" << h.id;
// piCoutObj << "Done Packet" << h.id;
}
if (is_receiving && h.id == 0) {
if (pt == pt_ReplySuccess) {
@@ -213,7 +216,7 @@ void PIBaseTransfer::received(PIByteArray data) {
}
if (is_receiving) {
if (header.session_id != h.session_id) {
piCoutObj << "restart receive";
piCoutObj << "restart receive"_tr("PIBaseTransfer");
mutex_header.unlock();
finish_receive(false, true);
} else {
@@ -344,7 +347,7 @@ bool PIBaseTransfer::send_process() {
mutex_send.unlock();
if (break_) return finish_send(false);
}
// piCoutObj << "send done, checking";
// piCoutObj << "send done, checking";
PITimeMeasurer rtm;
int prev_chk = 0;
mutex_send.lock();
@@ -516,7 +519,7 @@ bool PIBaseTransfer::getStartRequest() {
diag.sended(ba.size_s());
sendRequest(ba);
if (break_) return false;
// piCoutObj << replies[0];
// piCoutObj << replies[0];
mutex_session.lock();
if (replies[0] == pt_ReplySuccess) {
state_string = "send permited!";
@@ -532,7 +535,7 @@ bool PIBaseTransfer::getStartRequest() {
void PIBaseTransfer::processData(int id, PIByteArray & data) {
// piCoutObj << "received packet" << id << ", size" << data.size();
// piCoutObj << "received packet" << id << ", size" << data.size();
if (id < 1 || id > replies.size_s()) return;
if (!session[id - 1].isEmpty()) {
header.id = id;
@@ -595,7 +598,7 @@ PIByteArray PIBaseTransfer::build_packet(int id) {
hdr << header;
mutex_header.unlock();
ret.insert(0, hdr);
// piCoutObj << "Send Packet" << header.id << ret.size();
// piCoutObj << "Send Packet" << header.id << ret.size();
return ret;
}

View File

@@ -23,6 +23,7 @@
#include "piiostream.h"
#include "piliterals_time.h"
#include "pitime.h"
#include "pitranslator.h"
/** \class PIConnection
* \brief Complex Input/Output point
@@ -142,7 +143,7 @@ bool PIConnection::configure(PIConfig & conf, const PIString & name_) {
// piCout << name_list << flt_list << chk_set;
chk_set.remove("");
if (!chk_set.isEmpty()) {
piCoutObj << "Error," << chk_set.toVector() << "names assigned to both devices and filters!";
piCoutObj << "Error,"_tr("PIConnection") << chk_set.toVector() << "names assigned to both devices and filters!"_tr("PIConnection");
return false;
}
PIMap<PIString, PIString> dev_aliases;
@@ -238,7 +239,7 @@ bool PIConnection::configure(PIConfig & conf, const PIString & name_) {
}
setDebug(pdebug);
for (const PIString & f: filter_fails) {
piCoutObj << "\"addFilter\" error: no such device \"" << f << "\"!";
piCoutObj << "\"addFilter\" error: no such device \"%1\"!"_tr("PIConnection").arg(f);
}
for (const PIConfig::Entry * e: cb) {
PIString f(e->getValue("from").value()), t(e->getValue("to").value());
@@ -469,7 +470,7 @@ PIPacketExtractor * PIConnection::addFilter(const PIString & name_, const PIStri
if (extractors.value(full_path, nullptr)) pe = extractors.value(full_path, nullptr)->extractor;
if (pe) dev = pe;
if (!dev) {
piCoutObj << "\"addFilter\" error: no such device or filter \"" << full_path << "\"!";
piCoutObj << "\"addFilter\" error: no such device or filter \"%1\"!"_tr("PIConnection").arg(full_path);
return nullptr;
}
if (!e) {
@@ -508,7 +509,7 @@ PIPacketExtractor * PIConnection::addFilter(PIPacketExtractor * filter, const PI
if (pe) {
dev = pe;
} else {
piCoutObj << "\"addFilter\" error: no such device or filter \"" << full_path << "\"!";
piCoutObj << "\"addFilter\" error: no such device or filter \"%1\"!"_tr("PIConnection").arg(full_path);
return nullptr;
}
if (!e) {
@@ -739,7 +740,7 @@ void PIConnection::addSender(const PIString & name_, const PIString & full_path_
}
PIIODevice * dev = devByString(full_path_name);
if (!dev) {
piCoutObj << "\"addSender\" error: no such device \"" << full_path_name << "\"!";
piCoutObj << "\"addSender\" error: no such device \"%1\"!"_tr("PIConnection").arg(full_path_name);
return;
}
if (!s->isRunning() && start_) {
@@ -899,7 +900,7 @@ int PIConnection::writeByFullPath(const PIString & full_path, const PIByteArray
PIIODevice * dev = __device_pool__->device(fp);
// piCout << "SEND" << full_path << fp;
if (!dev) {
piCoutObj << "No such full path \"" << full_path << "\"!";
piCoutObj << "No such full path \"%1\"!"_tr("PIConnection").arg(full_path);
return -1;
}
return write(dev, data);
@@ -909,7 +910,7 @@ int PIConnection::writeByFullPath(const PIString & full_path, const PIByteArray
int PIConnection::writeByName(const PIString & name_, const PIByteArray & data) {
PIIODevice * dev = deviceByName(name_);
if (!dev) {
piCoutObj << "No such device \"" << name_ << "\"!";
piCoutObj << "No such device \"%1\"!"_tr("PIConnection").arg(name_);
return -1;
}
return write(dev, data);
@@ -918,12 +919,12 @@ int PIConnection::writeByName(const PIString & name_, const PIByteArray & data)
int PIConnection::write(PIIODevice * dev, const PIByteArray & data) {
if (!dev) {
piCoutObj << "Null Device!";
piCoutObj << "Null Device!"_tr("PIConnection");
return -1;
}
if (!dev->isOpened()) return -1;
if (!dev->canWrite()) {
piCoutObj << "Device \"" << dev->constructFullPath() << "\" can`t write!";
piCoutObj << "Device \"%1\" can`t write!"_tr("PIConnection").arg(dev->constructFullPath());
return -1;
}
int ret = dev->write(data);
@@ -982,7 +983,7 @@ PIIODevice * PIConnection::DevicePool::addDevice(PIConnection * parent, const PI
// piCout << "new device" << fp;
dd->dev = PIIODevice::createFromFullPath(fp);
if (!dd->dev) {
piCoutObj << "Error: can`t create device \"" << fp << "\"!"; //:" << errorString();
piCoutObj << "Error: can`t create device \"%1\"!"_tr("PIConnection").arg(fp);
return nullptr;
}
dd->dev->setProperty("__fullPath__", fp);
@@ -1258,7 +1259,7 @@ void PIConnection::unboundExtractor(PIPacketExtractor * pe) {
void PIConnection::packetExtractorReceived(const uchar * data, int size) {
PIString from(emitter() ? emitter()->name() : PIString());
PIIODevice * cd = (PIIODevice *)emitter();
// piCout << "packetExtractorReceived" << from << cd;
// piCout << "packetExtractorReceived" << from << cd;
if (cd) {
PIVector<PIPacketExtractor *> be(bounded_extractors.value(cd));
// piCout << be << (void*)data << size;

View File

@@ -152,16 +152,16 @@ void PIDiagnostics::sended(int size) {
void PIDiagnostics::tick(int) {
auto speed_sec = "/s"_tr("PIDiag");
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;
@@ -197,7 +197,7 @@ void PIDiagnostics::tick(int) {
diag = PIDiagnostics::Good;
}
if ((tcnt_send + tcnt_recv) != 0) {
// piCoutObj << tcnt_recv << tcnt_send;
// piCoutObj << tcnt_recv << tcnt_send;
history_rec.dequeue();
history_send.dequeue();
Entry e;
@@ -225,7 +225,7 @@ PIDiagnostics::Entry PIDiagnostics::calcHistory(PIQueue<Entry> & hist, int & cnt
if (!hist[i].empty) cnt++;
}
e.empty = false;
// piCoutObj << hist.size() << cnt;
// piCoutObj << hist.size() << cnt;
return e;
}

View File

@@ -19,7 +19,6 @@
#include "piresourcesstorage.h"
#include "pichunkstream.h"
#include "piset.h"
@@ -42,11 +41,11 @@ void PIResourcesStorage::Section::add(const PIResourcesStorage::Section & s) {
void PIResourcesStorage::Section::purge() {
PIVector<PIByteArray *> bav = entries.values();
PISet<PIByteArray *> bas;
piForeach(PIByteArray * i, bav) {
for (auto i: bav) {
if (i) bas << i;
}
bav = bas.toVector();
piForeach(PIByteArray * i, bav)
for (auto i: bav)
delete i;
entries.clear();
}
@@ -76,14 +75,14 @@ void PIResourcesStorage::registerSection(const uchar * rc_data, const uchar * rc
PIVector<PIResourcesStorage::__RCEntry> el;
dba >> el;
PIMap<PIString, PIVector<PIResourcesStorage::__RCEntry>> ebs;
piForeachC(PIResourcesStorage::__RCEntry & e, el) {
for (const auto & e: el) {
ebs[e.section] << e;
}
auto it = ebs.makeIterator();
while (it.next()) {
PIResourcesStorage::Section s;
const PIVector<PIResourcesStorage::__RCEntry> & itv(it.value());
piForeachC(PIResourcesStorage::__RCEntry & e, itv) {
for (const auto & e: itv) {
// piCout << "add" << e.name << e.alias << PIString::readableSize(e.size);
PIByteArray * eba = new PIByteArray(&(rc_data[e.offset]), e.size);
s.entries[e.name] = eba;
@@ -123,7 +122,7 @@ PIByteArray PIResourcesStorage::get(const PIString & entry_name) const {
void PIResourcesStorage::clear() {
// piCout << "PIResourcesStorage clear";
PIVector<Section *> sv = sections.values();
piForeach(Section * i, sv) {
for (auto i: sv) {
if (i) i->purge();
}
sections.clear();

View File

@@ -20,7 +20,7 @@
#include "pistatemachine_state.h"
#include "pistatemachine_transition.h"
#include "pitranslator.h"
PIStateBase::~PIStateBase() {
piDeleteAll(transitions);
@@ -108,7 +108,7 @@ bool PIStateBase::start(bool force) {
setActive(true);
return initial_state->start();
} else {
piCout << "error:" << getName() << "no initial state!";
piCout << "Error: \"%1\" no initial state!"_tr("PIStateMachine").arg(getName());
return false;
}
} else {

View File

@@ -19,6 +19,7 @@
#include "piliterals_time.h"
#include "pitime.h"
#include "pitranslator.h"
#ifndef MICRO_PIP
# include "piincludes_p.h"
@@ -196,7 +197,7 @@ void PIProcess::startProc(bool detached) {
CloseHandle(PRIVATE->pi.hThread);
CloseHandle(PRIVATE->pi.hProcess);
} else
piCoutObj << "\"CreateProcess\" error, " << errorString();
piCoutObj << "\"CreateProcess\" error: %1"_tr("PIProcess").arg(errorString());
# else
// cout << "exec " << tf_in << ", " << tf_out << ", " << tf_err << endl;

View File

@@ -297,7 +297,7 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
void PIString::appendFromChars(const char * c, int s, const char * codepage) {
// piCout << "appendFromChars";
// piCout << "appendFromChars";
if (s == 0) return;
int old_sz = size_s();
if (s == -1) s = strlen(c);
@@ -523,6 +523,31 @@ void PIString::trimsubstr(int & st, int & fn) const {
}
PIString PIString::minArgPlaceholder() {
if (size() < 2) return {};
int min = -1;
PIString ret, tmp;
for (int i = 0; i < size_s(); ++i) {
if (at(i) == '%') {
int j = 0;
for (j = i + 1; j < size_s(); ++j) {
if (!at(j).isDigit()) break;
}
bool ok = false;
tmp = mid(i + 1, j - i - 1);
int cur = tmp.toInt(10, &ok);
if (!ok) continue;
if (min < 0 || min > cur) {
min = cur;
ret = tmp;
}
}
}
if (ret.isEmpty()) return {};
return "%" + ret;
}
uint PIString::hash() const {
return piHashData((const uchar *)d.data(), d.size() * sizeof(PIChar));
}
@@ -1744,10 +1769,9 @@ 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) + " "_a + PITranslator::tr("B", tr_c));
*this += (PIString::fromNumber(bytes) + " "_a + "B"_tr("PIString"));
return *this;
}
double fres = bytes;
@@ -1762,14 +1786,21 @@ PIString & PIString::setReadableSize(llong bytes) {
}
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);
if (checkRange("KiB"_tr("PIString"))) return *this;
if (checkRange("MiB"_tr("PIString"))) return *this;
if (checkRange("GiB"_tr("PIString"))) return *this;
if (checkRange("TiB"_tr("PIString"))) return *this;
if (checkRange("PiB"_tr("PIString"))) return *this;
if (checkRange("EiB"_tr("PIString"))) return *this;
if (checkRange("ZiB"_tr("PIString"))) return *this;
checkRange("YiB"_tr("PIString"), true);
return *this;
}
PIString & PIString::arg(const PIString & v) {
auto ph = minArgPlaceholder();
if (!ph.isEmpty()) replaceAll(ph, v);
return *this;
}

View File

@@ -1682,6 +1682,61 @@ public:
//! \~\sa PIString::readableSize()
PIString & setReadableSize(llong bytes);
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
//! \~\details
//! \~\code
//! piCout << PIString("color %1 is not %2, but %1").arg("red").arg("green"); // color red is not green, but red
//! \endcode
PIString & arg(const PIString & v);
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
PIString & arg(short v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
PIString & arg(ushort v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
//! \~\details
//! \~\code
//! piCout << PIString("ten = %1").arg(10); // ten = 10
//! piCout << PIString("'%1' is max hex letter (%2 in dec)").arg(0xF, 16).arg(0xF); // 'F' is max hex letter (15 in dec)
//! \endcode
PIString & arg(int v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
PIString & arg(uint v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
PIString & arg(llong v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
PIString & arg(ullong v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
PIString & arg(float v, char format = 'f', int precision = 8) { return arg(PIString::fromNumber(v, format, precision)); }
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
//! \~\details
//! \~\code
//! piCout << PIString("light speed = %1 %2").arg(M_LIGHT_SPEED, 'g', 4).arg("m/s"); // light speed = 2.998e+08 m/s
//! \endcode
PIString & arg(double v, char format = 'f', int precision = 8) { return arg(PIString::fromNumber(v, format, precision)); }
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
PIString & arg(ldouble v, char format = 'f', int precision = 8) { return arg(PIString::fromNumber(v, format, precision)); }
//! \~english Returns string contains numeric representation of "value" in base "base".
//! \~russian Возвращает строковое представление числа "value" по основанию "base".
//! \~\details
@@ -1867,6 +1922,7 @@ private:
void buildData(const char * cp = __syslocname__) const;
void deleteData() const;
void trimsubstr(int & st, int & fn) const;
PIString minArgPlaceholder();
PIDeque<PIChar> d;
mutable bool changed_ = true;

View File

@@ -22,6 +22,7 @@
#include "piincludes_p.h"
#include "piintrospection_threads.h"
#include "pitime.h"
#include "pitranslator.h"
#ifndef MICRO_PIP
# include "pisystemtests.h"
#endif
@@ -568,7 +569,7 @@ PIThread::PIThread(bool startNow, PISystemTime loop_delay): PIObject() {
PIThread::~PIThread() {
PIINTROSPECTION_THREAD_DELETE(this);
if (!running_ || PRIVATE->thread == 0) return;
piCout << "[PIThread \"" << name() << "\"] Warning, terminate on destructor!";
piCout << "[PIThread \"%1\"] Warning, terminate on destructor!"_tr("PIThread").arg(name());
#ifdef FREERTOS
// void * ret(0);
// PICout(PICoutManipulators::DefaultControls) << "~PIThread" << PRIVATE->thread;
@@ -663,7 +664,7 @@ void PIThread::stop() {
void PIThread::terminate() {
piCoutObj << "Warning, terminate!";
piCoutObj << "Warning, terminate!"_tr("PIThread");
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ..." << running_;
#ifdef FREERTOS
PICout(PICoutManipulators::DefaultControls) << "FreeRTOS can't terminate pthreads! waiting for stop";
@@ -781,7 +782,7 @@ bool PIThread::_startThread(void * func) {
running_ = false;
PRIVATE->thread = 0;
piCoutObj << "Error: Can`t start new thread:" << errorString();
piCoutObj << "Error: Can`t start new thread: %1"_tr("PIThread").arg(errorString());
return false;
}

View File

@@ -23,6 +23,7 @@
#include "piiostream.h"
#include "piliterals_time.h"
#include "pitime.h"
#include "pitranslator.h"
#include <ctime>
#ifdef QNX
@@ -320,7 +321,8 @@ PISystemTime PITimeMeasurer::elapsed() const {
PISystemTime PISystemTime::Frequency::toSystemTime() const {
if (value_hz <= 0.) {
piCout << "[PISystemTime::Frequency] toSystemTime() warning: invalid hertz" << value_hz;
piCout << "[PISystemTime::Frequency]"
<< "toSystemTime() Warning: invalid hertz: %1"_tr("PISystemTime").arg(value_hz);
return PISystemTime();
}
return PISystemTime::fromSeconds(1. / value_hz);
@@ -329,7 +331,8 @@ PISystemTime PISystemTime::Frequency::toSystemTime() const {
PISystemTime::Frequency PISystemTime::Frequency::fromSystemTime(const PISystemTime & st) {
if (st == PISystemTime()) {
piCout << "[PISystemTime::Frequency] fromSystemTime() warning: null frequency";
piCout << "[PISystemTime::Frequency]"
<< "fromSystemTime() Warning: null frequency"_tr("PISystemTime");
return Frequency();
}
return Frequency(1. / st.toSeconds());

View File

@@ -19,6 +19,8 @@
#include "pivariant.h"
#include "pitranslator.h"
//! \class PIVariant pivariant.h
//! \details
@@ -388,7 +390,7 @@ PIVariant PIVariant::fromValue(const PIByteArray & c, uint type_id) {
} else
#endif
{
piCout << "Can`t initialize PIVariant from unregistered typeID \"" << type_id << "\"!";
piCout << "Can`t initialize PIVariant from unregistered typeID \"%1\"!"_tr("PIVariant").arg(type_id);
return ret;
}
}
@@ -410,7 +412,7 @@ PIVariant PIVariant::fromValue(const PIByteArray & c, const PIString & type) {
} else
#endif
{
piCout << "Can`t initialize PIVariant from unregistered type \"" << type << "\"!";
piCout << "Can`t initialize PIVariant from unregistered type \"%1\"!"_tr("PIVariant").arg(type);
return ret;
}
}