PICout refactoring, new SHSTKMacros
This commit is contained in:
@@ -23,12 +23,12 @@
|
||||
|
||||
PICout operator <<(PICout s, const PIBitArray & ba) {
|
||||
s.space();
|
||||
s.setControl(0, true);
|
||||
s.saveAndSetControls(0);
|
||||
for (uint i = 0; i < ba.bitSize(); ++i) {
|
||||
s << int(ba[i]);
|
||||
if (i % 8 == 7) s << ' ';
|
||||
}
|
||||
s.restoreControl();
|
||||
s.restoreControls();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -406,14 +406,14 @@ PIByteArray PIByteArray::fromHex(PIString str) {
|
||||
|
||||
PICout operator <<(PICout s, const PIByteArray & ba) {
|
||||
s.space();
|
||||
s.setControl(0, true);
|
||||
s.saveAndSetControls(0);
|
||||
s << "{";
|
||||
for (uint i = 0; i < ba.size(); ++i) {
|
||||
s << ba[i];
|
||||
if (i < ba.size() - 1) s << ", ";
|
||||
}
|
||||
s << "}";
|
||||
s.restoreControl();
|
||||
s.restoreControls();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -359,7 +359,7 @@ PIChar PIChar::toLower() const {
|
||||
|
||||
PICout operator <<(PICout s, const PIChar & v) {
|
||||
s.space();
|
||||
s.setControl(0, true);
|
||||
s.saveAndSetControls(0);
|
||||
if (v.isAscii()) s << char(v.ch);
|
||||
else {
|
||||
#ifdef PIP_ICU
|
||||
@@ -380,6 +380,6 @@ PICout operator <<(PICout s, const PIChar & v) {
|
||||
s << PIString(v);
|
||||
#endif
|
||||
}
|
||||
s.restoreControl();
|
||||
s.restoreControls();
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -267,8 +267,8 @@ PICout PICout::operator <<(const PICoutAction v) {
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case PICoutManipulators::SaveContol: saveControl(); break;
|
||||
case PICoutManipulators::RestoreControl: restoreControl(); break;
|
||||
case PICoutManipulators::SaveContol: saveControls(); break;
|
||||
case PICoutManipulators::RestoreControl: restoreControls(); break;
|
||||
default: break;
|
||||
};
|
||||
return *this;
|
||||
@@ -440,14 +440,14 @@ PICout PICout::operator <<(const PICoutSpecialChar v) {
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::saveControl() {
|
||||
PICout & PICout::saveControls() {
|
||||
if (!act_) return *this;
|
||||
PRIVATE->cos_.push(co_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::restoreControl() {
|
||||
PICout & PICout::restoreControls() {
|
||||
if (!act_) return *this;
|
||||
if (!PRIVATE->cos_.isEmpty()) {
|
||||
co_ = PRIVATE->cos_.top();
|
||||
@@ -650,24 +650,17 @@ void PICout::applyFormat(PICoutFormat f) {
|
||||
}
|
||||
|
||||
|
||||
bool PICout::setBufferActive(bool on, bool clear) {
|
||||
PIString PICout::getBuffer() {
|
||||
PIMutexLocker ml(PICout::__mutex__());
|
||||
bool ret = isBufferActive();
|
||||
if (clear) PICout::__string__().clear();
|
||||
setOutputDevice(Buffer, on);
|
||||
PIString ret = PICout::__string__();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool PICout::isBufferActive() {
|
||||
return isOutputDeviceActive(Buffer);
|
||||
}
|
||||
|
||||
|
||||
PIString PICout::buffer(bool clear) {
|
||||
PIString PICout::getBufferAndClear() {
|
||||
PIMutexLocker ml(PICout::__mutex__());
|
||||
PIString ret = PICout::__string__();
|
||||
if (clear) PICout::__string__().clear();
|
||||
PICout::__string__().clear();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -261,19 +261,23 @@ public:
|
||||
//! \~russian Установить флаг "c" в "on" состояние
|
||||
PICout & setControl(PICoutManipulators::PICoutControl c, bool on = true) {co_.setFlag(c, on); return *this;}
|
||||
|
||||
//! \~english Set control flags "c" and if "save" exec \a saveControl()
|
||||
//! \~russian Установить флаг "c" и если "save" то выполнить \a saveControl()
|
||||
PICout & setControl(PICoutManipulators::PICoutControls c, bool save = false) {if (save) saveControl(); co_ = c; return *this;}
|
||||
//! \~english Set control flags "c"
|
||||
//! \~russian Установить флаги "c"
|
||||
PICout & setControls(PICoutManipulators::PICoutControls c) {co_ = c; return *this;}
|
||||
|
||||
//! \~english Exec \a saveControls() and set control flags to "c"
|
||||
//! \~russian Иыполнить \a saveControls() и Установить флаги "c"
|
||||
PICout & saveAndSetControls(PICoutManipulators::PICoutControls c) {saveControls(); co_ = c; return *this;}
|
||||
|
||||
//! \~english Save control flags to internal stack
|
||||
//! \~russian Сохраняет состояние флагов во внутренний стек
|
||||
//! \~\sa \a restoreControl()
|
||||
PICout & saveControl();
|
||||
PICout & saveControls();
|
||||
|
||||
//! \~english Restore control flags from internal stack
|
||||
//! \~russian Восстанавливает состояние флагов из внутреннего стека
|
||||
//! \~\sa \a saveControl()
|
||||
PICout & restoreControl();
|
||||
PICout & restoreControls();
|
||||
|
||||
//! \~english Conditional put space character to output
|
||||
//! \~russian Условно добавляет пробел
|
||||
@@ -307,17 +311,13 @@ public:
|
||||
//! \~russian Вывод \a PIString в stdout
|
||||
static void stdoutPIString(const PIString & s);
|
||||
|
||||
//! \~english Set output device to \a PICout::Buffer and if "clear" clear it
|
||||
//! \~russian Устанавливает устройство вывода на \a PICout::Buffer и если "clear" то очищает его
|
||||
static bool setBufferActive(bool on, bool clear = false);
|
||||
//! \~english Returns internal PIString buffer
|
||||
//! \~russian Возвращает внутренний PIString буфер
|
||||
static PIString getBuffer();
|
||||
|
||||
//! \~english Equivalent to \a isOutputDeviceActive(OutputDevice)
|
||||
//! \~russian Аналог \a isOutputDeviceActive(OutputDevice)
|
||||
static bool isBufferActive();
|
||||
|
||||
//! \~english Returns internal PIString buffer and if "clear" clear it
|
||||
//! \~russian Возвращает внутренний PIString буфер и если "clear" то очищает его
|
||||
static PIString buffer(bool clear = false);
|
||||
//! \~english Returns internal PIString buffer and clear it
|
||||
//! \~russian Возвращает внутренний PIString буфер и очищает его
|
||||
static PIString getBufferAndClear();
|
||||
|
||||
//! \~english Clear internal PIString buffer
|
||||
//! \~russian Очищает внутренний PIString буфер
|
||||
@@ -328,10 +328,22 @@ public:
|
||||
//! \~russian Устройство вывода "d" устанавливается в "on". Возвращает было ли устройство активно
|
||||
static bool setOutputDevice(OutputDevice d, bool on = true);
|
||||
|
||||
//! \~english Turn on output device "d". Returns if it was enabled
|
||||
//! \~russian Включает устройство вывода "d". Возвращает было ли устройство активно
|
||||
static bool enableOutputDevice(OutputDevice d) {return setOutputDevice(d, true);}
|
||||
|
||||
//! \~english Turn off output device "d". Returns if it was enabled
|
||||
//! \~russian Выключает устройство вывода "d". Возвращает было ли устройство активно
|
||||
static bool disableOutputDevice(OutputDevice d) {return setOutputDevice(d, false);}
|
||||
|
||||
//! \~english Set output to devices to "d"
|
||||
//! \~russian Устанавливает устройства вывода "d"
|
||||
static void setOutputDevices(OutputDevices d);
|
||||
|
||||
//! \~english Returns current output devices
|
||||
//! \~russian Возвращает текущие устройства вывода
|
||||
static OutputDevices currentOutputDevices() {return devs;}
|
||||
|
||||
//! \~english Returns if output device "d" is active
|
||||
//! \~russian Возвращает активно ли устройство вывода "d"
|
||||
static bool isOutputDeviceActive(OutputDevice d);
|
||||
|
||||
@@ -312,30 +312,30 @@ PIString datetime2string(const PIDateTime & date, const PIString & format) {
|
||||
|
||||
PICout operator <<(PICout s, const PITime & v) {
|
||||
s.space();
|
||||
s.setControl(0, true);
|
||||
s.saveAndSetControls(0);
|
||||
s << "PITime(" << v.hours << ":";
|
||||
s << PIString::fromNumber(v.minutes).expandLeftTo(2, '0') << ":";
|
||||
s << PIString::fromNumber(v.seconds).expandLeftTo(2, '0') << ":";
|
||||
s << PIString::fromNumber(v.milliseconds).expandLeftTo(3, '0') << ")";
|
||||
s.restoreControl();
|
||||
s.restoreControls();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
PICout operator <<(PICout s, const PIDate & v) {
|
||||
s.space();
|
||||
s.setControl(0, true);
|
||||
s.saveAndSetControls(0);
|
||||
s << "PIDate(" << v.day << "-";
|
||||
s << PIString::fromNumber(v.month).expandLeftTo(2, '0') << "-";
|
||||
s << v.year << ")";
|
||||
s.restoreControl();
|
||||
s.restoreControls();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
PICout operator <<(PICout s, const PIDateTime & v) {
|
||||
s.space();
|
||||
s.setControl(0, true);
|
||||
s.saveAndSetControls(0);
|
||||
s << "PIDateTime(";
|
||||
s << v.day << "-";
|
||||
s << PIString::fromNumber(v.month).expandLeftTo(2, '0') << "-";
|
||||
@@ -344,7 +344,7 @@ PICout operator <<(PICout s, const PIDateTime & v) {
|
||||
s << PIString::fromNumber(v.minutes).expandLeftTo(2, '0') << ":";
|
||||
s << PIString::fromNumber(v.seconds).expandLeftTo(2, '0') << ":";
|
||||
s << PIString::fromNumber(v.milliseconds).expandLeftTo(3, '0') << ")";
|
||||
s.restoreControl();
|
||||
s.restoreControls();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -751,13 +751,14 @@ bool dumpApplicationToFile(const PIString & path, bool with_objects) {
|
||||
f.setName("__S__DumpFile");
|
||||
f.clear();
|
||||
if (!f.open(PIIODevice::WriteOnly)) return false;
|
||||
bool ba = PICout::isBufferActive();
|
||||
PICout::setBufferActive(true, true);
|
||||
auto out_devs = PICout::currentOutputDevices();
|
||||
PICout::setOutputDevices(PICout::Buffer);
|
||||
PICout::clearBuffer();
|
||||
dumpApplication(with_objects);
|
||||
PIIOTextStream ts(&f);
|
||||
ts << PICout::buffer();
|
||||
ts << PICout::getBuffer();
|
||||
f.close();
|
||||
PICout::setBufferActive(ba, true);
|
||||
PICout::setOutputDevices(out_devs);
|
||||
PIFile::rename(path + "_tmp", path);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -146,6 +146,6 @@ BINARY_STREAM_READ(PIStringList) {
|
||||
//! \relatesalso PICout
|
||||
//! \~english Output operator to \a PICout
|
||||
//! \~russian Оператор вывода в \a PICout
|
||||
inline PICout operator <<(PICout s, const PIStringList & v) {s.space(); s.setControl(0, true); s << "{"; for (uint i = 0; i < v.size(); ++i) {s << "\"" << v[i] << "\""; if (i < v.size() - 1) s << ", ";} s << "}"; s.restoreControl(); return s;}
|
||||
inline PICout operator <<(PICout s, const PIStringList & v) {s.space(); s.saveAndSetControls(0); s << "{"; for (uint i = 0; i < v.size(); ++i) {s << "\"" << v[i] << "\""; if (i < v.size() - 1) s << ", ";} s << "}"; s.restoreControls(); return s;}
|
||||
|
||||
#endif // PISTRINGLIST_H
|
||||
|
||||
@@ -186,7 +186,7 @@ private:
|
||||
//! \relatesalso PICout
|
||||
//! \~english \brief Output operator to PICout
|
||||
//! \~russian \brief Оператор вывода в PICout
|
||||
inline PICout operator <<(PICout s, const PISystemTime & v) {s.space(); s.setControl(0, true); s << "(" << v.seconds << " s, " << v.nanoseconds << " ns)"; s.restoreControl(); return s;}
|
||||
inline PICout operator <<(PICout s, const PISystemTime & v) {s.space(); s.saveAndSetControls(0); s << "(" << v.seconds << " s, " << v.nanoseconds << " ns)"; s.restoreControls(); return s;}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -809,12 +809,12 @@ BINARY_STREAM_READ(PIVariant) {
|
||||
}
|
||||
|
||||
inline PICout operator <<(PICout s, const PIVariant & v) {
|
||||
s.space(); s.setControl(0, true);
|
||||
s.space(); s.saveAndSetControls(0);
|
||||
s << "PIVariant(" << v.typeName();
|
||||
if (v.isValid())
|
||||
s << ", " << v.toString();
|
||||
s << ")";
|
||||
s.restoreControl(); return s;
|
||||
s.restoreControls(); return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ inline PICout operator <<(PICout s, const PIVariantTypes::File & v) {s << "File(
|
||||
|
||||
inline PICout operator <<(PICout s, const PIVariantTypes::Dir & v) {s << "Dir(\"" << v.dir << "\")"; return s;}
|
||||
|
||||
inline PICout operator <<(PICout s, const PIVariantTypes::Color & v) {s.saveControl(); s << PICoutManipulators::Hex << "Color(#" << v.rgba << ")"; s.restoreControl(); return s;}
|
||||
inline PICout operator <<(PICout s, const PIVariantTypes::Color & v) {s.saveControls(); s << PICoutManipulators::Hex << "Color(#" << v.rgba << ")"; s.restoreControls(); return s;}
|
||||
|
||||
inline PICout operator <<(PICout s, const PIVariantTypes::IODevice & v) {s << v.toPICout(); return s;}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user