PICout optimization
This commit is contained in:
@@ -451,7 +451,7 @@ if (NOT CROSSTOOLS)
|
|||||||
#target_link_libraries(pip_plugin pip)
|
#target_link_libraries(pip_plugin pip)
|
||||||
|
|
||||||
add_executable(pip_test "main.cpp")
|
add_executable(pip_test "main.cpp")
|
||||||
target_link_libraries(pip_test pip pip_cloud pip_lua)
|
target_link_libraries(pip_test pip)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
else()
|
else()
|
||||||
|
|||||||
@@ -155,11 +155,7 @@ WORD PICout::__Private__::dattr = 0;
|
|||||||
DWORD PICout::__Private__::smode = 0;
|
DWORD PICout::__Private__::smode = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PICout::PICout(PIFlags<PICoutControl> controls): fo_(true), cc_(false), fc_(false), act_(true), cnb_(10), co_(controls) {
|
PICout::PICout(int controls): fo_(true), cc_(false), fc_(false), act_(true), cnb_(10), co_(controls) {
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
PICout::PICout(PICoutControl control): fo_(true), cc_(false), fc_(false), act_(true), cnb_(10), co_(control) {
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +319,7 @@ PICout PICout::operator <<(const PIFlags<PICoutManipulators::PICoutFormat> & v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define PICOUTTOTARGET(v) { \
|
#define PICOUTTOTARGET(v) { \
|
||||||
if (buffer_) {\
|
if (buffer_) {\
|
||||||
(*buffer_) << (v);\
|
(*buffer_) << (v);\
|
||||||
} else {\
|
} else {\
|
||||||
@@ -331,15 +327,14 @@ PICout PICout::operator <<(const PIFlags<PICoutManipulators::PICoutFormat> & v)
|
|||||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v);\
|
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v);\
|
||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
#define PICOUTTOTARGETS(v) { \
|
|
||||||
if (buffer_) {\
|
#define PINUMERICCOUT(v) { \
|
||||||
(*buffer_) << (v);\
|
if (!act_) return *this; \
|
||||||
} else {\
|
space(); \
|
||||||
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v).dataConsole();\
|
if (cnb_ == 10) PICOUTTOTARGET(v) \
|
||||||
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v);\
|
else writePIString(PIString::fromNumber(v, cnb_)); \
|
||||||
}\
|
return *this; \
|
||||||
}
|
}
|
||||||
#define PINUMERICCOUT if (cnb_ == 10) PICOUTTOTARGET(v) else PICOUTTOTARGETS(PIString::fromNumber(v, cnb_))
|
|
||||||
|
|
||||||
|
|
||||||
PICout PICout::operator <<(const char * v) {if (!act_) return *this; if (v[0] == '\0') return *this; space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
|
PICout PICout::operator <<(const char * v) {if (!act_) return *this; if (v[0] == '\0') return *this; space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
|
||||||
@@ -348,29 +343,29 @@ PICout PICout::operator <<(const bool v) {if (!act_) return *this; space(); if (
|
|||||||
|
|
||||||
PICout PICout::operator <<(const char v) {if (!act_) return *this; space(); PICOUTTOTARGET(v) return *this;}
|
PICout PICout::operator <<(const char v) {if (!act_) return *this; space(); PICOUTTOTARGET(v) return *this;}
|
||||||
|
|
||||||
PICout PICout::operator <<(const uchar v) {if (!act_) return *this; space(); if (cnb_ == 10) PICOUTTOTARGET(ushort(v)) else PICOUTTOTARGETS(PIString::fromNumber(v, cnb_)) return *this;}
|
PICout PICout::operator <<(const uchar v) {PINUMERICCOUT(ushort(v))}
|
||||||
|
|
||||||
PICout PICout::operator <<(const short int v) {if (!act_) return *this; space(); PINUMERICCOUT return *this;}
|
PICout PICout::operator <<(const short int v) {PINUMERICCOUT(v)}
|
||||||
|
|
||||||
PICout PICout::operator <<(const ushort v) {if (!act_) return *this; space(); PINUMERICCOUT return *this;}
|
PICout PICout::operator <<(const ushort v) {PINUMERICCOUT(v)}
|
||||||
|
|
||||||
PICout PICout::operator <<(const int v) {if (!act_) return *this; space(); PINUMERICCOUT return *this;}
|
PICout PICout::operator <<(const int v) {PINUMERICCOUT(v)}
|
||||||
|
|
||||||
PICout PICout::operator <<(const uint v) {if (!act_) return *this; space(); PINUMERICCOUT return *this;}
|
PICout PICout::operator <<(const uint v) {PINUMERICCOUT(v)}
|
||||||
|
|
||||||
PICout PICout::operator <<(const long v) {if (!act_) return *this; space(); PINUMERICCOUT return *this;}
|
PICout PICout::operator <<(const long v) {PINUMERICCOUT(v)}
|
||||||
|
|
||||||
PICout PICout::operator <<(const ulong v) {if (!act_) return *this; space(); PINUMERICCOUT return *this;}
|
PICout PICout::operator <<(const ulong v) {PINUMERICCOUT(v)}
|
||||||
|
|
||||||
PICout PICout::operator <<(const llong v) {if (!act_) return *this; space(); PINUMERICCOUT return *this;}
|
PICout PICout::operator <<(const llong v) {PINUMERICCOUT(v)}
|
||||||
|
|
||||||
PICout PICout::operator <<(const ullong v) {if (!act_) return *this; space(); PINUMERICCOUT return *this;}
|
PICout PICout::operator <<(const ullong v) {PINUMERICCOUT(v)}
|
||||||
|
|
||||||
PICout PICout::operator <<(const float v) {if (!act_) return *this; space(); PICOUTTOTARGET(v) return *this;}
|
PICout PICout::operator <<(const float v) {if (!act_) return *this; space(); PICOUTTOTARGET(v) return *this;}
|
||||||
|
|
||||||
PICout PICout::operator <<(const double v) {if (!act_) return *this; space(); PICOUTTOTARGET(v) return *this;}
|
PICout PICout::operator <<(const double v) {if (!act_) return *this; space(); PICOUTTOTARGET(v) return *this;}
|
||||||
|
|
||||||
PICout PICout::operator <<(const void * v) {if (!act_) return *this; space(); PICOUTTOTARGET("0x") PICOUTTOTARGETS(PIString::fromNumber(ullong(v), 16)) return *this;}
|
PICout PICout::operator <<(const void * v) {if (!act_) return *this; space(); PICOUTTOTARGET("0x") writePIString(PIString::fromNumber(ullong(v), 16)); return *this;}
|
||||||
|
|
||||||
PICout PICout::operator <<(const PIObject * v) {
|
PICout PICout::operator <<(const PIObject * v) {
|
||||||
if (!act_) return *this;
|
if (!act_) return *this;
|
||||||
@@ -379,9 +374,9 @@ PICout PICout::operator <<(const PIObject * v) {
|
|||||||
else {
|
else {
|
||||||
PICOUTTOTARGET(v->className())
|
PICOUTTOTARGET(v->className())
|
||||||
PICOUTTOTARGET("*(0x")
|
PICOUTTOTARGET("*(0x")
|
||||||
PICOUTTOTARGETS(PIString::fromNumber(ullong(v), 16))
|
writePIString(PIString::fromNumber(ullong(v), 16));
|
||||||
PICOUTTOTARGET(", \"")
|
PICOUTTOTARGET(", \"")
|
||||||
PICOUTTOTARGET(v->name())
|
writePIString(v->name());
|
||||||
PICOUTTOTARGET("\")")
|
PICOUTTOTARGET("\")")
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -526,6 +521,30 @@ PICout & PICout::newLine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PICout & PICout::write(const char * str, int len) {
|
||||||
|
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::writePIString(const PIString & s) {
|
||||||
|
if (buffer_) {
|
||||||
|
buffer_->append(s);
|
||||||
|
} else {
|
||||||
|
if (PICout::isOutputDeviceActive(PICout::StdOut)) {
|
||||||
|
for (const PIChar & c: s) std::wcout.put(c.toWChar());
|
||||||
|
}
|
||||||
|
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__().append(s);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PICout::init() {
|
void PICout::init() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (__Private__::hOut == 0) {
|
if (__Private__::hOut == 0) {
|
||||||
|
|||||||
@@ -130,8 +130,7 @@ public:
|
|||||||
|
|
||||||
//! \~english Default constructor with default features (AddSpaces and AddNewLine)
|
//! \~english Default constructor with default features (AddSpaces and AddNewLine)
|
||||||
//! \~russian Конструктор по умолчанию (AddSpaces и AddNewLine)
|
//! \~russian Конструктор по умолчанию (AddSpaces и AddNewLine)
|
||||||
PICout(PIFlags<PICoutManipulators::PICoutControl> controls = PICoutManipulators::DefaultControls);
|
PICout(int controls = PICoutManipulators::DefaultControls);
|
||||||
PICout(PICoutManipulators::PICoutControl control = PICoutManipulators::DefaultControls);
|
|
||||||
|
|
||||||
//! \~english Construct with default features (AddSpaces and AddNewLine), but if \"active\" is false does nothing
|
//! \~english Construct with default features (AddSpaces and AddNewLine), but if \"active\" is false does nothing
|
||||||
//! \~russian Конструктор по умолчанию (AddSpaces и AddNewLine), но если не \"active\" то будет неактивным
|
//! \~russian Конструктор по умолчанию (AddSpaces и AddNewLine), но если не \"active\" то будет неактивным
|
||||||
@@ -284,6 +283,14 @@ public:
|
|||||||
//! \~russian Условно добавляет новую строку
|
//! \~russian Условно добавляет новую строку
|
||||||
PICout & newLine();
|
PICout & newLine();
|
||||||
|
|
||||||
|
//! \~english Write raw data
|
||||||
|
//! \~russian Пишет сырые символы
|
||||||
|
PICout & write(const char * str, int len);
|
||||||
|
|
||||||
|
//! \~english Write raw \a PIString
|
||||||
|
//! \~russian Пишет сырой \a PIString
|
||||||
|
PICout & writePIString(const PIString & s);
|
||||||
|
|
||||||
//! \~english Set output device to \a PICout::Buffer and if "clear" clear it
|
//! \~english Set output device to \a PICout::Buffer and if "clear" clear it
|
||||||
//! \~russian Устанавливает устройство вывода на \a PICout::Buffer и если "clear" то очищает его
|
//! \~russian Устанавливает устройство вывода на \a PICout::Buffer и если "clear" то очищает его
|
||||||
static bool setBufferActive(bool on, bool clear = false);
|
static bool setBufferActive(bool on, bool clear = false);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
# include "esp_system.h"
|
# include "esp_system.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include <codecvt>
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
extern FILETIME __pi_ftjan1970;
|
extern FILETIME __pi_ftjan1970;
|
||||||
@@ -208,8 +209,12 @@ PIInit::PIInit() {
|
|||||||
#endif
|
#endif
|
||||||
char cbuff[1024];
|
char cbuff[1024];
|
||||||
memset(cbuff, 0, 1024);
|
memset(cbuff, 0, 1024);
|
||||||
if (gethostname(cbuff, 1023) == 0)
|
if (gethostname(cbuff, 1023) == 0) {
|
||||||
sinfo->hostname = cbuff;
|
sinfo->hostname = cbuff;
|
||||||
|
}
|
||||||
|
// std::ios_base::sync_with_stdio(false);
|
||||||
|
// std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> );
|
||||||
|
// std::wcout.imbue(utf8);
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
SYSTEM_INFO sysinfo;
|
SYSTEM_INFO sysinfo;
|
||||||
GetSystemInfo(&sysinfo);
|
GetSystemInfo(&sysinfo);
|
||||||
|
|||||||
@@ -1729,9 +1729,7 @@ PIString versionNormalize(const PIString & v) {
|
|||||||
PICout operator <<(PICout s, const PIString & v) {
|
PICout operator <<(PICout s, const PIString & v) {
|
||||||
s.space();
|
s.space();
|
||||||
s.quote();
|
s.quote();
|
||||||
s.setControl(0, true);
|
s.writePIString(v);
|
||||||
s << v.data();
|
|
||||||
s.restoreControl();
|
|
||||||
s.quote();
|
s.quote();
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
91
main.cpp
91
main.cpp
@@ -1,9 +1,92 @@
|
|||||||
#include "pip.h"
|
#include "pip.h"
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
|
class ROString {
|
||||||
|
public:
|
||||||
|
inline ROString() : len(0), str(nullptr) {}
|
||||||
|
inline ROString(const char * string) {
|
||||||
|
str = string;
|
||||||
|
len = strlen(string);
|
||||||
|
}
|
||||||
|
inline ROString(const char * data, size_t size) {
|
||||||
|
str = data;
|
||||||
|
len = size;
|
||||||
|
}
|
||||||
|
// inline ROString(const char string[]) {
|
||||||
|
// str = string;
|
||||||
|
// len = sizeof(string);
|
||||||
|
// }
|
||||||
|
|
||||||
|
inline const char & operator[](size_t pos) const {return str[pos];}
|
||||||
|
inline const char * data() const {return str;}
|
||||||
|
|
||||||
|
inline bool isEmpty() const {return len == 0;}
|
||||||
|
inline bool isNotEmpty() const {return len > 0;}
|
||||||
|
inline size_t length() const {return len;}
|
||||||
|
inline size_t size() const {return len;}
|
||||||
|
inline ssize_t size_s() const {return len;}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Assign operator.
|
||||||
|
//! \~russian Оператор присваивания.
|
||||||
|
inline ROString & operator =(const ROString & s) {
|
||||||
|
if (this == &s) return *this;
|
||||||
|
len = s.len;
|
||||||
|
str = s.str;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Assign move operator.
|
||||||
|
//! \~russian Оператор перемещающего присваивания.
|
||||||
|
inline ROString & operator =(ROString && s) {
|
||||||
|
swap(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void swap(ROString& v) {
|
||||||
|
piSwap<const char *>(str, v.str);
|
||||||
|
piSwap<size_t>(len, v.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t len;
|
||||||
|
const char * str;
|
||||||
|
};
|
||||||
|
|
||||||
|
PICout operator <<(PICout s, const ROString & v) {
|
||||||
|
s.space();
|
||||||
|
s.quote();
|
||||||
|
s.write(v.data(), v.size());
|
||||||
|
s.quote();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
PIVector<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
|
const char * dd = "12345";
|
||||||
v.sort([](const int & a, const int & b){return a > b;});
|
char text[]{ "hello" };
|
||||||
piCout << v; // 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
ROString s("test");
|
||||||
|
piCout << s;
|
||||||
|
ROString s2;
|
||||||
|
piCout << s2;
|
||||||
|
s2 = s;
|
||||||
|
piCout << s2;
|
||||||
|
s2 = text;
|
||||||
|
s = s2;
|
||||||
|
piCout << s << s2;
|
||||||
|
// s2 = s;
|
||||||
|
text[1] = '0';
|
||||||
|
piCout << text;
|
||||||
|
piCout << s << s2 << ROString(text, 3);
|
||||||
|
// piCout << s << s2;
|
||||||
|
// PIString ss(s.data(), s.length());
|
||||||
|
// piCout << ss;
|
||||||
|
PICout(PICoutManipulators::DefaultControls | PICoutManipulators::AddQuotes) << PIString(dd);
|
||||||
|
|
||||||
|
piCout << PIString::fromUTF8("test");
|
||||||
|
piCout << PIString::fromUTF8("бюд\n");
|
||||||
|
piCout.writePIString(PIString::fromUTF8("test\n"));
|
||||||
|
piCout.writePIString(PIString::fromUTF8("бюд\n"));
|
||||||
|
piCout << "бюд\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user