before formatting
This commit is contained in:
@@ -17,16 +17,17 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "piscreen.h"
|
#include "piscreen.h"
|
||||||
|
|
||||||
#include "piincludes_p.h"
|
#include "piincludes_p.h"
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
# include <sys/ioctl.h>
|
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
|
# include <sys/ioctl.h>
|
||||||
# include <termios.h>
|
# include <termios.h>
|
||||||
#else
|
#else
|
||||||
# include <wingdi.h>
|
|
||||||
# include <wincon.h>
|
# include <wincon.h>
|
||||||
|
# include <wingdi.h>
|
||||||
# ifndef COMMON_LVB_UNDERSCORE
|
# ifndef COMMON_LVB_UNDERSCORE
|
||||||
# define COMMON_LVB_UNDERSCORE 0x8000
|
# define COMMON_LVB_UNDERSCORE 0x8000
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -66,11 +67,11 @@ void PIScreen::SystemConsole::begin() {
|
|||||||
int w, h;
|
int w, h;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
PRIVATE->ulcoord.X = 0;
|
PRIVATE->ulcoord.X = 0;
|
||||||
PRIVATE->hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
PRIVATE->hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
GetConsoleScreenBufferInfo(PRIVATE->hOut, &PRIVATE->sbi);
|
GetConsoleScreenBufferInfo(PRIVATE->hOut, &PRIVATE->sbi);
|
||||||
PRIVATE->dattr = PRIVATE->sbi.wAttributes;
|
PRIVATE->dattr = PRIVATE->sbi.wAttributes;
|
||||||
w = PRIVATE->sbi.srWindow.Right - PRIVATE->sbi.srWindow.Left;
|
w = PRIVATE->sbi.srWindow.Right - PRIVATE->sbi.srWindow.Left;
|
||||||
h = PRIVATE->sbi.srWindow.Bottom - PRIVATE->sbi.srWindow.Top;
|
h = PRIVATE->sbi.srWindow.Bottom - PRIVATE->sbi.srWindow.Top;
|
||||||
PRIVATE->ulcoord.Y = PRIVATE->sbi.srWindow.Top;
|
PRIVATE->ulcoord.Y = PRIVATE->sbi.srWindow.Top;
|
||||||
GetConsoleMode(PRIVATE->hOut, &PRIVATE->smode);
|
GetConsoleMode(PRIVATE->hOut, &PRIVATE->smode);
|
||||||
GetConsoleCursorInfo(PRIVATE->hOut, &PRIVATE->curinfo);
|
GetConsoleCursorInfo(PRIVATE->hOut, &PRIVATE->curinfo);
|
||||||
@@ -135,9 +136,9 @@ void PIScreen::SystemConsole::clear() {
|
|||||||
|
|
||||||
void PIScreen::SystemConsole::resize(int w, int h) {
|
void PIScreen::SystemConsole::resize(int w, int h) {
|
||||||
if (w == pwidth && h == pheight) return;
|
if (w == pwidth && h == pheight) return;
|
||||||
width = piMaxi(w, 0);
|
width = piMaxi(w, 0);
|
||||||
height = piMaxi(h, 0);
|
height = piMaxi(h, 0);
|
||||||
pwidth = width;
|
pwidth = width;
|
||||||
pheight = height;
|
pheight = height;
|
||||||
cells.resize(height);
|
cells.resize(height);
|
||||||
pcells.resize(height);
|
pcells.resize(height);
|
||||||
@@ -158,7 +159,7 @@ void PIScreen::SystemConsole::resize(int w, int h) {
|
|||||||
|
|
||||||
void PIScreen::SystemConsole::print() {
|
void PIScreen::SystemConsole::print() {
|
||||||
if (mouse_x >= 0 && mouse_x < width && mouse_y >= 0 && mouse_y < height) {
|
if (mouse_x >= 0 && mouse_x < width && mouse_y >= 0 && mouse_y < height) {
|
||||||
///cells[mouse_y][mouse_x].format.flags ^= Inverse;
|
/// cells[mouse_y][mouse_x].format.flags ^= Inverse;
|
||||||
}
|
}
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
PRIVATE->srect = PRIVATE->sbi.srWindow;
|
PRIVATE->srect = PRIVATE->sbi.srWindow;
|
||||||
@@ -186,10 +187,10 @@ void PIScreen::SystemConsole::print() {
|
|||||||
int k = j * dw + i;
|
int k = j * dw + i;
|
||||||
Cell & c(cells[j + dy0][i + dx0]);
|
Cell & c(cells[j + dy0][i + dx0]);
|
||||||
PRIVATE->chars[k].Char.UnicodeChar = 0;
|
PRIVATE->chars[k].Char.UnicodeChar = 0;
|
||||||
PRIVATE->chars[k].Char.AsciiChar = c.symbol.toConsole1Byte();
|
PRIVATE->chars[k].Char.AsciiChar = c.symbol.toConsole1Byte();
|
||||||
PRIVATE->chars[k].Attributes = attributes(c);
|
PRIVATE->chars[k].Attributes = attributes(c);
|
||||||
}
|
}
|
||||||
//piCout << "draw" << dw << dh;
|
// piCout << "draw" << dw << dh;
|
||||||
PRIVATE->bs.X = dw;
|
PRIVATE->bs.X = dw;
|
||||||
PRIVATE->bs.Y = dh;
|
PRIVATE->bs.Y = dh;
|
||||||
PRIVATE->srect.Left += dx0;
|
PRIVATE->srect.Left += dx0;
|
||||||
@@ -228,7 +229,7 @@ void PIScreen::SystemConsole::print() {
|
|||||||
if (!s.isEmpty()) {
|
if (!s.isEmpty()) {
|
||||||
moveTo(si, sj);
|
moveTo(si, sj);
|
||||||
PICout::stdoutPIString(s);
|
PICout::stdoutPIString(s);
|
||||||
//printf("%s", s.data());
|
// printf("%s", s.data());
|
||||||
s.clear();
|
s.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,33 +241,37 @@ void PIScreen::SystemConsole::print() {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
#define FOREGROUND_MASK (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
|
# define FOREGROUND_MASK (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
|
||||||
#define BACKGROUND_MASK (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
|
# define BACKGROUND_MASK (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
|
||||||
ushort PIScreen::SystemConsole::attributes(const PIScreenTypes::Cell & c) {
|
ushort PIScreen::SystemConsole::attributes(const PIScreenTypes::Cell & c) {
|
||||||
WORD attr = PRIVATE->dattr;
|
WORD attr = PRIVATE->dattr;
|
||||||
if (c.format.flags & Bold) attr |= FOREGROUND_INTENSITY;
|
if (c.format.flags & Bold)
|
||||||
else attr &= ~FOREGROUND_INTENSITY;
|
attr |= FOREGROUND_INTENSITY;
|
||||||
if (c.format.flags & Underline) attr |= COMMON_LVB_UNDERSCORE;
|
else
|
||||||
else attr &= ~COMMON_LVB_UNDERSCORE;
|
attr &= ~FOREGROUND_INTENSITY;
|
||||||
|
if (c.format.flags & Underline)
|
||||||
|
attr |= COMMON_LVB_UNDERSCORE;
|
||||||
|
else
|
||||||
|
attr &= ~COMMON_LVB_UNDERSCORE;
|
||||||
switch (c.format.color_char) {
|
switch (c.format.color_char) {
|
||||||
case Black: attr = (attr & ~FOREGROUND_MASK); break;
|
case Black: attr = (attr & ~FOREGROUND_MASK); break;
|
||||||
case Red: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_RED; break;
|
case Red: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_RED; break;
|
||||||
case Green: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_GREEN; break;
|
case Green: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_GREEN; break;
|
||||||
case Blue: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_BLUE; break;
|
case Blue: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_BLUE; break;
|
||||||
case Cyan: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
|
case Cyan: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
|
||||||
case Magenta: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_RED | FOREGROUND_BLUE; break;
|
case Magenta: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_RED | FOREGROUND_BLUE; break;
|
||||||
case Yellow: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_RED | FOREGROUND_GREEN; break;
|
case Yellow: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_RED | FOREGROUND_GREEN; break;
|
||||||
case White: attr = attr | FOREGROUND_MASK; break;
|
case White: attr = attr | FOREGROUND_MASK; break;
|
||||||
}
|
}
|
||||||
switch (c.format.color_back) {
|
switch (c.format.color_back) {
|
||||||
case Black: attr = (attr & ~BACKGROUND_MASK); break;
|
case Black: attr = (attr & ~BACKGROUND_MASK); break;
|
||||||
case Red: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_RED; break;
|
case Red: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_RED; break;
|
||||||
case Green: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_GREEN; break;
|
case Green: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_GREEN; break;
|
||||||
case Blue: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_BLUE; break;
|
case Blue: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_BLUE; break;
|
||||||
case Cyan: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
|
case Cyan: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
|
||||||
case Magenta: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_RED | BACKGROUND_BLUE; break;
|
case Magenta: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_RED | BACKGROUND_BLUE; break;
|
||||||
case Yellow: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_RED | BACKGROUND_GREEN; break;
|
case Yellow: attr = (attr & ~BACKGROUND_MASK) | BACKGROUND_RED | BACKGROUND_GREEN; break;
|
||||||
case White: attr = attr | BACKGROUND_MASK; break;
|
case White: attr = attr | BACKGROUND_MASK; break;
|
||||||
}
|
}
|
||||||
if ((c.format.flags & Inverse) == Inverse) {
|
if ((c.format.flags & Inverse) == Inverse) {
|
||||||
uchar f = attr & 0xFF;
|
uchar f = attr & 0xFF;
|
||||||
@@ -276,8 +281,8 @@ ushort PIScreen::SystemConsole::attributes(const PIScreenTypes::Cell & c) {
|
|||||||
}
|
}
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
#undef FOREGROUND_MASK
|
# undef FOREGROUND_MASK
|
||||||
#undef BACKGROUND_MASK
|
# undef BACKGROUND_MASK
|
||||||
|
|
||||||
void PIScreen::SystemConsole::getWinCurCoord() {
|
void PIScreen::SystemConsole::getWinCurCoord() {
|
||||||
GetConsoleScreenBufferInfo(PRIVATE->hOut, &PRIVATE->csbi);
|
GetConsoleScreenBufferInfo(PRIVATE->hOut, &PRIVATE->csbi);
|
||||||
@@ -292,36 +297,37 @@ void PIScreen::SystemConsole::clearLine() {
|
|||||||
|
|
||||||
void PIScreen::SystemConsole::newLine() {
|
void PIScreen::SystemConsole::newLine() {
|
||||||
getWinCurCoord();
|
getWinCurCoord();
|
||||||
PRIVATE->ccoord.X = 0; PRIVATE->ccoord.Y++;
|
PRIVATE->ccoord.X = 0;
|
||||||
|
PRIVATE->ccoord.Y++;
|
||||||
SetConsoleCursorPosition(PRIVATE->hOut, PRIVATE->ccoord);
|
SetConsoleCursorPosition(PRIVATE->hOut, PRIVATE->ccoord);
|
||||||
}
|
}
|
||||||
#else // WINDOWS
|
#else // WINDOWS
|
||||||
PIString PIScreen::SystemConsole::formatString(const PIScreenTypes::Cell & c) {
|
PIString PIScreen::SystemConsole::formatString(const PIScreenTypes::Cell & c) {
|
||||||
PIString ts = PIStringAscii("\e[0");
|
PIString ts = PIStringAscii("\e[0");
|
||||||
switch (c.format.color_char) {
|
switch (c.format.color_char) {
|
||||||
case Black: ts += PIStringAscii(";30"); break;
|
case Black: ts += PIStringAscii(";30"); break;
|
||||||
case Red: ts += PIStringAscii(";31"); break;
|
case Red: ts += PIStringAscii(";31"); break;
|
||||||
case Green: ts += PIStringAscii(";32"); break;
|
case Green: ts += PIStringAscii(";32"); break;
|
||||||
case Blue: ts += PIStringAscii(";34"); break;
|
case Blue: ts += PIStringAscii(";34"); break;
|
||||||
case Cyan: ts += PIStringAscii(";36"); break;
|
case Cyan: ts += PIStringAscii(";36"); break;
|
||||||
case Magenta: ts += PIStringAscii(";35"); break;
|
case Magenta: ts += PIStringAscii(";35"); break;
|
||||||
case Yellow: ts += PIStringAscii(";33"); break;
|
case Yellow: ts += PIStringAscii(";33"); break;
|
||||||
case White: ts += PIStringAscii(";37"); break;
|
case White: ts += PIStringAscii(";37"); break;
|
||||||
}
|
}
|
||||||
switch (c.format.color_back) {
|
switch (c.format.color_back) {
|
||||||
case Black: ts += PIStringAscii(";40"); break;
|
case Black: ts += PIStringAscii(";40"); break;
|
||||||
case Red: ts += PIStringAscii(";41"); break;
|
case Red: ts += PIStringAscii(";41"); break;
|
||||||
case Green: ts += PIStringAscii(";42"); break;
|
case Green: ts += PIStringAscii(";42"); break;
|
||||||
case Blue: ts += PIStringAscii(";44"); break;
|
case Blue: ts += PIStringAscii(";44"); break;
|
||||||
case Cyan: ts += PIStringAscii(";46"); break;
|
case Cyan: ts += PIStringAscii(";46"); break;
|
||||||
case Magenta: ts += PIStringAscii(";45"); break;
|
case Magenta: ts += PIStringAscii(";45"); break;
|
||||||
case Yellow: ts += PIStringAscii(";43"); break;
|
case Yellow: ts += PIStringAscii(";43"); break;
|
||||||
case White: ts += PIStringAscii(";47"); break;
|
case White: ts += PIStringAscii(";47"); break;
|
||||||
}
|
}
|
||||||
if ((c.format.flags & Bold ) == Bold ) ts += PIStringAscii(";1");
|
if ((c.format.flags & Bold) == Bold) ts += PIStringAscii(";1");
|
||||||
if ((c.format.flags & Underline) == Underline) ts += PIStringAscii(";4");
|
if ((c.format.flags & Underline) == Underline) ts += PIStringAscii(";4");
|
||||||
if ((c.format.flags & Blink ) == Blink ) ts += PIStringAscii(";5");
|
if ((c.format.flags & Blink) == Blink) ts += PIStringAscii(";5");
|
||||||
if ((c.format.flags & Inverse ) == Inverse ) ts += PIStringAscii(";7");
|
if ((c.format.flags & Inverse) == Inverse) ts += PIStringAscii(";7");
|
||||||
return ts + 'm';
|
return ts + 'm';
|
||||||
}
|
}
|
||||||
#endif // WINDOWS
|
#endif // WINDOWS
|
||||||
@@ -358,8 +364,16 @@ void PIScreen::SystemConsole::clearScreen() {
|
|||||||
void PIScreen::SystemConsole::clearScreenLower() {
|
void PIScreen::SystemConsole::clearScreenLower() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
getWinCurCoord();
|
getWinCurCoord();
|
||||||
FillConsoleOutputAttribute(PRIVATE->hOut, PRIVATE->dattr, width * height - width * PRIVATE->ccoord.Y + PRIVATE->ccoord.X, PRIVATE->ccoord, &PRIVATE->written);
|
FillConsoleOutputAttribute(PRIVATE->hOut,
|
||||||
FillConsoleOutputCharacter(PRIVATE->hOut, ' ', width * height - width * PRIVATE->ccoord.Y + PRIVATE->ccoord.X, PRIVATE->ccoord, &PRIVATE->written);
|
PRIVATE->dattr,
|
||||||
|
width * height - width * PRIVATE->ccoord.Y + PRIVATE->ccoord.X,
|
||||||
|
PRIVATE->ccoord,
|
||||||
|
&PRIVATE->written);
|
||||||
|
FillConsoleOutputCharacter(PRIVATE->hOut,
|
||||||
|
' ',
|
||||||
|
width * height - width * PRIVATE->ccoord.Y + PRIVATE->ccoord.X,
|
||||||
|
PRIVATE->ccoord,
|
||||||
|
&PRIVATE->written);
|
||||||
#else
|
#else
|
||||||
printf("\e[0m\e[J");
|
printf("\e[0m\e[J");
|
||||||
#endif
|
#endif
|
||||||
@@ -384,17 +398,17 @@ void PIScreen::SystemConsole::showCursor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// PIScreen
|
||||||
|
|
||||||
PIScreen::PIScreen(bool startNow, PIKbdListener::KBFunc slot): PIThread(), drawer_(console.cells), root("rootTile") {
|
PIScreen::PIScreen(bool startNow, PIKbdListener::KBFunc slot): PIThread(), drawer_(console.cells), root("rootTile") {
|
||||||
setName("screen");
|
setName("screen");
|
||||||
setPriority(piLow);
|
setPriority(piLow);
|
||||||
needLockRun(true);
|
needLockRun(true);
|
||||||
mouse_ = false;
|
mouse_ = false;
|
||||||
ret_func = slot;
|
ret_func = slot;
|
||||||
tile_focus = tile_dialog = nullptr;
|
tile_focus = tile_dialog = nullptr;
|
||||||
root.screen = this;
|
root.screen = this;
|
||||||
listener = new PIKbdListener(key_eventS, this, startNow);
|
listener = new PIKbdListener(key_eventS, this, startNow);
|
||||||
CONNECT1(void, PIKbdListener::MouseEvent, listener, mouseEvent, this, mouse_event);
|
CONNECT1(void, PIKbdListener::MouseEvent, listener, mouseEvent, this, mouse_event);
|
||||||
CONNECT1(void, PIKbdListener::WheelEvent, listener, wheelEvent, this, wheel_event);
|
CONNECT1(void, PIKbdListener::WheelEvent, listener, wheelEvent, this, wheel_event);
|
||||||
if (startNow) start();
|
if (startNow) start();
|
||||||
@@ -410,7 +424,7 @@ PIScreen::~PIScreen() {
|
|||||||
|
|
||||||
|
|
||||||
void PIScreen::setMouseEnabled(bool on) {
|
void PIScreen::setMouseEnabled(bool on) {
|
||||||
mouse_ = on;
|
mouse_ = on;
|
||||||
console.mouse_x = console.mouse_y = -1;
|
console.mouse_x = console.mouse_y = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,14 +436,12 @@ void PIScreen::key_event(PIKbdListener::KeyEvent key) {
|
|||||||
return;
|
return;
|
||||||
*/
|
*/
|
||||||
PIScreenTile * rtile = rootTile();
|
PIScreenTile * rtile = rootTile();
|
||||||
if (tile_dialog)
|
if (tile_dialog) rtile = tile_dialog;
|
||||||
rtile = tile_dialog;
|
|
||||||
bool used = nextFocus(rtile, key);
|
bool used = nextFocus(rtile, key);
|
||||||
if (used) return;
|
if (used) return;
|
||||||
if (!used && tile_focus) {
|
if (!used && tile_focus) {
|
||||||
if (tile_focus->visible) {
|
if (tile_focus->visible) {
|
||||||
if (tile_focus->keyEvent(key))
|
if (tile_focus->keyEvent(key)) return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret_func != 0) ret_func(key, data_);
|
if (ret_func != 0) ret_func(key, data_);
|
||||||
@@ -437,14 +449,14 @@ void PIScreen::key_event(PIKbdListener::KeyEvent key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIVector<PIScreenTile * > PIScreen::prepareMouse(PIKbdListener::MouseEvent * e) {
|
PIVector<PIScreenTile *> PIScreen::prepareMouse(PIKbdListener::MouseEvent * e) {
|
||||||
PIVector<PIScreenTile * > ret;
|
PIVector<PIScreenTile *> ret;
|
||||||
if (!mouse_ || !e) return ret;
|
if (!mouse_ || !e) return ret;
|
||||||
console.mouse_x = e->x;
|
console.mouse_x = e->x;
|
||||||
console.mouse_y = e->y;
|
console.mouse_y = e->y;
|
||||||
PIVector<PIScreenTile * > tl = tilesUnderMouse(e->x, e->y);
|
PIVector<PIScreenTile *> tl = tilesUnderMouse(e->x, e->y);
|
||||||
bool ff = false;
|
bool ff = false;
|
||||||
piForeachR (PIScreenTile * t, tl) {
|
piForeachR(PIScreenTile * t, tl) {
|
||||||
if (!ff) {
|
if (!ff) {
|
||||||
if (t->focus_flags[FocusOnMouse] && (e->action == PIKbdListener::MouseButtonPress)) {
|
if (t->focus_flags[FocusOnMouse] && (e->action == PIKbdListener::MouseButtonPress)) {
|
||||||
t->setFocus();
|
t->setFocus();
|
||||||
@@ -455,20 +467,19 @@ PIVector<PIScreenTile * > PIScreen::prepareMouse(PIKbdListener::MouseEvent * e)
|
|||||||
ff = true;
|
ff = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return tl;
|
return tl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIVector<PIScreenTile * > PIScreen::tilesUnderMouse(int x, int y) {
|
PIVector<PIScreenTile *> PIScreen::tilesUnderMouse(int x, int y) {
|
||||||
PIVector<PIScreenTile * > ret;
|
PIVector<PIScreenTile *> ret;
|
||||||
if (x < 0 || x >= console.width || y < 0 || y >= console.height) return ret;
|
if (x < 0 || x >= console.width || y < 0 || y >= console.height) return ret;
|
||||||
PIScreenTile * ct = tile_dialog ? tile_dialog : rootTile();
|
PIScreenTile * ct = tile_dialog ? tile_dialog : rootTile();
|
||||||
bool f = true;
|
bool f = true;
|
||||||
while (ct) {
|
while (ct) {
|
||||||
if (!f) ret << ct;
|
if (!f) ret << ct;
|
||||||
f = false;
|
f = false;
|
||||||
ct = ct->childUnderMouse(x, y);
|
ct = ct->childUnderMouse(x, y);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@@ -476,27 +487,25 @@ PIVector<PIScreenTile * > PIScreen::tilesUnderMouse(int x, int y) {
|
|||||||
|
|
||||||
|
|
||||||
void PIScreen::mouse_event(PIKbdListener::MouseEvent me) {
|
void PIScreen::mouse_event(PIKbdListener::MouseEvent me) {
|
||||||
PIVector<PIScreenTile * > tl = prepareMouse(&me);
|
PIVector<PIScreenTile *> tl = prepareMouse(&me);
|
||||||
if (tl.isEmpty()) return;
|
if (tl.isEmpty()) return;
|
||||||
piForeachR (PIScreenTile * t, tl)
|
piForeachR(PIScreenTile * t, tl)
|
||||||
if (t->mouseEvent(me)) break;
|
if (t->mouseEvent(me)) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIScreen::wheel_event(PIKbdListener::WheelEvent we) {
|
void PIScreen::wheel_event(PIKbdListener::WheelEvent we) {
|
||||||
PIVector<PIScreenTile * > tl = prepareMouse(&we);
|
PIVector<PIScreenTile *> tl = prepareMouse(&we);
|
||||||
if (tl.isEmpty()) return;
|
if (tl.isEmpty()) return;
|
||||||
piForeachR (PIScreenTile * t, tl)
|
piForeachR(PIScreenTile * t, tl)
|
||||||
if (t->wheelEvent(we)) break;
|
if (t->wheelEvent(we)) break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIScreen::nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key) {
|
bool PIScreen::nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key) {
|
||||||
PIVector<PIScreenTile*> vtl = rt->children(true), ftl;
|
PIVector<PIScreenTile *> vtl = rt->children(true), ftl;
|
||||||
piForeach (PIScreenTile * t, vtl) {
|
piForeach(PIScreenTile * t, vtl) {
|
||||||
if (t->focus_flags[CanHasFocus])
|
if (t->focus_flags[CanHasFocus]) ftl << t;
|
||||||
ftl << t;
|
|
||||||
}
|
}
|
||||||
int ind = -1;
|
int ind = -1;
|
||||||
for (int i = 0; i < ftl.size_s(); ++i)
|
for (int i = 0; i < ftl.size_s(); ++i)
|
||||||
@@ -504,18 +513,15 @@ bool PIScreen::nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key) {
|
|||||||
ind = i;
|
ind = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ind < 0)
|
if (ind < 0) tile_focus = 0;
|
||||||
tile_focus = 0;
|
|
||||||
if (ftl.isEmpty())
|
if (ftl.isEmpty())
|
||||||
tile_focus = 0;
|
tile_focus = 0;
|
||||||
else {
|
else {
|
||||||
if (tile_focus)
|
if (tile_focus)
|
||||||
if (!tile_focus->visible)
|
if (!tile_focus->visible) tile_focus = 0;
|
||||||
tile_focus = 0;
|
|
||||||
int next = tile_focus ? 0 : 1;
|
int next = tile_focus ? 0 : 1;
|
||||||
if (tile_focus) {
|
if (tile_focus) {
|
||||||
if (tile_focus->focus_flags[NextByTab] && key.key == PIKbdListener::Tab)
|
if (tile_focus->focus_flags[NextByTab] && key.key == PIKbdListener::Tab) next = 1;
|
||||||
next = 1;
|
|
||||||
if (tile_focus->focus_flags[NextByArrowsHorizontal]) {
|
if (tile_focus->focus_flags[NextByArrowsHorizontal]) {
|
||||||
if (key.key == PIKbdListener::LeftArrow) next = -1;
|
if (key.key == PIKbdListener::LeftArrow) next = -1;
|
||||||
if (key.key == PIKbdListener::RightArrow) next = 1;
|
if (key.key == PIKbdListener::RightArrow) next = 1;
|
||||||
@@ -525,16 +531,16 @@ bool PIScreen::nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key) {
|
|||||||
if (key.key == PIKbdListener::DownArrow) next = 1;
|
if (key.key == PIKbdListener::DownArrow) next = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//piCout << ftl.size() << ind << next;
|
// piCout << ftl.size() << ind << next;
|
||||||
if (next != 0) {
|
if (next != 0) {
|
||||||
PIVector<PIScreenTile*> tl = rt->children();
|
PIVector<PIScreenTile *> tl = rt->children();
|
||||||
piForeach (PIScreenTile * t, tl)
|
piForeach(PIScreenTile * t, tl)
|
||||||
t->has_focus = false;
|
t->has_focus = false;
|
||||||
if (!ftl.isEmpty()) {
|
if (!ftl.isEmpty()) {
|
||||||
ind += next;
|
ind += next;
|
||||||
if (ind >= ftl.size_s()) ind = 0;
|
if (ind >= ftl.size_s()) ind = 0;
|
||||||
if (ind < 0) ind = ftl.size_s() - 1;
|
if (ind < 0) ind = ftl.size_s() - 1;
|
||||||
tile_focus = ftl[ind];
|
tile_focus = ftl[ind];
|
||||||
tile_focus->has_focus = true;
|
tile_focus->has_focus = true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -550,22 +556,19 @@ void PIScreen::tileEventInternal(PIScreenTile * t, TileEvent e) {
|
|||||||
|
|
||||||
|
|
||||||
void PIScreen::tileRemovedInternal(PIScreenTile * t) {
|
void PIScreen::tileRemovedInternal(PIScreenTile * t) {
|
||||||
if (tile_dialog == t)
|
if (tile_dialog == t) tile_dialog = 0;
|
||||||
tile_dialog = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIScreen::tileSetFocusInternal(PIScreenTile * t) {
|
void PIScreen::tileSetFocusInternal(PIScreenTile * t) {
|
||||||
PIScreenTile * rt = rootTile();
|
PIScreenTile * rt = rootTile();
|
||||||
if (tile_dialog)
|
if (tile_dialog) rt = tile_dialog;
|
||||||
rt = tile_dialog;
|
PIVector<PIScreenTile *> tl = rt->children(), ftl;
|
||||||
PIVector<PIScreenTile*> tl = rt->children(), ftl;
|
piForeach(PIScreenTile * i, tl)
|
||||||
piForeach (PIScreenTile * i, tl)
|
|
||||||
i->has_focus = false;
|
i->has_focus = false;
|
||||||
tile_focus = t;
|
tile_focus = t;
|
||||||
if (!tile_focus) return;
|
if (!tile_focus) return;
|
||||||
if (tile_focus->focus_flags[CanHasFocus])
|
if (tile_focus->focus_flags[CanHasFocus]) tile_focus->has_focus = true;
|
||||||
tile_focus->has_focus = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -612,16 +615,21 @@ void PIScreen::run() {
|
|||||||
if (tile_dialog) {
|
if (tile_dialog) {
|
||||||
int sw(0), sh(0);
|
int sw(0), sh(0);
|
||||||
tile_dialog->sizeHint(sw, sh);
|
tile_dialog->sizeHint(sw, sh);
|
||||||
sw = piClampi(sw, tile_dialog->minimumWidth, tile_dialog->maximumWidth);
|
sw = piClampi(sw, tile_dialog->minimumWidth, tile_dialog->maximumWidth);
|
||||||
sh = piClampi(sh, tile_dialog->minimumHeight, tile_dialog->maximumHeight);
|
sh = piClampi(sh, tile_dialog->minimumHeight, tile_dialog->maximumHeight);
|
||||||
tile_dialog->x_ = (console.width - sw) / 2;
|
tile_dialog->x_ = (console.width - sw) / 2;
|
||||||
tile_dialog->y_ = (console.height - sh) / 2;
|
tile_dialog->y_ = (console.height - sh) / 2;
|
||||||
tile_dialog->width_ = sw;
|
tile_dialog->width_ = sw;
|
||||||
tile_dialog->height_ = sh;
|
tile_dialog->height_ = sh;
|
||||||
tile_dialog->layout();
|
tile_dialog->layout();
|
||||||
int dx = tile_dialog->x_ - 1, dy = tile_dialog->y_ - 1, dw = tile_dialog->width_, dh = tile_dialog->height_;
|
int dx = tile_dialog->x_ - 1, dy = tile_dialog->y_ - 1, dw = tile_dialog->width_, dh = tile_dialog->height_;
|
||||||
drawer_.drawFrame(dx, dy, dx + dw + 1, dy + dh + 1, (Color)tile_dialog->back_format.color_char,
|
drawer_.drawFrame(dx,
|
||||||
(Color)tile_dialog->back_format.color_back, (CharFlags)tile_dialog->back_format.flags);
|
dy,
|
||||||
|
dx + dw + 1,
|
||||||
|
dy + dh + 1,
|
||||||
|
(Color)tile_dialog->back_format.color_char,
|
||||||
|
(Color)tile_dialog->back_format.color_back,
|
||||||
|
(CharFlags)tile_dialog->back_format.flags);
|
||||||
tile_dialog->drawEventInternal(&drawer_);
|
tile_dialog->drawEventInternal(&drawer_);
|
||||||
}
|
}
|
||||||
console.print();
|
console.print();
|
||||||
@@ -635,10 +643,8 @@ void PIScreen::end() {
|
|||||||
|
|
||||||
|
|
||||||
PIScreenTile * PIScreen::tileByName(const PIString & name) {
|
PIScreenTile * PIScreen::tileByName(const PIString & name) {
|
||||||
PIVector<PIScreenTile*> tl(tiles());
|
PIVector<PIScreenTile *> tl(tiles());
|
||||||
piForeach (PIScreenTile * t, tl)
|
piForeach(PIScreenTile * t, tl)
|
||||||
if (t->name() == name)
|
if (t->name() == name) return t;
|
||||||
return t;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "piscreentiles.h"
|
#include "piscreentiles.h"
|
||||||
|
|
||||||
#include "piscreendrawer.h"
|
#include "piscreendrawer.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ TileSimple::TileSimple(const TileSimple::Row & r): PIScreenTile() {
|
|||||||
|
|
||||||
void TileSimple::sizeHint(int & w, int & h) const {
|
void TileSimple::sizeHint(int & w, int & h) const {
|
||||||
w = h = 0;
|
w = h = 0;
|
||||||
piForeachC (Row & r, content)
|
piForeachC(Row & r, content)
|
||||||
w = piMaxi(w, r.first.size_s());
|
w = piMaxi(w, r.first.size_s());
|
||||||
h = content.size_s();
|
h = content.size_s();
|
||||||
}
|
}
|
||||||
@@ -57,13 +58,13 @@ void TileSimple::drawEvent(PIScreenDrawer * d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TileScrollBar
|
||||||
|
|
||||||
TileScrollBar::TileScrollBar(const PIString & n) {
|
TileScrollBar::TileScrollBar(const PIString & n) {
|
||||||
direction = Vertical;
|
direction = Vertical;
|
||||||
thickness = 1;
|
thickness = 1;
|
||||||
minimum_ = value_ = 0;
|
minimum_ = value_ = 0;
|
||||||
maximum_ = 100;
|
maximum_ = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -122,15 +123,15 @@ bool TileScrollBar::mouseEvent(PIKbdListener::MouseEvent me) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TileList
|
||||||
|
|
||||||
TileList::TileList(const PIString & n, SelectionMode sm): PIScreenTile(n) {
|
TileList::TileList(const PIString & n, SelectionMode sm): PIScreenTile(n) {
|
||||||
alignment = Left;
|
alignment = Left;
|
||||||
focus_flags = CanHasFocus | NextByArrowsHorizontal | NextByTab | FocusOnMouseOrWheel;
|
focus_flags = CanHasFocus | NextByArrowsHorizontal | NextByTab | FocusOnMouseOrWheel;
|
||||||
lhei = offset = cur = 0;
|
lhei = offset = cur = 0;
|
||||||
mouse_sel = false;
|
mouse_sel = false;
|
||||||
selection_mode = sm;
|
selection_mode = sm;
|
||||||
scroll = new TileScrollBar();
|
scroll = new TileScrollBar();
|
||||||
scroll->size_policy = Ignore;
|
scroll->size_policy = Ignore;
|
||||||
addTile(scroll);
|
addTile(scroll);
|
||||||
}
|
}
|
||||||
@@ -138,26 +139,26 @@ TileList::TileList(const PIString & n, SelectionMode sm): PIScreenTile(n) {
|
|||||||
|
|
||||||
void TileList::sizeHint(int & w, int & h) const {
|
void TileList::sizeHint(int & w, int & h) const {
|
||||||
w = h = 0;
|
w = h = 0;
|
||||||
piForeachC (Row & r, content)
|
piForeachC(Row & r, content)
|
||||||
w = piMaxi(w, r.first.size_s());
|
w = piMaxi(w, r.first.size_s());
|
||||||
h = 3;
|
h = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TileList::resizeEvent(int w, int h) {
|
void TileList::resizeEvent(int w, int h) {
|
||||||
scroll->x_ = x_ + width_ - 1;
|
scroll->x_ = x_ + width_ - 1;
|
||||||
scroll->y_ = y_;
|
scroll->y_ = y_;
|
||||||
scroll->width_ = 1;
|
scroll->width_ = 1;
|
||||||
scroll->height_ = height_;
|
scroll->height_ = height_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TileList::drawEvent(PIScreenDrawer * d) {
|
void TileList::drawEvent(PIScreenDrawer * d) {
|
||||||
lhei = height_ - 2;
|
lhei = height_ - 2;
|
||||||
int is = piClampi(offset, 0, piMaxi(0, content.size_s() - 1)), ie = piClampi(offset + lhei, 0, content.size_s());
|
int is = piClampi(offset, 0, piMaxi(0, content.size_s() - 1)), ie = piClampi(offset + lhei, 0, content.size_s());
|
||||||
if (is > 0) d->drawText(x_, y_, PIString(" /\\ ").repeat(width_ / 4), Green, Default, Bold);
|
if (is > 0) d->drawText(x_, y_, PIString(" /\\ ").repeat(width_ / 4), Green, Default, Bold);
|
||||||
if (ie < content.size_s()) d->drawText(x_, y_ + height_ - 1, PIString(" \\/ ").repeat(width_ / 4), Green, Default, Bold);
|
if (ie < content.size_s()) d->drawText(x_, y_ + height_ - 1, PIString(" \\/ ").repeat(width_ / 4), Green, Default, Bold);
|
||||||
//piCout << is << ie << offset << lhei << content.size_s();
|
// piCout << is << ie << offset << lhei << content.size_s();
|
||||||
for (int i = is; i < ie; ++i) {
|
for (int i = is; i < ie; ++i) {
|
||||||
Row & r(content[i]);
|
Row & r(content[i]);
|
||||||
bool sel = i == cur && has_focus;
|
bool sel = i == cur && has_focus;
|
||||||
@@ -172,7 +173,7 @@ void TileList::drawEvent(PIScreenDrawer * d) {
|
|||||||
case Right: rx = x_ + width_ - 1 - r.first.size_s(); break;
|
case Right: rx = x_ + width_ - 1 - r.first.size_s(); break;
|
||||||
};
|
};
|
||||||
CharFlags cf = r.second.flags;
|
CharFlags cf = r.second.flags;
|
||||||
Color cc = (Color)r.second.color_char;
|
Color cc = (Color)r.second.color_char;
|
||||||
if (selected[i]) {
|
if (selected[i]) {
|
||||||
cf |= Bold;
|
cf |= Bold;
|
||||||
cc = Yellow;
|
cc = Yellow;
|
||||||
@@ -188,9 +189,7 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
lhei = height_ - 2;
|
lhei = height_ - 2;
|
||||||
int oo(0), osp = piMini(3, lhei / 4);
|
int oo(0), osp = piMini(3, lhei / 4);
|
||||||
switch (key.key) {
|
switch (key.key) {
|
||||||
case PIKbdListener::PageUp:
|
case PIKbdListener::PageUp: cur -= lhei / 2; oo -= lhei / 2;
|
||||||
cur -= lhei / 2;
|
|
||||||
oo -= lhei / 2;
|
|
||||||
case PIKbdListener::UpArrow:
|
case PIKbdListener::UpArrow:
|
||||||
cur--;
|
cur--;
|
||||||
oo--;
|
oo--;
|
||||||
@@ -207,7 +206,8 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
switch (selection_mode) {
|
switch (selection_mode) {
|
||||||
case NoSelection: return false;
|
case NoSelection: return false;
|
||||||
case SingleSelection:
|
case SingleSelection:
|
||||||
if (selected.isEmpty()) selected << cur;
|
if (selected.isEmpty())
|
||||||
|
selected << cur;
|
||||||
else {
|
else {
|
||||||
bool add = !selected[cur];
|
bool add = !selected[cur];
|
||||||
selected.clear();
|
selected.clear();
|
||||||
@@ -216,8 +216,10 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
raiseEvent(TileEvent(SelectionChanged));
|
raiseEvent(TileEvent(SelectionChanged));
|
||||||
return true;
|
return true;
|
||||||
case MultiSelection:
|
case MultiSelection:
|
||||||
if (selected[cur]) selected.remove(cur);
|
if (selected[cur])
|
||||||
else selected << cur;
|
selected.remove(cur);
|
||||||
|
else
|
||||||
|
selected << cur;
|
||||||
raiseEvent(TileEvent(SelectionChanged));
|
raiseEvent(TileEvent(SelectionChanged));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -238,17 +240,14 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
if (offset >= content.size_s() - lhei) offset = content.size_s() - lhei;
|
if (offset >= content.size_s() - lhei) offset = content.size_s() - lhei;
|
||||||
if (offset < 0) offset = 0;
|
if (offset < 0) offset = 0;
|
||||||
return true;
|
return true;
|
||||||
case PIKbdListener::Home:
|
case PIKbdListener::Home: cur = offset = 0; return true;
|
||||||
cur = offset = 0;
|
|
||||||
return true;
|
|
||||||
case PIKbdListener::End:
|
case PIKbdListener::End:
|
||||||
cur = content.size_s() - 1;
|
cur = content.size_s() - 1;
|
||||||
offset = content.size_s() - lhei;
|
offset = content.size_s() - lhei;
|
||||||
if (offset < 0) offset = 0;
|
if (offset < 0) offset = 0;
|
||||||
return true;
|
return true;
|
||||||
case PIKbdListener::Return:
|
case PIKbdListener::Return:
|
||||||
if (cur >= 0 && cur < content.size_s())
|
if (cur >= 0 && cur < content.size_s()) raiseEvent(TileEvent(RowPressed, cur));
|
||||||
raiseEvent(TileEvent(RowPressed, cur));
|
|
||||||
return true;
|
return true;
|
||||||
case '*':
|
case '*':
|
||||||
if (selection_mode == TileList::MultiSelection) {
|
if (selection_mode == TileList::MultiSelection) {
|
||||||
@@ -278,12 +277,8 @@ bool TileList::mouseEvent(PIKbdListener::MouseEvent me) {
|
|||||||
if (mp < 0 || mp >= content.size_s()) return true;
|
if (mp < 0 || mp >= content.size_s()) return true;
|
||||||
cur = mp;
|
cur = mp;
|
||||||
switch (me.action) {
|
switch (me.action) {
|
||||||
case PIKbdListener::MouseButtonPress:
|
case PIKbdListener::MouseButtonPress: mouse_sel = !selected.contains(cur); break;
|
||||||
mouse_sel = !selected.contains(cur);
|
case PIKbdListener::MouseButtonDblClick: keyEvent(PIKbdListener::KeyEvent(PIKbdListener::Return)); return true;
|
||||||
break;
|
|
||||||
case PIKbdListener::MouseButtonDblClick:
|
|
||||||
keyEvent(PIKbdListener::KeyEvent(PIKbdListener::Return));
|
|
||||||
return true;
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
if (me.buttons[PIKbdListener::MouseRight]) {
|
if (me.buttons[PIKbdListener::MouseRight]) {
|
||||||
@@ -294,8 +289,10 @@ bool TileList::mouseEvent(PIKbdListener::MouseEvent me) {
|
|||||||
raiseEvent(TileEvent(SelectionChanged));
|
raiseEvent(TileEvent(SelectionChanged));
|
||||||
break;
|
break;
|
||||||
case MultiSelection:
|
case MultiSelection:
|
||||||
if (mouse_sel) selected << cur;
|
if (mouse_sel)
|
||||||
else selected.remove(cur);
|
selected << cur;
|
||||||
|
else
|
||||||
|
selected.remove(cur);
|
||||||
raiseEvent(TileEvent(SelectionChanged));
|
raiseEvent(TileEvent(SelectionChanged));
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
@@ -311,7 +308,7 @@ bool TileList::wheelEvent(PIKbdListener::WheelEvent we) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TileButton
|
||||||
|
|
||||||
TileButton::TileButton(const PIString & n): PIScreenTile(n) {
|
TileButton::TileButton(const PIString & n): PIScreenTile(n) {
|
||||||
focus_flags = CanHasFocus | NextByTab | NextByArrowsAll | FocusOnMouse;
|
focus_flags = CanHasFocus | NextByTab | NextByArrowsAll | FocusOnMouse;
|
||||||
@@ -327,7 +324,7 @@ void TileButton::sizeHint(int & w, int & h) const {
|
|||||||
void TileButton::drawEvent(PIScreenDrawer * d) {
|
void TileButton::drawEvent(PIScreenDrawer * d) {
|
||||||
Color cb = has_focus ? Blue : Cyan;
|
Color cb = has_focus ? Blue : Cyan;
|
||||||
Color ct = has_focus ? White : Black;
|
Color ct = has_focus ? White : Black;
|
||||||
int ff = has_focus ? Bold : 0;
|
int ff = has_focus ? Bold : 0;
|
||||||
d->fillRect(x_, y_, x_ + width_, y_ + 1, ' ', Default, cb);
|
d->fillRect(x_, y_, x_ + width_, y_ + 1, ' ', Default, cb);
|
||||||
d->drawText(x_, y_, "[", ct, Transparent, ff);
|
d->drawText(x_, y_, "[", ct, Transparent, ff);
|
||||||
d->drawText(x_ + (width_ - text.size_s()) / 2, y_, text, ct, Transparent, ff);
|
d->drawText(x_ + (width_ - text.size_s()) / 2, y_, text, ct, Transparent, ff);
|
||||||
@@ -351,25 +348,25 @@ bool TileButton::mouseEvent(PIKbdListener::MouseEvent me) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TileButtons
|
||||||
|
|
||||||
TileButtons::TileButtons(const PIString & n): PIScreenTile(n) {
|
TileButtons::TileButtons(const PIString & n): PIScreenTile(n) {
|
||||||
focus_flags = CanHasFocus | NextByTab | FocusOnMouse;
|
focus_flags = CanHasFocus | NextByTab | FocusOnMouse;
|
||||||
direction = Horizontal;
|
direction = Horizontal;
|
||||||
alignment = PIScreenTypes::Center;
|
alignment = PIScreenTypes::Center;
|
||||||
cur = 0;
|
cur = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TileButtons::sizeHint(int & w, int & h) const {
|
void TileButtons::sizeHint(int & w, int & h) const {
|
||||||
w = h = 0;
|
w = h = 0;
|
||||||
if (direction == Horizontal) {
|
if (direction == Horizontal) {
|
||||||
piForeachC (Button & b, content)
|
piForeachC(Button & b, content)
|
||||||
w += b.first.size_s() + 4;
|
w += b.first.size_s() + 4;
|
||||||
w += piMaxi(0, content.size_s() - 1) * 2;
|
w += piMaxi(0, content.size_s() - 1) * 2;
|
||||||
h += 1;
|
h += 1;
|
||||||
} else {
|
} else {
|
||||||
piForeachC (Button & b, content)
|
piForeachC(Button & b, content)
|
||||||
w = piMaxi(w, b.first.size_s() + 4);
|
w = piMaxi(w, b.first.size_s() + 4);
|
||||||
h += content.size_s();
|
h += content.size_s();
|
||||||
h += piMaxi(0, content.size_s() - 1);
|
h += piMaxi(0, content.size_s() - 1);
|
||||||
@@ -387,12 +384,11 @@ void TileButtons::drawEvent(PIScreenDrawer * d) {
|
|||||||
case PIScreenTypes::Right: dx = width_ - shw; break;
|
case PIScreenTypes::Right: dx = width_ - shw; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
if (direction == PIScreenTypes::Horizontal)
|
if (direction == PIScreenTypes::Horizontal) cx += dx;
|
||||||
cx += dx;
|
|
||||||
for (int i = 0; i < content.size_s(); ++i) {
|
for (int i = 0; i < content.size_s(); ++i) {
|
||||||
Color cb = Cyan;
|
Color cb = Cyan;
|
||||||
Color ct = Black;
|
Color ct = Black;
|
||||||
int ff = 0;
|
int ff = 0;
|
||||||
if (i == cur && has_focus) {
|
if (i == cur && has_focus) {
|
||||||
cb = Blue;
|
cb = Blue;
|
||||||
ct = White;
|
ct = White;
|
||||||
@@ -430,9 +426,7 @@ bool TileButtons::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
if (cur >= content.size_s()) cur = content.size_s() - 1;
|
if (cur >= content.size_s()) cur = content.size_s() - 1;
|
||||||
return true;
|
return true;
|
||||||
case PIKbdListener::Space:
|
case PIKbdListener::Space:
|
||||||
case PIKbdListener::Return:
|
case PIKbdListener::Return: raiseEvent(TileEvent(ButtonSelected, cur)); return true;
|
||||||
raiseEvent(TileEvent(ButtonSelected, cur));
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
return PIScreenTile::keyEvent(key);
|
return PIScreenTile::keyEvent(key);
|
||||||
}
|
}
|
||||||
@@ -441,8 +435,7 @@ bool TileButtons::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
bool TileButtons::mouseEvent(PIKbdListener::MouseEvent me) {
|
bool TileButtons::mouseEvent(PIKbdListener::MouseEvent me) {
|
||||||
if (me.action == PIKbdListener::MouseMove || me.action == PIKbdListener::MouseButtonPress) {
|
if (me.action == PIKbdListener::MouseMove || me.action == PIKbdListener::MouseButtonPress) {
|
||||||
for (int i = 0; i < btn_rects.size_s(); ++i)
|
for (int i = 0; i < btn_rects.size_s(); ++i)
|
||||||
if (me.x >= btn_rects[i].x0 && me.x < btn_rects[i].x1 &&
|
if (me.x >= btn_rects[i].x0 && me.x < btn_rects[i].x1 && me.y >= btn_rects[i].y0 && me.y < btn_rects[i].y1) {
|
||||||
me.y >= btn_rects[i].y0 && me.y < btn_rects[i].y1) {
|
|
||||||
cur = i;
|
cur = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -454,11 +447,11 @@ bool TileButtons::mouseEvent(PIKbdListener::MouseEvent me) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TileCheck
|
||||||
|
|
||||||
TileCheck::TileCheck(const PIString & n): PIScreenTile(n) {
|
TileCheck::TileCheck(const PIString & n): PIScreenTile(n) {
|
||||||
focus_flags = CanHasFocus | NextByTab | NextByArrowsAll | FocusOnMouse;
|
focus_flags = CanHasFocus | NextByTab | NextByArrowsAll | FocusOnMouse;
|
||||||
toggled = false;
|
toggled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -471,7 +464,7 @@ void TileCheck::sizeHint(int & w, int & h) const {
|
|||||||
void TileCheck::drawEvent(PIScreenDrawer * d) {
|
void TileCheck::drawEvent(PIScreenDrawer * d) {
|
||||||
Color cb = has_focus ? Blue : Cyan;
|
Color cb = has_focus ? Blue : Cyan;
|
||||||
Color ct = has_focus ? White : Black;
|
Color ct = has_focus ? White : Black;
|
||||||
int ff = has_focus ? Bold : 0;
|
int ff = has_focus ? Bold : 0;
|
||||||
PIString cs("[ ]");
|
PIString cs("[ ]");
|
||||||
if (toggled) cs[1] = '*';
|
if (toggled) cs[1] = '*';
|
||||||
d->fillRect(x_, y_, x_ + width_, y_ + 1, ' ', Default, cb);
|
d->fillRect(x_, y_, x_ + width_, y_ + 1, ' ', Default, cb);
|
||||||
@@ -499,12 +492,12 @@ bool TileCheck::mouseEvent(PIKbdListener::MouseEvent me) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TileProgress
|
||||||
|
|
||||||
TileProgress::TileProgress(const PIString & n): PIScreenTile(n) {
|
TileProgress::TileProgress(const PIString & n): PIScreenTile(n) {
|
||||||
maximum = 100.;
|
maximum = 100.;
|
||||||
value = 0.;
|
value = 0.;
|
||||||
suffix = " %";
|
suffix = " %";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -515,7 +508,7 @@ void TileProgress::sizeHint(int & w, int & h) const {
|
|||||||
|
|
||||||
|
|
||||||
void TileProgress::drawEvent(PIScreenDrawer * d) {
|
void TileProgress::drawEvent(PIScreenDrawer * d) {
|
||||||
int v = maximum == 0. ? 0 : piClampd(piRoundd(value / maximum * 100.), 0, 100);
|
int v = maximum == 0. ? 0 : piClampd(piRoundd(value / maximum * 100.), 0, 100);
|
||||||
PIString s = prefix + PIString::fromNumber(piRoundd(value)) + suffix;
|
PIString s = prefix + PIString::fromNumber(piRoundd(value)) + suffix;
|
||||||
int w = piRoundd(v / 100. * width_), sx = (width_ - s.size_s()) / 2;
|
int w = piRoundd(v / 100. * width_), sx = (width_ - s.size_s()) / 2;
|
||||||
d->fillRect(x_, y_, x_ + width_, y_ + 1, ' ', Default, Cyan);
|
d->fillRect(x_, y_, x_ + width_, y_ + 1, ' ', Default, Cyan);
|
||||||
@@ -532,10 +525,10 @@ void TileProgress::drawEvent(PIScreenDrawer * d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TilePICout
|
||||||
|
|
||||||
TilePICout::TilePICout(const PIString & n): TileList(n) {
|
TilePICout::TilePICout(const PIString & n): TileList(n) {
|
||||||
max_lines = 1024;
|
max_lines = 1024;
|
||||||
selection_mode = TileList::SingleSelection;
|
selection_mode = TileList::SingleSelection;
|
||||||
PICout::setOutputDevices(PICout::Buffer);
|
PICout::setOutputDevices(PICout::Buffer);
|
||||||
}
|
}
|
||||||
@@ -545,14 +538,13 @@ void TilePICout::drawEvent(PIScreenDrawer * d) {
|
|||||||
PIString out = PICout::getBufferAndClear();
|
PIString out = PICout::getBufferAndClear();
|
||||||
if (!out.isEmpty()) {
|
if (!out.isEmpty()) {
|
||||||
PIStringList l = out.split("\n");
|
PIStringList l = out.split("\n");
|
||||||
bool scroll = (cur == content.size_s() - 1) || !has_focus;
|
bool scroll = (cur == content.size_s() - 1) || !has_focus;
|
||||||
piForeachC (PIString & s, l)
|
piForeachC(PIString & s, l)
|
||||||
content << TileList::Row(s.trimmed(), format);
|
content << TileList::Row(s.trimmed(), format);
|
||||||
if (content.size_s() > max_lines)
|
if (content.size_s() > max_lines) content.remove(0, content.size_s() - max_lines);
|
||||||
content.remove(0, content.size_s() - max_lines);
|
|
||||||
if (scroll) {
|
if (scroll) {
|
||||||
offset = piMaxi(0, content.size_s() - lhei);
|
offset = piMaxi(0, content.size_s() - lhei);
|
||||||
cur = content.size_s() - 1;
|
cur = content.size_s() - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TileList::drawEvent(d);
|
TileList::drawEvent(d);
|
||||||
@@ -569,16 +561,16 @@ bool TilePICout::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TileInput
|
||||||
|
|
||||||
TileInput::TileInput(const PIString & n): PIScreenTile(n) {
|
TileInput::TileInput(const PIString & n): PIScreenTile(n) {
|
||||||
focus_flags = CanHasFocus | NextByTab | FocusOnMouse;
|
focus_flags = CanHasFocus | NextByTab | FocusOnMouse;
|
||||||
back_format.color_back = White;
|
back_format.color_back = White;
|
||||||
format.color_char = Black;
|
format.color_char = Black;
|
||||||
format.color_back = White;
|
format.color_back = White;
|
||||||
max_length = 1024;
|
max_length = 1024;
|
||||||
cur = offset = 0;
|
cur = offset = 0;
|
||||||
inv = false;
|
inv = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -591,10 +583,8 @@ void TileInput::sizeHint(int & w, int & h) const {
|
|||||||
void TileInput::drawEvent(PIScreenDrawer * d) {
|
void TileInput::drawEvent(PIScreenDrawer * d) {
|
||||||
PIString ps = text.mid(offset, width_ - 2);
|
PIString ps = text.mid(offset, width_ - 2);
|
||||||
d->drawText(x_ + 1, y_, ps, (Color)format.color_char, Transparent, (CharFlags)format.flags);
|
d->drawText(x_ + 1, y_, ps, (Color)format.color_char, Transparent, (CharFlags)format.flags);
|
||||||
if (offset > 0)
|
if (offset > 0) d->drawText(x_, y_, "<", Green, Black, Bold);
|
||||||
d->drawText(x_, y_, "<", Green, Black, Bold);
|
if (text.size_s() - offset >= width_ - 2) d->drawText(x_ + width_ - 1, y_, ">", Green, Black, Bold);
|
||||||
if (text.size_s() - offset >= width_ - 2)
|
|
||||||
d->drawText(x_ + width_ - 1, y_, ">", Green, Black, Bold);
|
|
||||||
if (!has_focus) return;
|
if (!has_focus) return;
|
||||||
Color cb = (Color)format.color_char, cc = (Color)format.color_back;
|
Color cb = (Color)format.color_char, cc = (Color)format.color_back;
|
||||||
if (tm_blink.elapsed_m() >= 650) {
|
if (tm_blink.elapsed_m() >= 650) {
|
||||||
@@ -641,14 +631,13 @@ bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
reserCursor();
|
reserCursor();
|
||||||
return true;
|
return true;
|
||||||
case PIKbdListener::End:
|
case PIKbdListener::End:
|
||||||
cur = text.size_s();
|
cur = text.size_s();
|
||||||
offset = text.size_s() - lwid;
|
offset = text.size_s() - lwid;
|
||||||
if (offset < 0) offset = 0;
|
if (offset < 0) offset = 0;
|
||||||
reserCursor();
|
reserCursor();
|
||||||
return true;
|
return true;
|
||||||
case PIKbdListener::Backspace:
|
case PIKbdListener::Backspace:
|
||||||
if (cur > text.size_s() || text.isEmpty())
|
if (cur > text.size_s() || text.isEmpty()) return true;
|
||||||
return true;
|
|
||||||
text.remove(cur - 1, 1);
|
text.remove(cur - 1, 1);
|
||||||
cur--;
|
cur--;
|
||||||
if (cur > text.size_s()) cur = text.size_s();
|
if (cur > text.size_s()) cur = text.size_s();
|
||||||
@@ -658,8 +647,7 @@ bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
reserCursor();
|
reserCursor();
|
||||||
return true;
|
return true;
|
||||||
case PIKbdListener::Delete:
|
case PIKbdListener::Delete:
|
||||||
if (cur >= text.size_s() || text.isEmpty())
|
if (cur >= text.size_s() || text.isEmpty()) return true;
|
||||||
return true;
|
|
||||||
text.remove(cur, 1);
|
text.remove(cur, 1);
|
||||||
if (cur < 0) cur = 0;
|
if (cur < 0) cur = 0;
|
||||||
if (cur > text.size_s()) cur = text.size_s();
|
if (cur > text.size_s()) cur = text.size_s();
|
||||||
@@ -685,8 +673,7 @@ bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
|
|||||||
case PIKbdListener::F9:
|
case PIKbdListener::F9:
|
||||||
case PIKbdListener::F10:
|
case PIKbdListener::F10:
|
||||||
case PIKbdListener::F11:
|
case PIKbdListener::F11:
|
||||||
case PIKbdListener::F12:
|
case PIKbdListener::F12: break;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
text.insert(cur, PIChar((ushort)key.key));
|
text.insert(cur, PIChar((ushort)key.key));
|
||||||
cur++;
|
cur++;
|
||||||
|
|||||||
@@ -25,16 +25,16 @@
|
|||||||
struct PIP_EXPORT PIIntrospectionContainersType {
|
struct PIP_EXPORT PIIntrospectionContainersType {
|
||||||
~PIIntrospectionContainersType();
|
~PIIntrospectionContainersType();
|
||||||
void finish();
|
void finish();
|
||||||
uint id = 0;
|
uint id = 0;
|
||||||
const char * name = nullptr;
|
const char * name = nullptr;
|
||||||
const char * demangled = "?";
|
const char * demangled = "?";
|
||||||
bool inited = false;
|
bool inited = false;
|
||||||
bool has_demangled = false;
|
bool has_demangled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||||
|
|
||||||
#include "piintrospection_base.h"
|
# include "piintrospection_base.h"
|
||||||
|
|
||||||
class PIIntrospectionContainers;
|
class PIIntrospectionContainers;
|
||||||
|
|
||||||
@@ -45,6 +45,7 @@ public:
|
|||||||
static PIIntrospectionContainersType ret = create();
|
static PIIntrospectionContainersType ret = create();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static PIIntrospectionContainersType create() {
|
static PIIntrospectionContainersType create() {
|
||||||
PIIntrospectionContainersType ret;
|
PIIntrospectionContainersType ret;
|
||||||
@@ -54,35 +55,39 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())
|
# define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())
|
||||||
|
|
||||||
# define PIINTROSPECTION_CONTAINER_NEW(t, isz) PIINTROSPECTION_CONTAINERS->containerNew (PIIntrospectionContainersTypeInfo<t>::get(), isz);
|
// clang-format off
|
||||||
# define PIINTROSPECTION_CONTAINER_DELETE(t) PIINTROSPECTION_CONTAINERS->containerDelete(PIIntrospectionContainersTypeInfo<t>::get());
|
# define PIINTROSPECTION_CONTAINER_NEW (t, isz) PIINTROSPECTION_CONTAINERS->containerNew (PIIntrospectionContainersTypeInfo<t>::get(), isz);
|
||||||
# define PIINTROSPECTION_CONTAINER_ALLOC(t, cnt) PIINTROSPECTION_CONTAINERS->containerAlloc (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
# define PIINTROSPECTION_CONTAINER_DELETE(t ) PIINTROSPECTION_CONTAINERS->containerDelete(PIIntrospectionContainersTypeInfo<t>::get() );
|
||||||
# define PIINTROSPECTION_CONTAINER_FREE(t, cnt) PIINTROSPECTION_CONTAINERS->containerFree (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
# define PIINTROSPECTION_CONTAINER_ALLOC (t, cnt) PIINTROSPECTION_CONTAINERS->containerAlloc (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||||
# define PIINTROSPECTION_CONTAINER_USED(t, cnt) PIINTROSPECTION_CONTAINERS->containerUsed (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
# define PIINTROSPECTION_CONTAINER_FREE (t, cnt) PIINTROSPECTION_CONTAINERS->containerFree (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||||
# define PIINTROSPECTION_CONTAINER_UNUSED(t, cnt) PIINTROSPECTION_CONTAINERS->containerUnused(PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
# define PIINTROSPECTION_CONTAINER_USED (t, cnt) PIINTROSPECTION_CONTAINERS->containerUsed (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||||
|
# define PIINTROSPECTION_CONTAINER_UNUSED(t, cnt) PIINTROSPECTION_CONTAINERS->containerUnused(PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
|
||||||
class PIP_EXPORT PIIntrospectionContainersInterface {
|
class PIP_EXPORT PIIntrospectionContainersInterface {
|
||||||
friend class PIIntrospection;
|
friend class PIIntrospection;
|
||||||
friend class PIIntrospectionServer;
|
friend class PIIntrospectionServer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
__PIINTROSPECTION_SINGLETON_H__(Containers)
|
__PIINTROSPECTION_SINGLETON_H__(Containers)
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
void containerNew (const PIIntrospectionContainersType & ti, uint isz);
|
void containerNew (const PIIntrospectionContainersType & ti, uint isz);
|
||||||
void containerDelete(const PIIntrospectionContainersType & ti);
|
void containerDelete(const PIIntrospectionContainersType & ti);
|
||||||
void containerAlloc (const PIIntrospectionContainersType & ti, ullong cnt);
|
void containerAlloc (const PIIntrospectionContainersType & ti, ullong cnt);
|
||||||
void containerFree (const PIIntrospectionContainersType & ti, ullong cnt);
|
void containerFree (const PIIntrospectionContainersType & ti, ullong cnt);
|
||||||
void containerUsed (const PIIntrospectionContainersType & ti, ullong cnt);
|
void containerUsed (const PIIntrospectionContainersType & ti, ullong cnt);
|
||||||
void containerUnused(const PIIntrospectionContainersType & ti, ullong cnt);
|
void containerUnused(const PIIntrospectionContainersType & ti, ullong cnt);
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
PIIntrospectionContainers * p;
|
PIIntrospectionContainers * p;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PIIntrospectionContainersInterface();
|
PIIntrospectionContainersInterface();
|
||||||
~PIIntrospectionContainersInterface();
|
~PIIntrospectionContainersInterface();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -96,5 +101,4 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // PIINTROSPECTION_CONTAINERS_H
|
#endif // PIINTROSPECTION_CONTAINERS_H
|
||||||
|
|||||||
@@ -20,10 +20,12 @@
|
|||||||
#ifndef PIINTROSPECTION_CONTAINERS_P_H
|
#ifndef PIINTROSPECTION_CONTAINERS_P_H
|
||||||
#define PIINTROSPECTION_CONTAINERS_P_H
|
#define PIINTROSPECTION_CONTAINERS_P_H
|
||||||
|
|
||||||
|
#include "piintrospection_containers.h"
|
||||||
#include "pispinlock.h"
|
#include "pispinlock.h"
|
||||||
|
#include "pistring.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "picrc.h"
|
|
||||||
|
|
||||||
|
|
||||||
class PIP_EXPORT PIIntrospectionContainers {
|
class PIP_EXPORT PIIntrospectionContainers {
|
||||||
@@ -32,28 +34,30 @@ public:
|
|||||||
|
|
||||||
struct TypeInfo;
|
struct TypeInfo;
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
void containerNew (const PIIntrospectionContainersType & ti, uint isz);
|
void containerNew (const PIIntrospectionContainersType & ti, uint isz);
|
||||||
void containerDelete(const PIIntrospectionContainersType & ti);
|
void containerDelete(const PIIntrospectionContainersType & ti);
|
||||||
void containerAlloc (const PIIntrospectionContainersType & ti, ullong cnt);
|
void containerAlloc (const PIIntrospectionContainersType & ti, ullong cnt);
|
||||||
void containerFree (const PIIntrospectionContainersType & ti, ullong cnt);
|
void containerFree (const PIIntrospectionContainersType & ti, ullong cnt);
|
||||||
void containerUsed (const PIIntrospectionContainersType & ti, ullong cnt);
|
void containerUsed (const PIIntrospectionContainersType & ti, ullong cnt);
|
||||||
void containerUnused(const PIIntrospectionContainersType & ti, ullong cnt);
|
void containerUnused(const PIIntrospectionContainersType & ti, ullong cnt);
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
PIVector<TypeInfo> getInfo() const;
|
PIVector<TypeInfo> getInfo() const;
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
struct PIP_EXPORT _Type {
|
struct PIP_EXPORT _Type {
|
||||||
uint id = 0u;
|
uint id = 0u;
|
||||||
uint count = 0u;
|
uint count = 0u;
|
||||||
uint item_size = 0u;
|
uint item_size = 0u;
|
||||||
ullong allocated = 0u;
|
ullong allocated = 0u;
|
||||||
ullong used = 0u;
|
ullong used = 0u;
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
struct PIP_EXPORT TypeInfo: _Type {
|
struct PIP_EXPORT TypeInfo: _Type {
|
||||||
ullong allocated_bytes = 0u;
|
ullong allocated_bytes = 0u;
|
||||||
ullong used_bytes = 0u;
|
ullong used_bytes = 0u;
|
||||||
PIString name;
|
PIString name;
|
||||||
PIString item_size_str;
|
PIString item_size_str;
|
||||||
PIString allocated_str;
|
PIString allocated_str;
|
||||||
|
|||||||
@@ -22,25 +22,29 @@
|
|||||||
|
|
||||||
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||||
|
|
||||||
#include "piintrospection_base.h"
|
# include "piintrospection_base.h"
|
||||||
|
|
||||||
class PIIntrospectionThreads;
|
class PIIntrospectionThreads;
|
||||||
|
|
||||||
#define PIINTROSPECTION_THREADS (PIIntrospectionThreadsInterface::instance())
|
# define PIINTROSPECTION_THREADS (PIIntrospectionThreadsInterface::instance())
|
||||||
|
|
||||||
# define PIINTROSPECTION_THREAD_NEW(t) PIINTROSPECTION_THREADS->threadNew (t);
|
// clang-format off
|
||||||
# define PIINTROSPECTION_THREAD_DELETE(t) PIINTROSPECTION_THREADS->threadDelete (t);
|
# define PIINTROSPECTION_THREAD_NEW (t ) PIINTROSPECTION_THREADS->threadNew (t );
|
||||||
# define PIINTROSPECTION_THREAD_START(t) PIINTROSPECTION_THREADS->threadStart (t);
|
# define PIINTROSPECTION_THREAD_DELETE (t ) PIINTROSPECTION_THREADS->threadDelete (t );
|
||||||
# define PIINTROSPECTION_THREAD_RUN(t) PIINTROSPECTION_THREADS->threadRun (t);
|
# define PIINTROSPECTION_THREAD_START (t ) PIINTROSPECTION_THREADS->threadStart (t );
|
||||||
# define PIINTROSPECTION_THREAD_WAIT(t) PIINTROSPECTION_THREADS->threadWait (t);
|
# define PIINTROSPECTION_THREAD_RUN (t ) PIINTROSPECTION_THREADS->threadRun (t );
|
||||||
# define PIINTROSPECTION_THREAD_STOP(t) PIINTROSPECTION_THREADS->threadStop (t);
|
# define PIINTROSPECTION_THREAD_WAIT (t ) PIINTROSPECTION_THREADS->threadWait (t );
|
||||||
# define PIINTROSPECTION_THREAD_RUN_DONE(t,us) PIINTROSPECTION_THREADS->threadRunDone(t,us);
|
# define PIINTROSPECTION_THREAD_STOP (t ) PIINTROSPECTION_THREADS->threadStop (t );
|
||||||
|
# define PIINTROSPECTION_THREAD_RUN_DONE(t,us) PIINTROSPECTION_THREADS->threadRunDone(t,us);
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
class PIP_EXPORT PIIntrospectionThreadsInterface {
|
class PIP_EXPORT PIIntrospectionThreadsInterface {
|
||||||
friend class PIIntrospection;
|
friend class PIIntrospection;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
__PIINTROSPECTION_SINGLETON_H__(Threads)
|
__PIINTROSPECTION_SINGLETON_H__(Threads)
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
void threadNew (PIThread * t);
|
void threadNew (PIThread * t);
|
||||||
void threadDelete (PIThread * t);
|
void threadDelete (PIThread * t);
|
||||||
void threadStart (PIThread * t);
|
void threadStart (PIThread * t);
|
||||||
@@ -48,13 +52,13 @@ public:
|
|||||||
void threadWait (PIThread * t);
|
void threadWait (PIThread * t);
|
||||||
void threadStop (PIThread * t);
|
void threadStop (PIThread * t);
|
||||||
void threadRunDone(PIThread * t, ullong us);
|
void threadRunDone(PIThread * t, ullong us);
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PIIntrospectionThreadsInterface();
|
PIIntrospectionThreadsInterface();
|
||||||
~PIIntrospectionThreadsInterface();
|
~PIIntrospectionThreadsInterface();
|
||||||
|
|
||||||
PIIntrospectionThreads * p;
|
PIIntrospectionThreads * p;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -64,7 +68,7 @@ private:
|
|||||||
# define PIINTROSPECTION_THREAD_RUN(t)
|
# define PIINTROSPECTION_THREAD_RUN(t)
|
||||||
# define PIINTROSPECTION_THREAD_WAIT(t)
|
# define PIINTROSPECTION_THREAD_WAIT(t)
|
||||||
# define PIINTROSPECTION_THREAD_STOP(t)
|
# define PIINTROSPECTION_THREAD_STOP(t)
|
||||||
# define PIINTROSPECTION_THREAD_RUN_DONE(t,us)
|
# define PIINTROSPECTION_THREAD_RUN_DONE(t, us)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // PIINTROSPECTION_THREADS_H
|
#endif // PIINTROSPECTION_THREADS_H
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public:
|
|||||||
ullong run_us, run_count;
|
ullong run_us, run_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
void threadNew (PIThread * t);
|
void threadNew (PIThread * t);
|
||||||
void threadDelete (PIThread * t);
|
void threadDelete (PIThread * t);
|
||||||
void threadStart (PIThread * t);
|
void threadStart (PIThread * t);
|
||||||
@@ -51,10 +52,10 @@ public:
|
|||||||
void threadWait (PIThread * t);
|
void threadWait (PIThread * t);
|
||||||
void threadStop (PIThread * t);
|
void threadStop (PIThread * t);
|
||||||
void threadRunDone(PIThread * t, ullong us);
|
void threadRunDone(PIThread * t, ullong us);
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
PIMap<PIThread*, ThreadInfo> threads;
|
PIMap<PIThread *, ThreadInfo> threads;
|
||||||
PIMutex mutex;
|
PIMutex mutex;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
#include "piiostream.h"
|
#include "piiostream.h"
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
#define PICONFIG_GET_VALUE \
|
#define PICONFIG_GET_VALUE \
|
||||||
Entry & getValue(const PIString & vname, const char * def, bool * exists = 0) {return getValue(vname, PIString(def), exists);} \
|
Entry & getValue(const PIString & vname, const char * def, bool * exists = 0) {return getValue(vname, PIString(def), exists);} \
|
||||||
Entry & getValue(const PIString & vname, const PIStringList & def, bool * exists = 0) {return getValue(vname, def.join("%|%"), exists);} \
|
Entry & getValue(const PIString & vname, const PIStringList & def, bool * exists = 0) {return getValue(vname, def.join("%|%"), exists);} \
|
||||||
@@ -55,13 +56,13 @@
|
|||||||
Entry & getValue(const PIString & vname, const ulong def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
|
Entry & getValue(const PIString & vname, const ulong def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
|
||||||
Entry & getValue(const PIString & vname, const float def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
|
Entry & getValue(const PIString & vname, const float def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);} \
|
||||||
Entry & getValue(const PIString & vname, const double def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);}
|
Entry & getValue(const PIString & vname, const double def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
class PIP_EXPORT PIConfig
|
class PIP_EXPORT PIConfig {
|
||||||
{
|
|
||||||
friend class Entry;
|
friend class Entry;
|
||||||
friend class Branch;
|
friend class Branch;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
//! Contructs and read configuration file at path "path" in mode "mode"
|
//! Contructs and read configuration file at path "path" in mode "mode"
|
||||||
PIConfig(const PIString & path, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
PIConfig(const PIString & path, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
|
|
||||||
@@ -76,18 +77,21 @@ public:
|
|||||||
class Entry;
|
class Entry;
|
||||||
|
|
||||||
|
|
||||||
class PIP_EXPORT Branch: public PIVector<Entry * > {
|
class PIP_EXPORT Branch: public PIVector<Entry *> {
|
||||||
friend class PIConfig;
|
friend class PIConfig;
|
||||||
friend class Entry;
|
friend class Entry;
|
||||||
#ifdef PIP_STD_IOSTREAM
|
#ifdef PIP_STD_IOSTREAM
|
||||||
friend std::ostream & operator <<(std::ostream & s, const Branch & v);
|
friend std::ostream & operator<<(std::ostream & s, const Branch & v);
|
||||||
#endif
|
#endif
|
||||||
friend PICout operator <<(PICout s, const Branch & v);
|
friend PICout operator<<(PICout s, const Branch & v);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Branch() {;}
|
Branch() { ; }
|
||||||
|
|
||||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0);
|
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0);
|
||||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0) const {return const_cast<Branch * >(this)->getValue(vname, def, exists);}
|
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0) const {
|
||||||
|
return const_cast<Branch *>(this)->getValue(vname, def, exists);
|
||||||
|
}
|
||||||
PICONFIG_GET_VALUE
|
PICONFIG_GET_VALUE
|
||||||
|
|
||||||
Branch allLeaves();
|
Branch allLeaves();
|
||||||
@@ -95,125 +99,226 @@ public:
|
|||||||
Branch getLeaves();
|
Branch getLeaves();
|
||||||
Branch getBranches();
|
Branch getBranches();
|
||||||
Branch & filter(const PIString & f);
|
Branch & filter(const PIString & f);
|
||||||
bool isEntryExists(const PIString & name) const {piForeachC (Entry * i, *this) if (entryExists(i, name)) return true; return false;}
|
bool isEntryExists(const PIString & name) const {
|
||||||
int indexOf(const Entry * e) {for (int i = 0; i < size_s(); ++i) if (at(i) == e) return i; return -1;}
|
piForeachC(Entry * i, *this)
|
||||||
|
if (entryExists(i, name)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int indexOf(const Entry * e) {
|
||||||
|
for (int i = 0; i < size_s(); ++i)
|
||||||
|
if (at(i) == e) return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool entryExists(const Entry * e, const PIString & name) const;
|
bool entryExists(const Entry * e, const PIString & name) const;
|
||||||
void allLeaves(Branch & b, Entry * e) {piForeach (Entry * i, e->_children) {if (i->isLeaf()) b << i; else allLeaves(b, i);}}
|
void allLeaves(Branch & b, Entry * e) {
|
||||||
|
piForeach(Entry * i, e->_children) {
|
||||||
|
if (i->isLeaf())
|
||||||
|
b << i;
|
||||||
|
else
|
||||||
|
allLeaves(b, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
#ifdef PIP_STD_IOSTREAM
|
#ifdef PIP_STD_IOSTREAM
|
||||||
void coutt(std::ostream & s, const PIString & p) const {piForeachC (Entry * i, *this) i->coutt(s, p);}
|
void coutt(std::ostream & s, const PIString & p) const {
|
||||||
|
piForeachC(Entry * i, *this)
|
||||||
|
i->coutt(s, p);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
void piCoutt(PICout s, const PIString & p) const {piForeachC (Entry * i, *this) i->piCoutt(s, p);}
|
void piCoutt(PICout s, const PIString & p) const {
|
||||||
|
piForeachC(Entry * i, *this)
|
||||||
|
i->piCoutt(s, p);
|
||||||
|
}
|
||||||
|
|
||||||
static Entry _empty;
|
static Entry _empty;
|
||||||
PIString delim;
|
PIString delim;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PIP_EXPORT Entry {
|
class PIP_EXPORT Entry {
|
||||||
friend class PIConfig;
|
friend class PIConfig;
|
||||||
friend class Branch;
|
friend class Branch;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Entry() {_parent = 0; _line = -1;}
|
Entry() {
|
||||||
|
_parent = 0;
|
||||||
|
_line = -1;
|
||||||
|
}
|
||||||
|
|
||||||
//! Returns parent entry, or 0 if there is no parent (root of default value)
|
//! Returns parent entry, or 0 if there is no parent (root of default value)
|
||||||
Entry * parent() const {return _parent;}
|
Entry * parent() const { return _parent; }
|
||||||
|
|
||||||
//! Returns children count
|
//! Returns children count
|
||||||
int childCount() const {return _children.size_s();}
|
int childCount() const { return _children.size_s(); }
|
||||||
|
|
||||||
//! Returns children as \a PIConfig::Branch
|
//! Returns children as \a PIConfig::Branch
|
||||||
Branch & children() const {_children.delim = delim; return _children;}
|
Branch & children() const {
|
||||||
|
_children.delim = delim;
|
||||||
|
return _children;
|
||||||
|
}
|
||||||
|
|
||||||
//! Returns child at index "index"
|
//! Returns child at index "index"
|
||||||
Entry * child(const int index) const {return _children[index];}
|
Entry * child(const int index) const { return _children[index]; }
|
||||||
|
|
||||||
//! Returns first child with name "name"
|
//! Returns first child with name "name"
|
||||||
Entry * findChild(const PIString & name) {piForeach (Entry * i, _children) if (i->_name == name) return i; return 0;}
|
Entry * findChild(const PIString & name) {
|
||||||
|
piForeach(Entry * i, _children)
|
||||||
|
if (i->_name == name) return i;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//! Returns first child with name "name"
|
//! Returns first child with name "name"
|
||||||
const Entry * findChild(const PIString & name) const {piForeachC (Entry * i, _children) if (i->_name == name) return i; return 0;}
|
const Entry * findChild(const PIString & name) const {
|
||||||
|
piForeachC(Entry * i, _children)
|
||||||
|
if (i->_name == name) return i;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//! Returns \b true if there is no children
|
//! Returns \b true if there is no children
|
||||||
bool isLeaf() const {return _children.isEmpty();}
|
bool isLeaf() const { return _children.isEmpty(); }
|
||||||
|
|
||||||
|
|
||||||
//! Returns name
|
//! Returns name
|
||||||
const PIString & name() const {return _name;}
|
const PIString & name() const { return _name; }
|
||||||
|
|
||||||
//! Returns value
|
//! Returns value
|
||||||
const PIString & value() const {return _value;}
|
const PIString & value() const { return _value; }
|
||||||
|
|
||||||
//! Returns type
|
//! Returns type
|
||||||
const PIString & type() const {return _type;}
|
const PIString & type() const { return _type; }
|
||||||
|
|
||||||
//! Returns comment
|
//! Returns comment
|
||||||
const PIString & comment() const {return _comment;}
|
const PIString & comment() const { return _comment; }
|
||||||
|
|
||||||
/** \brief Returns full name, i.e. name as it looks in file
|
/** \brief Returns full name, i.e. name as it looks in file
|
||||||
* \details In case of default entry full name always is empty
|
* \details In case of default entry full name always is empty
|
||||||
* \snippet piconfig.cpp fullName */
|
* \snippet piconfig.cpp fullName */
|
||||||
const PIString & fullName() const {return _full_name;}
|
const PIString & fullName() const { return _full_name; }
|
||||||
|
|
||||||
//! Set name to "value" and returns this
|
//! Set name to "value" and returns this
|
||||||
Entry & setName(const PIString & value) {_name = value; return *this;}
|
Entry & setName(const PIString & value) {
|
||||||
|
_name = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set type to "value" and returns this
|
//! Set type to "value" and returns this
|
||||||
Entry & setType(const PIString & value) {_type = value; return *this;}
|
Entry & setType(const PIString & value) {
|
||||||
|
_type = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set comment to "value" and returns this
|
//! Set comment to "value" and returns this
|
||||||
Entry & setComment(const PIString & value) {_comment = value; return *this;}
|
Entry & setComment(const PIString & value) {
|
||||||
|
_comment = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this
|
//! Set value to "value" and returns this
|
||||||
Entry & setValue(const PIString & value) {_value = value; return *this;}
|
Entry & setValue(const PIString & value) {
|
||||||
|
_value = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "l"
|
//! Set value to "value" and returns this. Type is set to "l"
|
||||||
Entry & setValue(const PIStringList & value) {setValue(value.join("%|%")); setType("l"); return *this;}
|
Entry & setValue(const PIStringList & value) {
|
||||||
|
setValue(value.join("%|%"));
|
||||||
|
setType("l");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "s"
|
//! Set value to "value" and returns this. Type is set to "s"
|
||||||
Entry & setValue(const char * value) {setValue(PIString(value)); setType("s"); return *this;}
|
Entry & setValue(const char * value) {
|
||||||
|
setValue(PIString(value));
|
||||||
|
setType("s");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "b"
|
//! Set value to "value" and returns this. Type is set to "b"
|
||||||
Entry & setValue(const bool value) {setValue(PIString::fromBool(value)); setType("b"); return *this;}
|
Entry & setValue(const bool value) {
|
||||||
|
setValue(PIString::fromBool(value));
|
||||||
|
setType("b");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "s"
|
//! Set value to "value" and returns this. Type is set to "s"
|
||||||
Entry & setValue(const char value) {setValue(PIString(1, value)); setType("s"); return *this;}
|
Entry & setValue(const char value) {
|
||||||
|
setValue(PIString(1, value));
|
||||||
|
setType("s");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "n"
|
//! Set value to "value" and returns this. Type is set to "n"
|
||||||
Entry & setValue(const short value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
|
Entry & setValue(const short value) {
|
||||||
|
setValue(PIString::fromNumber(value));
|
||||||
|
setType("n");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "n"
|
//! Set value to "value" and returns this. Type is set to "n"
|
||||||
Entry & setValue(const int value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
|
Entry & setValue(const int value) {
|
||||||
|
setValue(PIString::fromNumber(value));
|
||||||
|
setType("n");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "n"
|
//! Set value to "value" and returns this. Type is set to "n"
|
||||||
Entry & setValue(const long value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
|
Entry & setValue(const long value) {
|
||||||
|
setValue(PIString::fromNumber(value));
|
||||||
|
setType("n");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "n"
|
//! Set value to "value" and returns this. Type is set to "n"
|
||||||
Entry & setValue(const uchar value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
|
Entry & setValue(const uchar value) {
|
||||||
|
setValue(PIString::fromNumber(value));
|
||||||
|
setType("n");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "n"
|
//! Set value to "value" and returns this. Type is set to "n"
|
||||||
Entry & setValue(const ushort value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
|
Entry & setValue(const ushort value) {
|
||||||
|
setValue(PIString::fromNumber(value));
|
||||||
|
setType("n");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "n"
|
//! Set value to "value" and returns this. Type is set to "n"
|
||||||
Entry & setValue(const uint value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
|
Entry & setValue(const uint value) {
|
||||||
|
setValue(PIString::fromNumber(value));
|
||||||
|
setType("n");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "n"
|
//! Set value to "value" and returns this. Type is set to "n"
|
||||||
Entry & setValue(const ulong value) {setValue(PIString::fromNumber(value)); setType("n"); return *this;}
|
Entry & setValue(const ulong value) {
|
||||||
|
setValue(PIString::fromNumber(value));
|
||||||
|
setType("n");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "f"
|
//! Set value to "value" and returns this. Type is set to "f"
|
||||||
Entry & setValue(const float value) {setValue(PIString::fromNumber(value)); setType("f"); return *this;}
|
Entry & setValue(const float value) {
|
||||||
|
setValue(PIString::fromNumber(value));
|
||||||
|
setType("f");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Set value to "value" and returns this. Type is set to "f"
|
//! Set value to "value" and returns this. Type is set to "f"
|
||||||
Entry & setValue(const double value) {setValue(PIString::fromNumber(value)); setType("f"); return *this;}
|
Entry & setValue(const double value) {
|
||||||
|
setValue(PIString::fromNumber(value));
|
||||||
|
setType("f");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** \brief Returns entry with name "vname" and default value "def"
|
/** \brief Returns entry with name "vname" and default value "def"
|
||||||
* \details If there is no suitable entry found, reference to default internal entry with
|
* \details If there is no suitable entry found, reference to default internal entry with
|
||||||
* value = "def" will be returned, and if "exists" not null it will be set to \b false */
|
* value = "def" will be returned, and if "exists" not null it will be set to \b false */
|
||||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0);
|
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0);
|
||||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0) const {return const_cast<Entry * >(this)->getValue(vname, def, exists);}
|
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0) const {
|
||||||
|
return const_cast<Entry *>(this)->getValue(vname, def, exists);
|
||||||
|
}
|
||||||
PICONFIG_GET_VALUE
|
PICONFIG_GET_VALUE
|
||||||
|
|
||||||
//! \fn Entry & getValue(const PIString & vname, const char * def, bool * exists = 0)
|
//! \fn Entry & getValue(const PIString & vname, const char * def, bool * exists = 0)
|
||||||
@@ -261,58 +366,68 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//! If there is no children returns if name == "name". Else returns if any child has name == "name"
|
//! If there is no children returns if name == "name". Else returns if any child has name == "name"
|
||||||
bool isEntryExists(const PIString & name) const {return entryExists(this, name);}
|
bool isEntryExists(const PIString & name) const { return entryExists(this, name); }
|
||||||
|
|
||||||
|
|
||||||
//! Convertion to boolean
|
//! Convertion to boolean
|
||||||
bool toBool() const {return _value.toBool();}
|
bool toBool() const { return _value.toBool(); }
|
||||||
|
|
||||||
//! Convertion to char
|
//! Convertion to char
|
||||||
char toChar() const {return (_value.isEmpty() ? 0 : _value[0].toAscii());}
|
char toChar() const { return (_value.isEmpty() ? 0 : _value[0].toAscii()); }
|
||||||
|
|
||||||
//! Convertion to short
|
//! Convertion to short
|
||||||
short toShort() const {return _value.toShort();}
|
short toShort() const { return _value.toShort(); }
|
||||||
|
|
||||||
//! Convertion to int
|
//! Convertion to int
|
||||||
int toInt() const {return _value.toInt();}
|
int toInt() const { return _value.toInt(); }
|
||||||
|
|
||||||
//! Convertion to long
|
//! Convertion to long
|
||||||
long toLong() const {return _value.toLong();}
|
long toLong() const { return _value.toLong(); }
|
||||||
|
|
||||||
//! Convertion to uchar
|
//! Convertion to uchar
|
||||||
uchar toUChar() const {return _value.toInt();}
|
uchar toUChar() const { return _value.toInt(); }
|
||||||
|
|
||||||
//! Convertion to ushort
|
//! Convertion to ushort
|
||||||
ushort toUShort() const {return _value.toShort();}
|
ushort toUShort() const { return _value.toShort(); }
|
||||||
|
|
||||||
//! Convertion to uint
|
//! Convertion to uint
|
||||||
uint toUInt() const {return _value.toInt();}
|
uint toUInt() const { return _value.toInt(); }
|
||||||
|
|
||||||
//! Convertion to ulong
|
//! Convertion to ulong
|
||||||
ulong toULong() const {return _value.toLong();}
|
ulong toULong() const { return _value.toLong(); }
|
||||||
|
|
||||||
//! Convertion to float
|
//! Convertion to float
|
||||||
float toFloat() const {return _value.toFloat();}
|
float toFloat() const { return _value.toFloat(); }
|
||||||
|
|
||||||
//! Convertion to double
|
//! Convertion to double
|
||||||
double toDouble() const {return _value.toDouble();}
|
double toDouble() const { return _value.toDouble(); }
|
||||||
|
|
||||||
//! Convertion to PIString
|
//! Convertion to PIString
|
||||||
PIString toString() const {return _value;}
|
PIString toString() const { return _value; }
|
||||||
|
|
||||||
//! Convertion to PIStringList
|
//! Convertion to PIStringList
|
||||||
PIStringList toStringList() const {return _value.split("%|%");}
|
PIStringList toStringList() const { return _value.split("%|%"); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool compare(PIConfig::Entry * const & f, PIConfig::Entry * const & s) {return f->_line < s->_line;}
|
static bool compare(PIConfig::Entry * const & f, PIConfig::Entry * const & s) { return f->_line < s->_line; }
|
||||||
bool entryExists(const Entry * e, const PIString & name) const;
|
bool entryExists(const Entry * e, const PIString & name) const;
|
||||||
void buildLine() {_all = _tab + _full_name + " = " + _value + " #" + _type + " " + _comment;}
|
void buildLine() { _all = _tab + _full_name + " = " + _value + " #" + _type + " " + _comment; }
|
||||||
void clear() {_children.clear(); _name = _value = _type = _comment = _all = PIString(); _line = 0; _parent = 0;}
|
void clear() {
|
||||||
|
_children.clear();
|
||||||
|
_name = _value = _type = _comment = _all = PIString();
|
||||||
|
_line = 0;
|
||||||
|
_parent = 0;
|
||||||
|
}
|
||||||
#ifdef PIP_STD_IOSTREAM
|
#ifdef PIP_STD_IOSTREAM
|
||||||
void coutt(std::ostream & s, const PIString & p) const;
|
void coutt(std::ostream & s, const PIString & p) const;
|
||||||
#endif
|
#endif
|
||||||
void piCoutt(PICout s, const PIString & p) const;
|
void piCoutt(PICout s, const PIString & p) const;
|
||||||
void deleteBranch() {piForeach (Entry * i, _children) {i->deleteBranch(); delete i;}}
|
void deleteBranch() {
|
||||||
|
piForeach(Entry * i, _children) {
|
||||||
|
i->deleteBranch();
|
||||||
|
delete i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Entry _empty;
|
static Entry _empty;
|
||||||
Entry * _parent;
|
Entry * _parent;
|
||||||
@@ -342,7 +457,9 @@ public:
|
|||||||
|
|
||||||
//! Returns top-level entry with name "vname", if doesn`t exists return entry with value "def" and set *exist to false
|
//! Returns top-level entry with name "vname", if doesn`t exists return entry with value "def" and set *exist to false
|
||||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0);
|
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0);
|
||||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0) const {return const_cast<PIConfig * >(this)->getValue(vname, def, exists);}
|
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0) const {
|
||||||
|
return const_cast<PIConfig *>(this)->getValue(vname, def, exists);
|
||||||
|
}
|
||||||
|
|
||||||
PICONFIG_GET_VALUE
|
PICONFIG_GET_VALUE
|
||||||
|
|
||||||
@@ -390,66 +507,91 @@ public:
|
|||||||
Branch getValues(const PIString & vname);
|
Branch getValues(const PIString & vname);
|
||||||
|
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "type" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "type" and if "write" immediate write to file. Add new entry if there
|
||||||
|
//! is no suitable exists
|
||||||
void setValue(const PIString & name, const PIString & value, const PIString & type = "s", bool write = true);
|
void setValue(const PIString & name, const PIString & value, const PIString & type = "s", bool write = true);
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "l" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "l" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const PIStringList & value, bool write = true) {setValue(name, value.join("%|%"), "l", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const PIStringList & value, bool write = true) { setValue(name, value.join("%|%"), "l", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "s" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "s" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const char * value, bool write = true) {setValue(name, PIString(value), "s", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const char * value, bool write = true) { setValue(name, PIString(value), "s", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "b" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "b" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const bool value, bool write = true) {setValue(name, PIString::fromBool(value), "b", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const bool value, bool write = true) { setValue(name, PIString::fromBool(value), "b", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const short value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const short value, bool write = true) { setValue(name, PIString::fromNumber(value), "n", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const int value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const int value, bool write = true) { setValue(name, PIString::fromNumber(value), "n", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const long value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const long value, bool write = true) { setValue(name, PIString::fromNumber(value), "n", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const uchar value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const uchar value, bool write = true) { setValue(name, PIString::fromNumber(value), "n", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const ushort value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const ushort value, bool write = true) { setValue(name, PIString::fromNumber(value), "n", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const uint value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const uint value, bool write = true) { setValue(name, PIString::fromNumber(value), "n", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "n" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const ulong value, bool write = true) {setValue(name, PIString::fromNumber(value), "n", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const ulong value, bool write = true) { setValue(name, PIString::fromNumber(value), "n", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "f" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "f" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const float value, bool write = true) {setValue(name, PIString::fromNumber(value), "f", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const float value, bool write = true) { setValue(name, PIString::fromNumber(value), "f", write); }
|
||||||
|
|
||||||
//! Set top-level entry with name "name" value to "value", type to "f" and if "write" immediate write to file. Add new entry if there is no suitable exists
|
//! Set top-level entry with name "name" value to "value", type to "f" and if "write" immediate write to file. Add new entry if there is
|
||||||
void setValue(const PIString & name, const double value, bool write = true) {setValue(name, PIString::fromNumber(value), "f", write);}
|
//! no suitable exists
|
||||||
|
void setValue(const PIString & name, const double value, bool write = true) { setValue(name, PIString::fromNumber(value), "f", write); }
|
||||||
|
|
||||||
//! Returns root entry
|
//! Returns root entry
|
||||||
Entry & rootEntry() {return root;}
|
Entry & rootEntry() { return root; }
|
||||||
|
|
||||||
//! Returns top-level entries count
|
//! Returns top-level entries count
|
||||||
int entriesCount() const {return childCount(&root);}
|
int entriesCount() const { return childCount(&root); }
|
||||||
|
|
||||||
//! Returns if top-level entry with name "name" exists
|
//! Returns if top-level entry with name "name" exists
|
||||||
bool isEntryExists(const PIString & name) const {return entryExists(&root, name);}
|
bool isEntryExists(const PIString & name) const { return entryExists(&root, name); }
|
||||||
|
|
||||||
//! Returns all top-level entries
|
//! Returns all top-level entries
|
||||||
Branch allTree() {Branch b; piForeach (Entry * i, root._children) b << i; b.delim = delim; return b;}
|
Branch allTree() {
|
||||||
|
Branch b;
|
||||||
|
piForeach(Entry * i, root._children)
|
||||||
|
b << i;
|
||||||
|
b.delim = delim;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
//! Returns all entries without children
|
//! Returns all entries without children
|
||||||
Branch allLeaves() {Branch b; allLeaves(b, &root); b.sort(Entry::compare); b.delim = delim; return b;}
|
Branch allLeaves() {
|
||||||
|
Branch b;
|
||||||
|
allLeaves(b, &root);
|
||||||
|
b.sort(Entry::compare);
|
||||||
|
b.delim = delim;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
int entryIndex(const PIString & name);
|
int entryIndex(const PIString & name);
|
||||||
|
|
||||||
PIString getName(uint number) {return entryByIndex(number)._name;}
|
PIString getName(uint number) { return entryByIndex(number)._name; }
|
||||||
PIString getValueByIndex(uint number) {return entryByIndex(number)._value;}
|
PIString getValueByIndex(uint number) { return entryByIndex(number)._value; }
|
||||||
PIChar getType(uint number) {return entryByIndex(number)._type[0];}
|
PIChar getType(uint number) { return entryByIndex(number)._type[0]; }
|
||||||
PIString getComment(uint number) {return entryByIndex(number)._comment;}
|
PIString getComment(uint number) { return entryByIndex(number)._comment; }
|
||||||
|
|
||||||
void addEntry(const PIString & name, const PIString & value, const PIString & type = "s", bool write = true);
|
void addEntry(const PIString & name, const PIString & value, const PIString & type = "s", bool write = true);
|
||||||
void setName(uint number, const PIString & name, bool write = true);
|
void setName(uint number, const PIString & name, bool write = true);
|
||||||
@@ -470,10 +612,14 @@ public:
|
|||||||
void writeAll();
|
void writeAll();
|
||||||
|
|
||||||
//! Returns current tree delimiter, default "."
|
//! Returns current tree delimiter, default "."
|
||||||
const PIString & delimiter() const {return delim;}
|
const PIString & delimiter() const { return delim; }
|
||||||
|
|
||||||
//! Set current tree delimiter
|
//! Set current tree delimiter
|
||||||
void setDelimiter(const PIString & d) {delim = d; setEntryDelim(&root, d); readAll();}
|
void setDelimiter(const PIString & d) {
|
||||||
|
delim = d;
|
||||||
|
setEntryDelim(&root, d);
|
||||||
|
readAll();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PIConfig(const PIString & path, PIStringList dirs);
|
PIConfig(const PIString & path, PIStringList dirs);
|
||||||
@@ -486,40 +632,75 @@ private:
|
|||||||
void _seekToBeginDev();
|
void _seekToBeginDev();
|
||||||
PIString _readLineDev();
|
PIString _readLineDev();
|
||||||
void _writeDev(const PIString & l);
|
void _writeDev(const PIString & l);
|
||||||
int childCount(const Entry * e) const {int c = 0; piForeachC (Entry * i, e->_children) c += childCount(i); c += e->_children.size_s(); return c;}
|
int childCount(const Entry * e) const {
|
||||||
|
int c = 0;
|
||||||
|
piForeachC(Entry * i, e->_children)
|
||||||
|
c += childCount(i);
|
||||||
|
c += e->_children.size_s();
|
||||||
|
return c;
|
||||||
|
}
|
||||||
bool entryExists(const Entry * e, const PIString & name) const;
|
bool entryExists(const Entry * e, const PIString & name) const;
|
||||||
void buildFullNames(Entry * e) {piForeach (Entry * i, e->_children) {if (e != &root) i->_full_name = e->_full_name + delim + i->_name; else i->_full_name = i->_name; buildFullNames(i);}}
|
void buildFullNames(Entry * e) {
|
||||||
void allLeaves(Branch & b, Entry * e) {piForeach (Entry * i, e->_children) {if ((!i->_value.isEmpty() && !i->isLeaf()) || i->isLeaf()) b << i; allLeaves(b, i);}}
|
piForeach(Entry * i, e->_children) {
|
||||||
void setEntryDelim(Entry * e, const PIString & d) {piForeach (Entry * i, e->_children) setEntryDelim(i, d); e->delim = d;}
|
if (e != &root)
|
||||||
Entry & entryByIndex(const int index) {Branch b = allLeaves(); if (index < 0 || index >= b.size_s()) return empty; return *(b[index]);}
|
i->_full_name = e->_full_name + delim + i->_name;
|
||||||
|
else
|
||||||
|
i->_full_name = i->_name;
|
||||||
|
buildFullNames(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void allLeaves(Branch & b, Entry * e) {
|
||||||
|
piForeach(Entry * i, e->_children) {
|
||||||
|
if ((!i->_value.isEmpty() && !i->isLeaf()) || i->isLeaf()) b << i;
|
||||||
|
allLeaves(b, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void setEntryDelim(Entry * e, const PIString & d) {
|
||||||
|
piForeach(Entry * i, e->_children)
|
||||||
|
setEntryDelim(i, d);
|
||||||
|
e->delim = d;
|
||||||
|
}
|
||||||
|
Entry & entryByIndex(const int index) {
|
||||||
|
Branch b = allLeaves();
|
||||||
|
if (index < 0 || index >= b.size_s()) return empty;
|
||||||
|
return *(b[index]);
|
||||||
|
}
|
||||||
void removeEntry(Branch & b, Entry * e);
|
void removeEntry(Branch & b, Entry * e);
|
||||||
void deleteEntry(Entry * e) {piForeach (Entry * i, e->_children) deleteEntry(i); delete e;}
|
void deleteEntry(Entry * e) {
|
||||||
|
piForeach(Entry * i, e->_children)
|
||||||
|
deleteEntry(i);
|
||||||
|
delete e;
|
||||||
|
}
|
||||||
PIString getPrefixFromLine(PIString line, bool * exists);
|
PIString getPrefixFromLine(PIString line, bool * exists);
|
||||||
void updateIncludes();
|
void updateIncludes();
|
||||||
PIString parseLine(PIString v);
|
PIString parseLine(PIString v);
|
||||||
void parse();
|
void parse();
|
||||||
|
|
||||||
bool own_dev = false, internal = false;
|
bool own_dev = false, internal = false;
|
||||||
PIVector<PIConfig * > includes, inc_devs;
|
PIVector<PIConfig *> includes, inc_devs;
|
||||||
Branch all_includes;
|
Branch all_includes;
|
||||||
PIIODevice * dev = nullptr;
|
PIIODevice * dev = nullptr;
|
||||||
PIIOTextStream * stream = nullptr;
|
PIIOTextStream * stream = nullptr;
|
||||||
PIString delim;
|
PIString delim;
|
||||||
PIStringList incdirs;
|
PIStringList incdirs;
|
||||||
Entry root, empty;
|
Entry root, empty;
|
||||||
uint lines = 0;
|
uint lines = 0;
|
||||||
PIStringList other;
|
PIStringList other;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#ifdef PIP_STD_IOSTREAM
|
#ifdef PIP_STD_IOSTREAM
|
||||||
PIP_EXPORT std::ostream & operator <<(std::ostream & s, const PIConfig::Branch & v);
|
PIP_EXPORT std::ostream & operator<<(std::ostream & s, const PIConfig::Branch & v);
|
||||||
PIP_EXPORT std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v);
|
PIP_EXPORT std::ostream & operator<<(std::ostream & s, const PIConfig::Entry & v);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline PICout operator <<(PICout s, const PIConfig::Branch & v) {s.saveAndSetControls(0); v.piCoutt(s, ""); s.restoreControls(); return s;}
|
inline PICout operator<<(PICout s, const PIConfig::Branch & v) {
|
||||||
inline PICout operator <<(PICout s, const PIConfig::Entry & v) {
|
s.saveAndSetControls(0);
|
||||||
|
v.piCoutt(s, "");
|
||||||
|
s.restoreControls();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
inline PICout operator<<(PICout s, const PIConfig::Entry & v) {
|
||||||
s << v.value() << "(" << v.type() << v.comment() << ")";
|
s << v.value() << "(" << v.type() << v.comment() << ")";
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,19 +26,18 @@
|
|||||||
#ifndef PISERIAL_H
|
#ifndef PISERIAL_H
|
||||||
#define PISERIAL_H
|
#define PISERIAL_H
|
||||||
|
|
||||||
#include "pitimer.h"
|
|
||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
|
#include "pitimer.h"
|
||||||
|
|
||||||
|
|
||||||
//! \ingroup IO
|
//! \ingroup IO
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Serial device.
|
//! \~english Serial device.
|
||||||
//! \~russian Последовательный порт.
|
//! \~russian Последовательный порт.
|
||||||
class PIP_EXPORT PISerial: public PIIODevice
|
class PIP_EXPORT PISerial: public PIIODevice {
|
||||||
{
|
|
||||||
PIIODEVICE(PISerial, "ser");
|
PIIODEVICE(PISerial, "ser");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! \~english Contructs an empty %PISerial
|
//! \~english Contructs an empty %PISerial
|
||||||
//! \~russian Создает пустой %PISerial
|
//! \~russian Создает пустой %PISerial
|
||||||
explicit PISerial();
|
explicit PISerial();
|
||||||
@@ -49,32 +48,32 @@ public:
|
|||||||
//! \~russian Параметры PISerial
|
//! \~russian Параметры PISerial
|
||||||
enum Parameters {
|
enum Parameters {
|
||||||
ParityControl /*! \~english Enable parity check and generate \~russian Включить генерацию и проверку контроля чётности */ = 0x1,
|
ParityControl /*! \~english Enable parity check and generate \~russian Включить генерацию и проверку контроля чётности */ = 0x1,
|
||||||
ParityOdd /*! \~english Parity is odd instead of even \~russian Нечётный контроль чётности вместо чётного */ = 0x2,
|
ParityOdd /*! \~english Parity is odd instead of even \~russian Нечётный контроль чётности вместо чётного */ = 0x2,
|
||||||
TwoStopBits /*! \~english Two stop bits instead of one \~russian Два стоповых бита вместо одного */ = 0x4
|
TwoStopBits /*! \~english Two stop bits instead of one \~russian Два стоповых бита вместо одного */ = 0x4
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \~english Speed of PISerial
|
//! \~english Speed of PISerial
|
||||||
//! \~russian Скорость PISerial
|
//! \~russian Скорость PISerial
|
||||||
enum Speed {
|
enum Speed {
|
||||||
S50 /*! 50 baud */ = 50,
|
S50 /*! 50 baud */ = 50,
|
||||||
S75 /*! 75 baud */ = 75,
|
S75 /*! 75 baud */ = 75,
|
||||||
S110 /*! 110 baud */ = 110,
|
S110 /*! 110 baud */ = 110,
|
||||||
S300 /*! 300 baud */ = 300,
|
S300 /*! 300 baud */ = 300,
|
||||||
S600 /*! 600 baud */ = 600,
|
S600 /*! 600 baud */ = 600,
|
||||||
S1200 /*! 1200 baud */ = 1200,
|
S1200 /*! 1200 baud */ = 1200,
|
||||||
S2400 /*! 2400 baud */ = 2400,
|
S2400 /*! 2400 baud */ = 2400,
|
||||||
S4800 /*! 4800 baud */ = 4800,
|
S4800 /*! 4800 baud */ = 4800,
|
||||||
S9600 /*! 9600 baud */ = 9600,
|
S9600 /*! 9600 baud */ = 9600,
|
||||||
S14400 /*! 14400 baud */ = 14400,
|
S14400 /*! 14400 baud */ = 14400,
|
||||||
S19200 /*! 19200 baud */ = 19200,
|
S19200 /*! 19200 baud */ = 19200,
|
||||||
S38400 /*! 38400 baud */ = 38400,
|
S38400 /*! 38400 baud */ = 38400,
|
||||||
S57600 /*! 57600 baud */ = 57600,
|
S57600 /*! 57600 baud */ = 57600,
|
||||||
S115200 /*! 115200 baud */ = 115200,
|
S115200 /*! 115200 baud */ = 115200,
|
||||||
S230400 /*! 230400 baud */ = 230400,
|
S230400 /*! 230400 baud */ = 230400,
|
||||||
S460800 /*! 460800 baud */ = 460800,
|
S460800 /*! 460800 baud */ = 460800,
|
||||||
S500000 /*! 500000 baud */ = 500000,
|
S500000 /*! 500000 baud */ = 500000,
|
||||||
S576000 /*! 576000 baud */ = 576000,
|
S576000 /*! 576000 baud */ = 576000,
|
||||||
S921600 /*! 921600 baud */ = 921600,
|
S921600 /*! 921600 baud */ = 921600,
|
||||||
S1000000 /*! 1000000 baud */ = 1000000,
|
S1000000 /*! 1000000 baud */ = 1000000,
|
||||||
S1152000 /*! 1152000 baud */ = 1152000,
|
S1152000 /*! 1152000 baud */ = 1152000,
|
||||||
S1500000 /*! 1500000 baud */ = 1500000,
|
S1500000 /*! 1500000 baud */ = 1500000,
|
||||||
@@ -113,66 +112,87 @@ public:
|
|||||||
//! \~english Device manufacturer
|
//! \~english Device manufacturer
|
||||||
//! \~russian Описание производителя
|
//! \~russian Описание производителя
|
||||||
PIString manufacturer;
|
PIString manufacturer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \~english Contructs %PISerial with device name "device", speed "speed" and parameters "params"
|
//! \~english Contructs %PISerial with device name "device", speed "speed" and parameters "params"
|
||||||
//! \~russian Создает %PISerial с именем устройства "device", скоростью "speed" и параметрами "params"
|
//! \~russian Создает %PISerial с именем устройства "device", скоростью "speed" и параметрами "params"
|
||||||
explicit PISerial(const PIString & device, PISerial::Speed speed = S115200, PIFlags<PISerial::Parameters> params = 0);
|
explicit PISerial(const PIString & device, PISerial::Speed speed = S115200, PIFlags<PISerial::Parameters> params = 0);
|
||||||
|
|
||||||
|
|
||||||
//! \~english Set both input and output speed to "speed"
|
//! \~english Set both input and output speed to "speed"
|
||||||
//! \~russian Устанавливает скорости приема и передачи в "speed"
|
//! \~russian Устанавливает скорости приема и передачи в "speed"
|
||||||
void setSpeed(PISerial::Speed speed) {setProperty("outSpeed", (int)speed); setProperty("inSpeed", (int)speed); applySettings();}
|
void setSpeed(PISerial::Speed speed) {
|
||||||
|
setProperty("outSpeed", (int)speed);
|
||||||
|
setProperty("inSpeed", (int)speed);
|
||||||
|
applySettings();
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Set output speed to "speed"
|
//! \~english Set output speed to "speed"
|
||||||
//! \~russian Устанавливает скорость передачи в "speed"
|
//! \~russian Устанавливает скорость передачи в "speed"
|
||||||
void setOutSpeed(PISerial::Speed speed) {setProperty("outSpeed", (int)speed); applySettings();}
|
void setOutSpeed(PISerial::Speed speed) {
|
||||||
|
setProperty("outSpeed", (int)speed);
|
||||||
|
applySettings();
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Set input speed to "speed"
|
//! \~english Set input speed to "speed"
|
||||||
//! \~russian Устанавливает скорость приема в "speed"
|
//! \~russian Устанавливает скорость приема в "speed"
|
||||||
void setInSpeed(PISerial::Speed speed) {setProperty("inSpeed", (int)speed); applySettings();}
|
void setInSpeed(PISerial::Speed speed) {
|
||||||
|
setProperty("inSpeed", (int)speed);
|
||||||
|
applySettings();
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Set device name to "dev"
|
//! \~english Set device name to "dev"
|
||||||
//! \~russian Устанавливает имя устройства в "dev"
|
//! \~russian Устанавливает имя устройства в "dev"
|
||||||
void setDevice(const PIString & dev) {setPath(dev); if (isOpened()) {close(); open();};}
|
void setDevice(const PIString & dev) {
|
||||||
|
setPath(dev);
|
||||||
|
if (isOpened()) {
|
||||||
|
close();
|
||||||
|
open();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//! \~english Set parameters to "parameters_"
|
//! \~english Set parameters to "parameters_"
|
||||||
//! \~russian Устанавливает параметры в "parameters_"
|
//! \~russian Устанавливает параметры в "parameters_"
|
||||||
void setParameters(PIFlags<PISerial::Parameters> parameters_) {setProperty("parameters", (int)parameters_); applySettings();}
|
void setParameters(PIFlags<PISerial::Parameters> parameters_) {
|
||||||
|
setProperty("parameters", (int)parameters_);
|
||||||
|
applySettings();
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Set parameter "parameter" to "on" state
|
//! \~english Set parameter "parameter" to "on" state
|
||||||
//! \~russian Устанавливает параметр "parameter" в "on"
|
//! \~russian Устанавливает параметр "parameter" в "on"
|
||||||
void setParameter(PISerial::Parameters parameter, bool on = true);
|
void setParameter(PISerial::Parameters parameter, bool on = true);
|
||||||
|
|
||||||
//! \~english Returns if parameter "parameter" is set
|
//! \~english Returns if parameter "parameter" is set
|
||||||
//! \~russian Возвращает установлен ли параметр "parameter"
|
//! \~russian Возвращает установлен ли параметр "parameter"
|
||||||
bool isParameterSet(PISerial::Parameters parameter) const;
|
bool isParameterSet(PISerial::Parameters parameter) const;
|
||||||
|
|
||||||
//! \~english Returns parameters
|
//! \~english Returns parameters
|
||||||
//! \~russian Возвращает параметры
|
//! \~russian Возвращает параметры
|
||||||
PIFlags<PISerial::Parameters> parameters() const {return (PIFlags<Parameters>)(property("parameters").toInt());}
|
PIFlags<PISerial::Parameters> parameters() const { return (PIFlags<Parameters>)(property("parameters").toInt()); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//! \~english Set data bits count. Valid range is from 5 to 8, befault is 8
|
//! \~english Set data bits count. Valid range is from 5 to 8, befault is 8
|
||||||
//! \~russian Устанавливает количество бит данных. Разрешены значения от 5 до 8, по умолчанию 8
|
//! \~russian Устанавливает количество бит данных. Разрешены значения от 5 до 8, по умолчанию 8
|
||||||
void setDataBitsCount(int bits) {setProperty("dataBitsCount", bits); applySettings();}
|
void setDataBitsCount(int bits) {
|
||||||
|
setProperty("dataBitsCount", bits);
|
||||||
|
applySettings();
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Returns data bits count
|
//! \~english Returns data bits count
|
||||||
//! \~russian Возвращает количество бит данных
|
//! \~russian Возвращает количество бит данных
|
||||||
int dataBitsCount() const {return property("dataBitsCount").toInt();}
|
int dataBitsCount() const { return property("dataBitsCount").toInt(); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//! \~english Set pin number "number" to logic level "on". Valid numbers are 4 (DTR) and 7 (RTS)
|
//! \~english Set pin number "number" to logic level "on". Valid numbers are 4 (DTR) and 7 (RTS)
|
||||||
//! \~russian Устанавливает пин с номером "number" в логический уровень "on". Разрешены номера 4 (DTR) и 7 (RTS)
|
//! \~russian Устанавливает пин с номером "number" в логический уровень "on". Разрешены номера 4 (DTR) и 7 (RTS)
|
||||||
bool setPin(int number, bool on);
|
bool setPin(int number, bool on);
|
||||||
|
|
||||||
//! \~english Returns pin number "number" logic level. Valid numbers range is from 1 to 9
|
//! \~english Returns pin number "number" logic level. Valid numbers range is from 1 to 9
|
||||||
//! \~russian Возвращает логический уровень пина с номером "number". Разрешены номера от 1 до 9
|
//! \~russian Возвращает логический уровень пина с номером "number". Разрешены номера от 1 до 9
|
||||||
bool isPin(int number) const;
|
bool isPin(int number) const;
|
||||||
|
|
||||||
bool setLE(bool on); // useless function, just formally
|
bool setLE(bool on); // useless function, just formally
|
||||||
bool setDTR(bool on);
|
bool setDTR(bool on);
|
||||||
bool setRTS(bool on);
|
bool setRTS(bool on);
|
||||||
bool setCTS(bool on); // useless function, just formally
|
bool setCTS(bool on); // useless function, just formally
|
||||||
@@ -196,27 +216,30 @@ public:
|
|||||||
//! \~russian Переключает состояние передачи в break
|
//! \~russian Переключает состояние передачи в break
|
||||||
bool setBreak(bool enabled);
|
bool setBreak(bool enabled);
|
||||||
|
|
||||||
void setVTime(int t) {vtime = t; applySettings();}
|
void setVTime(int t) {
|
||||||
|
vtime = t;
|
||||||
|
applySettings();
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Returns device name
|
//! \~english Returns device name
|
||||||
//! \~russian Возвращает имя устройства
|
//! \~russian Возвращает имя устройства
|
||||||
PIString device() const {return path();}
|
PIString device() const { return path(); }
|
||||||
|
|
||||||
//! \~english Returns output speed
|
//! \~english Returns output speed
|
||||||
//! \~russian Возвращает скорость передачи
|
//! \~russian Возвращает скорость передачи
|
||||||
PISerial::Speed outSpeed() const {return (PISerial::Speed)(property("outSpeed").toInt());}
|
PISerial::Speed outSpeed() const { return (PISerial::Speed)(property("outSpeed").toInt()); }
|
||||||
|
|
||||||
//! \~english Returns input speed
|
//! \~english Returns input speed
|
||||||
//! \~russian Возвращает скорость приема
|
//! \~russian Возвращает скорость приема
|
||||||
PISerial::Speed inSpeed() const {return (PISerial::Speed)(property("inSpeed").toInt());}
|
PISerial::Speed inSpeed() const { return (PISerial::Speed)(property("inSpeed").toInt()); }
|
||||||
|
|
||||||
int VTime() const {return vtime;}
|
int VTime() const { return vtime; }
|
||||||
|
|
||||||
//! \~english Discard all buffered input and output data
|
//! \~english Discard all buffered input and output data
|
||||||
//! \~russian Откидывает все буферизированные данные для передачи и приема
|
//! \~russian Откидывает все буферизированные данные для передачи и приема
|
||||||
virtual void flush() override;
|
virtual void flush() override;
|
||||||
|
|
||||||
int read(void * read_to, int max_size) {return readDevice(read_to, max_size);}
|
int read(void * read_to, int max_size) { return readDevice(read_to, max_size); }
|
||||||
|
|
||||||
//! \~english Read from device no more "max_size" bytes into "read_to" with "timeout_ms" timeout
|
//! \~english Read from device no more "max_size" bytes into "read_to" with "timeout_ms" timeout
|
||||||
//! \~russian Читает из устройства не более "max_size" байт в "read_to" с таймаутом "timeout_ms"
|
//! \~russian Читает из устройства не более "max_size" байт в "read_to" с таймаутом "timeout_ms"
|
||||||
@@ -236,14 +259,14 @@ public:
|
|||||||
|
|
||||||
//! \~english Write to device byte array "data". Returns if sended bytes count = size of "data"
|
//! \~english Write to device byte array "data". Returns if sended bytes count = size of "data"
|
||||||
//! \~russian Пишет в порт байтовый массив "data". Возвращает если количество записанных байт = размер "data"
|
//! \~russian Пишет в порт байтовый массив "data". Возвращает если количество записанных байт = размер "data"
|
||||||
bool send(const PIByteArray & data) {return send(data.data(), data.size_s());}
|
bool send(const PIByteArray & data) { return send(data.data(), data.size_s()); }
|
||||||
|
|
||||||
void interrupt() override;
|
void interrupt() override;
|
||||||
|
|
||||||
//! \~english Returns all available speeds for serial devices
|
//! \~english Returns all available speeds for serial devices
|
||||||
//! \~russian Возвращает все возможные скорости для устройств
|
//! \~russian Возвращает все возможные скорости для устройств
|
||||||
static PIVector<int> availableSpeeds();
|
static PIVector<int> availableSpeeds();
|
||||||
|
|
||||||
//! \~english Returns all available system devices path. If "test" each device will be tried to open
|
//! \~english Returns all available system devices path. If "test" each device will be tried to open
|
||||||
//! \~russian Возвращает пути всех доступных устройств в системе. Если "test", то каждое устройство будет опробовано на открытие
|
//! \~russian Возвращает пути всех доступных устройств в системе. Если "test", то каждое устройство будет опробовано на открытие
|
||||||
static PIStringList availableDevices(bool test = false);
|
static PIStringList availableDevices(bool test = false);
|
||||||
@@ -258,29 +281,29 @@ public:
|
|||||||
//! \~english device, default ""
|
//! \~english device, default ""
|
||||||
//! \~russian устройство, по умолчанию ""
|
//! \~russian устройство, по умолчанию ""
|
||||||
string device;
|
string device;
|
||||||
|
|
||||||
//! \~english input/output speed, default 115200
|
//! \~english input/output speed, default 115200
|
||||||
//! \~russian скорость чтения/записи, по умолчанию 115200
|
//! \~russian скорость чтения/записи, по умолчанию 115200
|
||||||
int speed;
|
int speed;
|
||||||
|
|
||||||
//! \~english dataBitsCount, default 8
|
//! \~english dataBitsCount, default 8
|
||||||
//! \~russian количесво бит данных, по умолчанию 8
|
//! \~russian количесво бит данных, по умолчанию 8
|
||||||
int dataBitsCount;
|
int dataBitsCount;
|
||||||
|
|
||||||
//! \~english parityControl, default false
|
//! \~english parityControl, default false
|
||||||
//! \~russian контроль четности, по умолчанию false
|
//! \~russian контроль четности, по умолчанию false
|
||||||
bool parityControl;
|
bool parityControl;
|
||||||
|
|
||||||
//! \~english parityOdd, default false
|
//! \~english parityOdd, default false
|
||||||
//! \~russian нечётный контроль четности, по умолчанию false
|
//! \~russian нечётный контроль четности, по умолчанию false
|
||||||
bool parityOdd;
|
bool parityOdd;
|
||||||
|
|
||||||
//! \~english twoStopBits, default false
|
//! \~english twoStopBits, default false
|
||||||
//! \~russian два стоповых бита, по умолчанию false
|
//! \~russian два стоповых бита, по умолчанию false
|
||||||
bool twoStopBits;
|
bool twoStopBits;
|
||||||
#endif
|
#endif
|
||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PIString constructFullPathDevice() const override;
|
PIString constructFullPathDevice() const override;
|
||||||
void configureFromFullPathDevice(const PIString & full_path) override;
|
void configureFromFullPathDevice(const PIString & full_path) override;
|
||||||
@@ -294,10 +317,10 @@ protected:
|
|||||||
//! \~russian Базовое чтение
|
//! \~russian Базовое чтение
|
||||||
ssize_t readDevice(void * read_to, ssize_t max_size) override;
|
ssize_t readDevice(void * read_to, ssize_t max_size) override;
|
||||||
ssize_t writeDevice(const void * data, ssize_t max_size) override;
|
ssize_t writeDevice(const void * data, ssize_t max_size) override;
|
||||||
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential;}
|
DeviceInfoFlags deviceInfoFlags() const override { return PIIODevice::Sequential; }
|
||||||
|
|
||||||
//! Executes when any read function was successful. Default implementation does nothing
|
//! Executes when any read function was successful. Default implementation does nothing
|
||||||
virtual void received(const void * data, int size) {;}
|
virtual void received(const void * data, int size) { ; }
|
||||||
|
|
||||||
void construct();
|
void construct();
|
||||||
void applySettings();
|
void applySettings();
|
||||||
@@ -313,36 +336,45 @@ protected:
|
|||||||
int fd = -1, vtime = 10;
|
int fd = -1, vtime = 10;
|
||||||
std::atomic_bool sending;
|
std::atomic_bool sending;
|
||||||
PITimeMeasurer tm_;
|
PITimeMeasurer tm_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//! \relatesalso PICout
|
//! \relatesalso PICout
|
||||||
//! \~english Output operator to \a PICout
|
//! \~english Output operator to \a PICout
|
||||||
//! \~russian Оператор вывода в \a PICout
|
//! \~russian Оператор вывода в \a PICout
|
||||||
inline PICout operator <<(PICout s, const PISerial::DeviceInfo & v) {
|
inline PICout operator<<(PICout s, const PISerial::DeviceInfo & v) {
|
||||||
s << v.path << " (" << v.id() << ", \"" << v.manufacturer << "\", \"" << v.description << "\")";
|
s << v.path << " (" << v.id() << ", \"" << v.manufacturer << "\", \"" << v.description << "\")";
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator ==(const PISerial::DeviceInfo & v0, const PISerial::DeviceInfo & v1) {return v0.path == v1.path;}
|
inline bool operator==(const PISerial::DeviceInfo & v0, const PISerial::DeviceInfo & v1) {
|
||||||
|
return v0.path == v1.path;
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator !=(const PISerial::DeviceInfo & v0, const PISerial::DeviceInfo & v1) {return v0.path != v1.path;}
|
inline bool operator!=(const PISerial::DeviceInfo & v0, const PISerial::DeviceInfo & v1) {
|
||||||
|
return v0.path != v1.path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! \relatesalso PIBinaryStream
|
//! \relatesalso PIBinaryStream
|
||||||
//! \~english Store operator.
|
//! \~english Store operator.
|
||||||
//! \~russian Оператор сохранения.
|
//! \~russian Оператор сохранения.
|
||||||
BINARY_STREAM_WRITE(PISerial::DeviceInfo) {s << v.vID << v.pID << v.path << v.description << v.manufacturer; return s;}
|
BINARY_STREAM_WRITE(PISerial::DeviceInfo) {
|
||||||
|
s << v.vID << v.pID << v.path << v.description << v.manufacturer;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIBinaryStream
|
//! \relatesalso PIBinaryStream
|
||||||
//! \~english Restore operator.
|
//! \~english Restore operator.
|
||||||
//! \~russian Оператор извлечения.
|
//! \~russian Оператор извлечения.
|
||||||
BINARY_STREAM_READ (PISerial::DeviceInfo) {s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer; return s;}
|
BINARY_STREAM_READ(PISerial::DeviceInfo) {
|
||||||
|
s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // PISERIAL_H
|
#endif // PISERIAL_H
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* \~\brief
|
* \~\brief
|
||||||
* \~english Basic mathematical functions and defines
|
* \~english Basic mathematical functions and defines
|
||||||
* \~russian Базовые математические функции и дефайны
|
* \~russian Базовые математические функции и дефайны
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
Basic mathematical functions and defines
|
Basic mathematical functions and defines
|
||||||
@@ -27,8 +27,8 @@
|
|||||||
#define PIMATHBASE_H
|
#define PIMATHBASE_H
|
||||||
|
|
||||||
#include "piinit.h"
|
#include "piinit.h"
|
||||||
#include "pivector.h"
|
|
||||||
#include "pipair.h"
|
#include "pipair.h"
|
||||||
|
#include "pivector.h"
|
||||||
#ifdef QNX
|
#ifdef QNX
|
||||||
# undef PIP_MATH_J0
|
# undef PIP_MATH_J0
|
||||||
# undef PIP_MATH_J1
|
# undef PIP_MATH_J1
|
||||||
@@ -94,20 +94,25 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const double deg2rad = M_PI_180;
|
const double deg2rad = M_PI_180;
|
||||||
const double rad2deg = M_180_PI;
|
const double rad2deg = M_180_PI;
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
inline int sign(const float & x) {return (x < 0.f) ? -1 : (x > 0.f ? 1 : 0);}
|
inline int sign(const float & x) {return (x < 0.f) ? -1 : (x > 0.f ? 1 : 0);}
|
||||||
inline int sign(const double & x) {return (x < 0. ) ? -1 : (x > 0. ? 1 : 0);}
|
inline int sign(const double & x) {return (x < 0. ) ? -1 : (x > 0. ? 1 : 0);}
|
||||||
inline int sign(const ldouble & x) {return (x < 0.L) ? -1 : (x > 0.L ? 1 : 0);}
|
inline int sign(const ldouble & x) {return (x < 0.L) ? -1 : (x > 0.L ? 1 : 0);}
|
||||||
|
|
||||||
inline int pow2(const int p) {return 1 << p;}
|
inline int pow2 (const int p ) {return 1 << p;}
|
||||||
inline float pow10(const int & e) {return powf(10.f, e);}
|
inline float pow10(const int & e) {return powf(10.f, e);}
|
||||||
inline double pow10(const double & e) {return pow(10., e);}
|
inline double pow10(const double & e) {return pow (10. , e);}
|
||||||
inline ldouble pow10(const ldouble & e) {return powl(10.L, e);}
|
inline ldouble pow10(const ldouble & e) {return powl(10.L, e);}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
inline double sinc(const double & v) {if (v == 0.) return 1.; double t = M_PI * v; return sin(t) / t;}
|
inline double sinc(const double & v) {
|
||||||
|
if (v == 0.) return 1.;
|
||||||
|
double t = M_PI * v;
|
||||||
|
return sin(t) / t;
|
||||||
|
}
|
||||||
|
|
||||||
PIP_EXPORT double piJ0(const double & v);
|
PIP_EXPORT double piJ0(const double & v);
|
||||||
PIP_EXPORT double piJ1(const double & v);
|
PIP_EXPORT double piJ1(const double & v);
|
||||||
@@ -116,22 +121,34 @@ PIP_EXPORT double piY0(const double & v);
|
|||||||
PIP_EXPORT double piY1(const double & v);
|
PIP_EXPORT double piY1(const double & v);
|
||||||
PIP_EXPORT double piYn(int n, const double & v);
|
PIP_EXPORT double piYn(int n, const double & v);
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
inline constexpr float toRad(float deg) {return deg * M_PI_180;}
|
inline constexpr float toRad(float deg) {return deg * M_PI_180;}
|
||||||
inline constexpr double toRad(double deg) {return deg * M_PI_180;}
|
inline constexpr double toRad(double deg) {return deg * M_PI_180;}
|
||||||
inline constexpr ldouble toRad(ldouble deg) {return deg * M_PI_180;}
|
inline constexpr ldouble toRad(ldouble deg) {return deg * M_PI_180;}
|
||||||
inline constexpr float toDeg(float rad) {return rad * M_180_PI;}
|
inline constexpr float toDeg(float rad) {return rad * M_180_PI;}
|
||||||
inline constexpr double toDeg(double rad) {return rad * M_180_PI;}
|
inline constexpr double toDeg(double rad) {return rad * M_180_PI;}
|
||||||
inline constexpr ldouble toDeg(ldouble rad) {return rad * M_180_PI;}
|
inline constexpr ldouble toDeg(ldouble rad) {return rad * M_180_PI;}
|
||||||
template <typename T> inline constexpr T sqr(const T & v) {return v * v;}
|
// clang-format on
|
||||||
template <typename T> inline constexpr T toDb (T val) {return T(10.) * std::log10(val);}
|
template<typename T>
|
||||||
template <typename T> inline constexpr T fromDb(T val) {return std::pow(T(10.), val / T(10.));}
|
inline constexpr T sqr(const T & v) {
|
||||||
|
return v * v;
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline constexpr T toDb(T val) {
|
||||||
|
return T(10.) * std::log10(val);
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline constexpr T fromDb(T val) {
|
||||||
|
return std::pow(T(10.), val / T(10.));
|
||||||
|
}
|
||||||
|
|
||||||
// [-1 ; 1]
|
// [-1 ; 1]
|
||||||
PIP_EXPORT double randomd();
|
PIP_EXPORT double randomd();
|
||||||
// [-1 ; 1] normal
|
// [-1 ; 1] normal
|
||||||
PIP_EXPORT double randomn(double dv = 0., double sv = 1.);
|
PIP_EXPORT double randomn(double dv = 0., double sv = 1.);
|
||||||
|
|
||||||
template<typename T> inline PIVector<T> piAbs(const PIVector<T> & v) {
|
template<typename T>
|
||||||
|
inline PIVector<T> piAbs(const PIVector<T> & v) {
|
||||||
PIVector<T> result;
|
PIVector<T> result;
|
||||||
result.resize(v.size());
|
result.resize(v.size());
|
||||||
for (uint i = 0; i < v.size(); i++)
|
for (uint i = 0; i < v.size(); i++)
|
||||||
@@ -140,12 +157,11 @@ template<typename T> inline PIVector<T> piAbs(const PIVector<T> & v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool OLS_Linear(const PIVector<PIPair<T, T> > & input, T * out_a, T * out_b) {
|
bool OLS_Linear(const PIVector<PIPair<T, T>> & input, T * out_a, T * out_b) {
|
||||||
static_assert(std::is_arithmetic<T>::value, "Type must be arithmetic");
|
static_assert(std::is_arithmetic<T>::value, "Type must be arithmetic");
|
||||||
if (input.size_s() < 2)
|
if (input.size_s() < 2) return false;
|
||||||
return false;
|
int n = input.size_s();
|
||||||
int n = input.size_s();
|
|
||||||
T a_t0 = T(), a_t1 = T(), a_t2 = T(), a_t3 = T(), a_t4 = T(), a = T(), b = T();
|
T a_t0 = T(), a_t1 = T(), a_t2 = T(), a_t3 = T(), a_t4 = T(), a = T(), b = T();
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
const PIPair<T, T> & cv(input[i]);
|
const PIPair<T, T> & cv(input[i]);
|
||||||
@@ -155,8 +171,7 @@ bool OLS_Linear(const PIVector<PIPair<T, T> > & input, T * out_a, T * out_b) {
|
|||||||
a_t3 += cv.first * cv.first;
|
a_t3 += cv.first * cv.first;
|
||||||
}
|
}
|
||||||
a_t4 = n * a_t3 - a_t1 * a_t1;
|
a_t4 = n * a_t3 - a_t1 * a_t1;
|
||||||
if (a_t4 != T())
|
if (a_t4 != T()) a = (n * a_t0 - a_t1 * a_t2) / a_t4;
|
||||||
a = (n * a_t0 - a_t1 * a_t2) / a_t4;
|
|
||||||
b = (a_t2 - a * a_t1) / n;
|
b = (a_t2 - a * a_t1) / n;
|
||||||
if (out_a != 0) *out_a = a;
|
if (out_a != 0) *out_a = a;
|
||||||
if (out_b != 0) *out_b = b;
|
if (out_b != 0) *out_b = b;
|
||||||
@@ -164,14 +179,12 @@ bool OLS_Linear(const PIVector<PIPair<T, T> > & input, T * out_a, T * out_b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
bool WLS_Linear(const PIVector<PIPair<T, T> > & input, const PIVector<T> & weights, T * out_a, T * out_b) {
|
bool WLS_Linear(const PIVector<PIPair<T, T>> & input, const PIVector<T> & weights, T * out_a, T * out_b) {
|
||||||
static_assert(std::is_arithmetic<T>::value, "Type must be arithmetic");
|
static_assert(std::is_arithmetic<T>::value, "Type must be arithmetic");
|
||||||
if (input.size_s() < 2)
|
if (input.size_s() < 2) return false;
|
||||||
return false;
|
if (input.size_s() != weights.size_s()) return false;
|
||||||
if (input.size_s() != weights.size_s())
|
int n = input.size_s();
|
||||||
return false;
|
|
||||||
int n = input.size_s();
|
|
||||||
T a_t0 = T(), a_t1 = T(), a_t2 = T(), a_t3 = T(), a_t4 = T(), a_n = T(), a = T(), b = T();
|
T a_t0 = T(), a_t1 = T(), a_t2 = T(), a_t3 = T(), a_t4 = T(), a_n = T(), a = T(), b = T();
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
T cp = weights[i];
|
T cp = weights[i];
|
||||||
@@ -183,8 +196,7 @@ bool WLS_Linear(const PIVector<PIPair<T, T> > & input, const PIVector<T> & weigh
|
|||||||
a_n += cp;
|
a_n += cp;
|
||||||
}
|
}
|
||||||
a_t4 = a_n * a_t3 - a_t1 * a_t1;
|
a_t4 = a_n * a_t3 - a_t1 * a_t1;
|
||||||
if (a_t4 != T())
|
if (a_t4 != T()) a = (a_n * a_t0 - a_t1 * a_t2) / a_t4;
|
||||||
a = (a_n * a_t0 - a_t1 * a_t2) / a_t4;
|
|
||||||
b = (a_t2 - a * a_t1) / a_n;
|
b = (a_t2 - a * a_t1) / a_n;
|
||||||
if (out_a != 0) *out_a = a;
|
if (out_a != 0) *out_a = a;
|
||||||
if (out_b != 0) *out_b = b;
|
if (out_b != 0) *out_b = b;
|
||||||
|
|||||||
@@ -28,26 +28,26 @@
|
|||||||
|
|
||||||
#include "pimathmatrix.h"
|
#include "pimathmatrix.h"
|
||||||
|
|
||||||
class PIP_EXPORT PIQuaternion
|
class PIP_EXPORT PIQuaternion {
|
||||||
{
|
friend PIP_EXPORT PIQuaternion operator*(const PIQuaternion & q0, const PIQuaternion & q1);
|
||||||
friend PIQuaternion operator*(const PIQuaternion & q0, const PIQuaternion & q1);
|
friend PIP_EXPORT PIQuaternion operator*(const double & a, const PIQuaternion & q);
|
||||||
friend PIQuaternion operator*(const double & a, const PIQuaternion & q);
|
|
||||||
public:
|
public:
|
||||||
PIQuaternion(const PIMathVectorT3d & u = PIMathVectorT3d(), double a = 0.);
|
PIQuaternion(const PIMathVectorT3d & u = PIMathVectorT3d(), double a = 0.);
|
||||||
|
|
||||||
PIQuaternion conjugate() const {return PIQuaternion(-vector(), scalar());}
|
PIQuaternion conjugate() const { return PIQuaternion(-vector(), scalar()); }
|
||||||
PIQuaternion rotated(const PIMathVectorT3d & u, double a) const;
|
PIQuaternion rotated(const PIMathVectorT3d & u, double a) const;
|
||||||
void rotate(const PIMathVectorT3d & u, double a);
|
void rotate(const PIMathVectorT3d & u, double a);
|
||||||
void normalize();
|
void normalize();
|
||||||
|
|
||||||
double & scalar() {return q[0];}
|
double & scalar() { return q[0]; }
|
||||||
double scalar() const {return q[0];}
|
double scalar() const { return q[0]; }
|
||||||
PIMathVectorT3d vector() const {return PIMathVectorT3d({q[1], q[2], q[3]});}
|
PIMathVectorT3d vector() const { return PIMathVectorT3d({q[1], q[2], q[3]}); }
|
||||||
|
|
||||||
PIMathVectorT3d eyler() const;
|
PIMathVectorT3d eyler() const;
|
||||||
PIMathMatrixT33d rotationMatrix() const;
|
PIMathMatrixT33d rotationMatrix() const;
|
||||||
void axis(PIMathVectorT3d*ret) const;
|
void axis(PIMathVectorT3d * ret) const;
|
||||||
|
|
||||||
static PIQuaternion fromEyler(double ax, double ay, double az);
|
static PIQuaternion fromEyler(double ax, double ay, double az);
|
||||||
static PIQuaternion fromRotationMatrix(const PIMathMatrixT33d & m);
|
static PIQuaternion fromRotationMatrix(const PIMathMatrixT33d & m);
|
||||||
static PIQuaternion fromAngles(double ax, double ay, double az);
|
static PIQuaternion fromAngles(double ax, double ay, double az);
|
||||||
@@ -57,10 +57,16 @@ protected:
|
|||||||
double q[4];
|
double q[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
PIP_EXPORT PIQuaternion operator *(const double & a, const PIQuaternion & q);
|
PIP_EXPORT PIQuaternion operator*(const double & a, const PIQuaternion & q);
|
||||||
PIP_EXPORT PIQuaternion operator *(const PIQuaternion & q0, const PIQuaternion & q1);
|
PIP_EXPORT PIQuaternion operator*(const PIQuaternion & q0, const PIQuaternion & q1);
|
||||||
inline PIQuaternion operator +(const PIQuaternion & q0, const PIQuaternion & q1) {return PIQuaternion(q0.vector() + q1.vector(), q0.scalar() + q1.scalar());}
|
inline PIQuaternion operator+(const PIQuaternion & q0, const PIQuaternion & q1) {
|
||||||
inline PIQuaternion operator -(const PIQuaternion & q0, const PIQuaternion & q1) {return PIQuaternion(q0.vector() - q1.vector(), q0.scalar() - q1.scalar());}
|
return PIQuaternion(q0.vector() + q1.vector(), q0.scalar() + q1.scalar());
|
||||||
inline PIQuaternion operator -(const PIQuaternion & q0) {return PIQuaternion(-q0.vector(), -q0.scalar());}
|
}
|
||||||
|
inline PIQuaternion operator-(const PIQuaternion & q0, const PIQuaternion & q1) {
|
||||||
|
return PIQuaternion(q0.vector() - q1.vector(), q0.scalar() - q1.scalar());
|
||||||
|
}
|
||||||
|
inline PIQuaternion operator-(const PIQuaternion & q0) {
|
||||||
|
return PIQuaternion(-q0.vector(), -q0.scalar());
|
||||||
|
}
|
||||||
|
|
||||||
#endif // PIQUATERNION_H
|
#endif // PIQUATERNION_H
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* \brief
|
* \brief
|
||||||
* \~english PIValueTree conversions
|
* \~english PIValueTree conversions
|
||||||
* \~russian Преобразования PIValueTree
|
* \~russian Преобразования PIValueTree
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
PIValueTree conversions
|
PIValueTree conversions
|
||||||
@@ -34,23 +34,23 @@ class PIIODevice;
|
|||||||
|
|
||||||
namespace PIValueTreeConversions {
|
namespace PIValueTreeConversions {
|
||||||
|
|
||||||
enum Option {
|
enum Option {
|
||||||
WithAttributes = 0x1,
|
WithAttributes = 0x1,
|
||||||
WithComment = 0x2,
|
WithComment = 0x2,
|
||||||
WithType = 0x4,
|
WithType = 0x4,
|
||||||
WithAll = 0xFFFFFF,
|
WithAll = 0xFFFFFF,
|
||||||
Default = WithAll
|
Default = WithAll
|
||||||
};
|
};
|
||||||
typedef PIFlags<Option> Options;
|
typedef PIFlags<Option> Options;
|
||||||
|
|
||||||
PIP_EXPORT PIValueTree fromPropertyStorage(const PIPropertyStorage & ps);
|
PIP_EXPORT PIValueTree fromPropertyStorage(const PIPropertyStorage & ps);
|
||||||
PIP_EXPORT PIValueTree fromVariantMap(const PIVariantMap & vm);
|
PIP_EXPORT PIValueTree fromVariantMap(const PIVariantMap & vm);
|
||||||
PIP_EXPORT PIValueTree fromJSON(const PIJSON & json);
|
PIP_EXPORT PIValueTree fromJSON(const PIJSON & json);
|
||||||
PIP_EXPORT PIValueTree fromText(PIIODevice * device);
|
PIP_EXPORT PIValueTree fromText(PIIODevice * device);
|
||||||
PIP_EXPORT PIValueTree fromText(const PIString & str);
|
PIP_EXPORT PIValueTree fromText(const PIString & str);
|
||||||
PIP_EXPORT PIJSON toJSON(const PIValueTree & root, Options options = Default);
|
PIP_EXPORT PIJSON toJSON(const PIValueTree & root, Options options = Default);
|
||||||
PIP_EXPORT PIString toText(const PIValueTree & root, Options options = Default);
|
PIP_EXPORT PIString toText(const PIValueTree & root, Options options = Default);
|
||||||
|
|
||||||
}
|
} // namespace PIValueTreeConversions
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* \~\brief
|
* \~\brief
|
||||||
* \~english Single string character
|
* \~english Single string character
|
||||||
* \~russian Один символ строки
|
* \~russian Один символ строки
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
Unicode char
|
Unicode char
|
||||||
@@ -36,26 +36,26 @@ extern PIP_EXPORT char * __utf8name__;
|
|||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english %PIChar represents a single character.
|
//! \~english %PIChar represents a single character.
|
||||||
//! \~russian %PIChar представляет собой один символ строки.
|
//! \~russian %PIChar представляет собой один символ строки.
|
||||||
class PIP_EXPORT PIChar
|
class PIP_EXPORT PIChar {
|
||||||
{
|
|
||||||
friend class PIString;
|
friend class PIString;
|
||||||
friend PICout operator <<(PICout s, const PIChar & v);
|
friend PIP_EXPORT PICout operator<<(PICout s, const PIChar & v);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! \~english Contructs Ascii symbol
|
//! \~english Contructs Ascii symbol
|
||||||
//! \~russian Создает символ Ascii
|
//! \~russian Создает символ Ascii
|
||||||
PIChar(char c) {ch = c;}
|
PIChar(char c) { ch = c; }
|
||||||
|
|
||||||
//! \~english Contructs ascii symbol
|
//! \~english Contructs ascii symbol
|
||||||
//! \~russian Создает символ Ascii
|
//! \~russian Создает символ Ascii
|
||||||
PIChar(uchar c) {ch = c;}
|
PIChar(uchar c) { ch = c; }
|
||||||
|
|
||||||
//! \~english Contructs 2-bytes symbol
|
//! \~english Contructs 2-bytes symbol
|
||||||
//! \~russian Создает 2-байтный символ
|
//! \~russian Создает 2-байтный символ
|
||||||
PIChar(ushort c = 0) {ch = c;}
|
PIChar(ushort c = 0) { ch = c; }
|
||||||
|
|
||||||
//! \~english Contructs 2-bytes symbol from `wchar_t`
|
//! \~english Contructs 2-bytes symbol from `wchar_t`
|
||||||
//! \~russian Создает 2-байтный символ из `wchar_t`
|
//! \~russian Создает 2-байтный символ из `wchar_t`
|
||||||
PIChar(wchar_t c) {ch = c;}
|
PIChar(wchar_t c) { ch = c; }
|
||||||
|
|
||||||
//! \~english Contructs symbol from system locale and no more than 4 bytes of string
|
//! \~english Contructs symbol from system locale and no more than 4 bytes of string
|
||||||
//! \~russian Создает символ из системной локали не более 4 байт длины
|
//! \~russian Создает символ из системной локали не более 4 байт длины
|
||||||
@@ -63,52 +63,58 @@ public:
|
|||||||
|
|
||||||
//! \~english Copy operator
|
//! \~english Copy operator
|
||||||
//! \~russian Оператор присваивания
|
//! \~russian Оператор присваивания
|
||||||
PIChar & operator =(const char v) {ch = v; return *this;}
|
PIChar & operator=(const char v) {
|
||||||
|
ch = v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Copy operator
|
//! \~english Copy operator
|
||||||
//! \~russian Оператор присваивания
|
//! \~russian Оператор присваивания
|
||||||
PIChar & operator =(const wchar_t v) {ch = v; return *this;}
|
PIChar & operator=(const wchar_t v) {
|
||||||
|
ch = v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
bool operator ==(const PIChar & o) const;
|
bool operator==(const PIChar & o) const;
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
bool operator !=(const PIChar & o) const {return !(o == *this);}
|
bool operator!=(const PIChar & o) const { return !(o == *this); }
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
bool operator >(const PIChar & o) const;
|
bool operator>(const PIChar & o) const;
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
bool operator <(const PIChar & o) const;
|
bool operator<(const PIChar & o) const;
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
bool operator >=(const PIChar & o) const;
|
bool operator>=(const PIChar & o) const;
|
||||||
|
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
bool operator <=(const PIChar & o) const;
|
bool operator<=(const PIChar & o) const;
|
||||||
|
|
||||||
//! \~english Returns \b true if symbol is digit ('0' to '9')
|
//! \~english Returns \b true if symbol is digit ('0' to '9')
|
||||||
//! \~russian Возвращает \b true если символ является
|
//! \~russian Возвращает \b true если символ является
|
||||||
bool isDigit() const;
|
bool isDigit() const;
|
||||||
|
|
||||||
//! \~english Returns \b true if symbol is HEX digit ('0' to '9', 'a' to 'f', 'A' to 'F')
|
//! \~english Returns \b true if symbol is HEX digit ('0' to '9', 'a' to 'f', 'A' to 'F')
|
||||||
//! \~russian Возвращает \b true если символ является HEX цифрой ('0' до '9', 'a' до 'f', 'A' до 'F')
|
//! \~russian Возвращает \b true если символ является HEX цифрой ('0' до '9', 'a' до 'f', 'A' до 'F')
|
||||||
bool isHex() const;
|
bool isHex() const;
|
||||||
|
|
||||||
//! \~english Returns \b true if symbol is drawable (without space)
|
//! \~english Returns \b true if symbol is drawable (without space)
|
||||||
//! \~russian Возвращает \b true если символ является графическим (исключая пробельные)
|
//! \~russian Возвращает \b true если символ является графическим (исключая пробельные)
|
||||||
bool isGraphical() const;
|
bool isGraphical() const;
|
||||||
|
|
||||||
//! \~english Returns \b true if symbol is control byte (< 32 or 127)
|
//! \~english Returns \b true if symbol is control byte (< 32 or 127)
|
||||||
//! \~russian Возвращает \b true если символ является контрольным (< 32 or 127)
|
//! \~russian Возвращает \b true если символ является контрольным (< 32 or 127)
|
||||||
bool isControl() const;
|
bool isControl() const;
|
||||||
|
|
||||||
//! \~english Returns \b true if symbol is in lower case
|
//! \~english Returns \b true if symbol is in lower case
|
||||||
//! \~russian Возвращает \b true если символ в нижнем регистре
|
//! \~russian Возвращает \b true если символ в нижнем регистре
|
||||||
bool isLower() const;
|
bool isLower() const;
|
||||||
@@ -116,34 +122,34 @@ public:
|
|||||||
//! \~english Returns \b true if symbol is in upper case
|
//! \~english Returns \b true if symbol is in upper case
|
||||||
//! \~russian Возвращает \b true если символ в верхнем регистре
|
//! \~russian Возвращает \b true если символ в верхнем регистре
|
||||||
bool isUpper() const;
|
bool isUpper() const;
|
||||||
|
|
||||||
//! \~english Returns \b true if symbol is printable (with space)
|
//! \~english Returns \b true if symbol is printable (with space)
|
||||||
//! \~russian Возвращает \b true если символ является печатным (включая пробельные)
|
//! \~russian Возвращает \b true если символ является печатным (включая пробельные)
|
||||||
bool isPrint() const;
|
bool isPrint() const;
|
||||||
|
|
||||||
//! \~english Returns \b true if symbol is space or tab
|
//! \~english Returns \b true if symbol is space or tab
|
||||||
//! \~russian Возвращает \b true если символ является пробельным или табуляцией
|
//! \~russian Возвращает \b true если символ является пробельным или табуляцией
|
||||||
bool isSpace() const;
|
bool isSpace() const;
|
||||||
|
|
||||||
//! \~english Returns \b true if symbol is alphabetical letter
|
//! \~english Returns \b true if symbol is alphabetical letter
|
||||||
//! \~russian Возвращает \b true если символ является алфавитной буквой
|
//! \~russian Возвращает \b true если символ является алфавитной буквой
|
||||||
bool isAlpha() const;
|
bool isAlpha() const;
|
||||||
|
|
||||||
//! \~english Returns \b true if symbol is Ascii (< 128)
|
//! \~english Returns \b true if symbol is Ascii (< 128)
|
||||||
//! \~russian Возвращает \b true если символ является Ascii (< 128)
|
//! \~russian Возвращает \b true если символ является Ascii (< 128)
|
||||||
bool isAscii() const;
|
bool isAscii() const;
|
||||||
|
|
||||||
const wchar_t * toWCharPtr() const;
|
const wchar_t * toWCharPtr() const;
|
||||||
|
|
||||||
//! \~english Returns as `char *` string
|
//! \~english Returns as `char *` string
|
||||||
//! \~russian Возвращает символ как указатель на `char *`
|
//! \~russian Возвращает символ как указатель на `char *`
|
||||||
const char * toCharPtr() const;
|
const char * toCharPtr() const;
|
||||||
|
|
||||||
wchar_t toWChar() const;
|
wchar_t toWChar() const;
|
||||||
|
|
||||||
//! \~english Returns symbol as Ascii
|
//! \~english Returns symbol as Ascii
|
||||||
//! \~russian Возвращает символ в Ascii
|
//! \~russian Возвращает символ в Ascii
|
||||||
char toAscii() const {return ch % 256;}
|
char toAscii() const { return ch % 256; }
|
||||||
|
|
||||||
//! \~english Returns symbol as console codepage
|
//! \~english Returns symbol as console codepage
|
||||||
//! \~russian Возвращает символ в консольной кодировке
|
//! \~russian Возвращает символ в консольной кодировке
|
||||||
@@ -153,16 +159,16 @@ public:
|
|||||||
//! \~russian Возвращает символ в системной кодировке
|
//! \~russian Возвращает символ в системной кодировке
|
||||||
char toSystem() const;
|
char toSystem() const;
|
||||||
|
|
||||||
ushort unicode16Code() const {return ch;}
|
ushort unicode16Code() const { return ch; }
|
||||||
|
|
||||||
//! \~english Returns symbol in upper case
|
//! \~english Returns symbol in upper case
|
||||||
//! \~russian Возвращает символ в нижнем регистре
|
//! \~russian Возвращает символ в нижнем регистре
|
||||||
PIChar toUpper() const;
|
PIChar toUpper() const;
|
||||||
|
|
||||||
//! \~english Returns symbol in lower case
|
//! \~english Returns symbol in lower case
|
||||||
//! \~russian Возвращает символ в верхнем регистре
|
//! \~russian Возвращает символ в верхнем регистре
|
||||||
PIChar toLower() const;
|
PIChar toLower() const;
|
||||||
|
|
||||||
//! \~english Returns symbol from console codepage
|
//! \~english Returns symbol from console codepage
|
||||||
//! \~russian Возвращает символ из консольной кодировки
|
//! \~russian Возвращает символ из консольной кодировки
|
||||||
static PIChar fromConsole(char c);
|
static PIChar fromConsole(char c);
|
||||||
@@ -177,89 +183,118 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ushort ch;
|
ushort ch;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Output operator to \a PICout
|
//! \~english Output operator to \a PICout
|
||||||
//! \~russian Оператор вывода в \a PICout
|
//! \~russian Оператор вывода в \a PICout
|
||||||
PIP_EXPORT PICout operator <<(PICout s, const PIChar & v);
|
PIP_EXPORT PICout operator<<(PICout s, const PIChar & v);
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator ==(const char v, const PIChar & c) {return (PIChar(v) == c);}
|
inline bool operator==(const char v, const PIChar & c) {
|
||||||
|
return (PIChar(v) == c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator >(const char v, const PIChar & c) {return (PIChar(v) > c);}
|
inline bool operator>(const char v, const PIChar & c) {
|
||||||
|
return (PIChar(v) > c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator <(const char v, const PIChar & c) {return (PIChar(v) < c);}
|
inline bool operator<(const char v, const PIChar & c) {
|
||||||
|
return (PIChar(v) < c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator >=(const char v, const PIChar & c) {return (PIChar(v) >= c);}
|
inline bool operator>=(const char v, const PIChar & c) {
|
||||||
|
return (PIChar(v) >= c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator <=(const char v, const PIChar & c) {return (PIChar(v) <= c);}
|
inline bool operator<=(const char v, const PIChar & c) {
|
||||||
|
return (PIChar(v) <= c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator ==(const char * v, const PIChar & c) {return (PIChar(v) == c);}
|
inline bool operator==(const char * v, const PIChar & c) {
|
||||||
|
return (PIChar(v) == c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator >(const char * v, const PIChar & c) {return (PIChar(v) > c);}
|
inline bool operator>(const char * v, const PIChar & c) {
|
||||||
|
return (PIChar(v) > c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator <(const char * v, const PIChar & c) {return (PIChar(v) < c);}
|
inline bool operator<(const char * v, const PIChar & c) {
|
||||||
|
return (PIChar(v) < c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator >=(const char * v, const PIChar & c) {return (PIChar(v) >= c);}
|
inline bool operator>=(const char * v, const PIChar & c) {
|
||||||
|
return (PIChar(v) >= c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator <=(const char * v, const PIChar & c) {return (PIChar(v) <= c);}
|
inline bool operator<=(const char * v, const PIChar & c) {
|
||||||
|
return (PIChar(v) <= c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator ==(const int v, const PIChar & c) {return (PIChar((ushort)v) == c);}
|
inline bool operator==(const int v, const PIChar & c) {
|
||||||
|
return (PIChar((ushort)v) == c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator >(const int v, const PIChar & c) {return (PIChar((ushort)v) > c);}
|
inline bool operator>(const int v, const PIChar & c) {
|
||||||
|
return (PIChar((ushort)v) > c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator <(const int v, const PIChar & c) {return (PIChar((ushort)v) < c);}
|
inline bool operator<(const int v, const PIChar & c) {
|
||||||
|
return (PIChar((ushort)v) < c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator >=(const int v, const PIChar & c) {return (PIChar((ushort)v) >= c);}
|
inline bool operator>=(const int v, const PIChar & c) {
|
||||||
|
return (PIChar((ushort)v) >= c);
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIChar
|
//! \relatesalso PIChar
|
||||||
//! \~english Compare operator
|
//! \~english Compare operator
|
||||||
//! \~russian Оператор сравнения
|
//! \~russian Оператор сравнения
|
||||||
inline bool operator <=(const int v, const PIChar & c) {return (PIChar((ushort)v) <= c);}
|
inline bool operator<=(const int v, const PIChar & c) {
|
||||||
|
return (PIChar((ushort)v) <= c);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // PICHAR_H
|
#endif // PICHAR_H
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
|
|
||||||
Stephan Fomenko
|
Stephan Fomenko
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
#define PITHREADPOOLEXECUTOR_H
|
#define PITHREADPOOLEXECUTOR_H
|
||||||
|
|
||||||
#include "piblockingqueue.h"
|
#include "piblockingqueue.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
|
|
||||||
@@ -30,22 +31,18 @@ public:
|
|||||||
|
|
||||||
virtual ~PIThreadPoolExecutor();
|
virtual ~PIThreadPoolExecutor();
|
||||||
|
|
||||||
/**
|
//! \brief Executes the given task sometime in the future. The task execute in an existing pooled thread. If the task
|
||||||
* \brief Executes the given task sometime in the future. The task execute in an existing pooled thread. If the task
|
//! cannot be submitted for execution, either because this executor has been shutdown or because its capacity has been
|
||||||
* cannot be submitted for execution, either because this executor has been shutdown or because its capacity has been
|
//! reached.
|
||||||
* reached.
|
//!
|
||||||
*
|
//! \param runnable not empty function for thread pool execution
|
||||||
* @param runnable not empty function for thread pool execution
|
|
||||||
*/
|
|
||||||
void execute(const std::function<void()> & runnable);
|
void execute(const std::function<void()> & runnable);
|
||||||
|
|
||||||
void shutdownNow();
|
void shutdownNow();
|
||||||
|
|
||||||
/**
|
//! \brief Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be
|
||||||
* \brief Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be
|
//! accepted. Invocation has no additional effect if already shut down. This method does not wait for previously
|
||||||
* accepted. Invocation has no additional effect if already shut down. This method does not wait for previously
|
//! submitted tasks to complete execution. Use awaitTermination to do that.
|
||||||
* submitted tasks to complete execution. Use awaitTermination to do that.
|
|
||||||
*/
|
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
bool isShutdown() const;
|
bool isShutdown() const;
|
||||||
@@ -54,8 +51,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::atomic_bool isShutdown_;
|
std::atomic_bool isShutdown_;
|
||||||
PIBlockingQueue<std::function<void()> > taskQueue;
|
PIBlockingQueue<std::function<void()>> taskQueue;
|
||||||
PIVector<PIThread*> threadPool;
|
PIVector<PIThread *> threadPool;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PITHREADPOOLEXECUTOR_H
|
#endif // PITHREADPOOLEXECUTOR_H
|
||||||
|
|||||||
@@ -35,35 +35,35 @@ class PITimer;
|
|||||||
|
|
||||||
class PIP_EXPORT _PITimerBase {
|
class PIP_EXPORT _PITimerBase {
|
||||||
friend class PITimer;
|
friend class PITimer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
_PITimerBase();
|
_PITimerBase();
|
||||||
virtual ~_PITimerBase() {}
|
virtual ~_PITimerBase() {}
|
||||||
|
|
||||||
double interval() const {return interval_;}
|
double interval() const { return interval_; }
|
||||||
void setInterval(double i);
|
void setInterval(double i);
|
||||||
|
|
||||||
bool isRunning() const {return running_;}
|
bool isRunning() const { return running_; }
|
||||||
|
|
||||||
bool isStopped() const {return !running_;}
|
bool isStopped() const { return !running_; }
|
||||||
|
|
||||||
bool start() {return start(interval_);}
|
bool start() { return start(interval_); }
|
||||||
bool start(double interval_ms);
|
bool start(double interval_ms);
|
||||||
void startDeferred(double delay_ms) {startDeferred(interval_, delay_ms);}
|
void startDeferred(double delay_ms) { startDeferred(interval_, delay_ms); }
|
||||||
void startDeferred(double interval_ms, double delay_ms);
|
void startDeferred(double interval_ms, double delay_ms);
|
||||||
void startDeferred(PIDateTime start_datetime) {startDeferred(interval_, start_datetime);}
|
void startDeferred(PIDateTime start_datetime) { startDeferred(interval_, start_datetime); }
|
||||||
void startDeferred(double interval_ms, PIDateTime start_datetime);
|
void startDeferred(double interval_ms, PIDateTime start_datetime);
|
||||||
|
|
||||||
bool stop();
|
bool stop();
|
||||||
|
|
||||||
typedef void(*TickFunc)(PITimer*);
|
typedef void (*TickFunc)(PITimer *);
|
||||||
TickFunc tfunc;
|
TickFunc tfunc;
|
||||||
PITimer * parent;
|
PITimer * parent;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual bool startTimer(double interval_ms) = 0;
|
virtual bool startTimer(double interval_ms) = 0;
|
||||||
virtual bool stopTimer() = 0;
|
virtual bool stopTimer() = 0;
|
||||||
|
|
||||||
double interval_, deferred_delay;
|
double interval_, deferred_delay;
|
||||||
bool deferred_, deferred_mode; // mode: true - date, false - delay
|
bool deferred_, deferred_mode; // mode: true - date, false - delay
|
||||||
std::atomic_bool running_;
|
std::atomic_bool running_;
|
||||||
@@ -71,10 +71,9 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PIP_EXPORT PITimer: public PIObject {
|
class PIP_EXPORT PITimer: public PIObject {
|
||||||
PIOBJECT_SUBCLASS(PITimer, PIObject);
|
PIOBJECT_SUBCLASS(PITimer, PIObject);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NO_COPY_CLASS(PITimer);
|
NO_COPY_CLASS(PITimer);
|
||||||
|
|
||||||
@@ -88,56 +87,59 @@ public:
|
|||||||
Thread /*!
|
Thread /*!
|
||||||
\~english Timer works in his own thread. Intervals are measured by the system time
|
\~english Timer works in his own thread. Intervals are measured by the system time
|
||||||
\~russian Таймер работает в собственном потоке. Интервалы измеряются с помощью системного времени
|
\~russian Таймер работает в собственном потоке. Интервалы измеряются с помощью системного времени
|
||||||
*/ = 0x01,
|
*/
|
||||||
|
= 0x01,
|
||||||
ThreadRT /*!
|
ThreadRT /*!
|
||||||
\~english Using POSIX timer with SIGEV_THREAD notification. \attention Doesn`t support on Windows and Mac OS!
|
\~english Using POSIX timer with SIGEV_THREAD notification. \attention Doesn`t support on Windows and Mac OS!
|
||||||
\~russian Использовать таймер POSIX с SIGEV_THREAD уведомлением. \attention Не поддерживается на Windows и Mac OS!
|
\~russian Использовать таймер POSIX с SIGEV_THREAD уведомлением. \attention Не поддерживается на Windows и Mac OS!
|
||||||
*/ = 0x02,
|
*/
|
||||||
|
= 0x02,
|
||||||
Pool /*!
|
Pool /*!
|
||||||
\~english Using single TimerPool for all timers with this implementation. TimerPool works as Thread implementation and
|
\~english Using single TimerPool for all timers with this implementation. TimerPool works as Thread implementation and
|
||||||
sequentially executes all timers. \attention Use this implementation with care!
|
sequentially executes all timers. \attention Use this implementation with care!
|
||||||
\~russian Использовать единый TimerPool для всех таймеров с этой реализацией. TimerPool реализован через Thread и
|
\~russian Использовать единый TimerPool для всех таймеров с этой реализацией. TimerPool реализован через Thread и
|
||||||
последовательно исполняет все таймеры. \attention Осторожнее с этой реализацией!
|
последовательно исполняет все таймеры. \attention Осторожнее с этой реализацией!
|
||||||
*/ = 0x04
|
*/
|
||||||
|
= 0x04
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \~english Constructs timer with "ti" implementation
|
//! \~english Constructs timer with "ti" implementation
|
||||||
//! \~russian Создает таймер с реализацией "ti"
|
//! \~russian Создает таймер с реализацией "ti"
|
||||||
explicit PITimer(TimerImplementation ti);
|
explicit PITimer(TimerImplementation ti);
|
||||||
|
|
||||||
//! \~english Constructs timer with "slot" slot void(void *,int), "data" data and "ti" implementation
|
//! \~english Constructs timer with "slot" slot void(void *,int), "data" data and "ti" implementation
|
||||||
//! \~russian Создает таймер со слотом "slot", данными "data" и реализацией "ti"
|
//! \~russian Создает таймер со слотом "slot", данными "data" и реализацией "ti"
|
||||||
explicit PITimer(TimerEvent slot, void * data = 0, TimerImplementation ti = Thread);
|
explicit PITimer(TimerEvent slot, void * data = 0, TimerImplementation ti = Thread);
|
||||||
|
|
||||||
//! \~english Constructs timer with "slot" slot void(), and "ti" implementation
|
//! \~english Constructs timer with "slot" slot void(), and "ti" implementation
|
||||||
//! \~russian Создает таймер со слотом "slot" и реализацией "ti"
|
//! \~russian Создает таймер со слотом "slot" и реализацией "ti"
|
||||||
explicit PITimer(std::function<void ()> slot, TimerImplementation ti = Thread);
|
explicit PITimer(std::function<void()> slot, TimerImplementation ti = Thread);
|
||||||
|
|
||||||
//! \~english Constructs timer with "slot" slot void(void *), "data" data and "ti" implementation
|
//! \~english Constructs timer with "slot" slot void(void *), "data" data and "ti" implementation
|
||||||
//! \~russian Создает таймер со слотом "slot", данными "data" и реализацией "ti"
|
//! \~russian Создает таймер со слотом "slot", данными "data" и реализацией "ti"
|
||||||
explicit PITimer(std::function<void (void *)> slot, void * data, TimerImplementation ti = Thread);
|
explicit PITimer(std::function<void(void *)> slot, void * data, TimerImplementation ti = Thread);
|
||||||
|
|
||||||
virtual ~PITimer();
|
virtual ~PITimer();
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns timer implementation
|
//! \~english Returns timer implementation
|
||||||
//! \~russian Возвращает реализацию таймера
|
//! \~russian Возвращает реализацию таймера
|
||||||
PITimer::TimerImplementation implementation() const {return imp_mode;}
|
PITimer::TimerImplementation implementation() const { return imp_mode; }
|
||||||
|
|
||||||
//! \~english Returns timer loop delay in milliseconds
|
//! \~english Returns timer loop delay in milliseconds
|
||||||
//! \~russian Возвращает задержку цикла таймера в миллисекундах
|
//! \~russian Возвращает задержку цикла таймера в миллисекундах
|
||||||
double interval() const;
|
double interval() const;
|
||||||
|
|
||||||
EVENT_HANDLER1(void, setInterval, double, ms);
|
EVENT_HANDLER1(void, setInterval, double, ms);
|
||||||
|
|
||||||
//! \~english Returns if timer is started
|
//! \~english Returns if timer is started
|
||||||
//! \~russian Возвращает работает ли таймер
|
//! \~russian Возвращает работает ли таймер
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
|
|
||||||
//! \~english Returns if timer is not started
|
//! \~english Returns if timer is not started
|
||||||
//! \~russian Возвращает остановлен ли таймер
|
//! \~russian Возвращает остановлен ли таймер
|
||||||
bool isStopped() const;
|
bool isStopped() const;
|
||||||
|
|
||||||
EVENT_HANDLER0(bool, start);
|
EVENT_HANDLER0(bool, start);
|
||||||
EVENT_HANDLER1(bool, start, double, interval_ms_d);
|
EVENT_HANDLER1(bool, start, double, interval_ms_d);
|
||||||
bool start(int interval_ms_i);
|
bool start(int interval_ms_i);
|
||||||
@@ -159,64 +161,78 @@ public:
|
|||||||
//! \~english Start timer with "interval_msecs" loop delay after "start_datetime" date and time
|
//! \~english Start timer with "interval_msecs" loop delay after "start_datetime" date and time
|
||||||
//! \~russian Запускает таймер с интервалом "interval_msecs" после наступления "start_datetime"
|
//! \~russian Запускает таймер с интервалом "interval_msecs" после наступления "start_datetime"
|
||||||
void startDeferred(double interval_ms, PIDateTime start_datetime);
|
void startDeferred(double interval_ms, PIDateTime start_datetime);
|
||||||
|
|
||||||
EVENT_HANDLER0(bool, stop);
|
EVENT_HANDLER0(bool, stop);
|
||||||
|
|
||||||
//! \~english Set custom data
|
//! \~english Set custom data
|
||||||
//! \~russian Установить данные, передаваемые в метод таймера
|
//! \~russian Установить данные, передаваемые в метод таймера
|
||||||
void setData(void * data_) {data_t = data_;}
|
void setData(void * data_) { data_t = data_; }
|
||||||
|
|
||||||
//! \~english Returns common data passed to tick functions
|
//! \~english Returns common data passed to tick functions
|
||||||
//! \~russian Возвращает данные, передаваемые в метод таймера
|
//! \~russian Возвращает данные, передаваемые в метод таймера
|
||||||
void * data() const {return data_t;}
|
void * data() const { return data_t; }
|
||||||
|
|
||||||
//! \~english Set timer tick function
|
//! \~english Set timer tick function
|
||||||
//! \~russian Установить вызываемый метод
|
//! \~russian Установить вызываемый метод
|
||||||
void setSlot(TimerEvent slot) {ret_func = slot;}
|
void setSlot(TimerEvent slot) { ret_func = slot; }
|
||||||
|
|
||||||
//! \~english Set timer tick function
|
//! \~english Set timer tick function
|
||||||
//! \~russian Установить вызываемый метод
|
//! \~russian Установить вызываемый метод
|
||||||
void setSlot(std::function<void ()> slot) {ret_func = [slot](void *, int){slot();};}
|
void setSlot(std::function<void()> slot) {
|
||||||
|
ret_func = [slot](void *, int) { slot(); };
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Set timer tick function
|
//! \~english Set timer tick function
|
||||||
//! \~russian Установить вызываемый метод
|
//! \~russian Установить вызываемый метод
|
||||||
void setSlot(std::function<void (void *)> slot) {ret_func = [slot](void *d, int){slot(d);};}
|
void setSlot(std::function<void(void *)> slot) {
|
||||||
|
ret_func = [slot](void * d, int) { slot(d); };
|
||||||
|
}
|
||||||
|
|
||||||
void needLockRun(bool need) {lockRun = need;}
|
void needLockRun(bool need) { lockRun = need; }
|
||||||
EVENT_HANDLER0(void, lock) {mutex_.lock();}
|
EVENT_HANDLER0(void, lock) { mutex_.lock(); }
|
||||||
EVENT_HANDLER0(void, unlock) {mutex_.unlock();}
|
EVENT_HANDLER0(void, unlock) { mutex_.unlock(); }
|
||||||
|
|
||||||
//! \~english Returns if timer should exec \a maybeCallQueuedEvents() at every tick. By default \b true
|
//! \~english Returns if timer should exec \a maybeCallQueuedEvents() at every tick. By default \b true
|
||||||
//! \~russian Возвращает должен ли таймер вызывать \a maybeCallQueuedEvents() каждый тик. По умолчанию \b true
|
//! \~russian Возвращает должен ли таймер вызывать \a maybeCallQueuedEvents() каждый тик. По умолчанию \b true
|
||||||
bool isCallQueuedEvents() const {return callEvents;}
|
bool isCallQueuedEvents() const { return callEvents; }
|
||||||
|
|
||||||
//! \~english Set timer exec \a maybeCallQueuedEvents() at every tick
|
//! \~english Set timer exec \a maybeCallQueuedEvents() at every tick
|
||||||
//! \~russian Установает должен ли таймер вызывать \a maybeCallQueuedEvents() каждый тик
|
//! \~russian Установает должен ли таймер вызывать \a maybeCallQueuedEvents() каждый тик
|
||||||
void setCallQueuedEvents(bool yes) {callEvents = yes;}
|
void setCallQueuedEvents(bool yes) { callEvents = yes; }
|
||||||
|
|
||||||
//! \~english Add frequency delimiter "delim" with optional delimiter slot "slot"
|
//! \~english Add frequency delimiter "delim" with optional delimiter slot "slot"
|
||||||
//! \~russian Добавляет делитель частоты "delim" с необязательным методом "slot"
|
//! \~russian Добавляет делитель частоты "delim" с необязательным методом "slot"
|
||||||
void addDelimiter(int delim, TimerEvent slot = 0) {delims << Delimiter(slot, delim);}
|
void addDelimiter(int delim, TimerEvent slot = 0) { delims << Delimiter(slot, delim); }
|
||||||
|
|
||||||
//! \~english Add frequency delimiter "delim" with optional delimiter slot "slot"
|
//! \~english Add frequency delimiter "delim" with optional delimiter slot "slot"
|
||||||
//! \~russian Добавляет делитель частоты "delim" с необязательным методом "slot"
|
//! \~russian Добавляет делитель частоты "delim" с необязательным методом "slot"
|
||||||
void addDelimiter(int delim, std::function<void ()> slot) {delims << Delimiter([slot](void *, int){slot();}, delim);}
|
void addDelimiter(int delim, std::function<void()> slot) {
|
||||||
|
delims << Delimiter([slot](void *, int) { slot(); }, delim);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Add frequency delimiter "delim" with optional delimiter slot "slot"
|
//! \~english Add frequency delimiter "delim" with optional delimiter slot "slot"
|
||||||
//! \~russian Добавляет делитель частоты "delim" с необязательным методом "slot"
|
//! \~russian Добавляет делитель частоты "delim" с необязательным методом "slot"
|
||||||
void addDelimiter(int delim, std::function<void (void *)> slot) {delims << Delimiter([slot](void *d, int){slot(d);}, delim);}
|
void addDelimiter(int delim, std::function<void(void *)> slot) {
|
||||||
|
delims << Delimiter([slot](void * d, int) { slot(d); }, delim);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Remove all frequency delimiters "delim"
|
//! \~english Remove all frequency delimiters "delim"
|
||||||
//! \~russian Удаляет все делители частоты "delim"
|
//! \~russian Удаляет все делители частоты "delim"
|
||||||
void removeDelimiter(int delim) {for (int i = 0; i < delims.size_s(); ++i) if (delims[i].delim == delim) {delims.remove(i); i--;}}
|
void removeDelimiter(int delim) {
|
||||||
|
for (int i = 0; i < delims.size_s(); ++i)
|
||||||
EVENT_HANDLER0(void, clearDelimiters) {delims.clear();}
|
if (delims[i].delim == delim) {
|
||||||
|
delims.remove(i);
|
||||||
EVENT2(tickEvent, void * , data_, int, delimiter);
|
i--;
|
||||||
|
}
|
||||||
//! \handlers
|
}
|
||||||
//! \{
|
|
||||||
|
EVENT_HANDLER0(void, clearDelimiters) { delims.clear(); }
|
||||||
|
|
||||||
|
EVENT2(tickEvent, void *, data_, int, delimiter);
|
||||||
|
|
||||||
|
//! \handlers
|
||||||
|
//! \{
|
||||||
|
|
||||||
//! \fn void setInterval(double ms)
|
//! \fn void setInterval(double ms)
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Set timer loop delay in milliseconds
|
//! \~english Set timer loop delay in milliseconds
|
||||||
@@ -250,21 +266,21 @@ public:
|
|||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Stop and start timer with \a interval() loop delay
|
//! \~english Stop and start timer with \a interval() loop delay
|
||||||
//! \~russian Остановить и запустить таймер с интервалом \a interval()
|
//! \~russian Остановить и запустить таймер с интервалом \a interval()
|
||||||
|
|
||||||
//! \fn bool stop(bool wait = true)
|
//! \fn bool stop(bool wait = true)
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Stop timer and wait for it finish if "wait"
|
//! \~english Stop timer and wait for it finish if "wait"
|
||||||
//! \~russian Остановить таймер и если "wait" то дождаться остановки
|
//! \~russian Остановить таймер и если "wait" то дождаться остановки
|
||||||
|
|
||||||
//! \fn void clearDelimiters()
|
//! \fn void clearDelimiters()
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Remove all frequency delimiters
|
//! \~english Remove all frequency delimiters
|
||||||
//! \~russian Удаляет все делители частоты
|
//! \~russian Удаляет все делители частоты
|
||||||
|
|
||||||
//! \}
|
//! \}
|
||||||
//! \events
|
//! \events
|
||||||
//! \{
|
//! \{
|
||||||
|
|
||||||
//! \fn void tickEvent(void * data, int delimiter)
|
//! \fn void tickEvent(void * data, int delimiter)
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Raise on timer tick
|
//! \~english Raise on timer tick
|
||||||
@@ -276,35 +292,39 @@ public:
|
|||||||
//! \~russian
|
//! \~russian
|
||||||
//! "data" устанавливается методом \a setData() или в конструкторе.
|
//! "data" устанавливается методом \a setData() или в конструкторе.
|
||||||
//! "delimiter" - делитель частоты, 1 для основного цикла
|
//! "delimiter" - делитель частоты, 1 для основного цикла
|
||||||
|
|
||||||
|
|
||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct PIP_EXPORT Delimiter {
|
struct PIP_EXPORT Delimiter {
|
||||||
Delimiter(TimerEvent slot_ = 0, int delim_ = 1) {slot = slot_; delim = delim_; tick = 0;}
|
Delimiter(TimerEvent slot_ = 0, int delim_ = 1) {
|
||||||
|
slot = slot_;
|
||||||
|
delim = delim_;
|
||||||
|
tick = 0;
|
||||||
|
}
|
||||||
TimerEvent slot;
|
TimerEvent slot;
|
||||||
int delim;
|
int delim;
|
||||||
int tick;
|
int tick;
|
||||||
};
|
};
|
||||||
|
|
||||||
void initFirst();
|
void initFirst();
|
||||||
void init() const;
|
void init() const;
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
static void tickImpS(PITimer * t) {t->tickImp();}
|
static void tickImpS(PITimer * t) { t->tickImp(); }
|
||||||
void tickImp();
|
void tickImp();
|
||||||
|
|
||||||
//! Timer execution function, similar to "slot" or event \a timeout(). By default does nothing
|
//! Timer execution function, similar to "slot" or event \a timeout(). By default does nothing
|
||||||
virtual void tick(void * data_, int delimiter) {}
|
virtual void tick(void * data_, int delimiter) {}
|
||||||
|
|
||||||
void * data_t;
|
void * data_t;
|
||||||
std::atomic_bool lockRun, callEvents;
|
std::atomic_bool lockRun, callEvents;
|
||||||
PIMutex mutex_;
|
PIMutex mutex_;
|
||||||
TimerEvent ret_func;
|
TimerEvent ret_func;
|
||||||
TimerImplementation imp_mode;
|
TimerImplementation imp_mode;
|
||||||
PIVector<Delimiter> delims;
|
PIVector<Delimiter> delims;
|
||||||
|
|
||||||
mutable _PITimerBase * imp;
|
mutable _PITimerBase * imp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user