PICout improvement:
* renamed private members for more clear code * registerExternalBufferID() method to obtain unique ID for withExternalBuffer() * PICoutManipulators::PICoutStdStream enum for select stream (stdout or stderr) * Constructors now accept optional stream * piCerr and piCerrObj macros PIDir::temporary() moved to "mkdtemp" PILog: * now 4 levels * you can set max level * Error writes to piCerr
This commit is contained in:
@@ -76,6 +76,10 @@ PILog::PILog(): PIThread(), log_ts(&log_file) {
|
||||
split_time = 8_h;
|
||||
timestamp_format = "yyyy-MM-dd hh:mm:ss.zzz";
|
||||
setLineFormat("t - c: m");
|
||||
id_by_cat[Level::Info] = PICout::registerExternalBufferID();
|
||||
id_by_cat[Level::Debug] = PICout::registerExternalBufferID();
|
||||
id_by_cat[Level::Warning] = PICout::registerExternalBufferID();
|
||||
id_by_cat[Level::Error] = PICout::registerExternalBufferID();
|
||||
CONNECTU(PICout::Notifier::object(), finished, this, coutDone);
|
||||
}
|
||||
|
||||
@@ -101,18 +105,28 @@ void PILog::setLineFormat(const PIString & f) {
|
||||
}
|
||||
|
||||
|
||||
PICout PILog::debug(PIObject * context) {
|
||||
return makePICout(context, Category::Debug);
|
||||
}
|
||||
|
||||
|
||||
PICout PILog::warning(PIObject * context) {
|
||||
return makePICout(context, Category::Warning);
|
||||
void PILog::setLevel(Level l) {
|
||||
max_level = l;
|
||||
}
|
||||
|
||||
|
||||
PICout PILog::error(PIObject * context) {
|
||||
return makePICout(context, Category::Error);
|
||||
return makePICout(context, Level::Error);
|
||||
}
|
||||
|
||||
|
||||
PICout PILog::warning(PIObject * context) {
|
||||
return makePICout(context, Level::Warning);
|
||||
}
|
||||
|
||||
|
||||
PICout PILog::info(PIObject * context) {
|
||||
return makePICout(context, Level::Info);
|
||||
}
|
||||
|
||||
|
||||
PICout PILog::debug(PIObject * context) {
|
||||
return makePICout(context, Level::Debug);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,35 +143,27 @@ void PILog::stop() {
|
||||
|
||||
|
||||
void PILog::coutDone(int id, PIString * buffer) {
|
||||
cout_mutex.lock();
|
||||
if (!cout_cat_by_id.contains(id)) {
|
||||
cout_mutex.unlock();
|
||||
return;
|
||||
}
|
||||
auto cat = cout_cat_by_id.take(id, PILog::Category::Debug);
|
||||
cout_mutex.unlock();
|
||||
if (!buffer) return;
|
||||
if (!id_by_cat.containsValue(id)) return;
|
||||
auto cat = id_by_cat.key(id, PILog::Level::Debug);
|
||||
if (cat > max_level) return;
|
||||
enqueue(*buffer, cat);
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
|
||||
PICout PILog::makePICout(PIObject * context, Category cat) {
|
||||
cout_mutex.lock();
|
||||
int id = ++cout_id;
|
||||
auto buffer = new PIString();
|
||||
cout_cat_by_id[id] = cat;
|
||||
cout_mutex.unlock();
|
||||
PICout PILog::makePICout(PIObject * context, Level cat) {
|
||||
auto buffer = new PIString();
|
||||
if (context) {
|
||||
*buffer = "["_a + context->className();
|
||||
if (context->name().isNotEmpty()) *buffer += " \"" + context->name() + "\"";
|
||||
*buffer += "] ";
|
||||
}
|
||||
return PICout::withExternalBuffer(buffer, id, PICoutManipulators::AddSpaces);
|
||||
return PICout::withExternalBuffer(buffer, id_by_cat.value(cat), PICoutManipulators::AddSpaces);
|
||||
}
|
||||
|
||||
|
||||
void PILog::enqueue(const PIString & msg, Category cat) {
|
||||
void PILog::enqueue(const PIString & msg, Level cat) {
|
||||
if (log_file.isClosed()) return;
|
||||
auto t = PIDateTime::fromSystemTime(PISystemTime::current());
|
||||
PIMutexLocker ml(log_mutex);
|
||||
@@ -166,7 +172,7 @@ void PILog::enqueue(const PIString & msg, Category cat) {
|
||||
|
||||
|
||||
PIString PILog::entryToString(const Entry & e) const {
|
||||
static PIStringList categories{"debug", "warn ", "error"};
|
||||
static PIStringList categories{"error", "warn ", "info ", "debug"};
|
||||
PIString t = e.time.toString(timestamp_format);
|
||||
PIString ret = line_format_p;
|
||||
ret.replace("${t}", t).replace("${c}", categories[static_cast<int>(e.cat)]).replace("${m}", e.msg);
|
||||
@@ -175,7 +181,7 @@ PIString PILog::entryToString(const Entry & e) const {
|
||||
|
||||
|
||||
void PILog::newFile() {
|
||||
PIString aname = app_name;
|
||||
PIString aname = log_name;
|
||||
if (aname.isNotEmpty()) aname += "__";
|
||||
log_file.open(log_dir + "/" + aname + PIDateTime::current().toString("yyyy_MM_dd__hh_mm_ss") + ".log." +
|
||||
PIString::fromNumber(++part_number),
|
||||
@@ -205,6 +211,9 @@ void PILog::run() {
|
||||
log_mutex.unlock();
|
||||
auto str = entryToString(qi);
|
||||
log_ts << str << "\n";
|
||||
piCout << str;
|
||||
if (qi.cat == Level::Error)
|
||||
piCerr << str;
|
||||
else
|
||||
piCout << str;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,11 +41,18 @@ public:
|
||||
PILog();
|
||||
~PILog();
|
||||
|
||||
enum class Level {
|
||||
Error,
|
||||
Warning,
|
||||
Info,
|
||||
Debug,
|
||||
};
|
||||
|
||||
//! \~english Returns prefix for filename.
|
||||
PIString applicationName() const { return app_name; }
|
||||
PIString logName() const { return log_name; }
|
||||
|
||||
//! \~english Set prefix for filename. Should be set \b before \a setDir()!
|
||||
void setApplicationName(const PIString & n) { app_name = n; }
|
||||
void setLogName(const PIString & n) { log_name = n; }
|
||||
|
||||
|
||||
//! \~english Returns directory for log files.
|
||||
@@ -75,27 +82,30 @@ public:
|
||||
//! \~english Set line format. "t" is timestamp, "c" is category and "m" is message. Default is "t - c: m".
|
||||
void setLineFormat(const PIString & f);
|
||||
|
||||
PICout debug(PIObject * context = nullptr);
|
||||
PICout warning(PIObject * context = nullptr);
|
||||
|
||||
//! \~english Returns maximum level.
|
||||
Level level() const { return max_level; }
|
||||
|
||||
//! \~english Set maximum level. All levels greater than \"l\" will be ignored. Default if \a Level::Debug.
|
||||
void setLevel(Level l);
|
||||
|
||||
|
||||
PICout error(PIObject * context = nullptr);
|
||||
PICout warning(PIObject * context = nullptr);
|
||||
PICout info(PIObject * context = nullptr);
|
||||
PICout debug(PIObject * context = nullptr);
|
||||
|
||||
//! \~english Write all queued lines and stop. Also called in destructor.
|
||||
void stop();
|
||||
|
||||
private:
|
||||
enum class Category {
|
||||
Debug,
|
||||
Warning,
|
||||
Error
|
||||
};
|
||||
|
||||
EVENT_HANDLER2(void, coutDone, int, id, PIString *, buff);
|
||||
|
||||
PICout makePICout(PIObject * context, Category cat);
|
||||
void enqueue(const PIString & msg, Category cat = Category::Debug);
|
||||
PICout makePICout(PIObject * context, Level cat);
|
||||
void enqueue(const PIString & msg, Level cat = Level::Debug);
|
||||
|
||||
struct Entry {
|
||||
Category cat;
|
||||
Level cat;
|
||||
PIDateTime time;
|
||||
PIString msg;
|
||||
};
|
||||
@@ -104,14 +114,15 @@ private:
|
||||
void newFile();
|
||||
void run() override;
|
||||
|
||||
PIMutex log_mutex, cout_mutex;
|
||||
PIMutex log_mutex;
|
||||
PIFile log_file;
|
||||
PIIOTextStream log_ts;
|
||||
PITimeMeasurer split_tm;
|
||||
PISystemTime split_time;
|
||||
PIString log_dir, timestamp_format, line_format, line_format_p, app_name;
|
||||
PIString log_dir, timestamp_format, line_format, line_format_p, log_name;
|
||||
PIQueue<Entry> queue;
|
||||
PIMap<int, Category> cout_cat_by_id;
|
||||
PIMap<Level, int> id_by_cat;
|
||||
Level max_level = Level::Debug;
|
||||
int part_number = -1, cout_id = -1;
|
||||
};
|
||||
|
||||
|
||||
@@ -1383,7 +1383,7 @@ public:
|
||||
if (v.isEmpty()) return *this;
|
||||
#ifndef NDEBUG
|
||||
if (&v == this) {
|
||||
printf("error with PIDeque<%s>::insert\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIDeque<%s>::insert\n", __PIP_TYPENAME__(T));
|
||||
}
|
||||
#endif
|
||||
assert(&v != this);
|
||||
@@ -1738,7 +1738,7 @@ public:
|
||||
if (v.isEmpty()) return *this;
|
||||
#ifndef NDEBUG
|
||||
if (&v == this) {
|
||||
printf("error with PIDeque<%s>::append\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIDeque<%s>::append\n", __PIP_TYPENAME__(T));
|
||||
}
|
||||
#endif
|
||||
assert(&v != this);
|
||||
@@ -2400,7 +2400,7 @@ public:
|
||||
if (isEmpty()) return ret;
|
||||
#ifndef NDEBUG
|
||||
if (rows * cols != pid_size) {
|
||||
printf("error with PIDeque<%s>::reshape\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIDeque<%s>::reshape\n", __PIP_TYPENAME__(T));
|
||||
}
|
||||
#endif
|
||||
assert(rows * cols == pid_size);
|
||||
@@ -2689,7 +2689,7 @@ private:
|
||||
T * p_d = reinterpret_cast<T *>(realloc(reinterpret_cast<void *>(pid_data), as * sizeof(T)));
|
||||
#ifndef NDEBUG
|
||||
if (!p_d) {
|
||||
printf("error with PIDeque<%s>::alloc\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIDeque<%s>::alloc\n", __PIP_TYPENAME__(T));
|
||||
}
|
||||
#endif
|
||||
assert(p_d);
|
||||
|
||||
@@ -355,7 +355,7 @@ public:
|
||||
inline PIMap<Key, T> & operator<<(const PIMap<Key, T> & other) {
|
||||
#ifndef NDEBUG
|
||||
if (&other == this) {
|
||||
printf("error with PIMap<%s, %s>::<<\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIMap<%s, %s>::<<\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T));
|
||||
}
|
||||
#endif
|
||||
assert(&other != this);
|
||||
|
||||
@@ -1341,7 +1341,7 @@ public:
|
||||
if (v.isEmpty()) return *this;
|
||||
#ifndef NDEBUG
|
||||
if (&v == this) {
|
||||
printf("error with PIVector<%s>::insert\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector<%s>::insert\n", __PIP_TYPENAME__(T));
|
||||
}
|
||||
#endif
|
||||
assert(&v != this);
|
||||
@@ -1663,7 +1663,7 @@ public:
|
||||
if (v.isEmpty()) return *this;
|
||||
#ifndef NDEBUG
|
||||
if (&v == this) {
|
||||
printf("error with PIVector<%s>::push_back\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector<%s>::push_back\n", __PIP_TYPENAME__(T));
|
||||
}
|
||||
#endif
|
||||
assert(&v != this);
|
||||
@@ -2296,7 +2296,7 @@ public:
|
||||
inline PIVector<PIVector<T>> reshape(size_t rows, size_t cols, ReshapeOrder order = ReshapeByRow) const {
|
||||
#ifndef NDEBUG
|
||||
if (rows * cols != piv_size) {
|
||||
printf("error with PIVector<%s>::reshape\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector<%s>::reshape\n", __PIP_TYPENAME__(T));
|
||||
}
|
||||
#endif
|
||||
assert(rows * cols == piv_size);
|
||||
@@ -2565,7 +2565,7 @@ private:
|
||||
T * p_d = reinterpret_cast<T *>(realloc(reinterpret_cast<void *>(piv_data), as * sizeof(T)));
|
||||
#ifndef NDEBUG
|
||||
if (!p_d) {
|
||||
printf("error with PIVector<%s>::alloc\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector<%s>::alloc\n", __PIP_TYPENAME__(T));
|
||||
}
|
||||
#endif
|
||||
assert(p_d);
|
||||
|
||||
@@ -141,7 +141,7 @@ PIString & PICout::__string__() {
|
||||
return *ret;
|
||||
}
|
||||
|
||||
PICout::OutputDevices PICout::devs = PICout::StdOut;
|
||||
PICout::OutputDevices PICout::devs = PICout::Console;
|
||||
|
||||
PRIVATE_DEFINITION_START(PICout)
|
||||
PIStack<PICoutControls> cos_;
|
||||
@@ -158,35 +158,53 @@ WORD PICout::__Private__::dattr = 0;
|
||||
DWORD PICout::__Private__::smode = 0;
|
||||
#endif
|
||||
|
||||
PICout::PICout(int controls): fo_(true), cc_(false), fc_(false), act_(true), cnb_(10), co_(controls) {
|
||||
buffer_ = nullptr;
|
||||
|
||||
std::ostream & getStdStream(PICoutManipulators::PICoutStdStream s) {
|
||||
switch (s) {
|
||||
case PICoutManipulators::StdOut: return std::cout;
|
||||
case PICoutManipulators::StdErr: return std::cerr;
|
||||
default: break;
|
||||
}
|
||||
return std::cout;
|
||||
}
|
||||
|
||||
std::wostream & getStdWStream(PICoutManipulators::PICoutStdStream s) {
|
||||
switch (s) {
|
||||
case PICoutManipulators::StdOut: return std::wcout;
|
||||
case PICoutManipulators::StdErr: return std::wcerr;
|
||||
default: break;
|
||||
}
|
||||
return std::wcout;
|
||||
}
|
||||
|
||||
|
||||
PICout::PICout(int controls, PICoutStdStream stream): ctrl_(controls), stream_(stream) {
|
||||
init();
|
||||
}
|
||||
|
||||
PICout::PICout(bool active): fo_(true), cc_(false), fc_(false), act_(active), cnb_(10), co_(PICoutManipulators::DefaultControls) {
|
||||
buffer_ = nullptr;
|
||||
if (act_) init();
|
||||
PICout::PICout(bool active, PICoutStdStream stream): actve_(active), stream_(stream) {
|
||||
if (actve_) init();
|
||||
}
|
||||
|
||||
|
||||
PICout::PICout(const PICout & other)
|
||||
: fo_(other.fo_)
|
||||
, cc_(true)
|
||||
, fc_(false)
|
||||
, act_(other.act_)
|
||||
, cnb_(other.cnb_)
|
||||
, attr_(other.attr_)
|
||||
: first_out_(other.first_out_)
|
||||
, is_copy_(true)
|
||||
, actve_(other.actve_)
|
||||
, int_base_(other.int_base_)
|
||||
, win_attr_(other.win_attr_)
|
||||
, id_(other.id_)
|
||||
, buffer_(other.buffer_)
|
||||
, co_(other.co_) {}
|
||||
, ctrl_(other.ctrl_)
|
||||
, stream_(other.stream_) {}
|
||||
|
||||
|
||||
PICout::~PICout() {
|
||||
if (!act_) return;
|
||||
if (fc_) applyFormat(PICoutManipulators::Default);
|
||||
if (cc_) return;
|
||||
if (!actve_) return;
|
||||
if (format_changed_) applyFormat(PICoutManipulators::Default);
|
||||
if (is_copy_) return;
|
||||
newLine();
|
||||
if ((co_ & NoLock) != NoLock) {
|
||||
if ((ctrl_ & NoLock) != NoLock) {
|
||||
PICout::__mutex__().unlock();
|
||||
}
|
||||
if (buffer_) {
|
||||
@@ -196,7 +214,7 @@ PICout::~PICout() {
|
||||
|
||||
|
||||
PICout & PICout::operator<<(PICoutAction v) {
|
||||
if (!act_) return *this;
|
||||
if (!actve_) return *this;
|
||||
#ifdef WINDOWS
|
||||
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||
COORD coord;
|
||||
@@ -204,12 +222,12 @@ PICout & PICout::operator<<(PICoutAction v) {
|
||||
#endif
|
||||
switch (v) {
|
||||
case PICoutManipulators::Flush:
|
||||
if (!buffer_ && isOutputDeviceActive(StdOut)) {
|
||||
std::cout << std::flush;
|
||||
if (!buffer_ && isOutputDeviceActive(Console)) {
|
||||
getStdStream(stream_) << std::flush;
|
||||
}
|
||||
break;
|
||||
case PICoutManipulators::Backspace:
|
||||
if (isOutputDeviceActive(StdOut)) {
|
||||
if (isOutputDeviceActive(Console)) {
|
||||
#ifdef WINDOWS
|
||||
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
|
||||
coord = sbi.dwCursorPosition;
|
||||
@@ -223,7 +241,7 @@ PICout & PICout::operator<<(PICoutAction v) {
|
||||
}
|
||||
break;
|
||||
case PICoutManipulators::ShowCursor:
|
||||
if (isOutputDeviceActive(StdOut)) {
|
||||
if (isOutputDeviceActive(Console)) {
|
||||
#ifdef WINDOWS
|
||||
GetConsoleCursorInfo(__Private__::hOut, &curinfo);
|
||||
curinfo.bVisible = true;
|
||||
@@ -234,7 +252,7 @@ PICout & PICout::operator<<(PICoutAction v) {
|
||||
}
|
||||
break;
|
||||
case PICoutManipulators::HideCursor:
|
||||
if (isOutputDeviceActive(StdOut)) {
|
||||
if (isOutputDeviceActive(Console)) {
|
||||
#ifdef WINDOWS
|
||||
GetConsoleCursorInfo(__Private__::hOut, &curinfo);
|
||||
curinfo.bVisible = false;
|
||||
@@ -245,7 +263,7 @@ PICout & PICout::operator<<(PICoutAction v) {
|
||||
}
|
||||
break;
|
||||
case PICoutManipulators::ClearLine:
|
||||
if (isOutputDeviceActive(StdOut)) {
|
||||
if (isOutputDeviceActive(Console)) {
|
||||
#ifdef WINDOWS
|
||||
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
|
||||
coord = sbi.dwCursorPosition;
|
||||
@@ -266,7 +284,7 @@ PICout & PICout::operator<<(PICoutAction v) {
|
||||
}
|
||||
break;
|
||||
case PICoutManipulators::ClearScreen:
|
||||
if (isOutputDeviceActive(StdOut)) {
|
||||
if (isOutputDeviceActive(Console)) {
|
||||
#ifdef WINDOWS
|
||||
/// TODO : wondows ClearScreen !!!
|
||||
#else
|
||||
@@ -282,12 +300,31 @@ PICout & PICout::operator<<(PICoutAction v) {
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::setControl(PICoutManipulators::PICoutControl c, bool on) {
|
||||
ctrl_.setFlag(c, on);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::setControls(PICoutManipulators::PICoutControls c) {
|
||||
ctrl_ = c;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::saveAndSetControls(PICoutManipulators::PICoutControls c) {
|
||||
saveControls();
|
||||
ctrl_ = c;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::operator<<(PICoutManipulators::PICoutFormat v) {
|
||||
switch (v) {
|
||||
case PICoutManipulators::Bin: cnb_ = 2; break;
|
||||
case PICoutManipulators::Oct: cnb_ = 8; break;
|
||||
case PICoutManipulators::Dec: cnb_ = 10; break;
|
||||
case PICoutManipulators::Hex: cnb_ = 16; break;
|
||||
case PICoutManipulators::Bin: int_base_ = 2; break;
|
||||
case PICoutManipulators::Oct: int_base_ = 8; break;
|
||||
case PICoutManipulators::Dec: int_base_ = 10; break;
|
||||
case PICoutManipulators::Hex: int_base_ = 16; break;
|
||||
default: applyFormat(v);
|
||||
};
|
||||
return *this;
|
||||
@@ -295,10 +332,10 @@ PICout & PICout::operator<<(PICoutManipulators::PICoutFormat v) {
|
||||
|
||||
|
||||
PICout & PICout::operator<<(PIFlags<PICoutManipulators::PICoutFormat> v) {
|
||||
if (v[PICoutManipulators::Bin]) cnb_ = 2;
|
||||
if (v[PICoutManipulators::Oct]) cnb_ = 8;
|
||||
if (v[PICoutManipulators::Dec]) cnb_ = 10;
|
||||
if (v[PICoutManipulators::Hex]) cnb_ = 16;
|
||||
if (v[PICoutManipulators::Bin]) int_base_ = 2;
|
||||
if (v[PICoutManipulators::Oct]) int_base_ = 8;
|
||||
if (v[PICoutManipulators::Dec]) int_base_ = 10;
|
||||
if (v[PICoutManipulators::Hex]) int_base_ = 16;
|
||||
if (v[PICoutManipulators::Bold]) applyFormat(PICoutManipulators::Bold);
|
||||
if (v[PICoutManipulators::Faint]) applyFormat(PICoutManipulators::Faint);
|
||||
if (v[PICoutManipulators::Italic]) applyFormat(PICoutManipulators::Italic);
|
||||
@@ -324,31 +361,78 @@ PICout & PICout::operator<<(PIFlags<PICoutManipulators::PICoutFormat> v) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
#define PIINTCOUT(v) \
|
||||
{ \
|
||||
if (!act_) return *this; \
|
||||
space(); \
|
||||
if (cnb_ == 10) { \
|
||||
if (buffer_) { \
|
||||
(*buffer_) += PIString::fromNumber(v); \
|
||||
} else { \
|
||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v); \
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() += PIString::fromNumber(v); \
|
||||
} \
|
||||
} else \
|
||||
write(PIString::fromNumber(v, cnb_)); \
|
||||
return *this; \
|
||||
|
||||
void PICout::stdoutPIString(const PIString & str, PICoutStdStream s) {
|
||||
#ifdef HAS_LOCALE
|
||||
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> utf8conv;
|
||||
getStdStream(s) << utf8conv.to_bytes((char16_t *)&(const_cast<PIString &>(str).front()),
|
||||
(char16_t *)&(const_cast<PIString &>(str).front()) + str.size());
|
||||
#else
|
||||
for (PIChar c: str)
|
||||
getStdWStream(s).put(c.toWChar());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::write(const char * str, int len) {
|
||||
if (!actve_ || !str) return *this;
|
||||
if (buffer_) {
|
||||
buffer_->append(PIString(str, len));
|
||||
} else {
|
||||
if (isOutputDeviceActive(Console)) getStdStream(stream_).write(str, len);
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__().append(PIString(str, len));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::write(const PIString & s) {
|
||||
if (!actve_) return *this;
|
||||
if (buffer_) {
|
||||
buffer_->append(s);
|
||||
} else {
|
||||
if (isOutputDeviceActive(Console)) stdoutPIString(s, stream_);
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__().append(s);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void PICout::writeChar(char c) {
|
||||
if (buffer_) {
|
||||
buffer_->append(c);
|
||||
} else {
|
||||
if (isOutputDeviceActive(Console)) getStdStream(stream_) << c;
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__().append(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define PIINTCOUT(v) \
|
||||
{ \
|
||||
if (!actve_) return *this; \
|
||||
space(); \
|
||||
if (int_base_ == 10) { \
|
||||
if (buffer_) { \
|
||||
(*buffer_) += PIString::fromNumber(v); \
|
||||
} else { \
|
||||
if (isOutputDeviceActive(Console)) getStdStream(stream_) << (v); \
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += PIString::fromNumber(v); \
|
||||
} \
|
||||
} else \
|
||||
write(PIString::fromNumber(v, int_base_)); \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
#define PIFLOATCOUT(v) \
|
||||
{ \
|
||||
if (buffer_) { \
|
||||
(*buffer_) += PIString::fromNumber(v, 'g'); \
|
||||
} else { \
|
||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v); \
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() += PIString::fromNumber(v, 'g'); \
|
||||
} \
|
||||
} \
|
||||
#define PIFLOATCOUT(v) \
|
||||
{ \
|
||||
if (buffer_) { \
|
||||
(*buffer_) += PIString::fromNumber(v, 'g'); \
|
||||
} else { \
|
||||
if (isOutputDeviceActive(Console)) getStdStream(stream_) << (v); \
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += PIString::fromNumber(v, 'g'); \
|
||||
} \
|
||||
} \
|
||||
return *this;
|
||||
|
||||
|
||||
@@ -361,7 +445,7 @@ PICout & PICout::operator<<(const PIString & v) {
|
||||
}
|
||||
|
||||
PICout & PICout::operator<<(const char * v) {
|
||||
if (!act_ || !v) return *this;
|
||||
if (!actve_ || !v) return *this;
|
||||
if (v[0] == '\0') return *this;
|
||||
space();
|
||||
quote();
|
||||
@@ -371,7 +455,7 @@ PICout & PICout::operator<<(const char * v) {
|
||||
}
|
||||
|
||||
PICout & PICout::operator<<(bool v) {
|
||||
if (!act_) return *this;
|
||||
if (!actve_) return *this;
|
||||
space();
|
||||
if (v)
|
||||
write("true");
|
||||
@@ -381,7 +465,7 @@ PICout & PICout::operator<<(bool v) {
|
||||
}
|
||||
|
||||
PICout & PICout::operator<<(char v) {
|
||||
if (!act_) return *this;
|
||||
if (!actve_) return *this;
|
||||
space();
|
||||
write(v);
|
||||
return *this;
|
||||
@@ -406,32 +490,32 @@ PICout & PICout::operator<<(llong v){PIINTCOUT(v)}
|
||||
PICout & PICout::operator<<(ullong v){PIINTCOUT(v)}
|
||||
|
||||
PICout & PICout::operator<<(float v) {
|
||||
if (!act_) return *this;
|
||||
if (!actve_) return *this;
|
||||
space();
|
||||
PIFLOATCOUT(v)
|
||||
}
|
||||
|
||||
PICout & PICout::operator<<(double v) {
|
||||
if (!act_) return *this;
|
||||
if (!actve_) return *this;
|
||||
space();
|
||||
PIFLOATCOUT(v)
|
||||
}
|
||||
|
||||
PICout & PICout::operator<<(ldouble v) {
|
||||
if (!act_) return *this;
|
||||
if (!actve_) return *this;
|
||||
space();
|
||||
PIFLOATCOUT(v)
|
||||
}
|
||||
|
||||
PICout & PICout::operator<<(const void * v) {
|
||||
if (!act_) return *this;
|
||||
if (!actve_) return *this;
|
||||
space();
|
||||
write("0x" + PIString::fromNumber(ullong(v), 16));
|
||||
return *this;
|
||||
}
|
||||
|
||||
PICout & PICout::operator<<(const PIObject * v) {
|
||||
if (!act_) return *this;
|
||||
if (!actve_) return *this;
|
||||
space();
|
||||
if (v == 0)
|
||||
write("PIObject*(0x0)");
|
||||
@@ -443,74 +527,38 @@ PICout & PICout::operator<<(const PIObject * v) {
|
||||
}
|
||||
|
||||
PICout & PICout::operator<<(PICoutSpecialChar v) {
|
||||
if (!act_) return *this;
|
||||
if (!actve_) return *this;
|
||||
switch (v) {
|
||||
case Null:
|
||||
if (buffer_) {
|
||||
(*buffer_) += PIChar();
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << char(0);
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += PIChar();
|
||||
}
|
||||
break;
|
||||
case Null: writeChar(char(0)); break;
|
||||
case NewLine:
|
||||
if (buffer_) {
|
||||
(*buffer_) += "\n";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '\n';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\n";
|
||||
}
|
||||
fo_ = true;
|
||||
break;
|
||||
case Tab:
|
||||
if (buffer_) {
|
||||
(*buffer_) += "\t";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '\t';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\t";
|
||||
}
|
||||
first_out_ = true;
|
||||
writeChar('\n');
|
||||
break;
|
||||
case Tab: writeChar('\t'); break;
|
||||
case Esc:
|
||||
#ifdef CC_VC
|
||||
if (buffer_) {
|
||||
(*buffer_) += PIChar(27);
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << char(27);
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += PIChar(27);
|
||||
}
|
||||
writeChar(char(27));
|
||||
#else
|
||||
if (buffer_) {
|
||||
(*buffer_) += "\e";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '\e';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\e";
|
||||
}
|
||||
writeChar('\e');
|
||||
#endif
|
||||
break;
|
||||
case Quote:
|
||||
if (buffer_) {
|
||||
(*buffer_) += "\"";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '"';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\"";
|
||||
}
|
||||
break;
|
||||
case Quote: writeChar('"'); break;
|
||||
};
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::saveControls() {
|
||||
if (!act_) return *this;
|
||||
PRIVATE->cos_.push(co_);
|
||||
if (!actve_) return *this;
|
||||
PRIVATE->cos_.push(ctrl_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::restoreControls() {
|
||||
if (!act_) return *this;
|
||||
if (!actve_) return *this;
|
||||
if (!PRIVATE->cos_.isEmpty()) {
|
||||
co_ = PRIVATE->cos_.top();
|
||||
ctrl_ = PRIVATE->cos_.top();
|
||||
PRIVATE->cos_.pop();
|
||||
}
|
||||
return *this;
|
||||
@@ -524,16 +572,11 @@ PICout & PICout::restoreControls() {
|
||||
//! Добавляет пробел если это не первый вывод и установлен флаг \a AddSpaces
|
||||
//! \~\sa \a quote(), \a newLine()
|
||||
PICout & PICout::space() {
|
||||
if (!act_) return *this;
|
||||
if (!fo_ && co_[AddSpaces]) {
|
||||
if (buffer_) {
|
||||
(*buffer_) += " ";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << ' ';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += " ";
|
||||
}
|
||||
if (!actve_) return *this;
|
||||
if (!first_out_ && ctrl_[AddSpaces]) {
|
||||
writeChar(' ');
|
||||
}
|
||||
fo_ = false;
|
||||
first_out_ = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -544,16 +587,11 @@ PICout & PICout::space() {
|
||||
//! Добавляет кавычки если установлен флаг \a AddQuotes
|
||||
//! \~\sa \a space(), \a newLine()
|
||||
PICout & PICout::quote() {
|
||||
if (!act_) return *this;
|
||||
if (co_[AddQuotes]) {
|
||||
if (buffer_) {
|
||||
(*buffer_) += "\"";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '"';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\"";
|
||||
}
|
||||
if (!actve_) return *this;
|
||||
if (ctrl_[AddQuotes]) {
|
||||
writeChar('"');
|
||||
}
|
||||
fo_ = false;
|
||||
first_out_ = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -564,74 +602,28 @@ PICout & PICout::quote() {
|
||||
//! Добавляет новую строку если установлен флаг \a AddNewLine
|
||||
//! \~\sa \a space(), \a quote()
|
||||
PICout & PICout::newLine() {
|
||||
if (!act_) return *this;
|
||||
if (co_[AddNewLine]) {
|
||||
if (buffer_) {
|
||||
(*buffer_) += "\n";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << std::endl;
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\n";
|
||||
}
|
||||
if (!actve_) return *this;
|
||||
if (ctrl_[AddNewLine]) {
|
||||
writeChar('\n');
|
||||
}
|
||||
fo_ = false;
|
||||
first_out_ = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::write(char c) {
|
||||
if (!act_) return *this;
|
||||
if (buffer_) {
|
||||
buffer_->append(c);
|
||||
} else {
|
||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << c;
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__().append(c);
|
||||
}
|
||||
if (!actve_) return *this;
|
||||
writeChar(c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::write(const char * str) {
|
||||
if (!act_ || !str) return *this;
|
||||
if (!actve_ || !str) return *this;
|
||||
return write(str, strlen(str));
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::write(const char * str, int len) {
|
||||
if (!act_ || !str) return *this;
|
||||
if (buffer_) {
|
||||
buffer_->append(PIString(str, len));
|
||||
} else {
|
||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout.write(str, len);
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__().append(PIString(str, len));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::write(const PIString & s) {
|
||||
if (!act_) return *this;
|
||||
if (buffer_) {
|
||||
buffer_->append(s);
|
||||
} else {
|
||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) stdoutPIString(s);
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__().append(s);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void PICout::stdoutPIString(const PIString & s) {
|
||||
#ifdef HAS_LOCALE
|
||||
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> utf8conv;
|
||||
std::cout << utf8conv.to_bytes((char16_t *)&(const_cast<PIString &>(s).front()),
|
||||
(char16_t *)&(const_cast<PIString &>(s).front()) + s.size());
|
||||
#else
|
||||
for (PIChar c: s)
|
||||
std::wcout.put(c.toWChar());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PICout::init() {
|
||||
#ifdef WINDOWS
|
||||
if (__Private__::hOut == 0) {
|
||||
@@ -640,19 +632,18 @@ void PICout::init() {
|
||||
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
|
||||
__Private__::dattr = sbi.wAttributes;
|
||||
}
|
||||
attr_ = __Private__::dattr;
|
||||
win_attr_ = __Private__::dattr;
|
||||
#endif
|
||||
id_ = 0;
|
||||
if ((co_ & NoLock) != NoLock) {
|
||||
if ((ctrl_ & NoLock) != NoLock) {
|
||||
PICout::__mutex__().lock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PICout::applyFormat(PICoutFormat f) {
|
||||
if (!act_) return;
|
||||
if (buffer_ || !isOutputDeviceActive(StdOut)) return;
|
||||
fc_ = true;
|
||||
if (!actve_) return;
|
||||
if (buffer_ || !isOutputDeviceActive(Console)) return;
|
||||
format_changed_ = true;
|
||||
#ifdef WINDOWS
|
||||
static int mask_fore = ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
static int mask_back = ~(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
|
||||
@@ -661,28 +652,28 @@ void PICout::applyFormat(PICoutFormat f) {
|
||||
case Oct:
|
||||
case Dec:
|
||||
case Hex: break;
|
||||
case PICoutManipulators::Bold: attr_ |= FOREGROUND_INTENSITY; break;
|
||||
case PICoutManipulators::Underline: attr_ |= COMMON_LVB_UNDERSCORE; break;
|
||||
case PICoutManipulators::Black: attr_ = (attr_ & mask_fore); break;
|
||||
case PICoutManipulators::Red: attr_ = (attr_ & mask_fore) | FOREGROUND_RED; break;
|
||||
case PICoutManipulators::Green: attr_ = (attr_ & mask_fore) | FOREGROUND_GREEN; break;
|
||||
case PICoutManipulators::Blue: attr_ = (attr_ & mask_fore) | FOREGROUND_BLUE; break;
|
||||
case PICoutManipulators::Yellow: attr_ = (attr_ & mask_fore) | FOREGROUND_RED | FOREGROUND_GREEN; break;
|
||||
case PICoutManipulators::Magenta: attr_ = (attr_ & mask_fore) | FOREGROUND_RED | FOREGROUND_BLUE; break;
|
||||
case PICoutManipulators::Cyan: attr_ = (attr_ & mask_fore) | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
|
||||
case PICoutManipulators::White: attr_ = (attr_ & mask_fore) | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
|
||||
case PICoutManipulators::BackBlack: attr_ = (attr_ & mask_back); break;
|
||||
case PICoutManipulators::BackRed: attr_ = (attr_ & mask_back) | BACKGROUND_RED; break;
|
||||
case PICoutManipulators::BackGreen: attr_ = (attr_ & mask_back) | BACKGROUND_GREEN; break;
|
||||
case PICoutManipulators::BackBlue: attr_ = (attr_ & mask_back) | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::BackYellow: attr_ = (attr_ & mask_back) | BACKGROUND_RED | BACKGROUND_GREEN; break;
|
||||
case PICoutManipulators::BackMagenta: attr_ = (attr_ & mask_back) | BACKGROUND_RED | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::BackCyan: attr_ = (attr_ & mask_back) | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::BackWhite: attr_ = (attr_ & mask_back) | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::Default: attr_ = __Private__::dattr; break;
|
||||
case PICoutManipulators::Bold: win_attr_ |= FOREGROUND_INTENSITY; break;
|
||||
case PICoutManipulators::Underline: win_attr_ |= COMMON_LVB_UNDERSCORE; break;
|
||||
case PICoutManipulators::Black: win_attr_ = (win_attr_ & mask_fore); break;
|
||||
case PICoutManipulators::Red: win_attr_ = (win_attr_ & mask_fore) | FOREGROUND_RED; break;
|
||||
case PICoutManipulators::Green: win_attr_ = (win_attr_ & mask_fore) | FOREGROUND_GREEN; break;
|
||||
case PICoutManipulators::Blue: win_attr_ = (win_attr_ & mask_fore) | FOREGROUND_BLUE; break;
|
||||
case PICoutManipulators::Yellow: win_attr_ = (win_attr_ & mask_fore) | FOREGROUND_RED | FOREGROUND_GREEN; break;
|
||||
case PICoutManipulators::Magenta: win_attr_ = (win_attr_ & mask_fore) | FOREGROUND_RED | FOREGROUND_BLUE; break;
|
||||
case PICoutManipulators::Cyan: win_attr_ = (win_attr_ & mask_fore) | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
|
||||
case PICoutManipulators::White: win_attr_ = (win_attr_ & mask_fore) | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
|
||||
case PICoutManipulators::BackBlack: win_attr_ = (win_attr_ & mask_back); break;
|
||||
case PICoutManipulators::BackRed: win_attr_ = (win_attr_ & mask_back) | BACKGROUND_RED; break;
|
||||
case PICoutManipulators::BackGreen: win_attr_ = (win_attr_ & mask_back) | BACKGROUND_GREEN; break;
|
||||
case PICoutManipulators::BackBlue: win_attr_ = (win_attr_ & mask_back) | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::BackYellow: win_attr_ = (win_attr_ & mask_back) | BACKGROUND_RED | BACKGROUND_GREEN; break;
|
||||
case PICoutManipulators::BackMagenta: win_attr_ = (win_attr_ & mask_back) | BACKGROUND_RED | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::BackCyan: win_attr_ = (win_attr_ & mask_back) | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::BackWhite: win_attr_ = (win_attr_ & mask_back) | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
|
||||
case PICoutManipulators::Default: win_attr_ = __Private__::dattr; break;
|
||||
default: break;
|
||||
}
|
||||
SetConsoleTextAttribute(__Private__::hOut, attr_);
|
||||
SetConsoleTextAttribute(__Private__::hOut, win_attr_);
|
||||
#else
|
||||
switch (f) {
|
||||
case Bin:
|
||||
@@ -761,3 +752,8 @@ PICout PICout::withExternalBuffer(PIString * buffer, int id, PIFlags<PICoutManip
|
||||
c.id_ = id;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
int PICout::registerExternalBufferID() {
|
||||
return Notifier::instance()->new_id.fetch_add(1);
|
||||
}
|
||||
|
||||
@@ -40,10 +40,14 @@
|
||||
# define piCoutObj
|
||||
|
||||
#else
|
||||
# define piCout PICout(piDebug)
|
||||
# define piCoutObj \
|
||||
PICout(piDebug && debug()) << (PIStringAscii("[") + className() + \
|
||||
(name().isEmpty() ? "]" : PIStringAscii(" \"") + name() + PIStringAscii("\"]")))
|
||||
# define piCout PICout(piDebug, PICoutManipulators::StdOut)
|
||||
# define piCoutObj \
|
||||
PICout(piDebug && debug(), PICoutManipulators::StdOut) \
|
||||
<< (PIStringAscii("[") + className() + (name().isEmpty() ? "]" : PIStringAscii(" \"") + name() + PIStringAscii("\"]")))
|
||||
# define piCerr PICout(piDebug, PICoutManipulators::StdErr)
|
||||
# define piCerrObj \
|
||||
PICout(piDebug && debug(), PICoutManipulators::StdErr) \
|
||||
<< (PIStringAscii("[") + className() + (name().isEmpty() ? "]" : PIStringAscii(" \"") + name() + PIStringAscii("\"]")))
|
||||
#endif
|
||||
|
||||
|
||||
@@ -55,6 +59,7 @@ class PIObject;
|
||||
//! \~russian Пространство имен содержит перечисления для контроля PICout
|
||||
namespace PICoutManipulators {
|
||||
|
||||
|
||||
//! \~english Enum contains special characters
|
||||
//! \~russian Перечисление со спецсимволами
|
||||
enum PICoutSpecialChar {
|
||||
@@ -65,6 +70,7 @@ enum PICoutSpecialChar {
|
||||
Quote /*! \~english Quote character, '\"' \~russian Кавычки, '\"' */
|
||||
};
|
||||
|
||||
|
||||
//! \~english Enum contains immediate action
|
||||
//! \~russian Перечисление с немедленными действиями
|
||||
enum PICoutAction {
|
||||
@@ -79,6 +85,7 @@ enum PICoutAction {
|
||||
restoreControl() */
|
||||
};
|
||||
|
||||
|
||||
//! \~english Enum contains control of PICout
|
||||
//! \~russian Перечисление с управлением PICout
|
||||
enum PICoutControl {
|
||||
@@ -91,6 +98,7 @@ enum PICoutControl {
|
||||
NoLock /*! \~english Don`t use mutex for output \~russian Не использовать мьютекс при выводе */ = 0x100,
|
||||
};
|
||||
|
||||
|
||||
//! \~english Enum contains output format
|
||||
//! \~russian Перечисление с форматом вывода
|
||||
enum PICoutFormat {
|
||||
@@ -122,7 +130,17 @@ enum PICoutFormat {
|
||||
Default /*! \~english Default format \~russian Формат по умолчанию */ = 0x4000000
|
||||
};
|
||||
|
||||
|
||||
//! \~english Enum contains console streams
|
||||
//! \~russian Перечисление с потоками консоли
|
||||
enum PICoutStdStream {
|
||||
StdOut /*! \~english Standard output stream \~russian Стандартный поток вывода */ = 0,
|
||||
StdErr /*! \~english Standard error stream \~russian Стандартный поток ошибок */ = 1,
|
||||
};
|
||||
|
||||
|
||||
typedef PIFlags<PICoutControl> PICoutControls;
|
||||
|
||||
} // namespace PICoutManipulators
|
||||
|
||||
|
||||
@@ -134,11 +152,11 @@ class PIP_EXPORT PICout {
|
||||
public:
|
||||
//! \~english Default constructor with default features (AddSpaces and AddNewLine)
|
||||
//! \~russian Конструктор по умолчанию (AddSpaces и AddNewLine)
|
||||
PICout(int controls = PICoutManipulators::DefaultControls);
|
||||
PICout(int controls = PICoutManipulators::DefaultControls, PICoutManipulators::PICoutStdStream stream = PICoutManipulators::StdOut);
|
||||
|
||||
//! \~english Construct with default features (AddSpaces and AddNewLine), but if \"active\" is false does nothing
|
||||
//! \~russian Конструктор по умолчанию (AddSpaces и AddNewLine), но если не \"active\" то будет неактивным
|
||||
PICout(bool active);
|
||||
PICout(bool active, PICoutManipulators::PICoutStdStream stream = PICoutManipulators::StdOut);
|
||||
|
||||
PICout(const PICout & other);
|
||||
|
||||
@@ -146,6 +164,8 @@ public:
|
||||
|
||||
|
||||
class PIP_EXPORT Notifier {
|
||||
friend class PICout;
|
||||
|
||||
public:
|
||||
//! \~english Singleton access to %PICout::Notifier
|
||||
//! \~russian Синглтон класса %PICout::Notifier
|
||||
@@ -158,15 +178,17 @@ public:
|
||||
private:
|
||||
Notifier();
|
||||
PIObject * o;
|
||||
std::atomic_int new_id = {1};
|
||||
};
|
||||
|
||||
//! \~english Enum contains output devices of %PICout
|
||||
//! \~russian Перечисление с устройствами вывода для %PICout
|
||||
enum OutputDevice {
|
||||
NoDevices /** \~english %PICout is disabled \~russian %PICout неактивен */ = 0x0,
|
||||
StdOut /** \~english Standard console output \~russian Стандартный вывод в консоль */ = 0x1,
|
||||
Buffer /** \~english Internal buffer \~russian Внутренний буфер */ = 0x2,
|
||||
AllDevices /** \~english All \~russian Все */ = 0xFFFF,
|
||||
NoDevices /** \~english %PICout is disabled \~russian %PICout неактивен */ = 0x0,
|
||||
Console /** \~english Standard console output \~russian Стандартный вывод в консоль */ = 0x1,
|
||||
StdOut DEPRECATEDM("use PICout::Console") = Console,
|
||||
Buffer /** \~english Internal buffer \~russian Внутренний буфер */ = 0x2,
|
||||
AllDevices /** \~english All \~russian Все */ = 0xFFFF,
|
||||
};
|
||||
|
||||
typedef PIFlags<OutputDevice> OutputDevices;
|
||||
@@ -261,25 +283,15 @@ public:
|
||||
|
||||
//! \~english Set control flag "c" is "on" state
|
||||
//! \~russian Установить флаг "c" в "on" состояние
|
||||
PICout & setControl(PICoutManipulators::PICoutControl c, bool on = true) {
|
||||
co_.setFlag(c, on);
|
||||
return *this;
|
||||
}
|
||||
PICout & setControl(PICoutManipulators::PICoutControl c, bool on = true);
|
||||
|
||||
//! \~english Set control flags "c"
|
||||
//! \~russian Установить флаги "c"
|
||||
PICout & setControls(PICoutManipulators::PICoutControls c) {
|
||||
co_ = c;
|
||||
return *this;
|
||||
}
|
||||
PICout & setControls(PICoutManipulators::PICoutControls c);
|
||||
|
||||
//! \~english Exec \a saveControls() and set control flags to "c"
|
||||
//! \~russian Иыполнить \a saveControls() и Установить флаги "c"
|
||||
PICout & saveAndSetControls(PICoutManipulators::PICoutControls c) {
|
||||
saveControls();
|
||||
co_ = c;
|
||||
return *this;
|
||||
}
|
||||
PICout & saveAndSetControls(PICoutManipulators::PICoutControls c);
|
||||
|
||||
//! \~english Save control flags to internal stack
|
||||
//! \~russian Сохраняет состояние флагов во внутренний стек
|
||||
@@ -321,7 +333,7 @@ public:
|
||||
|
||||
//! \~english Output \a PIString to stdout
|
||||
//! \~russian Вывод \a PIString в stdout
|
||||
static void stdoutPIString(const PIString & s);
|
||||
static void stdoutPIString(const PIString & str, PICoutManipulators::PICoutStdStream s = PICoutManipulators::StdOut);
|
||||
|
||||
//! \~english Returns internal PIString buffer
|
||||
//! \~russian Возвращает внутренний PIString буфер
|
||||
@@ -368,19 +380,25 @@ public:
|
||||
PIFlags<PICoutManipulators::PICoutControl> controls = PICoutManipulators::AddSpaces |
|
||||
PICoutManipulators::AddNewLine);
|
||||
|
||||
//! \~english Returns unique external buffer ID for later use in \a withExternalBuffer()
|
||||
//! \~russian Возвращает уникальный ID для внешнего буфера для дальнейшего использования в \a withExternalBuffer()
|
||||
static int registerExternalBufferID();
|
||||
|
||||
static PIMutex & __mutex__();
|
||||
static PIString & __string__();
|
||||
|
||||
private:
|
||||
void init();
|
||||
void applyFormat(PICoutManipulators::PICoutFormat f);
|
||||
void writeChar(char c);
|
||||
|
||||
static OutputDevices devs;
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
bool fo_, cc_, fc_, act_;
|
||||
int cnb_, attr_, id_;
|
||||
PIString * buffer_;
|
||||
PICoutManipulators::PICoutControls co_;
|
||||
bool first_out_ = true, is_copy_ = false, format_changed_ = false, actve_ = true;
|
||||
int int_base_ = 10, win_attr_ = 0, id_ = 0;
|
||||
PIString * buffer_ = nullptr;
|
||||
PICoutManipulators::PICoutControls ctrl_ = PICoutManipulators::DefaultControls;
|
||||
PICoutManipulators::PICoutStdStream stream_ = PICoutManipulators::StdOut;
|
||||
};
|
||||
|
||||
#endif // PICOUT_H
|
||||
|
||||
@@ -459,7 +459,7 @@ PIDir PIDir::current() {
|
||||
|
||||
PIDir PIDir::home() {
|
||||
#ifndef ESP_PLATFORM
|
||||
char * rc = 0;
|
||||
char * rc = nullptr;
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
rc = new char[1024];
|
||||
@@ -482,7 +482,7 @@ PIDir PIDir::home() {
|
||||
#else
|
||||
# ifndef ESP_PLATFORM
|
||||
rc = getenv("HOME");
|
||||
if (rc == 0) return PIDir();
|
||||
if (!rc) return PIDir();
|
||||
return PIDir(rc);
|
||||
# else
|
||||
return PIDir();
|
||||
@@ -492,7 +492,7 @@ PIDir PIDir::home() {
|
||||
|
||||
|
||||
PIDir PIDir::temporary() {
|
||||
char * rc = 0;
|
||||
char * rc = nullptr;
|
||||
#ifdef WINDOWS
|
||||
rc = new char[1024];
|
||||
memset(rc, 0, 1024);
|
||||
@@ -507,8 +507,8 @@ PIDir PIDir::temporary() {
|
||||
s.prepend(separator);
|
||||
return PIDir(s);
|
||||
#else
|
||||
rc = tmpnam(0);
|
||||
if (rc == 0) return PIDir();
|
||||
rc = mkdtemp("/tmp/pidir_tmp_XXXXXX");
|
||||
if (!rc) return PIDir();
|
||||
PIString s(rc);
|
||||
return PIDir(s.left(s.findLast(PIDir::separator)));
|
||||
#endif
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
bool binaryStreamAppend(const void * d, size_t s) {
|
||||
if (!static_cast<P *>(this)->binaryStreamAppendImp(d, s)) {
|
||||
return false;
|
||||
printf("[PIBinaryStream] binaryStreamAppend() error\n");
|
||||
fprintf(stderr, "[PIBinaryStream] binaryStreamAppend() error\n");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
if (!static_cast<P *>(this)->binaryStreamTakeImp(d, s)) {
|
||||
_was_read_error_ = true;
|
||||
return false;
|
||||
printf("[PIBinaryStream] binaryStreamTake() error\n");
|
||||
fprintf(stderr, "[PIBinaryStream] binaryStreamTake() error\n");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -323,7 +323,7 @@ template<typename P,
|
||||
typename std::enable_if<std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||
inline PIBinaryStreamTrivialRef<P> operator>>(PIBinaryStream<P> & s, T & v) {
|
||||
if (!s.binaryStreamTake(&v, sizeof(v))) {
|
||||
printf("error with %s\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with %s\n", __PIP_TYPENAME__(T));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -341,13 +341,13 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIVector<T> & v) {
|
||||
// piCout << ">> vector trivial default";
|
||||
int sz = s.binaryStreamTakeInt();
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
v._resizeRaw(sz);
|
||||
if (!s.binaryStreamTake(v.data(), sz * sizeof(T))) {
|
||||
printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
}
|
||||
return s;
|
||||
@@ -362,7 +362,7 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIVector<T> & v) {
|
||||
// piCout << ">> vector trivial custom";
|
||||
int sz = s.binaryStreamTakeInt();
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -370,7 +370,7 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIVector<T> & v) {
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
s >> v[i];
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -391,13 +391,13 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIDeque<T> & v) {
|
||||
// piCout << ">> deque trivial default";
|
||||
int sz = s.binaryStreamTakeInt();
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
v._resizeRaw(sz);
|
||||
if (!s.binaryStreamTake(v.data(), sz * sizeof(T))) {
|
||||
printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
}
|
||||
return s;
|
||||
@@ -412,7 +412,7 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIDeque<T> & v) {
|
||||
// piCout << ">> deque trivial custom";
|
||||
int sz = s.binaryStreamTakeInt();
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -420,7 +420,7 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIDeque<T> & v) {
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
s >> v[i];
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -443,13 +443,13 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIVector2D<T> & v)
|
||||
r = s.binaryStreamTakeInt();
|
||||
c = s.binaryStreamTakeInt();
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIVector2D<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector2D<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
v._resizeRaw(r, c);
|
||||
if (!s.binaryStreamTake(v.data(), v.size() * sizeof(T))) {
|
||||
printf("error with PIVector2D<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector2D<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
}
|
||||
return s;
|
||||
@@ -468,7 +468,7 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIVector2D<T> & v)
|
||||
c = s.binaryStreamTakeInt();
|
||||
s >> tmp;
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIVector2D<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector2D<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -543,7 +543,7 @@ template<typename P, typename T, typename std::enable_if<!std::is_trivially_copy
|
||||
inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIVector<T> & v) {
|
||||
int sz = s.binaryStreamTakeInt();
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -551,7 +551,7 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIVector<T> & v) {
|
||||
for (size_t i = 0; i < v.size(); ++i) {
|
||||
s >> v[i];
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -566,7 +566,7 @@ template<typename P, typename T, typename std::enable_if<!std::is_trivially_copy
|
||||
inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIDeque<T> & v) {
|
||||
int sz = s.binaryStreamTakeInt();
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -574,7 +574,7 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIDeque<T> & v) {
|
||||
for (size_t i = 0; i < v.size(); ++i) {
|
||||
s >> v[i];
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -593,7 +593,7 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIVector2D<T> & v)
|
||||
c = s.binaryStreamTakeInt();
|
||||
s >> tmp;
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIVector2D<%s>\n", __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIVector2D<%s>\n", __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -625,7 +625,7 @@ template<typename P, typename Key, typename T>
|
||||
inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIMap<Key, T> & v) {
|
||||
int sz = s.binaryStreamTakeInt();
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIMap<%s, %s>\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIMap<%s, %s>\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -635,7 +635,7 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIMap<Key, T> & v)
|
||||
ind = s.binaryStreamTakeInt();
|
||||
s >> v.pim_index[i].key;
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIMap<%s, %s>\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIMap<%s, %s>\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
@@ -643,7 +643,7 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIMap<Key, T> & v)
|
||||
}
|
||||
s >> v.pim_content;
|
||||
if (s.wasReadError()) {
|
||||
printf("error with PIMap<%s, %s>\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T));
|
||||
fprintf(stderr, "error with PIMap<%s, %s>\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T));
|
||||
v.clear();
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user