git-svn-id: svn://db.shs.com.ru/pip@623 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -49,6 +49,49 @@
|
||||
* \snippet picout.cpp own
|
||||
*/
|
||||
|
||||
|
||||
/*! \class PICout::Notifier
|
||||
* \brief Class for emit notifications of PICout
|
||||
*
|
||||
* \section PICout_sec0 Synopsis
|
||||
* This class used as PICout events emitter. When
|
||||
* PICout constructs with external PIString* buffer
|
||||
* and some id, last copy of this PICout on delete
|
||||
* emit event "finished()" on object Notifier::object().
|
||||
* Sample:
|
||||
* \snippet picout.cpp notifier
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
class NotifierObject: public PIObject {
|
||||
PIOBJECT(NotifierObject)
|
||||
public:
|
||||
NotifierObject() {}
|
||||
EVENT2(finished, int, id, PIString*, buffer)
|
||||
};
|
||||
|
||||
|
||||
|
||||
PICout::Notifier::Notifier() {
|
||||
o = new NotifierObject();
|
||||
}
|
||||
|
||||
|
||||
PICout::Notifier * PICout::Notifier::instance() {
|
||||
static PICout::Notifier ret;
|
||||
return &ret;
|
||||
}
|
||||
|
||||
|
||||
PIObject * PICout::Notifier::object() {
|
||||
return instance()->o;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
PIMutex & PICout::__mutex__() {static PIMutex ret; return ret;}
|
||||
@@ -72,20 +115,20 @@ DWORD PICout::__Private__::smode = 0;
|
||||
#endif
|
||||
|
||||
PICout::PICout(PIFlags<PICoutControl> controls): fo_(true), cc_(false), fc_(false), cnb_(10), co_(controls) {
|
||||
#ifdef WINDOWS
|
||||
if (__Private__::hOut == 0) {
|
||||
__Private__::hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
|
||||
__Private__::dattr = sbi.wAttributes;
|
||||
}
|
||||
attr_ = __Private__::dattr;
|
||||
#endif
|
||||
PICout::__mutex__().lock();
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
PICout::PICout(const PICout & other): fo_(other.fo_), cc_(true), fc_(false), cnb_(other.cnb_), attr_(other.attr_), co_(other.co_) {
|
||||
PICout::PICout(PIString * buffer, int id, PIFlags<PICoutManipulators::PICoutControl> controls): fo_(true), cc_(false),
|
||||
fc_(false), cnb_(10), co_(controls) {
|
||||
init();
|
||||
buffer_ = buffer;
|
||||
id_ = id;
|
||||
}
|
||||
|
||||
|
||||
PICout::PICout(const PICout & other): fo_(other.fo_), cc_(true), fc_(false), cnb_(other.cnb_), attr_(other.attr_),
|
||||
id_(other.id_), buffer_(other.buffer_), co_(other.co_) {
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +137,8 @@ PICout::~PICout() {
|
||||
if (cc_) return;
|
||||
newLine();
|
||||
PICout::__mutex__().unlock();
|
||||
if (buffer_)
|
||||
((NotifierObject*)Notifier::object())->finished(id_, buffer_);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +150,7 @@ PICout PICout::operator <<(const PICoutAction v) {
|
||||
#endif
|
||||
switch (v) {
|
||||
case PICoutManipulators::Flush:
|
||||
if (isOutputDeviceActive(StdOut))
|
||||
if (!buffer_ && isOutputDeviceActive(StdOut))
|
||||
std::cout << std::flush;
|
||||
break;
|
||||
case PICoutManipulators::Backspace:
|
||||
@@ -190,12 +235,20 @@ PICout PICout::operator <<(const PICoutAction v) {
|
||||
|
||||
|
||||
#define PICOUTTOTARGET(v) { \
|
||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v);\
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v);\
|
||||
if (buffer_) {\
|
||||
(*buffer_) << (v);\
|
||||
} else {\
|
||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v);\
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v);\
|
||||
}\
|
||||
}
|
||||
#define PICOUTTOTARGETS(v) { \
|
||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v).dataConsole();\
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v);\
|
||||
if (buffer_) {\
|
||||
(*buffer_) << (v);\
|
||||
} else {\
|
||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v).dataConsole();\
|
||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v);\
|
||||
}\
|
||||
}
|
||||
//#define PICOUTTOTARGETS(v) {if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v); else printf("%s", (v).dataConsole());}
|
||||
#define PINUMERICCOUT if (cnb_ == 10) PICOUTTOTARGET(v) else PICOUTTOTARGETS(PIString::fromNumber(v, cnb_))
|
||||
@@ -250,30 +303,54 @@ PICout PICout::operator <<(const PIObject * v) {
|
||||
PICout PICout::operator <<(const PICoutSpecialChar v) {
|
||||
switch (v) {
|
||||
case Null:
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << char(0);
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << PIChar(0);
|
||||
if (buffer_) {
|
||||
(*buffer_) << PIChar(0);
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << char(0);
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << PIChar(0);
|
||||
}
|
||||
break;
|
||||
case NewLine:
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '\n';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\n";
|
||||
if (buffer_) {
|
||||
(*buffer_) << "\n";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '\n';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\n";
|
||||
}
|
||||
fo_ = true;
|
||||
break;
|
||||
case Tab:
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '\t';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\t";
|
||||
if (buffer_) {
|
||||
(*buffer_) << "\t";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '\t';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\t";
|
||||
}
|
||||
break;
|
||||
case Esc:
|
||||
#ifdef CC_VC
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << char(27);
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << PIChar(27);
|
||||
if (buffer_) {
|
||||
(*buffer_) << PIChar(27);
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << char(27);
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << PIChar(27);
|
||||
}
|
||||
#else
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '\e';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\e";
|
||||
if (buffer_) {
|
||||
(*buffer_) << "\e";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '\e';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\e";
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case Quote:
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '"';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\"";
|
||||
if (buffer_) {
|
||||
(*buffer_) << "\"";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '"';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\"";
|
||||
}
|
||||
break;
|
||||
};
|
||||
return *this;
|
||||
@@ -300,8 +377,12 @@ PICout & PICout::restoreControl() {
|
||||
|
||||
PICout & PICout::space() {
|
||||
if (!fo_ && co_[AddSpaces]) {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << ' ';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << " ";
|
||||
if (buffer_) {
|
||||
(*buffer_) << " ";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << ' ';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << " ";
|
||||
}
|
||||
}
|
||||
fo_ = false;
|
||||
return *this;
|
||||
@@ -309,8 +390,12 @@ PICout & PICout::space() {
|
||||
|
||||
PICout & PICout::quote() {
|
||||
if (co_[AddQuotes]) {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '"';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\"";
|
||||
if (buffer_) {
|
||||
(*buffer_) << "\"";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << '"';
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\"";
|
||||
}
|
||||
}
|
||||
fo_ = false;
|
||||
return *this;
|
||||
@@ -318,16 +403,36 @@ PICout & PICout::quote() {
|
||||
|
||||
PICout & PICout::newLine() {
|
||||
if (co_[AddNewLine]) {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << std::endl;
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\n";
|
||||
if (buffer_) {
|
||||
(*buffer_) << "\n";
|
||||
} else {
|
||||
if (isOutputDeviceActive(StdOut)) std::cout << std::endl;
|
||||
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\n";
|
||||
}
|
||||
}
|
||||
fo_ = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void PICout::init() {
|
||||
#ifdef WINDOWS
|
||||
if (__Private__::hOut == 0) {
|
||||
__Private__::hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
|
||||
__Private__::dattr = sbi.wAttributes;
|
||||
}
|
||||
attr_ = __Private__::dattr;
|
||||
#endif
|
||||
buffer_ = 0;
|
||||
id_ = 0;
|
||||
PICout::__mutex__().lock();
|
||||
}
|
||||
|
||||
|
||||
void PICout::applyFormat(PICoutFormat f) {
|
||||
if (!isOutputDeviceActive(StdOut)) return;
|
||||
if (buffer_ || !isOutputDeviceActive(StdOut)) return;
|
||||
fc_ = true;
|
||||
#ifdef WINDOWS
|
||||
static int mask_fore = ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
@@ -416,7 +521,9 @@ void PICout::clearBuffer() {
|
||||
|
||||
|
||||
bool PICout::setOutputDevice(PICout::OutputDevice d, bool on) {
|
||||
bool ret = devs[d];
|
||||
devs.setFlag(d, on);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user