before formatting

This commit is contained in:
2022-12-14 13:56:19 +03:00
parent c74ba871cd
commit 430a41fefc
14 changed files with 912 additions and 623 deletions

View File

@@ -17,14 +17,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piscreen.h"
#include "piincludes_p.h"
#ifndef WINDOWS
# include <sys/ioctl.h>
# include <fcntl.h>
# include <sys/ioctl.h>
# include <termios.h>
#else
# include <wingdi.h>
# include <wincon.h>
# include <wingdi.h>
# ifndef COMMON_LVB_UNDERSCORE
# define COMMON_LVB_UNDERSCORE 0x8000
# endif
@@ -244,10 +245,14 @@ void PIScreen::SystemConsole::print() {
# define BACKGROUND_MASK (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
ushort PIScreen::SystemConsole::attributes(const PIScreenTypes::Cell & c) {
WORD attr = PRIVATE->dattr;
if (c.format.flags & Bold) attr |= FOREGROUND_INTENSITY;
else attr &= ~FOREGROUND_INTENSITY;
if (c.format.flags & Underline) attr |= COMMON_LVB_UNDERSCORE;
else attr &= ~COMMON_LVB_UNDERSCORE;
if (c.format.flags & Bold)
attr |= FOREGROUND_INTENSITY;
else
attr &= ~FOREGROUND_INTENSITY;
if (c.format.flags & Underline)
attr |= COMMON_LVB_UNDERSCORE;
else
attr &= ~COMMON_LVB_UNDERSCORE;
switch (c.format.color_char) {
case Black: attr = (attr & ~FOREGROUND_MASK); break;
case Red: attr = (attr & ~FOREGROUND_MASK) | FOREGROUND_RED; break;
@@ -292,7 +297,8 @@ void PIScreen::SystemConsole::clearLine() {
void PIScreen::SystemConsole::newLine() {
getWinCurCoord();
PRIVATE->ccoord.X = 0; PRIVATE->ccoord.Y++;
PRIVATE->ccoord.X = 0;
PRIVATE->ccoord.Y++;
SetConsoleCursorPosition(PRIVATE->hOut, PRIVATE->ccoord);
}
#else // WINDOWS
@@ -358,8 +364,16 @@ void PIScreen::SystemConsole::clearScreen() {
void PIScreen::SystemConsole::clearScreenLower() {
#ifdef WINDOWS
getWinCurCoord();
FillConsoleOutputAttribute(PRIVATE->hOut, 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);
FillConsoleOutputAttribute(PRIVATE->hOut,
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
printf("\e[0m\e[J");
#endif
@@ -384,7 +398,7 @@ void PIScreen::SystemConsole::showCursor() {
}
// PIScreen
PIScreen::PIScreen(bool startNow, PIKbdListener::KBFunc slot): PIThread(), drawer_(console.cells), root("rootTile") {
setName("screen");
@@ -422,14 +436,12 @@ void PIScreen::key_event(PIKbdListener::KeyEvent key) {
return;
*/
PIScreenTile * rtile = rootTile();
if (tile_dialog)
rtile = tile_dialog;
if (tile_dialog) rtile = tile_dialog;
bool used = nextFocus(rtile, key);
if (used) return;
if (!used && tile_focus) {
if (tile_focus->visible) {
if (tile_focus->keyEvent(key))
return;
if (tile_focus->keyEvent(key)) return;
}
}
if (ret_func != 0) ret_func(key, data_);
@@ -455,7 +467,6 @@ PIVector<PIScreenTile * > PIScreen::prepareMouse(PIKbdListener::MouseEvent * e)
ff = true;
}
}
}
return tl;
}
@@ -488,15 +499,13 @@ void PIScreen::wheel_event(PIKbdListener::WheelEvent we) {
if (tl.isEmpty()) return;
piForeachR(PIScreenTile * t, tl)
if (t->wheelEvent(we)) break;
}
bool PIScreen::nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key) {
PIVector<PIScreenTile *> vtl = rt->children(true), ftl;
piForeach(PIScreenTile * t, vtl) {
if (t->focus_flags[CanHasFocus])
ftl << t;
if (t->focus_flags[CanHasFocus]) ftl << t;
}
int ind = -1;
for (int i = 0; i < ftl.size_s(); ++i)
@@ -504,18 +513,15 @@ bool PIScreen::nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key) {
ind = i;
break;
}
if (ind < 0)
tile_focus = 0;
if (ind < 0) tile_focus = 0;
if (ftl.isEmpty())
tile_focus = 0;
else {
if (tile_focus)
if (!tile_focus->visible)
tile_focus = 0;
if (!tile_focus->visible) tile_focus = 0;
int next = tile_focus ? 0 : 1;
if (tile_focus) {
if (tile_focus->focus_flags[NextByTab] && key.key == PIKbdListener::Tab)
next = 1;
if (tile_focus->focus_flags[NextByTab] && key.key == PIKbdListener::Tab) next = 1;
if (tile_focus->focus_flags[NextByArrowsHorizontal]) {
if (key.key == PIKbdListener::LeftArrow) next = -1;
if (key.key == PIKbdListener::RightArrow) next = 1;
@@ -550,22 +556,19 @@ void PIScreen::tileEventInternal(PIScreenTile * t, TileEvent e) {
void PIScreen::tileRemovedInternal(PIScreenTile * t) {
if (tile_dialog == t)
tile_dialog = 0;
if (tile_dialog == t) tile_dialog = 0;
}
void PIScreen::tileSetFocusInternal(PIScreenTile * t) {
PIScreenTile * rt = rootTile();
if (tile_dialog)
rt = tile_dialog;
if (tile_dialog) rt = tile_dialog;
PIVector<PIScreenTile *> tl = rt->children(), ftl;
piForeach(PIScreenTile * i, tl)
i->has_focus = false;
tile_focus = t;
if (!tile_focus) return;
if (tile_focus->focus_flags[CanHasFocus])
tile_focus->has_focus = true;
if (tile_focus->focus_flags[CanHasFocus]) tile_focus->has_focus = true;
}
@@ -620,8 +623,13 @@ void PIScreen::run() {
tile_dialog->height_ = sh;
tile_dialog->layout();
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,
(Color)tile_dialog->back_format.color_back, (CharFlags)tile_dialog->back_format.flags);
drawer_.drawFrame(dx,
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_);
}
console.print();
@@ -637,8 +645,6 @@ void PIScreen::end() {
PIScreenTile * PIScreen::tileByName(const PIString & name) {
PIVector<PIScreenTile *> tl(tiles());
piForeach(PIScreenTile * t, tl)
if (t->name() == name)
return t;
if (t->name() == name) return t;
return 0;
}

View File

@@ -18,6 +18,7 @@
*/
#include "piscreentiles.h"
#include "piscreendrawer.h"
@@ -57,7 +58,7 @@ void TileSimple::drawEvent(PIScreenDrawer * d) {
}
// TileScrollBar
TileScrollBar::TileScrollBar(const PIString & n) {
direction = Vertical;
@@ -122,7 +123,7 @@ bool TileScrollBar::mouseEvent(PIKbdListener::MouseEvent me) {
}
// TileList
TileList::TileList(const PIString & n, SelectionMode sm): PIScreenTile(n) {
alignment = Left;
@@ -188,9 +189,7 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
lhei = height_ - 2;
int oo(0), osp = piMini(3, lhei / 4);
switch (key.key) {
case PIKbdListener::PageUp:
cur -= lhei / 2;
oo -= lhei / 2;
case PIKbdListener::PageUp: cur -= lhei / 2; oo -= lhei / 2;
case PIKbdListener::UpArrow:
cur--;
oo--;
@@ -207,7 +206,8 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
switch (selection_mode) {
case NoSelection: return false;
case SingleSelection:
if (selected.isEmpty()) selected << cur;
if (selected.isEmpty())
selected << cur;
else {
bool add = !selected[cur];
selected.clear();
@@ -216,8 +216,10 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
raiseEvent(TileEvent(SelectionChanged));
return true;
case MultiSelection:
if (selected[cur]) selected.remove(cur);
else selected << cur;
if (selected[cur])
selected.remove(cur);
else
selected << cur;
raiseEvent(TileEvent(SelectionChanged));
break;
}
@@ -238,17 +240,14 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
if (offset >= content.size_s() - lhei) offset = content.size_s() - lhei;
if (offset < 0) offset = 0;
return true;
case PIKbdListener::Home:
cur = offset = 0;
return true;
case PIKbdListener::Home: cur = offset = 0; return true;
case PIKbdListener::End:
cur = content.size_s() - 1;
offset = content.size_s() - lhei;
if (offset < 0) offset = 0;
return true;
case PIKbdListener::Return:
if (cur >= 0 && cur < content.size_s())
raiseEvent(TileEvent(RowPressed, cur));
if (cur >= 0 && cur < content.size_s()) raiseEvent(TileEvent(RowPressed, cur));
return true;
case '*':
if (selection_mode == TileList::MultiSelection) {
@@ -278,12 +277,8 @@ bool TileList::mouseEvent(PIKbdListener::MouseEvent me) {
if (mp < 0 || mp >= content.size_s()) return true;
cur = mp;
switch (me.action) {
case PIKbdListener::MouseButtonPress:
mouse_sel = !selected.contains(cur);
break;
case PIKbdListener::MouseButtonDblClick:
keyEvent(PIKbdListener::KeyEvent(PIKbdListener::Return));
return true;
case PIKbdListener::MouseButtonPress: mouse_sel = !selected.contains(cur); break;
case PIKbdListener::MouseButtonDblClick: keyEvent(PIKbdListener::KeyEvent(PIKbdListener::Return)); return true;
default: break;
}
if (me.buttons[PIKbdListener::MouseRight]) {
@@ -294,8 +289,10 @@ bool TileList::mouseEvent(PIKbdListener::MouseEvent me) {
raiseEvent(TileEvent(SelectionChanged));
break;
case MultiSelection:
if (mouse_sel) selected << cur;
else selected.remove(cur);
if (mouse_sel)
selected << cur;
else
selected.remove(cur);
raiseEvent(TileEvent(SelectionChanged));
break;
default: break;
@@ -311,7 +308,7 @@ bool TileList::wheelEvent(PIKbdListener::WheelEvent we) {
}
// TileButton
TileButton::TileButton(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab | NextByArrowsAll | FocusOnMouse;
@@ -351,7 +348,7 @@ bool TileButton::mouseEvent(PIKbdListener::MouseEvent me) {
}
// TileButtons
TileButtons::TileButtons(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab | FocusOnMouse;
@@ -387,8 +384,7 @@ void TileButtons::drawEvent(PIScreenDrawer * d) {
case PIScreenTypes::Right: dx = width_ - shw; break;
default: break;
}
if (direction == PIScreenTypes::Horizontal)
cx += dx;
if (direction == PIScreenTypes::Horizontal) cx += dx;
for (int i = 0; i < content.size_s(); ++i) {
Color cb = Cyan;
Color ct = Black;
@@ -430,9 +426,7 @@ bool TileButtons::keyEvent(PIKbdListener::KeyEvent key) {
if (cur >= content.size_s()) cur = content.size_s() - 1;
return true;
case PIKbdListener::Space:
case PIKbdListener::Return:
raiseEvent(TileEvent(ButtonSelected, cur));
return true;
case PIKbdListener::Return: raiseEvent(TileEvent(ButtonSelected, cur)); return true;
};
return PIScreenTile::keyEvent(key);
}
@@ -441,8 +435,7 @@ bool TileButtons::keyEvent(PIKbdListener::KeyEvent key) {
bool TileButtons::mouseEvent(PIKbdListener::MouseEvent me) {
if (me.action == PIKbdListener::MouseMove || me.action == PIKbdListener::MouseButtonPress) {
for (int i = 0; i < btn_rects.size_s(); ++i)
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) {
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) {
cur = i;
break;
}
@@ -454,7 +447,7 @@ bool TileButtons::mouseEvent(PIKbdListener::MouseEvent me) {
}
// TileCheck
TileCheck::TileCheck(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab | NextByArrowsAll | FocusOnMouse;
@@ -499,7 +492,7 @@ bool TileCheck::mouseEvent(PIKbdListener::MouseEvent me) {
}
// TileProgress
TileProgress::TileProgress(const PIString & n): PIScreenTile(n) {
maximum = 100.;
@@ -532,7 +525,7 @@ void TileProgress::drawEvent(PIScreenDrawer * d) {
}
// TilePICout
TilePICout::TilePICout(const PIString & n): TileList(n) {
max_lines = 1024;
@@ -548,8 +541,7 @@ void TilePICout::drawEvent(PIScreenDrawer * d) {
bool scroll = (cur == content.size_s() - 1) || !has_focus;
piForeachC(PIString & s, l)
content << TileList::Row(s.trimmed(), format);
if (content.size_s() > max_lines)
content.remove(0, content.size_s() - max_lines);
if (content.size_s() > max_lines) content.remove(0, content.size_s() - max_lines);
if (scroll) {
offset = piMaxi(0, content.size_s() - lhei);
cur = content.size_s() - 1;
@@ -569,7 +561,7 @@ bool TilePICout::keyEvent(PIKbdListener::KeyEvent key) {
}
// TileInput
TileInput::TileInput(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab | FocusOnMouse;
@@ -591,10 +583,8 @@ void TileInput::sizeHint(int & w, int & h) const {
void TileInput::drawEvent(PIScreenDrawer * d) {
PIString ps = text.mid(offset, width_ - 2);
d->drawText(x_ + 1, y_, ps, (Color)format.color_char, Transparent, (CharFlags)format.flags);
if (offset > 0)
d->drawText(x_, y_, "<", Green, Black, Bold);
if (text.size_s() - offset >= width_ - 2)
d->drawText(x_ + width_ - 1, y_, ">", Green, Black, Bold);
if (offset > 0) d->drawText(x_, y_, "<", Green, Black, Bold);
if (text.size_s() - offset >= width_ - 2) d->drawText(x_ + width_ - 1, y_, ">", Green, Black, Bold);
if (!has_focus) return;
Color cb = (Color)format.color_char, cc = (Color)format.color_back;
if (tm_blink.elapsed_m() >= 650) {
@@ -647,8 +637,7 @@ bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
reserCursor();
return true;
case PIKbdListener::Backspace:
if (cur > text.size_s() || text.isEmpty())
return true;
if (cur > text.size_s() || text.isEmpty()) return true;
text.remove(cur - 1, 1);
cur--;
if (cur > text.size_s()) cur = text.size_s();
@@ -658,8 +647,7 @@ bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
reserCursor();
return true;
case PIKbdListener::Delete:
if (cur >= text.size_s() || text.isEmpty())
return true;
if (cur >= text.size_s() || text.isEmpty()) return true;
text.remove(cur, 1);
if (cur < 0) cur = 0;
if (cur > text.size_s()) cur = text.size_s();
@@ -685,8 +673,7 @@ bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
case PIKbdListener::F9:
case PIKbdListener::F10:
case PIKbdListener::F11:
case PIKbdListener::F12:
break;
case PIKbdListener::F12: break;
default:
text.insert(cur, PIChar((ushort)key.key));
cur++;

View File

@@ -45,6 +45,7 @@ public:
static PIIntrospectionContainersType ret = create();
return ret;
}
private:
static PIIntrospectionContainersType create() {
PIIntrospectionContainersType ret;
@@ -56,33 +57,37 @@ private:
# define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())
// clang-format off
# define PIINTROSPECTION_CONTAINER_NEW (t, isz) PIINTROSPECTION_CONTAINERS->containerNew (PIIntrospectionContainersTypeInfo<t>::get(), isz);
# define PIINTROSPECTION_CONTAINER_DELETE(t ) PIINTROSPECTION_CONTAINERS->containerDelete(PIIntrospectionContainersTypeInfo<t>::get() );
# define PIINTROSPECTION_CONTAINER_ALLOC (t, cnt) PIINTROSPECTION_CONTAINERS->containerAlloc (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
# define PIINTROSPECTION_CONTAINER_FREE (t, cnt) PIINTROSPECTION_CONTAINERS->containerFree (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 {
friend class PIIntrospection;
friend class PIIntrospectionServer;
public:
__PIINTROSPECTION_SINGLETON_H__(Containers)
// clang-format off
void containerNew (const PIIntrospectionContainersType & ti, uint isz);
void containerDelete(const PIIntrospectionContainersType & ti);
void containerAlloc (const PIIntrospectionContainersType & ti, ullong cnt);
void containerFree (const PIIntrospectionContainersType & ti, ullong cnt);
void containerUsed (const PIIntrospectionContainersType & ti, ullong cnt);
void containerUnused(const PIIntrospectionContainersType & ti, ullong cnt);
// clang-format on
PIIntrospectionContainers * p;
private:
PIIntrospectionContainersInterface();
~PIIntrospectionContainersInterface();
};
@@ -96,5 +101,4 @@ private:
#endif
#endif // PIINTROSPECTION_CONTAINERS_H

View File

@@ -20,10 +20,12 @@
#ifndef PIINTROSPECTION_CONTAINERS_P_H
#define PIINTROSPECTION_CONTAINERS_P_H
#include "piintrospection_containers.h"
#include "pispinlock.h"
#include "pistring.h"
#include <map>
#include <string>
#include "picrc.h"
class PIP_EXPORT PIIntrospectionContainers {
@@ -32,12 +34,14 @@ public:
struct TypeInfo;
// clang-format off
void containerNew (const PIIntrospectionContainersType & ti, uint isz);
void containerDelete(const PIIntrospectionContainersType & ti);
void containerAlloc (const PIIntrospectionContainersType & ti, ullong cnt);
void containerFree (const PIIntrospectionContainersType & ti, ullong cnt);
void containerUsed (const PIIntrospectionContainersType & ti, ullong cnt);
void containerUnused(const PIIntrospectionContainersType & ti, ullong cnt);
// clang-format on
PIVector<TypeInfo> getInfo() const;

View File

@@ -28,6 +28,7 @@ class PIIntrospectionThreads;
# define PIINTROSPECTION_THREADS (PIIntrospectionThreadsInterface::instance())
// clang-format off
# define PIINTROSPECTION_THREAD_NEW (t ) PIINTROSPECTION_THREADS->threadNew (t );
# define PIINTROSPECTION_THREAD_DELETE (t ) PIINTROSPECTION_THREADS->threadDelete (t );
# define PIINTROSPECTION_THREAD_START (t ) PIINTROSPECTION_THREADS->threadStart (t );
@@ -35,12 +36,15 @@ class PIIntrospectionThreads;
# define PIINTROSPECTION_THREAD_WAIT (t ) PIINTROSPECTION_THREADS->threadWait (t );
# 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 {
friend class PIIntrospection;
public:
__PIINTROSPECTION_SINGLETON_H__(Threads)
// clang-format off
void threadNew (PIThread * t);
void threadDelete (PIThread * t);
void threadStart (PIThread * t);
@@ -48,13 +52,13 @@ public:
void threadWait (PIThread * t);
void threadStop (PIThread * t);
void threadRunDone(PIThread * t, ullong us);
// clang-format on
private:
PIIntrospectionThreadsInterface();
~PIIntrospectionThreadsInterface();
PIIntrospectionThreads * p;
};
#else

View File

@@ -44,6 +44,7 @@ public:
ullong run_us, run_count;
};
// clang-format off
void threadNew (PIThread * t);
void threadDelete (PIThread * t);
void threadStart (PIThread * t);
@@ -51,10 +52,10 @@ public:
void threadWait (PIThread * t);
void threadStop (PIThread * t);
void threadRunDone(PIThread * t, ullong us);
// clang-format on
PIMap<PIThread *, ThreadInfo> threads;
PIMutex mutex;
};

View File

@@ -29,6 +29,7 @@
#include "piiodevice.h"
#include "piiostream.h"
// clang-format off
#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 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 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);}
// clang-format on
class PIP_EXPORT PIConfig
{
class PIP_EXPORT PIConfig {
friend class Entry;
friend class Branch;
public:
public:
//! Contructs and read configuration file at path "path" in mode "mode"
PIConfig(const PIString & path, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
@@ -83,11 +84,14 @@ public:
friend std::ostream & operator<<(std::ostream & s, const Branch & v);
#endif
friend PICout operator<<(PICout s, const Branch & v);
public:
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) 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
Branch allLeaves();
@@ -95,28 +99,52 @@ public:
Branch getLeaves();
Branch getBranches();
Branch & filter(const PIString & f);
bool isEntryExists(const PIString & name) const {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;}
bool isEntryExists(const PIString & name) const {
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:
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
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
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;
PIString delim;
};
class PIP_EXPORT Entry {
friend class PIConfig;
friend class Branch;
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)
Entry * parent() const { return _parent; }
@@ -125,16 +153,27 @@ public:
int childCount() const { return _children.size_s(); }
//! 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"
Entry * child(const int index) const { return _children[index]; }
//! 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"
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
bool isLeaf() const { return _children.isEmpty(); }
@@ -158,62 +197,128 @@ public:
const PIString & fullName() const { return _full_name; }
//! 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
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
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
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"
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"
* \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 */
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
//! \fn Entry & getValue(const PIString & vname, const char * def, bool * exists = 0)
@@ -307,12 +412,22 @@ public:
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;
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
void coutt(std::ostream & s, const PIString & p) const;
#endif
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;
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
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
@@ -390,43 +507,56 @@ public:
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);
//! 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
//! 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
//! 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
//! 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
//! 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
//! 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
//! 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
//! 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
//! 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
//! 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
//! 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
//! 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
//! no suitable exists
void setValue(const PIString & name, const double value, bool write = true) { setValue(name, PIString::fromNumber(value), "f", write); }
//! Returns root entry
@@ -439,10 +569,22 @@ public:
bool isEntryExists(const PIString & name) const { return entryExists(&root, name); }
//! 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
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);
@@ -473,7 +615,11 @@ public:
const PIString & delimiter() const { return delim; }
//! 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:
PIConfig(const PIString & path, PIStringList dirs);
@@ -486,14 +632,45 @@ private:
void _seekToBeginDev();
PIString _readLineDev();
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;
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 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 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 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 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);
void updateIncludes();
PIString parseLine(PIString v);
@@ -509,7 +686,6 @@ private:
Entry root, empty;
uint lines = 0;
PIStringList other;
};
@@ -518,7 +694,12 @@ PIP_EXPORT std::ostream & operator <<(std::ostream & s, const PIConfig::Branch &
PIP_EXPORT std::ostream & operator<<(std::ostream & s, const PIConfig::Entry & v);
#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) {
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() << ")";
return s;

View File

@@ -26,19 +26,18 @@
#ifndef PISERIAL_H
#define PISERIAL_H
#include "pitimer.h"
#include "piiodevice.h"
#include "pitimer.h"
//! \ingroup IO
//! \~\brief
//! \~english Serial device.
//! \~russian Последовательный порт.
class PIP_EXPORT PISerial: public PIIODevice
{
class PIP_EXPORT PISerial: public PIIODevice {
PIIODEVICE(PISerial, "ser");
public:
public:
//! \~english Contructs an empty %PISerial
//! \~russian Создает пустой %PISerial
explicit PISerial();
@@ -113,7 +112,6 @@ public:
//! \~english Device manufacturer
//! \~russian Описание производителя
PIString manufacturer;
};
//! \~english Contructs %PISerial with device name "device", speed "speed" and parameters "params"
@@ -123,24 +121,43 @@ public:
//! \~english Set both input and output speed to "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"
//! \~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"
//! \~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"
//! \~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_"
//! \~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
//! \~russian Устанавливает параметр "parameter" в "on"
@@ -157,7 +174,10 @@ public:
//! \~english Set data bits count. Valid range is from 5 to 8, befault is 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
//! \~russian Возвращает количество бит данных
@@ -196,7 +216,10 @@ public:
//! \~russian Переключает состояние передачи в break
bool setBreak(bool enabled);
void setVTime(int t) {vtime = t; applySettings();}
void setVTime(int t) {
vtime = t;
applySettings();
}
//! \~english Returns device name
//! \~russian Возвращает имя устройства
@@ -313,7 +336,6 @@ protected:
int fd = -1, vtime = 10;
std::atomic_bool sending;
PITimeMeasurer tm_;
};
@@ -327,22 +349,32 @@ inline PICout operator <<(PICout s, const PISerial::DeviceInfo & v) {
//! \~english Compare operator
//! \~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
//! \~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
//! \~english Store operator.
//! \~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
//! \~english Restore operator.
//! \~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

View File

@@ -27,8 +27,8 @@
#define PIMATHBASE_H
#include "piinit.h"
#include "pivector.h"
#include "pipair.h"
#include "pivector.h"
#ifdef QNX
# undef PIP_MATH_J0
# undef PIP_MATH_J1
@@ -94,10 +94,10 @@
#endif
const double deg2rad = M_PI_180;
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 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);}
@@ -106,8 +106,13 @@ inline int pow2(const int p) {return 1 << p;}
inline float pow10(const int & e) {return powf(10.f, e);}
inline double pow10(const double & e) {return pow (10. , 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 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 piYn(int n, const double & v);
// clang-format off
inline constexpr float toRad(float 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 float toDeg(float 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;}
template <typename T> 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.));}
// clang-format on
template<typename T>
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]
PIP_EXPORT double randomd();
// [-1 ; 1] normal
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;
result.resize(v.size());
for (uint i = 0; i < v.size(); i++)
@@ -143,8 +160,7 @@ template<typename T> inline PIVector<T> piAbs(const PIVector<T> & v) {
template<typename T>
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");
if (input.size_s() < 2)
return false;
if (input.size_s() < 2) return false;
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();
for (int i = 0; i < n; ++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_t4 = n * a_t3 - a_t1 * a_t1;
if (a_t4 != T())
a = (n * a_t0 - a_t1 * a_t2) / a_t4;
if (a_t4 != T()) a = (n * a_t0 - a_t1 * a_t2) / a_t4;
b = (a_t2 - a * a_t1) / n;
if (out_a != 0) *out_a = a;
if (out_b != 0) *out_b = b;
@@ -167,10 +182,8 @@ bool OLS_Linear(const PIVector<PIPair<T, T> > & input, T * out_a, T * out_b) {
template<typename T>
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");
if (input.size_s() < 2)
return false;
if (input.size_s() != weights.size_s())
return false;
if (input.size_s() < 2) return false;
if (input.size_s() != weights.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();
for (int i = 0; i < n; ++i) {
@@ -183,8 +196,7 @@ bool WLS_Linear(const PIVector<PIPair<T, T> > & input, const PIVector<T> & weigh
a_n += cp;
}
a_t4 = a_n * a_t3 - a_t1 * a_t1;
if (a_t4 != T())
a = (a_n * a_t0 - a_t1 * a_t2) / a_t4;
if (a_t4 != T()) a = (a_n * a_t0 - a_t1 * a_t2) / a_t4;
b = (a_t2 - a * a_t1) / a_n;
if (out_a != 0) *out_a = a;
if (out_b != 0) *out_b = b;

View File

@@ -28,10 +28,10 @@
#include "pimathmatrix.h"
class PIP_EXPORT PIQuaternion
{
friend PIQuaternion operator*(const PIQuaternion & q0, const PIQuaternion & q1);
friend PIQuaternion operator*(const double & a, const PIQuaternion & q);
class PIP_EXPORT PIQuaternion {
friend PIP_EXPORT PIQuaternion operator*(const PIQuaternion & q0, const PIQuaternion & q1);
friend PIP_EXPORT PIQuaternion operator*(const double & a, const PIQuaternion & q);
public:
PIQuaternion(const PIMathVectorT3d & u = PIMathVectorT3d(), double a = 0.);
@@ -59,8 +59,14 @@ protected:
PIP_EXPORT PIQuaternion operator*(const double & a, const PIQuaternion & q);
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) {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, 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

View File

@@ -51,6 +51,6 @@ namespace PIValueTreeConversions {
PIP_EXPORT PIJSON toJSON(const PIValueTree & root, Options options = Default);
PIP_EXPORT PIString toText(const PIValueTree & root, Options options = Default);
}
} // namespace PIValueTreeConversions
#endif

View File

@@ -36,10 +36,10 @@ extern PIP_EXPORT char * __utf8name__;
//! \~\brief
//! \~english %PIChar represents a single character.
//! \~russian %PIChar представляет собой один символ строки.
class PIP_EXPORT PIChar
{
class PIP_EXPORT PIChar {
friend class PIString;
friend PICout operator <<(PICout s, const PIChar & v);
friend PIP_EXPORT PICout operator<<(PICout s, const PIChar & v);
public:
//! \~english Contructs Ascii symbol
//! \~russian Создает символ Ascii
@@ -63,11 +63,17 @@ public:
//! \~english Copy operator
//! \~russian Оператор присваивания
PIChar & operator =(const char v) {ch = v; return *this;}
PIChar & operator=(const char v) {
ch = v;
return *this;
}
//! \~english Copy operator
//! \~russian Оператор присваивания
PIChar & operator =(const wchar_t v) {ch = v; return *this;}
PIChar & operator=(const wchar_t v) {
ch = v;
return *this;
}
//! \~english Compare operator
//! \~russian Оператор сравнения
@@ -177,7 +183,6 @@ public:
private:
ushort ch;
};
//! \relatesalso PIChar
@@ -188,78 +193,108 @@ PIP_EXPORT PICout operator <<(PICout s, const PIChar & v);
//! \relatesalso PIChar
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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
//! \~english Compare operator
//! \~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

View File

@@ -21,6 +21,7 @@
#define PITHREADPOOLEXECUTOR_H
#include "piblockingqueue.h"
#include <atomic>
@@ -30,22 +31,18 @@ public:
virtual ~PIThreadPoolExecutor();
/**
* \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
* reached.
*
* @param runnable not empty function for thread pool execution
*/
//! \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
//! reached.
//!
//! \param runnable not empty function for thread pool execution
void execute(const std::function<void()> & runnable);
void shutdownNow();
/**
* \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
* submitted tasks to complete execution. Use awaitTermination to do that.
*/
//! \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
//! submitted tasks to complete execution. Use awaitTermination to do that.
void shutdown();
bool isShutdown() const;

View File

@@ -35,6 +35,7 @@ class PITimer;
class PIP_EXPORT _PITimerBase {
friend class PITimer;
public:
_PITimerBase();
virtual ~_PITimerBase() {}
@@ -60,7 +61,6 @@ public:
PITimer * parent;
protected:
virtual bool startTimer(double interval_ms) = 0;
virtual bool stopTimer() = 0;
@@ -71,10 +71,9 @@ protected:
};
class PIP_EXPORT PITimer: public PIObject {
PIOBJECT_SUBCLASS(PITimer, PIObject);
public:
NO_COPY_CLASS(PITimer);
@@ -88,17 +87,20 @@ public:
Thread /*!
\~english Timer works in his own thread. Intervals are measured by the system time
\~russian Таймер работает в собственном потоке. Интервалы измеряются с помощью системного времени
*/ = 0x01,
*/
= 0x01,
ThreadRT /*!
\~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!
*/ = 0x02,
*/
= 0x02,
Pool /*!
\~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!
\~russian Использовать единый TimerPool для всех таймеров с этой реализацией. TimerPool реализован через Thread и
последовательно исполняет все таймеры. \attention Осторожнее с этой реализацией!
*/ = 0x04
*/
= 0x04
};
//! \~english Constructs timer with "ti" implementation
@@ -176,11 +178,15 @@ public:
//! \~english Set timer tick function
//! \~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
//! \~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; }
EVENT_HANDLER0(void, lock) { mutex_.lock(); }
@@ -200,15 +206,25 @@ public:
//! \~english Add frequency delimiter "delim" with optional delimiter slot "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"
//! \~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"
//! \~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)
if (delims[i].delim == delim) {
delims.remove(i);
i--;
}
}
EVENT_HANDLER0(void, clearDelimiters) { delims.clear(); }
@@ -282,7 +298,11 @@ public:
protected:
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;
int delim;
int tick;