code format
This commit is contained in:
@@ -1,35 +1,36 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Universal output to console class
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Universal output to console class
|
||||
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 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.
|
||||
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/>.
|
||||
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 "piincludes_p.h"
|
||||
#include "picout.h"
|
||||
|
||||
#include "pibytearray.h"
|
||||
#include "pistack.h"
|
||||
#include "piincludes_p.h"
|
||||
#include "piobject.h"
|
||||
#include "pistack.h"
|
||||
#include "pistring_std.h"
|
||||
#ifdef HAS_LOCALE
|
||||
# include <locale>
|
||||
# include <codecvt>
|
||||
# include <locale>
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
# include <wincon.h>
|
||||
# include <windows.h>
|
||||
# include <wingdi.h>
|
||||
# include <wincon.h>
|
||||
# define COMMON_LVB_UNDERSCORE 0x8000
|
||||
#endif
|
||||
|
||||
@@ -106,13 +107,13 @@
|
||||
|
||||
class NotifierObject: public PIObject {
|
||||
PIOBJECT(NotifierObject)
|
||||
|
||||
public:
|
||||
NotifierObject() {}
|
||||
EVENT2(finished, int, id, PIString*, buffer);
|
||||
EVENT2(finished, int, id, PIString *, buffer);
|
||||
};
|
||||
|
||||
|
||||
|
||||
PICout::Notifier::Notifier() {
|
||||
o = new NotifierObject();
|
||||
}
|
||||
@@ -129,12 +130,16 @@ PIObject * PICout::Notifier::object() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
PIMutex & PICout::__mutex__() {static PIMutex * ret = new PIMutex(); return *ret;}
|
||||
PIString & PICout::__string__() {static PIString * ret = new PIString(); return *ret;}
|
||||
PIMutex & PICout::__mutex__() {
|
||||
static PIMutex * ret = new PIMutex();
|
||||
return *ret;
|
||||
}
|
||||
PIString & PICout::__string__() {
|
||||
static PIString * ret = new PIString();
|
||||
return *ret;
|
||||
}
|
||||
|
||||
PICout::OutputDevices PICout::devs = PICout::StdOut;
|
||||
|
||||
@@ -149,7 +154,7 @@ PRIVATE_DEFINITION_END(PICout)
|
||||
|
||||
#ifdef WINDOWS
|
||||
void * PICout::__Private__::hOut = 0;
|
||||
WORD PICout::__Private__::dattr = 0;
|
||||
WORD PICout::__Private__::dattr = 0;
|
||||
DWORD PICout::__Private__::smode = 0;
|
||||
#endif
|
||||
|
||||
@@ -164,9 +169,16 @@ PICout::PICout(bool active): fo_(true), cc_(false), fc_(false), act_(active), cn
|
||||
}
|
||||
|
||||
|
||||
PICout::PICout(const PICout & other): fo_(other.fo_), cc_(true), fc_(false), act_(other.act_), cnb_(other.cnb_), attr_(other.attr_),
|
||||
id_(other.id_), buffer_(other.buffer_), co_(other.co_) {
|
||||
}
|
||||
PICout::PICout(const PICout & other)
|
||||
: fo_(other.fo_)
|
||||
, cc_(true)
|
||||
, fc_(false)
|
||||
, act_(other.act_)
|
||||
, cnb_(other.cnb_)
|
||||
, attr_(other.attr_)
|
||||
, id_(other.id_)
|
||||
, buffer_(other.buffer_)
|
||||
, co_(other.co_) {}
|
||||
|
||||
|
||||
PICout::~PICout() {
|
||||
@@ -178,12 +190,12 @@ PICout::~PICout() {
|
||||
PICout::__mutex__().unlock();
|
||||
}
|
||||
if (buffer_) {
|
||||
((NotifierObject*)Notifier::object())->finished(id_, buffer_);
|
||||
((NotifierObject *)Notifier::object())->finished(id_, buffer_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::operator <<(PICoutAction v) {
|
||||
PICout & PICout::operator<<(PICoutAction v) {
|
||||
if (!act_) return *this;
|
||||
#ifdef WINDOWS
|
||||
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||
@@ -200,7 +212,7 @@ PICout & PICout::operator <<(PICoutAction v) {
|
||||
if (isOutputDeviceActive(StdOut)) {
|
||||
#ifdef WINDOWS
|
||||
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
|
||||
coord = sbi.dwCursorPosition;
|
||||
coord = sbi.dwCursorPosition;
|
||||
coord.X = piMax<int>(0, int(coord.X) - 1);
|
||||
SetConsoleCursorPosition(__Private__::hOut, coord);
|
||||
printf(" ");
|
||||
@@ -236,8 +248,8 @@ PICout & PICout::operator <<(PICoutAction v) {
|
||||
if (isOutputDeviceActive(StdOut)) {
|
||||
#ifdef WINDOWS
|
||||
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
|
||||
coord = sbi.dwCursorPosition;
|
||||
int dx = coord.X;
|
||||
coord = sbi.dwCursorPosition;
|
||||
int dx = coord.X;
|
||||
coord.X = 0;
|
||||
SetConsoleCursorPosition(__Private__::hOut, coord);
|
||||
if (dx > 0) {
|
||||
@@ -270,7 +282,7 @@ PICout & PICout::operator <<(PICoutAction v) {
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::operator <<(PICoutManipulators::PICoutFormat v) {
|
||||
PICout & PICout::operator<<(PICoutManipulators::PICoutFormat v) {
|
||||
switch (v) {
|
||||
case PICoutManipulators::Bin: cnb_ = 2; break;
|
||||
case PICoutManipulators::Oct: cnb_ = 8; break;
|
||||
@@ -282,7 +294,7 @@ PICout & PICout::operator <<(PICoutManipulators::PICoutFormat v) {
|
||||
}
|
||||
|
||||
|
||||
PICout & PICout::operator <<(PIFlags<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;
|
||||
@@ -312,32 +324,35 @@ 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; \
|
||||
#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; \
|
||||
}
|
||||
|
||||
#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 (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v); \
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() += PIString::fromNumber(v, 'g'); \
|
||||
} \
|
||||
} \
|
||||
return *this;
|
||||
|
||||
|
||||
PICout & PICout::operator <<(const PIString & v) {
|
||||
PICout & PICout::operator<<(const PIString & v) {
|
||||
space();
|
||||
quote();
|
||||
write(v);
|
||||
@@ -345,7 +360,7 @@ PICout & PICout::operator <<(const PIString & v) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
PICout & PICout::operator <<(const char * v) {
|
||||
PICout & PICout::operator<<(const char * v) {
|
||||
if (!act_ || !v) return *this;
|
||||
if (v[0] == '\0') return *this;
|
||||
space();
|
||||
@@ -355,56 +370,71 @@ PICout & PICout::operator <<(const char * v) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
PICout & PICout::operator <<(bool v) {
|
||||
PICout & PICout::operator<<(bool v) {
|
||||
if (!act_) return *this;
|
||||
space();
|
||||
if (v) write("true");
|
||||
else write("false");
|
||||
if (v)
|
||||
write("true");
|
||||
else
|
||||
write("false");
|
||||
return *this;
|
||||
}
|
||||
|
||||
PICout & PICout::operator <<(char v) {
|
||||
PICout & PICout::operator<<(char v) {
|
||||
if (!act_) return *this;
|
||||
space();
|
||||
write(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PICout & PICout::operator <<(uchar v) {PIINTCOUT(ushort(v))}
|
||||
PICout & PICout::operator<<(uchar v){PIINTCOUT(ushort(v))}
|
||||
|
||||
PICout & PICout::operator <<(short int v) {PIINTCOUT(v)}
|
||||
PICout & PICout::operator<<(short int v){PIINTCOUT(v)}
|
||||
|
||||
PICout & PICout::operator <<(ushort v) {PIINTCOUT(v)}
|
||||
PICout & PICout::operator<<(ushort v){PIINTCOUT(v)}
|
||||
|
||||
PICout & PICout::operator <<(int v) {PIINTCOUT(v)}
|
||||
PICout & PICout::operator<<(int v){PIINTCOUT(v)}
|
||||
|
||||
PICout & PICout::operator <<(uint v) {PIINTCOUT(v)}
|
||||
PICout & PICout::operator<<(uint v){PIINTCOUT(v)}
|
||||
|
||||
PICout & PICout::operator <<(long v) {PIINTCOUT(v)}
|
||||
PICout & PICout::operator<<(long v){PIINTCOUT(v)}
|
||||
|
||||
PICout & PICout::operator <<(ulong v) {PIINTCOUT(v)}
|
||||
PICout & PICout::operator<<(ulong v){PIINTCOUT(v)}
|
||||
|
||||
PICout & PICout::operator <<(llong v) {PIINTCOUT(v)}
|
||||
PICout & PICout::operator<<(llong v){PIINTCOUT(v)}
|
||||
|
||||
PICout & PICout::operator <<(ullong v) {PIINTCOUT(v)}
|
||||
PICout & PICout::operator<<(ullong v){PIINTCOUT(v)}
|
||||
|
||||
PICout & PICout::operator <<(float v) {if (!act_) return *this; space(); PIFLOATCOUT(v)}
|
||||
PICout & PICout::operator<<(float v) {
|
||||
if (!act_) return *this;
|
||||
space();
|
||||
PIFLOATCOUT(v)
|
||||
}
|
||||
|
||||
PICout & PICout::operator <<(double v) {if (!act_) return *this; space(); PIFLOATCOUT(v)}
|
||||
PICout & PICout::operator<<(double v) {
|
||||
if (!act_) return *this;
|
||||
space();
|
||||
PIFLOATCOUT(v)
|
||||
}
|
||||
|
||||
PICout & PICout::operator <<(ldouble v) {if (!act_) return *this; space(); PIFLOATCOUT(v)}
|
||||
PICout & PICout::operator<<(ldouble v) {
|
||||
if (!act_) return *this;
|
||||
space();
|
||||
PIFLOATCOUT(v)
|
||||
}
|
||||
|
||||
PICout & PICout::operator <<(const void * v) {
|
||||
PICout & PICout::operator<<(const void * v) {
|
||||
if (!act_) return *this;
|
||||
space();
|
||||
write("0x" + PIString::fromNumber(ullong(v), 16));
|
||||
return *this;
|
||||
}
|
||||
|
||||
PICout & PICout::operator <<(const PIObject * v) {
|
||||
PICout & PICout::operator<<(const PIObject * v) {
|
||||
if (!act_) return *this;
|
||||
space();
|
||||
if (v == 0) write("PIObject*(0x0)");
|
||||
if (v == 0)
|
||||
write("PIObject*(0x0)");
|
||||
else {
|
||||
write(v->className());
|
||||
write("*(0x" + PIString::fromNumber(ullong(v), 16) + ", \"" + v->name() + "\")");
|
||||
@@ -412,7 +442,7 @@ PICout & PICout::operator <<(const PIObject * v) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
PICout & PICout::operator <<(PICoutSpecialChar v) {
|
||||
PICout & PICout::operator<<(PICoutSpecialChar v) {
|
||||
if (!act_) return *this;
|
||||
switch (v) {
|
||||
case Null:
|
||||
@@ -487,7 +517,6 @@ PICout & PICout::restoreControls() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! \details
|
||||
//! \~english
|
||||
//! If it is not a first output and control \a AddSpaces is set space character is put
|
||||
@@ -594,9 +623,11 @@ PICout & PICout::write(const PIString & s) {
|
||||
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());
|
||||
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());
|
||||
for (PIChar c: s)
|
||||
std::wcout.put(c.toWChar());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -626,7 +657,10 @@ void PICout::applyFormat(PICoutFormat f) {
|
||||
static int mask_fore = ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
static int mask_back = ~(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
|
||||
switch (f) {
|
||||
case Bin: case Oct: case Dec: case Hex: break;
|
||||
case Bin:
|
||||
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;
|
||||
@@ -651,7 +685,10 @@ void PICout::applyFormat(PICoutFormat f) {
|
||||
SetConsoleTextAttribute(__Private__::hOut, attr_);
|
||||
#else
|
||||
switch (f) {
|
||||
case Bin: case Oct: case Dec: case Hex: break;
|
||||
case Bin:
|
||||
case Oct:
|
||||
case Dec:
|
||||
case Hex: break;
|
||||
case PICoutManipulators::Bold: printf("\e[1m"); break;
|
||||
case PICoutManipulators::Faint: printf("\e[2m"); break;
|
||||
case PICoutManipulators::Italic: printf("\e[3m"); break;
|
||||
@@ -721,6 +758,6 @@ bool PICout::isOutputDeviceActive(PICout::OutputDevice d) {
|
||||
PICout PICout::withExternalBuffer(PIString * buffer, int id, PIFlags<PICoutManipulators::PICoutControl> controls) {
|
||||
PICout c(controls);
|
||||
c.buffer_ = buffer;
|
||||
c.id_ = id;
|
||||
c.id_ = id;
|
||||
return c;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user