pivariant, enum, tiny format
This commit is contained in:
@@ -16,13 +16,14 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "piincludes_p.h"
|
||||
#include "pikbdlistener.h"
|
||||
|
||||
#include "piincludes_p.h"
|
||||
#ifndef WINDOWS
|
||||
# include <termios.h>
|
||||
#else
|
||||
# include <wingdi.h>
|
||||
# include <wincon.h>
|
||||
# include <wingdi.h>
|
||||
#endif
|
||||
|
||||
/** \class PIKbdListener
|
||||
@@ -119,8 +120,10 @@ const PIKbdListener::EscSeq PIKbdListener::esc_seq[] = {
|
||||
{0, 0, 0, 0, 0},
|
||||
};
|
||||
void setupTerminal(bool on) {
|
||||
printf("\e[?1000"); printf(on ? "h" : "l");
|
||||
printf("\e[?1002"); printf(on ? "h" : "l");
|
||||
printf("\e[?1000");
|
||||
printf(on ? "h" : "l");
|
||||
printf("\e[?1002");
|
||||
printf(on ? "h" : "l");
|
||||
fflush(0);
|
||||
}
|
||||
#endif
|
||||
@@ -224,33 +227,111 @@ void PIKbdListener::readKeyboard() {
|
||||
ke.modifiers = getModifiers(ker.dwControlKeyState, &shift);
|
||||
// piCout << "key" << int(ker.wVirtualKeyCode) << int(ker.uChar.AsciiChar);
|
||||
switch (ker.wVirtualKeyCode) {
|
||||
case 8: PRIVATE->ret = 1; ke.key = Backspace; break;
|
||||
case 33: PRIVATE->ret = 1; ke.key = PageUp; break;
|
||||
case 34: PRIVATE->ret = 1; ke.key = PageDown; break;
|
||||
case 35: PRIVATE->ret = 1; ke.key = End; break;
|
||||
case 36: PRIVATE->ret = 1; ke.key = Home; break;
|
||||
case 37: PRIVATE->ret = 1; ke.key = LeftArrow; break;
|
||||
case 38: PRIVATE->ret = 1; ke.key = UpArrow; break;
|
||||
case 39: PRIVATE->ret = 1; ke.key = RightArrow; break;
|
||||
case 40: PRIVATE->ret = 1; ke.key = DownArrow; break;
|
||||
case 45: PRIVATE->ret = 1; ke.key = Insert; break;
|
||||
case 46: PRIVATE->ret = 1; ke.key = Delete; break;
|
||||
case 8:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = Backspace;
|
||||
break;
|
||||
case 33:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = PageUp;
|
||||
break;
|
||||
case 34:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = PageDown;
|
||||
break;
|
||||
case 35:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = End;
|
||||
break;
|
||||
case 36:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = Home;
|
||||
break;
|
||||
case 37:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = LeftArrow;
|
||||
break;
|
||||
case 38:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = UpArrow;
|
||||
break;
|
||||
case 39:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = RightArrow;
|
||||
break;
|
||||
case 40:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = DownArrow;
|
||||
break;
|
||||
case 45:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = Insert;
|
||||
break;
|
||||
case 46:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = Delete;
|
||||
break;
|
||||
case '\r':
|
||||
case '\n': PRIVATE->ret = 1; ke.key = Return; break;
|
||||
case ' ': PRIVATE->ret = 1; ke.key = Space; break;
|
||||
case '\t': PRIVATE->ret = 1; ke.key = Tab; break;
|
||||
case 112: PRIVATE->ret = 1; ke.key = F1; break;
|
||||
case 113: PRIVATE->ret = 1; ke.key = F2; break;
|
||||
case 114: PRIVATE->ret = 1; ke.key = F3; break;
|
||||
case 115: PRIVATE->ret = 1; ke.key = F4; break;
|
||||
case 116: PRIVATE->ret = 1; ke.key = F5; break;
|
||||
case 117: PRIVATE->ret = 1; ke.key = F6; break;
|
||||
case 118: PRIVATE->ret = 1; ke.key = F7; break;
|
||||
case 119: PRIVATE->ret = 1; ke.key = F8; break;
|
||||
case 120: PRIVATE->ret = 1; ke.key = F9; break;
|
||||
case 121: PRIVATE->ret = 1; ke.key = F10; break;
|
||||
case 122: PRIVATE->ret = 1; ke.key = F11; break;
|
||||
case 123: PRIVATE->ret = 1; ke.key = F12; break;
|
||||
case '\n':
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = Return;
|
||||
break;
|
||||
case ' ':
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = Space;
|
||||
break;
|
||||
case '\t':
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = Tab;
|
||||
break;
|
||||
case 112:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F1;
|
||||
break;
|
||||
case 113:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F2;
|
||||
break;
|
||||
case 114:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F3;
|
||||
break;
|
||||
case 115:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F4;
|
||||
break;
|
||||
case 116:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F5;
|
||||
break;
|
||||
case 117:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F6;
|
||||
break;
|
||||
case 118:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F7;
|
||||
break;
|
||||
case 119:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F8;
|
||||
break;
|
||||
case 120:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F9;
|
||||
break;
|
||||
case 121:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F10;
|
||||
break;
|
||||
case 122:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F11;
|
||||
break;
|
||||
case 123:
|
||||
PRIVATE->ret = 1;
|
||||
ke.key = F12;
|
||||
break;
|
||||
default:
|
||||
PRIVATE->ret = 1;
|
||||
rc[0] = 1;
|
||||
@@ -261,10 +342,15 @@ void PIKbdListener::readKeyboard() {
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ke.key == 0) {piMSleep(10); return;}
|
||||
} else {piMSleep(10); return;}
|
||||
if (ke.key == 0) {
|
||||
piMSleep(10);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
piMSleep(10);
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
case MOUSE_EVENT: {
|
||||
MOUSE_EVENT_RECORD mer = ir.Event.MouseEvent;
|
||||
GetConsoleScreenBufferInfo(PRIVATE->hOut, &PRIVATE->sbi);
|
||||
@@ -297,24 +383,23 @@ void PIKbdListener::readKeyboard() {
|
||||
prev_p_me = me;
|
||||
}
|
||||
tm_dbl.reset();
|
||||
} else if (mb < me.buttons)
|
||||
me.action = MouseButtonRelease;
|
||||
else {
|
||||
if (mb != 0) piCoutObj << "WTF";
|
||||
break;
|
||||
}
|
||||
else if (mb < me.buttons) me.action = MouseButtonRelease;
|
||||
else {if (mb != 0) piCoutObj << "WTF"; break;}
|
||||
}
|
||||
me.buttons = mb;
|
||||
if (piCompareBinary(&prev_me, &me, sizeof(me)))
|
||||
break;
|
||||
if (piCompareBinary(&prev_me, &me, sizeof(me))) break;
|
||||
memcpy((void *)(&prev_me), (const void *)(&me), sizeof(me));
|
||||
// PIString _s[] = {"press", "release", "dbl click", "move"};
|
||||
// piCoutObj << _s[me.action] << me.buttons << ":" << me.x << me.y;
|
||||
mouseEvent(me, kbddata_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
piMSleep(10);
|
||||
return;
|
||||
} break;
|
||||
default: piMSleep(10); return;
|
||||
}
|
||||
#else
|
||||
tcsetattr(0, TCSANOW, &PRIVATE->tterm);
|
||||
@@ -327,8 +412,14 @@ void PIKbdListener::readKeyboard() {
|
||||
for (int i = 0; i < PRIVATE->ret; ++i)
|
||||
std::cout << "'" << (char)(rc[i]) << "' " << (int)(uchar)(rc[i]);
|
||||
std::cout << std::endl;*/
|
||||
if (rc[0] == 0) {piMSleep(10); return;}
|
||||
if (PRIVATE->ret < 0 || PRIVATE->ret > 7) {piMSleep(10); return;}
|
||||
if (rc[0] == 0) {
|
||||
piMSleep(10);
|
||||
return;
|
||||
}
|
||||
if (PRIVATE->ret < 0 || PRIVATE->ret > 7) {
|
||||
piMSleep(10);
|
||||
return;
|
||||
}
|
||||
if (PRIVATE->ret == 1) {
|
||||
if (rc[0] == 8)
|
||||
ke.key = Backspace;
|
||||
@@ -347,7 +438,8 @@ void PIKbdListener::readKeyboard() {
|
||||
ke.key = PIChar::fromConsole(rc[1]).unicode16Code();
|
||||
} else { // escape-seq
|
||||
if (rc[1] == '\e') { // search for Alt
|
||||
for (int i = 1; i < 7; ++i) rc[i] = rc[i + 1];
|
||||
for (int i = 1; i < 7; ++i)
|
||||
rc[i] = rc[i + 1];
|
||||
mod = 2;
|
||||
PRIVATE->ret--;
|
||||
}
|
||||
@@ -396,7 +488,8 @@ void PIKbdListener::readKeyboard() {
|
||||
for (int i = 2; i < 7; ++i) // search for modifier
|
||||
if (rc[i] == ';') {
|
||||
mod |= rc[i + 1] - '0' - 1;
|
||||
for (int j = i; j < 6; ++j) rc[j] = rc[j + 2];
|
||||
for (int j = i; j < 6; ++j)
|
||||
rc[j] = rc[j + 2];
|
||||
rc[6] = rc[7] = 0;
|
||||
PRIVATE->ret -= 2;
|
||||
break;
|
||||
@@ -406,7 +499,8 @@ void PIKbdListener::readKeyboard() {
|
||||
if (PRIVATE->ret >= 3 && rc[1] == 'O') { // search for modifier (F1-F4)
|
||||
if (rc[2] >= '1' && rc[2] <= '8') {
|
||||
mod |= rc[2] - '0' - 1;
|
||||
for (int j = 2; j < 6; ++j) rc[j] = rc[j + 1];
|
||||
for (int j = 2; j < 6; ++j)
|
||||
rc[j] = rc[j + 1];
|
||||
rc[7] = 0;
|
||||
PRIVATE->ret--;
|
||||
}
|
||||
@@ -432,11 +526,9 @@ void PIKbdListener::readKeyboard() {
|
||||
cout << "'" << (char)(rc[i]) << "' ";
|
||||
cout << endl;*/
|
||||
}
|
||||
if (ke.key == 0 && PRIVATE->ret > 1)
|
||||
ke.key = PIChar(rc).unicode16Code();
|
||||
if (ke.key == 0 && PRIVATE->ret > 1) ke.key = PIChar(rc).unicode16Code();
|
||||
#endif
|
||||
if ((rc[0] == '\n' || rc[0] == '\r') && PRIVATE->ret == 1)
|
||||
ke.key = Return;
|
||||
if ((rc[0] == '\n' || rc[0] == '\r') && PRIVATE->ret == 1) ke.key = Return;
|
||||
if (exit_enabled && ke.key == exit_key) {
|
||||
PIKbdListener::exiting = true;
|
||||
return;
|
||||
|
||||
@@ -27,17 +27,19 @@
|
||||
#define PIKBDLISTENER_H
|
||||
|
||||
#include "pithread.h"
|
||||
#include "pitime.h"
|
||||
|
||||
#define WAIT_FOR_EXIT while (!PIKbdListener::exiting) piMSleep(PIP_MIN_MSLEEP*5); // TODO: rewrite with condvar
|
||||
#define WAIT_FOR_EXIT \
|
||||
while (!PIKbdListener::exiting) \
|
||||
piMSleep(PIP_MIN_MSLEEP * 5); // TODO: rewrite with condvar
|
||||
|
||||
|
||||
class PIP_EXPORT PIKbdListener: public PIThread
|
||||
{
|
||||
class PIP_EXPORT PIKbdListener: public PIThread {
|
||||
PIOBJECT_SUBCLASS(PIKbdListener, PIThread);
|
||||
friend class PIConsole;
|
||||
friend class PITerminal;
|
||||
public:
|
||||
|
||||
public:
|
||||
//! Special keyboard keys
|
||||
enum SpecialKey {
|
||||
Tab /** Tab key */ = 0x09,
|
||||
@@ -81,7 +83,10 @@ public:
|
||||
|
||||
//! This struct contains information about pressed keyboard key
|
||||
struct PIP_EXPORT KeyEvent {
|
||||
KeyEvent(int k = 0, KeyModifiers m = 0) {key = k; modifiers = m;}
|
||||
KeyEvent(int k = 0, KeyModifiers m = 0) {
|
||||
key = k;
|
||||
modifiers = m;
|
||||
}
|
||||
|
||||
//! Pressed key. It can be simple \b char or special key (see PIKbdListener::SpecialKey)
|
||||
int key;
|
||||
@@ -110,7 +115,12 @@ public:
|
||||
|
||||
//! This struct contains information about mouse action
|
||||
struct PIP_EXPORT MouseEvent {
|
||||
MouseEvent(MouseAction a = MouseButtonPress, MouseButtons b = 0, KeyModifiers m = 0) {x = y = 0; action = a; buttons = b; modifiers = m;}
|
||||
MouseEvent(MouseAction a = MouseButtonPress, MouseButtons b = 0, KeyModifiers m = 0) {
|
||||
x = y = 0;
|
||||
action = a;
|
||||
buttons = b;
|
||||
modifiers = m;
|
||||
}
|
||||
|
||||
//! Event X coordinate in view-space, from 0
|
||||
int x;
|
||||
@@ -154,7 +164,9 @@ public:
|
||||
void setSlot(KBFunc slot) { ret_func = slot; }
|
||||
|
||||
//! Set external function to "slot"
|
||||
void setSlot(std::function<void(KeyEvent)> slot) {ret_func = [slot](KeyEvent e, void *){slot(e);};}
|
||||
void setSlot(std::function<void(KeyEvent)> slot) {
|
||||
ret_func = [slot](KeyEvent e, void *) { slot(e); };
|
||||
}
|
||||
|
||||
//! Returns if exit key if awaiting
|
||||
bool exitCaptured() const { return exit_enabled; }
|
||||
@@ -171,7 +183,10 @@ public:
|
||||
bool isActive() { return is_active; }
|
||||
|
||||
EVENT_HANDLER(void, enableExitCapture) { enableExitCapture('Q'); }
|
||||
EVENT_HANDLER1(void, enableExitCapture, int, key) {exit_enabled = true; exit_key = key;}
|
||||
EVENT_HANDLER1(void, enableExitCapture, int, key) {
|
||||
exit_enabled = true;
|
||||
exit_key = key;
|
||||
}
|
||||
EVENT_HANDLER(void, disableExitCapture) { exit_enabled = false; }
|
||||
EVENT_HANDLER(void, setActive) { setActive(true); }
|
||||
EVENT_HANDLER1(void, setActive, bool, yes);
|
||||
@@ -243,30 +258,41 @@ private:
|
||||
MouseEvent me, prev_me, prev_p_me;
|
||||
WheelEvent we;
|
||||
static PIKbdListener * _object;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//! \relatesalso PIBinaryStream
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
BINARY_STREAM_WRITE(PIKbdListener::MouseEvent) {s << v.x << v.y << v.action << v.buttons << v.modifiers; return s;}
|
||||
BINARY_STREAM_WRITE(PIKbdListener::MouseEvent) {
|
||||
s << v.x << v.y << v.action << v.buttons << v.modifiers;
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIBinaryStream
|
||||
//! \~english Restore operator
|
||||
//! \~russian Оператор извлечения
|
||||
BINARY_STREAM_READ (PIKbdListener::MouseEvent) {s >> v.x >> v.y >> v.action >> v.buttons >> v.modifiers; return s;}
|
||||
BINARY_STREAM_READ(PIKbdListener::MouseEvent) {
|
||||
s >> v.x >> v.y >> v.action >> v.buttons >> v.modifiers;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
//! \relatesalso PIBinaryStream
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
BINARY_STREAM_WRITE(PIKbdListener::WheelEvent) {s << (*(PIKbdListener::MouseEvent*)&v) << v.direction; return s;}
|
||||
BINARY_STREAM_WRITE(PIKbdListener::WheelEvent) {
|
||||
s << (*(PIKbdListener::MouseEvent *)&v) << v.direction;
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIBinaryStream
|
||||
//! \~english Restore operator
|
||||
//! \~russian Оператор извлечения
|
||||
BINARY_STREAM_READ (PIKbdListener::WheelEvent) {s >> (*(PIKbdListener::MouseEvent*)&v) >> v.direction; return s;}
|
||||
BINARY_STREAM_READ(PIKbdListener::WheelEvent) {
|
||||
s >> (*(PIKbdListener::MouseEvent *)&v) >> v.direction;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
REGISTER_PIVARIANTSIMPLE(PIKbdListener::KeyEvent)
|
||||
|
||||
@@ -1391,6 +1391,31 @@ PIString PIString::takeNumber() {
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::takeInteger() {
|
||||
PIString ret;
|
||||
int sz = size_s(), ws = -1, we = -1;
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
PIChar c = at(i);
|
||||
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
|
||||
if (we < 0 && ws >= 0) {
|
||||
we = i;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (ws < 0) ws = i;
|
||||
if (!c.isDigit()) {
|
||||
we = i;
|
||||
break;
|
||||
}
|
||||
if (we >= 0) break;
|
||||
}
|
||||
}
|
||||
ret = mid(ws, we - ws);
|
||||
cutLeft(we < 0 ? sz : we);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~english "shield" symbol prevent analysis of the next symbol
|
||||
//! \~russian Символ "shield" экранирует следующий символ
|
||||
|
||||
@@ -807,6 +807,10 @@ public:
|
||||
//! \~russian Извлекает число в C-формате с начала строки и возвращает его как строку.
|
||||
PIString takeNumber();
|
||||
|
||||
//! \~english Take a digits from the begin of this string and return it.
|
||||
//! \~russian Извлекает цифры с начала строки и возвращает их как строку.
|
||||
PIString takeInteger();
|
||||
|
||||
//! \~english Take a range between "start" and "end" characters from the begin of this string and return it.
|
||||
//! \~russian Извлекает диапазон между символами "start" и "end" с начала строки и возвращает его.
|
||||
PIString takeRange(const PIChar start, const PIChar end, const PIChar shield = '\\');
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "piincludes_p.h"
|
||||
#include "pithread.h"
|
||||
#include "piintrospection_threads.h"
|
||||
#include "pitime.h"
|
||||
#ifndef MICRO_PIP
|
||||
# include "pisystemtests.h"
|
||||
#endif
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
|
||||
#include "colors_p.h"
|
||||
|
||||
#define CSS_COLOR(n,v) {#n,v}
|
||||
#define CSS_COLOR(n, v) \
|
||||
{ #n, v }
|
||||
|
||||
// clang-format off
|
||||
struct CSSColor {
|
||||
const char * name;
|
||||
uint color;
|
||||
@@ -174,6 +176,7 @@ struct CSSColor {
|
||||
CSS_COLOR(yellowgreen ,0x9acd32),
|
||||
{nullptr, 0}
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
#undef CSS_COLOR
|
||||
|
||||
@@ -193,4 +196,3 @@ PIColorCollection::PIColorCollection() {
|
||||
++c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,11 @@
|
||||
*/
|
||||
|
||||
#include "pibytearray.h"
|
||||
#include "pistringlist.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "picrc.h"
|
||||
#include "pistringlist.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//! \class PIByteArray pibytearray.h
|
||||
//! \~\details
|
||||
@@ -71,51 +73,27 @@
|
||||
//!
|
||||
|
||||
|
||||
static const uchar base64Table[64] = {
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
|
||||
0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
|
||||
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
|
||||
0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
|
||||
0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
|
||||
0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
|
||||
0x77, 0x78, 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33,
|
||||
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f};
|
||||
static const uchar base64Table[64] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
|
||||
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
|
||||
0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
|
||||
0x77, 0x78, 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f};
|
||||
|
||||
static const uchar base64InvTable[256] = {
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x3E, 0x0, 0x0, 0x0, 0x3F,
|
||||
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
|
||||
0x3C, 0x3D, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6,
|
||||
0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE,
|
||||
0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
|
||||
0x17, 0x18, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
|
||||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
|
||||
0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
|
||||
0x31, 0x32, 0x33, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3E,
|
||||
0x0, 0x0, 0x0, 0x3F, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
|
||||
0x17, 0x18, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
|
||||
0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
||||
|
||||
|
||||
// clang-format off
|
||||
struct base64HelpStruct {
|
||||
base64HelpStruct() {v = 0;}
|
||||
inline void setBytes(const uchar * r, int size = 3) {
|
||||
@@ -148,6 +126,7 @@ struct base64HelpStruct {
|
||||
}
|
||||
uint v;
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
||||
PIByteArray & PIByteArray::convertToBase64() {
|
||||
@@ -214,7 +193,8 @@ PIByteArray PIByteArray::fromBase64(const PIByteArray & base64) {
|
||||
ret[++ind] = (t[2]);
|
||||
}
|
||||
if (base64.back() == '=') ret.pop_back();
|
||||
if (sz > 1) if (base64[sz - 2] == '=') ret.pop_back();
|
||||
if (sz > 1)
|
||||
if (base64[sz - 2] == '=') ret.pop_back();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -232,8 +212,7 @@ PIByteArray & PIByteArray::compressRLE(uchar threshold) {
|
||||
clen = 1;
|
||||
while (at(++i) == fb) {
|
||||
++clen;
|
||||
if (clen == mlen)
|
||||
break;
|
||||
if (clen == mlen) break;
|
||||
}
|
||||
if (clen > 1) {
|
||||
t.push_back(threshold + clen);
|
||||
@@ -354,11 +333,15 @@ PIString PIByteArray::toHex() const {
|
||||
const uchar * d = data();
|
||||
for (int i = 0; i < size_s(); ++i) {
|
||||
int j = (d[i] >> 4) & 0xf;
|
||||
if (j <= 9) hexData[i*2] = (j + '0');
|
||||
else hexData[i*2] = (j + 'a' - 10);
|
||||
if (j <= 9)
|
||||
hexData[i * 2] = (j + '0');
|
||||
else
|
||||
hexData[i * 2] = (j + 'a' - 10);
|
||||
j = d[i] & 0xf;
|
||||
if (j <= 9) hexData[i*2+1] = (j + '0');
|
||||
else hexData[i*2+1] = (j + 'a' - 10);
|
||||
if (j <= 9)
|
||||
hexData[i * 2 + 1] = (j + '0');
|
||||
else
|
||||
hexData[i * 2 + 1] = (j + 'a' - 10);
|
||||
}
|
||||
return PIString(hex);
|
||||
}
|
||||
@@ -386,10 +369,14 @@ PIByteArray PIByteArray::fromHex(PIString str) {
|
||||
for (int i = hexEncoded.size() - 1; i >= 0; --i) {
|
||||
int ch = hexEncoded.at(i);
|
||||
int tmp;
|
||||
if (ch >= '0' && ch <= '9') tmp = ch - '0';
|
||||
else if (ch >= 'a' && ch <= 'f') tmp = ch - 'a' + 10;
|
||||
else if (ch >= 'A' && ch <= 'F') tmp = ch - 'A' + 10;
|
||||
else continue;
|
||||
if (ch >= '0' && ch <= '9')
|
||||
tmp = ch - '0';
|
||||
else if (ch >= 'a' && ch <= 'f')
|
||||
tmp = ch - 'a' + 10;
|
||||
else if (ch >= 'A' && ch <= 'F')
|
||||
tmp = ch - 'A' + 10;
|
||||
else
|
||||
continue;
|
||||
if (odd_digit) {
|
||||
--result;
|
||||
*result = tmp;
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
//! \~russian
|
||||
//!
|
||||
//!
|
||||
|
||||
// clang-format off
|
||||
const char PIValueTree::attributeHidden [] = "hidden" ;
|
||||
const char PIValueTree::attributeReadOnly [] = "readOnly" ;
|
||||
const char PIValueTree::attributeIsLabel [] = "label" ;
|
||||
@@ -45,10 +47,10 @@ const char PIValueTree::attributeSingleStep [] = "singleStep" ;
|
||||
const char PIValueTree::attributeDecimals [] = "decimals" ;
|
||||
const char PIValueTree::attributePrefix [] = "prefix" ;
|
||||
const char PIValueTree::attributeSuffix [] = "suffix" ;
|
||||
// clang-format on
|
||||
|
||||
|
||||
PIValueTree::PIValueTree() {
|
||||
}
|
||||
PIValueTree::PIValueTree() {}
|
||||
|
||||
|
||||
PIValueTree::PIValueTree(const PIVariant & v) {
|
||||
@@ -91,8 +93,7 @@ void PIValueTree::mergeAttributes(const PIVariantMap & a) {
|
||||
if (_is_null) return;
|
||||
auto it = a.makeIterator();
|
||||
while (it.next()) {
|
||||
if (!_attributes.contains(it.key()))
|
||||
_attributes.insert(it.key(), it.value());
|
||||
if (!_attributes.contains(it.key())) _attributes.insert(it.key(), it.value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,8 +101,7 @@ void PIValueTree::mergeAttributes(const PIVariantMap & a) {
|
||||
bool PIValueTree::contains(const PIString & name) const {
|
||||
if (_is_null) return true;
|
||||
for (const auto & c: _children)
|
||||
if (c.name() == name)
|
||||
return true;
|
||||
if (c.name() == name) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -118,8 +118,7 @@ bool PIValueTree::contains(const PIStringList & path) const {
|
||||
const PIValueTree & PIValueTree::child(const PIString & name) const {
|
||||
if (_is_null) return *this;
|
||||
for (const auto & c: _children)
|
||||
if (c.name() == name)
|
||||
return c;
|
||||
if (c.name() == name) return c;
|
||||
return nullValue();
|
||||
}
|
||||
|
||||
@@ -127,8 +126,7 @@ const PIValueTree & PIValueTree::child(const PIString & name) const {
|
||||
PIValueTree & PIValueTree::child(const PIString & name) {
|
||||
if (_is_null) return *this;
|
||||
for (auto & c: _children)
|
||||
if (c.name() == name)
|
||||
return c;
|
||||
if (c.name() == name) return c;
|
||||
return nullValue();
|
||||
}
|
||||
|
||||
@@ -163,8 +161,7 @@ PIValueTree & PIValueTree::remove(const PIString & name) {
|
||||
PIValueTree & PIValueTree::operator[](const PIString & name) {
|
||||
if (_is_null) return *this;
|
||||
for (auto & c: _children)
|
||||
if (c.name() == name)
|
||||
return c;
|
||||
if (c.name() == name) return c;
|
||||
_children << PIValueTree(name, PIVariant());
|
||||
return _children.back();
|
||||
}
|
||||
@@ -182,10 +179,8 @@ PIValueTree & PIValueTree::operator[](const PIStringList & path) {
|
||||
void PIValueTree::print(PIString & s, const PIValueTree & v, PIString tab) {
|
||||
PIString ntab = tab + " ", nntab = ntab + " ";
|
||||
s += tab + v.name() + " {\n";
|
||||
if (v.value().isValid())
|
||||
s += ntab + "value: " + v.value().toString() + "\n";
|
||||
if (v.comment().isNotEmpty())
|
||||
s += ntab + "comment: " + v.comment() + "\n";
|
||||
if (v.value().isValid()) s += ntab + "value: " + v.value().toString() + "\n";
|
||||
if (v.comment().isNotEmpty()) s += ntab + "comment: " + v.comment() + "\n";
|
||||
if (v.attributes().isNotEmpty()) {
|
||||
s += ntab + "attributes: [\n";
|
||||
auto ait = v.attributes().makeIterator();
|
||||
|
||||
@@ -26,18 +26,20 @@
|
||||
#ifndef PIVALUETREE_H
|
||||
#define PIVALUETREE_H
|
||||
|
||||
#include "pivariant.h"
|
||||
#include "pichunkstream.h"
|
||||
#include "pivariant.h"
|
||||
|
||||
|
||||
class PIP_EXPORT PIValueTree {
|
||||
BINARY_STREAM_FRIEND(PIValueTree);
|
||||
friend PICout operator<<(PICout s, const PIValueTree & v);
|
||||
|
||||
public:
|
||||
PIValueTree();
|
||||
PIValueTree(const PIVariant & v);
|
||||
PIValueTree(const PIString & n, const PIVariant & v, const PIVariantMap & a = PIVariantMap());
|
||||
|
||||
// clang-format off
|
||||
static const char attributeHidden [];
|
||||
static const char attributeReadOnly [];
|
||||
static const char attributeIsLabel [];
|
||||
@@ -55,6 +57,7 @@ public:
|
||||
static const char attributePrefix [];
|
||||
static const char attributeSuffix [];
|
||||
//static constexpr char attribute[] = "";
|
||||
// clang-format on
|
||||
|
||||
bool isNull() const { return _is_null; }
|
||||
bool isValid() const { return _value.isValid(); }
|
||||
@@ -101,7 +104,6 @@ private:
|
||||
PIVariant _value;
|
||||
PIVector<PIValueTree> _children;
|
||||
bool _is_null = false;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -110,11 +112,7 @@ private:
|
||||
//! \~russian Оператор сохранения.
|
||||
BINARY_STREAM_WRITE(PIValueTree) {
|
||||
PIChunkStream cs;
|
||||
cs.add(1, v._name)
|
||||
.add(2, v._comment)
|
||||
.add(3, v._attributes)
|
||||
.add(4, v._value)
|
||||
.add(5, v._children);
|
||||
cs.add(1, v._name).add(2, v._comment).add(3, v._attributes).add(4, v._value).add(5, v._children);
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
@@ -123,7 +121,8 @@ BINARY_STREAM_WRITE(PIValueTree) {
|
||||
//! \~english Restore operator.
|
||||
//! \~russian Оператор извлечения.
|
||||
BINARY_STREAM_READ(PIValueTree) {
|
||||
PIByteArray csba; s >> csba;
|
||||
PIByteArray csba;
|
||||
s >> csba;
|
||||
PIChunkStream cs(csba);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
|
||||
@@ -69,8 +69,7 @@ PIMap<uint, __PIVariantInfo__ * > * __PIVariantInfoStorage__::map = nullptr;
|
||||
#endif
|
||||
|
||||
|
||||
PIVariant::PIVariant() {
|
||||
}
|
||||
PIVariant::PIVariant() {}
|
||||
|
||||
|
||||
PIVariant::PIVariant(const PIVariant & v) {
|
||||
@@ -90,38 +89,96 @@ PIVariant::PIVariant(PIVariant && v) {
|
||||
|
||||
void PIVariant::setValueFromString(const PIString & v) {
|
||||
switch (_type) {
|
||||
case PIVariant::pivBool: {setValue(v.toBool());} break;
|
||||
case PIVariant::pivChar: {setValue(v.toChar());} break;
|
||||
case PIVariant::pivUChar: {setValue((uchar)v.toChar());} break;
|
||||
case PIVariant::pivShort: {setValue(v.toShort());} break;
|
||||
case PIVariant::pivUShort: {setValue(v.toUShort());} break;
|
||||
case PIVariant::pivInt: {setValue(v.toInt());} break;
|
||||
case PIVariant::pivUInt: {setValue(v.toUInt());} break;
|
||||
case PIVariant::pivLLong: {setValue(v.toLLong());} break;
|
||||
case PIVariant::pivULLong: {setValue(v.toULLong());} break;
|
||||
case PIVariant::pivFloat: {setValue(v.toFloat());} break;
|
||||
case PIVariant::pivDouble: {setValue(v.toDouble());} break;
|
||||
case PIVariant::pivLDouble: {setValue(v.toLDouble());} break;
|
||||
case PIVariant::pivTime: {setValue(PITime::fromString(v));} break;
|
||||
case PIVariant::pivDate: {setValue(PIDate::fromString(v));} break;
|
||||
case PIVariant::pivDateTime: {setValue(PIDateTime::fromString(v));} break;
|
||||
case PIVariant::pivString: {setValue(v);} break;
|
||||
case PIVariant::pivStringList: {setValue(v.split("%|%"));} break;
|
||||
case PIVariant::pivEnum: {PIVariantTypes::Enum r = toEnum(); r.selectName(v); setValue(r);} break;
|
||||
case PIVariant::pivFile: {PIVariantTypes::File r = toFile(); r.file = v; setValue(r);} break;
|
||||
case PIVariant::pivDir: {PIVariantTypes::Dir r = toDir(); r.dir = v; setValue(r);} break;
|
||||
case PIVariant::pivColor: {setValue(PIVariantTypes::Color::fromString(v));} break;
|
||||
case PIVariant::pivIODevice: {setValue(PIVariantTypes::IODevice());} break; // TODO
|
||||
case PIVariant::pivPoint: {PIStringList l = v.split(';'); if (l.size() >= 2) setValue(PIPointd(l[0].toDouble(), l[1].toDouble()));} break;
|
||||
case PIVariant::pivRect: {PIStringList l = v.split(';'); if (l.size() >= 4) setValue(PIRectd(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble()));} break;
|
||||
case PIVariant::pivLine: {PIStringList l = v.split(';'); if (l.size() >= 4) setValue(PILined(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble()));} break;
|
||||
case PIVariant::pivBool: {
|
||||
setValue(v.toBool());
|
||||
} break;
|
||||
case PIVariant::pivChar: {
|
||||
setValue(v.toChar());
|
||||
} break;
|
||||
case PIVariant::pivUChar: {
|
||||
setValue((uchar)v.toChar());
|
||||
} break;
|
||||
case PIVariant::pivShort: {
|
||||
setValue(v.toShort());
|
||||
} break;
|
||||
case PIVariant::pivUShort: {
|
||||
setValue(v.toUShort());
|
||||
} break;
|
||||
case PIVariant::pivInt: {
|
||||
setValue(v.toInt());
|
||||
} break;
|
||||
case PIVariant::pivUInt: {
|
||||
setValue(v.toUInt());
|
||||
} break;
|
||||
case PIVariant::pivLLong: {
|
||||
setValue(v.toLLong());
|
||||
} break;
|
||||
case PIVariant::pivULLong: {
|
||||
setValue(v.toULLong());
|
||||
} break;
|
||||
case PIVariant::pivFloat: {
|
||||
setValue(v.toFloat());
|
||||
} break;
|
||||
case PIVariant::pivDouble: {
|
||||
setValue(v.toDouble());
|
||||
} break;
|
||||
case PIVariant::pivLDouble: {
|
||||
setValue(v.toLDouble());
|
||||
} break;
|
||||
case PIVariant::pivTime: {
|
||||
setValue(PITime::fromString(v));
|
||||
} break;
|
||||
case PIVariant::pivDate: {
|
||||
setValue(PIDate::fromString(v));
|
||||
} break;
|
||||
case PIVariant::pivDateTime: {
|
||||
setValue(PIDateTime::fromString(v));
|
||||
} break;
|
||||
case PIVariant::pivString: {
|
||||
setValue(v);
|
||||
} break;
|
||||
case PIVariant::pivStringList: {
|
||||
setValue(v.split("%|%"));
|
||||
} break;
|
||||
case PIVariant::pivEnum: {
|
||||
setValue(PIVariantTypes::Enum::fromString(v));
|
||||
} break;
|
||||
case PIVariant::pivFile: {
|
||||
PIVariantTypes::File r = toFile();
|
||||
r.file = v;
|
||||
setValue(r);
|
||||
} break;
|
||||
case PIVariant::pivDir: {
|
||||
PIVariantTypes::Dir r = toDir();
|
||||
r.dir = v;
|
||||
setValue(r);
|
||||
} break;
|
||||
case PIVariant::pivColor: {
|
||||
setValue(PIVariantTypes::Color::fromString(v));
|
||||
} break;
|
||||
case PIVariant::pivIODevice: {
|
||||
setValue(PIVariantTypes::IODevice());
|
||||
} break; // TODO
|
||||
case PIVariant::pivPoint: {
|
||||
PIStringList l = v.split(';');
|
||||
if (l.size() >= 2) setValue(PIPointd(l[0].toDouble(), l[1].toDouble()));
|
||||
} break;
|
||||
case PIVariant::pivRect: {
|
||||
PIStringList l = v.split(';');
|
||||
if (l.size() >= 4) setValue(PIRectd(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble()));
|
||||
} break;
|
||||
case PIVariant::pivLine: {
|
||||
PIStringList l = v.split(';');
|
||||
if (l.size() >= 4) setValue(PILined(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble()));
|
||||
} break;
|
||||
case PIVariant::pivCustom: {
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
__PIVariantInfo__ * vi = __PIVariantInfoStorage__::get()->map->value(__PIVariantFunctions__<PIString>::typeIDHelper());
|
||||
if (vi) {
|
||||
__PIVariantInfo__::castHelperFunc cf = vi->cast.value(_typeID);
|
||||
if (cf) {
|
||||
PIByteArray sba; sba << v;
|
||||
PIByteArray sba;
|
||||
sba << v;
|
||||
_content = cf(sba);
|
||||
}
|
||||
}
|
||||
@@ -161,7 +218,8 @@ PIVariant::Type PIVariant::typeFromName(const PIString & tname) {
|
||||
if (s == "short" || s == "shortint" || s == "signedshort" || s == "signedshortint" || s == "sword") return PIVariant::pivShort;
|
||||
if (s == "int" || s == "signed" || s == "signedint") return PIVariant::pivInt;
|
||||
if (s == "long" || s == "longint" || s == "signedlong" || s == "signedlongint" || s == "sdword") return PIVariant::pivInt;
|
||||
if (s == "llong" || s == "longlong" || s == "longlongint" || s == "signedlonglong" || s == "signedlonglongint" || s == "sqword") return PIVariant::pivLLong;
|
||||
if (s == "llong" || s == "longlong" || s == "longlongint" || s == "signedlonglong" || s == "signedlonglongint" || s == "sqword")
|
||||
return PIVariant::pivLLong;
|
||||
if (s == "uchar" || s == "byte") return PIVariant::pivUChar;
|
||||
if (s == "ushort" || s == "unsignedshort" || s == "unsignedshortint" || s == "word") return PIVariant::pivUShort;
|
||||
if (s == "uint" || s == "unsigned" || s == "unsignedint") return PIVariant::pivUInt;
|
||||
@@ -173,10 +231,13 @@ PIVariant::Type PIVariant::typeFromName(const PIString & tname) {
|
||||
if (s == "complexd" || s == "complex<double>") return PIVariant::pivComplexd;
|
||||
if (s == "complexld" || s == "complex<ldouble>" || s == "complex<longdouble>") return PIVariant::pivComplexld;
|
||||
if (s == "pibitarray" || s == "bitarray") return PIVariant::pivBitArray;
|
||||
if (s == "pibytearray" || s == "bytearray" || s == "vector<uchar>" || s == "pivector<uchar>" || s == "vector<unsignedchar>" || s == "pivector<unsignedchar>" ||
|
||||
s == "vector<char>" || s == "pivector<char>") return PIVariant::pivByteArray;
|
||||
if (s == "pibytearray" || s == "bytearray" || s == "vector<uchar>" || s == "pivector<uchar>" || s == "vector<unsignedchar>" ||
|
||||
s == "pivector<unsignedchar>" || s == "vector<char>" || s == "pivector<char>")
|
||||
return PIVariant::pivByteArray;
|
||||
if (s == "pistring" || s == "string" || s == "text") return PIVariant::pivString;
|
||||
if (s == "pistringlist" || s == "stringlist" || s == "vector<string>" || s == "vector<pistring>" || s == "pivector<string>" || s == "pivector<pistring>") return PIVariant::pivStringList;
|
||||
if (s == "pistringlist" || s == "stringlist" || s == "vector<string>" || s == "vector<pistring>" || s == "pivector<string>" ||
|
||||
s == "pivector<pistring>")
|
||||
return PIVariant::pivStringList;
|
||||
if (s == "pitime" || s == "time") return PIVariant::pivTime;
|
||||
if (s == "pidate" || s == "date") return PIVariant::pivDate;
|
||||
if (s == "pidatetime" || s == "datetime") return PIVariant::pivDateTime;
|
||||
@@ -231,8 +292,7 @@ PIVariant::Type PIVariant::typeFromID(uint type_id) {
|
||||
if (type_id == typeID<PIMathMatrixd>()) return PIVariant::pivMathMatrix;
|
||||
if (type_id == typeID<PILined>()) return PIVariant::pivLine;
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
if (__PIVariantInfoStorage__::get()->map->contains(type_id))
|
||||
return PIVariant::pivCustom;
|
||||
if (__PIVariantInfoStorage__::get()->map->contains(type_id)) return PIVariant::pivCustom;
|
||||
#endif
|
||||
return PIVariant::pivInvalid;
|
||||
}
|
||||
@@ -246,6 +306,7 @@ uint PIVariant::typeIDFromName(const PIString & tname) {
|
||||
}
|
||||
|
||||
|
||||
// clang-format off
|
||||
uint PIVariant::typeIDFromType(Type type) {
|
||||
switch (type) {
|
||||
case (PIVariant::pivBool ): return typeID<bool >();
|
||||
@@ -284,12 +345,12 @@ uint PIVariant::typeIDFromType(Type type) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
|
||||
PIString PIVariant::typeName() const {
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
if ((_type == pivCustom) && _info)
|
||||
return _info->typeName;
|
||||
if ((_type == pivCustom) && _info) return _info->typeName;
|
||||
#endif
|
||||
return typeName(_type);
|
||||
}
|
||||
@@ -411,6 +472,25 @@ PIString PIVariant::typeNameFromID(uint type_id) {
|
||||
}
|
||||
|
||||
|
||||
PIVector<uint> PIVariant::knownTypeIDs() {
|
||||
PIVector<uint> ret;
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
auto it = __PIVariantInfoStorage__::get()->map->makeIterator();
|
||||
while (it.next())
|
||||
ret << it.key();
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int PIVariant::knownTypeIDsCount() {
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
return __PIVariantInfoStorage__::get()->map->size_s();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Returns variant content as boolean
|
||||
//! \~russian Возвращает содержимое как boolean
|
||||
@@ -433,20 +513,77 @@ PIString PIVariant::typeNameFromID(uint type_id) {
|
||||
bool PIVariant::toBool() const {
|
||||
PIByteArray ba(_content);
|
||||
switch (_type) {
|
||||
case PIVariant::pivBool: {bool r; ba >> r; return r;}
|
||||
case PIVariant::pivChar: {char r; ba >> r; return r != 0;}
|
||||
case PIVariant::pivUChar: {uchar r; ba >> r; return r != 0;}
|
||||
case PIVariant::pivShort: {short r; ba >> r; return r != 0;}
|
||||
case PIVariant::pivUShort: {ushort r; ba >> r; return r != 0;}
|
||||
case PIVariant::pivInt: {int r; ba >> r; return r != 0;}
|
||||
case PIVariant::pivUInt: {uint r; ba >> r; return r != 0;}
|
||||
case PIVariant::pivLLong: {llong r; ba >> r; return r != 0;}
|
||||
case PIVariant::pivULLong: {ullong r; ba >> r; return r != 0;}
|
||||
case PIVariant::pivFloat: {float r; ba >> r; return r > 0.f;}
|
||||
case PIVariant::pivDouble: {double r; ba >> r; return r > 0.;}
|
||||
case PIVariant::pivLDouble: {ldouble r; ba >> r; return r > 0.;}
|
||||
case PIVariant::pivString: {PIString r; ba >> r; return r.toBool();}
|
||||
case PIVariant::pivStringList: {PIStringList r; ba >> r; if (r.isEmpty()) return false; return r.front().toBool();}
|
||||
case PIVariant::pivBool: {
|
||||
bool r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivChar: {
|
||||
char r;
|
||||
ba >> r;
|
||||
return r != 0;
|
||||
}
|
||||
case PIVariant::pivUChar: {
|
||||
uchar r;
|
||||
ba >> r;
|
||||
return r != 0;
|
||||
}
|
||||
case PIVariant::pivShort: {
|
||||
short r;
|
||||
ba >> r;
|
||||
return r != 0;
|
||||
}
|
||||
case PIVariant::pivUShort: {
|
||||
ushort r;
|
||||
ba >> r;
|
||||
return r != 0;
|
||||
}
|
||||
case PIVariant::pivInt: {
|
||||
int r;
|
||||
ba >> r;
|
||||
return r != 0;
|
||||
}
|
||||
case PIVariant::pivUInt: {
|
||||
uint r;
|
||||
ba >> r;
|
||||
return r != 0;
|
||||
}
|
||||
case PIVariant::pivLLong: {
|
||||
llong r;
|
||||
ba >> r;
|
||||
return r != 0;
|
||||
}
|
||||
case PIVariant::pivULLong: {
|
||||
ullong r;
|
||||
ba >> r;
|
||||
return r != 0;
|
||||
}
|
||||
case PIVariant::pivFloat: {
|
||||
float r;
|
||||
ba >> r;
|
||||
return r > 0.f;
|
||||
}
|
||||
case PIVariant::pivDouble: {
|
||||
double r;
|
||||
ba >> r;
|
||||
return r > 0.;
|
||||
}
|
||||
case PIVariant::pivLDouble: {
|
||||
ldouble r;
|
||||
ba >> r;
|
||||
return r > 0.;
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return r.toBool();
|
||||
}
|
||||
case PIVariant::pivStringList: {
|
||||
PIStringList r;
|
||||
ba >> r;
|
||||
if (r.isEmpty()) return false;
|
||||
return r.front().toBool();
|
||||
}
|
||||
case PIVariant::pivCustom: return getAsValue<bool>(*this);
|
||||
default: break;
|
||||
}
|
||||
@@ -454,7 +591,6 @@ bool PIVariant::toBool() const {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Returns variant content as int
|
||||
//! \~russian Возвращает содержимое как int
|
||||
@@ -477,22 +613,87 @@ bool PIVariant::toBool() const {
|
||||
int PIVariant::toInt() const {
|
||||
PIByteArray ba(_content);
|
||||
switch (_type) {
|
||||
case PIVariant::pivBool: {bool r; ba >> r; return r;}
|
||||
case PIVariant::pivChar: {char r; ba >> r; return r;}
|
||||
case PIVariant::pivUChar: {uchar r; ba >> r; return r;}
|
||||
case PIVariant::pivShort: {short r; ba >> r; return r;}
|
||||
case PIVariant::pivUShort: {ushort r; ba >> r; return r;}
|
||||
case PIVariant::pivInt: {int r; ba >> r; return r;}
|
||||
case PIVariant::pivUInt: {uint r; ba >> r; return r;}
|
||||
case PIVariant::pivLLong: {llong r; ba >> r; return r;}
|
||||
case PIVariant::pivULLong: {ullong r; ba >> r; return r;}
|
||||
case PIVariant::pivFloat: {float r; ba >> r; return r;}
|
||||
case PIVariant::pivDouble: {double r; ba >> r; return r;}
|
||||
case PIVariant::pivLDouble: {ldouble r; ba >> r; return r;}
|
||||
case PIVariant::pivString: {PIString r; ba >> r; return r.toInt();}
|
||||
case PIVariant::pivStringList: {PIStringList r; ba >> r; if (r.isEmpty()) return 0; return r.front().toInt();}
|
||||
case PIVariant::pivEnum: {PIVariantTypes::Enum r; ba >> r; return r.selectedValue();}
|
||||
case PIVariant::pivColor: {PIVariantTypes::Color r; ba >> r; return (int)r.rgba;}
|
||||
case PIVariant::pivBool: {
|
||||
bool r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivChar: {
|
||||
char r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUChar: {
|
||||
uchar r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivShort: {
|
||||
short r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUShort: {
|
||||
ushort r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivInt: {
|
||||
int r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUInt: {
|
||||
uint r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivLLong: {
|
||||
llong r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivULLong: {
|
||||
ullong r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivFloat: {
|
||||
float r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivDouble: {
|
||||
double r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivLDouble: {
|
||||
ldouble r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return r.toInt();
|
||||
}
|
||||
case PIVariant::pivStringList: {
|
||||
PIStringList r;
|
||||
ba >> r;
|
||||
if (r.isEmpty()) return 0;
|
||||
return r.front().toInt();
|
||||
}
|
||||
case PIVariant::pivEnum: {
|
||||
PIVariantTypes::Enum r;
|
||||
ba >> r;
|
||||
return r.selectedValue();
|
||||
}
|
||||
case PIVariant::pivColor: {
|
||||
PIVariantTypes::Color r;
|
||||
ba >> r;
|
||||
return (int)r.rgba;
|
||||
}
|
||||
case PIVariant::pivCustom: return getAsValue<int>(*this);
|
||||
default: break;
|
||||
}
|
||||
@@ -522,21 +723,82 @@ int PIVariant::toInt() const {
|
||||
llong PIVariant::toLLong() const {
|
||||
PIByteArray ba(_content);
|
||||
switch (_type) {
|
||||
case PIVariant::pivBool: {bool r; ba >> r; return r;}
|
||||
case PIVariant::pivChar: {char r; ba >> r; return r;}
|
||||
case PIVariant::pivUChar: {uchar r; ba >> r; return r;}
|
||||
case PIVariant::pivShort: {short r; ba >> r; return r;}
|
||||
case PIVariant::pivUShort: {ushort r; ba >> r; return r;}
|
||||
case PIVariant::pivInt: {int r; ba >> r; return r;}
|
||||
case PIVariant::pivUInt: {uint r; ba >> r; return r;}
|
||||
case PIVariant::pivLLong: {llong r; ba >> r; return r;}
|
||||
case PIVariant::pivULLong: {ullong r; ba >> r; return r;}
|
||||
case PIVariant::pivFloat: {float r; ba >> r; return r;}
|
||||
case PIVariant::pivDouble: {double r; ba >> r; return r;}
|
||||
case PIVariant::pivLDouble: {ldouble r; ba >> r; return r;}
|
||||
case PIVariant::pivString: {PIString r; ba >> r; return r.toLLong();}
|
||||
case PIVariant::pivStringList: {PIStringList r; ba >> r; if (r.isEmpty()) return 0L; return r.front().toLLong();}
|
||||
case PIVariant::pivEnum: {PIVariantTypes::Enum r; ba >> r; return llong(r.selectedValue());}
|
||||
case PIVariant::pivBool: {
|
||||
bool r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivChar: {
|
||||
char r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUChar: {
|
||||
uchar r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivShort: {
|
||||
short r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUShort: {
|
||||
ushort r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivInt: {
|
||||
int r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUInt: {
|
||||
uint r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivLLong: {
|
||||
llong r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivULLong: {
|
||||
ullong r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivFloat: {
|
||||
float r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivDouble: {
|
||||
double r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivLDouble: {
|
||||
ldouble r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return r.toLLong();
|
||||
}
|
||||
case PIVariant::pivStringList: {
|
||||
PIStringList r;
|
||||
ba >> r;
|
||||
if (r.isEmpty()) return 0L;
|
||||
return r.front().toLLong();
|
||||
}
|
||||
case PIVariant::pivEnum: {
|
||||
PIVariantTypes::Enum r;
|
||||
ba >> r;
|
||||
return llong(r.selectedValue());
|
||||
}
|
||||
case PIVariant::pivCustom: return getAsValue<llong>(*this);
|
||||
default: break;
|
||||
}
|
||||
@@ -566,21 +828,82 @@ llong PIVariant::toLLong() const {
|
||||
float PIVariant::toFloat() const {
|
||||
PIByteArray ba(_content);
|
||||
switch (_type) {
|
||||
case PIVariant::pivBool: {bool r; ba >> r; return r;}
|
||||
case PIVariant::pivChar: {char r; ba >> r; return r;}
|
||||
case PIVariant::pivUChar: {uchar r; ba >> r; return r;}
|
||||
case PIVariant::pivShort: {short r; ba >> r; return r;}
|
||||
case PIVariant::pivUShort: {ushort r; ba >> r; return r;}
|
||||
case PIVariant::pivInt: {int r; ba >> r; return r;}
|
||||
case PIVariant::pivUInt: {uint r; ba >> r; return r;}
|
||||
case PIVariant::pivLLong: {llong r; ba >> r; return r;}
|
||||
case PIVariant::pivULLong: {ullong r; ba >> r; return r;}
|
||||
case PIVariant::pivFloat: {float r; ba >> r; return r;}
|
||||
case PIVariant::pivDouble: {double r; ba >> r; return r;}
|
||||
case PIVariant::pivLDouble: {ldouble r; ba >> r; return r;}
|
||||
case PIVariant::pivString: {PIString r; ba >> r; return r.toFloat();}
|
||||
case PIVariant::pivStringList: {PIStringList r; ba >> r; if (r.isEmpty()) return 0.f; return r.front().toFloat();}
|
||||
case PIVariant::pivEnum: {PIVariantTypes::Enum r; ba >> r; return float(r.selectedValue());}
|
||||
case PIVariant::pivBool: {
|
||||
bool r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivChar: {
|
||||
char r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUChar: {
|
||||
uchar r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivShort: {
|
||||
short r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUShort: {
|
||||
ushort r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivInt: {
|
||||
int r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUInt: {
|
||||
uint r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivLLong: {
|
||||
llong r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivULLong: {
|
||||
ullong r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivFloat: {
|
||||
float r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivDouble: {
|
||||
double r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivLDouble: {
|
||||
ldouble r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return r.toFloat();
|
||||
}
|
||||
case PIVariant::pivStringList: {
|
||||
PIStringList r;
|
||||
ba >> r;
|
||||
if (r.isEmpty()) return 0.f;
|
||||
return r.front().toFloat();
|
||||
}
|
||||
case PIVariant::pivEnum: {
|
||||
PIVariantTypes::Enum r;
|
||||
ba >> r;
|
||||
return float(r.selectedValue());
|
||||
}
|
||||
case PIVariant::pivCustom: return getAsValue<float>(*this);
|
||||
default: break;
|
||||
}
|
||||
@@ -610,21 +933,82 @@ float PIVariant::toFloat() const {
|
||||
double PIVariant::toDouble() const {
|
||||
PIByteArray ba(_content);
|
||||
switch (_type) {
|
||||
case PIVariant::pivBool: {bool r; ba >> r; return r;}
|
||||
case PIVariant::pivChar: {char r; ba >> r; return r;}
|
||||
case PIVariant::pivUChar: {uchar r; ba >> r; return r;}
|
||||
case PIVariant::pivShort: {short r; ba >> r; return r;}
|
||||
case PIVariant::pivUShort: {ushort r; ba >> r; return r;}
|
||||
case PIVariant::pivInt: {int r; ba >> r; return r;}
|
||||
case PIVariant::pivUInt: {uint r; ba >> r; return r;}
|
||||
case PIVariant::pivLLong: {llong r; ba >> r; return r;}
|
||||
case PIVariant::pivULLong: {ullong r; ba >> r; return r;}
|
||||
case PIVariant::pivFloat: {float r; ba >> r; return r;}
|
||||
case PIVariant::pivDouble: {double r; ba >> r; return r;}
|
||||
case PIVariant::pivLDouble: {ldouble r; ba >> r; return r;}
|
||||
case PIVariant::pivString: {PIString r; ba >> r; return r.toDouble();}
|
||||
case PIVariant::pivStringList: {PIStringList r; ba >> r; if (r.isEmpty()) return 0.; return r.front().toDouble();}
|
||||
case PIVariant::pivEnum: {PIVariantTypes::Enum r; ba >> r; return double(r.selectedValue());}
|
||||
case PIVariant::pivBool: {
|
||||
bool r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivChar: {
|
||||
char r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUChar: {
|
||||
uchar r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivShort: {
|
||||
short r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUShort: {
|
||||
ushort r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivInt: {
|
||||
int r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUInt: {
|
||||
uint r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivLLong: {
|
||||
llong r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivULLong: {
|
||||
ullong r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivFloat: {
|
||||
float r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivDouble: {
|
||||
double r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivLDouble: {
|
||||
ldouble r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return r.toDouble();
|
||||
}
|
||||
case PIVariant::pivStringList: {
|
||||
PIStringList r;
|
||||
ba >> r;
|
||||
if (r.isEmpty()) return 0.;
|
||||
return r.front().toDouble();
|
||||
}
|
||||
case PIVariant::pivEnum: {
|
||||
PIVariantTypes::Enum r;
|
||||
ba >> r;
|
||||
return double(r.selectedValue());
|
||||
}
|
||||
case PIVariant::pivCustom: return getAsValue<double>(*this);
|
||||
default: break;
|
||||
}
|
||||
@@ -654,21 +1038,82 @@ double PIVariant::toDouble() const {
|
||||
ldouble PIVariant::toLDouble() const {
|
||||
PIByteArray ba(_content);
|
||||
switch (_type) {
|
||||
case PIVariant::pivBool: {bool r; ba >> r; return r;}
|
||||
case PIVariant::pivChar: {char r; ba >> r; return r;}
|
||||
case PIVariant::pivUChar: {uchar r; ba >> r; return r;}
|
||||
case PIVariant::pivShort: {short r; ba >> r; return r;}
|
||||
case PIVariant::pivUShort: {ushort r; ba >> r; return r;}
|
||||
case PIVariant::pivInt: {int r; ba >> r; return r;}
|
||||
case PIVariant::pivUInt: {uint r; ba >> r; return r;}
|
||||
case PIVariant::pivLLong: {llong r; ba >> r; return r;}
|
||||
case PIVariant::pivULLong: {ullong r; ba >> r; return r;}
|
||||
case PIVariant::pivFloat: {float r; ba >> r; return r;}
|
||||
case PIVariant::pivDouble: {double r; ba >> r; return r;}
|
||||
case PIVariant::pivLDouble: {ldouble r; ba >> r; return r;}
|
||||
case PIVariant::pivString: {PIString r; ba >> r; return r.toLDouble();}
|
||||
case PIVariant::pivStringList: {PIStringList r; ba >> r; if (r.isEmpty()) return 0.; return r.front().toLDouble();}
|
||||
case PIVariant::pivEnum: {PIVariantTypes::Enum r; ba >> r; return ldouble(r.selectedValue());}
|
||||
case PIVariant::pivBool: {
|
||||
bool r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivChar: {
|
||||
char r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUChar: {
|
||||
uchar r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivShort: {
|
||||
short r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUShort: {
|
||||
ushort r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivInt: {
|
||||
int r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivUInt: {
|
||||
uint r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivLLong: {
|
||||
llong r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivULLong: {
|
||||
ullong r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivFloat: {
|
||||
float r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivDouble: {
|
||||
double r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivLDouble: {
|
||||
ldouble r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return r.toLDouble();
|
||||
}
|
||||
case PIVariant::pivStringList: {
|
||||
PIStringList r;
|
||||
ba >> r;
|
||||
if (r.isEmpty()) return 0.;
|
||||
return r.front().toLDouble();
|
||||
}
|
||||
case PIVariant::pivEnum: {
|
||||
PIVariantTypes::Enum r;
|
||||
ba >> r;
|
||||
return ldouble(r.selectedValue());
|
||||
}
|
||||
case PIVariant::pivCustom: return getAsValue<float>(*this);
|
||||
default: break;
|
||||
}
|
||||
@@ -693,10 +1138,24 @@ ldouble PIVariant::toLDouble() const {
|
||||
//!
|
||||
PITime PIVariant::toTime() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivString) {PIString r; ba >> r; return PITime::fromString(r);}
|
||||
if (_type == PIVariant::pivTime) {PITime r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivDateTime) {PIDateTime r; ba >> r; return r.time();}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PITime>(*this);}
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return PITime::fromString(r);
|
||||
}
|
||||
if (_type == PIVariant::pivTime) {
|
||||
PITime r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivDateTime) {
|
||||
PIDateTime r;
|
||||
ba >> r;
|
||||
return r.time();
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PITime>(*this);
|
||||
}
|
||||
return PITime();
|
||||
}
|
||||
|
||||
@@ -718,10 +1177,24 @@ PITime PIVariant::toTime() const {
|
||||
//!
|
||||
PIDate PIVariant::toDate() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivString) {PIString r; ba >> r; return PIDate::fromString(r);}
|
||||
if (_type == PIVariant::pivDate) {PIDate r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivDateTime) {PIDateTime r; ba >> r; return r.date();}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PIDate>(*this);}
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return PIDate::fromString(r);
|
||||
}
|
||||
if (_type == PIVariant::pivDate) {
|
||||
PIDate r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivDateTime) {
|
||||
PIDateTime r;
|
||||
ba >> r;
|
||||
return r.date();
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PIDate>(*this);
|
||||
}
|
||||
return PIDate();
|
||||
}
|
||||
|
||||
@@ -745,11 +1218,29 @@ PIDate PIVariant::toDate() const {
|
||||
//!
|
||||
PIDateTime PIVariant::toDateTime() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivString) {PIString r; ba >> r; return PIDateTime::fromString(r);}
|
||||
if (_type == PIVariant::pivTime) {PITime r; ba >> r; return PIDateTime(r);}
|
||||
if (_type == PIVariant::pivDate) {PIDate r; ba >> r; return PIDateTime(r);}
|
||||
if (_type == PIVariant::pivDateTime) {PIDateTime r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PIDateTime>(*this);}
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return PIDateTime::fromString(r);
|
||||
}
|
||||
if (_type == PIVariant::pivTime) {
|
||||
PITime r;
|
||||
ba >> r;
|
||||
return PIDateTime(r);
|
||||
}
|
||||
if (_type == PIVariant::pivDate) {
|
||||
PIDate r;
|
||||
ba >> r;
|
||||
return PIDateTime(r);
|
||||
}
|
||||
if (_type == PIVariant::pivDateTime) {
|
||||
PIDateTime r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PIDateTime>(*this);
|
||||
}
|
||||
return PIDateTime();
|
||||
}
|
||||
|
||||
@@ -769,8 +1260,14 @@ PIDateTime PIVariant::toDateTime() const {
|
||||
//!
|
||||
PISystemTime PIVariant::toSystemTime() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivSystemTime) {PISystemTime r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PISystemTime>(*this);}
|
||||
if (_type == PIVariant::pivSystemTime) {
|
||||
PISystemTime r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PISystemTime>(*this);
|
||||
}
|
||||
return PISystemTime::fromSeconds(toDouble());
|
||||
}
|
||||
|
||||
@@ -802,31 +1299,134 @@ PISystemTime PIVariant::toSystemTime() const {
|
||||
PIString PIVariant::toString() const {
|
||||
PIByteArray ba(_content);
|
||||
switch (_type) {
|
||||
case PIVariant::pivBool: {bool r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivChar: {char r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivUChar: {uchar r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivShort: {short r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivUShort: {ushort r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivInt: {int r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivUInt: {uint r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivLLong: {llong r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivULLong: {ullong r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivFloat: {float r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivDouble: {double r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivLDouble: {ldouble r; ba >> r; return PIString::fromNumber(r);}
|
||||
case PIVariant::pivTime: {PITime r; ba >> r; return r.toString();}
|
||||
case PIVariant::pivDate: {PIDate r; ba >> r; return r.toString();}
|
||||
case PIVariant::pivDateTime: {PIDateTime r; ba >> r; return r.toString();}
|
||||
case PIVariant::pivString: {PIString r; ba >> r; return r;}
|
||||
case PIVariant::pivStringList: {PIStringList r; ba >> r; if (r.isEmpty()) return PIString(); return r.join(";");}
|
||||
case PIVariant::pivEnum: {PIVariantTypes::Enum r; ba >> r; return r.selectedName();}
|
||||
case PIVariant::pivFile: {PIVariantTypes::File r; ba >> r; return r.file;}
|
||||
case PIVariant::pivDir: {PIVariantTypes::Dir r; ba >> r; return r.dir;}
|
||||
case PIVariant::pivColor: {PIVariantTypes::Color r; ba >> r; return r.toName();}
|
||||
case PIVariant::pivIODevice: {PIVariantTypes::IODevice r; ba >> r; return "IODevice";} // TODO
|
||||
case PIVariant::pivPoint: {PIPointd r; ba >> r; return PIString::fromNumber(r.x) + ";" + PIString::fromNumber(r.y);} break;
|
||||
case PIVariant::pivRect: {PIRectd r; ba >> r; return PIString::fromNumber(r.left()) + ";" + PIString::fromNumber(r.bottom()) + ";" + PIString::fromNumber(r.width()) + ";" + PIString::fromNumber(r.height());} break;
|
||||
case PIVariant::pivLine: {PILined r; ba >> r; return PIString::fromNumber(r.p0.x) + ";" + PIString::fromNumber(r.p0.y) + ";" + PIString::fromNumber(r.p1.x) + ";" + PIString::fromNumber(r.p1.y);} break;
|
||||
case PIVariant::pivBool: {
|
||||
bool r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivChar: {
|
||||
char r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivUChar: {
|
||||
uchar r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivShort: {
|
||||
short r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivUShort: {
|
||||
ushort r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivInt: {
|
||||
int r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivUInt: {
|
||||
uint r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivLLong: {
|
||||
llong r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivULLong: {
|
||||
ullong r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivFloat: {
|
||||
float r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivDouble: {
|
||||
double r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivLDouble: {
|
||||
ldouble r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivTime: {
|
||||
PITime r;
|
||||
ba >> r;
|
||||
return r.toString();
|
||||
}
|
||||
case PIVariant::pivDate: {
|
||||
PIDate r;
|
||||
ba >> r;
|
||||
return r.toString();
|
||||
}
|
||||
case PIVariant::pivDateTime: {
|
||||
PIDateTime r;
|
||||
ba >> r;
|
||||
return r.toString();
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivStringList: {
|
||||
PIStringList r;
|
||||
ba >> r;
|
||||
if (r.isEmpty()) return PIString();
|
||||
return r.join(";");
|
||||
}
|
||||
case PIVariant::pivEnum: {
|
||||
PIVariantTypes::Enum r;
|
||||
ba >> r;
|
||||
return r.toString();
|
||||
}
|
||||
case PIVariant::pivFile: {
|
||||
PIVariantTypes::File r;
|
||||
ba >> r;
|
||||
return r.file;
|
||||
}
|
||||
case PIVariant::pivDir: {
|
||||
PIVariantTypes::Dir r;
|
||||
ba >> r;
|
||||
return r.dir;
|
||||
}
|
||||
case PIVariant::pivColor: {
|
||||
PIVariantTypes::Color r;
|
||||
ba >> r;
|
||||
return r.toName();
|
||||
}
|
||||
case PIVariant::pivIODevice: {
|
||||
PIVariantTypes::IODevice r;
|
||||
ba >> r;
|
||||
return "IODevice";
|
||||
} // TODO
|
||||
case PIVariant::pivPoint: {
|
||||
PIPointd r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r.x) + ";" + PIString::fromNumber(r.y);
|
||||
} break;
|
||||
case PIVariant::pivRect: {
|
||||
PIRectd r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r.left()) + ";" + PIString::fromNumber(r.bottom()) + ";" + PIString::fromNumber(r.width()) + ";" +
|
||||
PIString::fromNumber(r.height());
|
||||
} break;
|
||||
case PIVariant::pivLine: {
|
||||
PILined r;
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r.p0.x) + ";" + PIString::fromNumber(r.p0.y) + ";" + PIString::fromNumber(r.p1.x) + ";" +
|
||||
PIString::fromNumber(r.p1.y);
|
||||
} break;
|
||||
case PIVariant::pivCustom: return getAsValue<PIString>(*this);
|
||||
default: break;
|
||||
}
|
||||
@@ -849,9 +1449,19 @@ PIString PIVariant::toString() const {
|
||||
//!
|
||||
PIStringList PIVariant::toStringList() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivStringList) {PIStringList r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivEnum) {PIVariantTypes::Enum r; ba >> r; return r.names();}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PIStringList>(*this);}
|
||||
if (_type == PIVariant::pivStringList) {
|
||||
PIStringList r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivEnum) {
|
||||
PIVariantTypes::Enum r;
|
||||
ba >> r;
|
||||
return r.names();
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PIStringList>(*this);
|
||||
}
|
||||
return PIStringList(toString());
|
||||
}
|
||||
|
||||
@@ -871,8 +1481,14 @@ PIStringList PIVariant::toStringList() const {
|
||||
//!
|
||||
PIBitArray PIVariant::toBitArray() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivBitArray) {PIBitArray r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PIBitArray>(*this);}
|
||||
if (_type == PIVariant::pivBitArray) {
|
||||
PIBitArray r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PIBitArray>(*this);
|
||||
}
|
||||
return PIBitArray(ullong(toLLong()));
|
||||
}
|
||||
|
||||
@@ -892,8 +1508,14 @@ PIBitArray PIVariant::toBitArray() const {
|
||||
//!
|
||||
PIByteArray PIVariant::toByteArray() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivByteArray) {PIByteArray r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PIByteArray>(*this);}
|
||||
if (_type == PIVariant::pivByteArray) {
|
||||
PIByteArray r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PIByteArray>(*this);
|
||||
}
|
||||
return PIByteArray();
|
||||
}
|
||||
|
||||
@@ -917,10 +1539,26 @@ PIByteArray PIVariant::toByteArray() const {
|
||||
//!
|
||||
PIVariantTypes::Enum PIVariant::toEnum() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivEnum) {PIVariantTypes::Enum r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivString) {PIString v; ba >> v; PIVariantTypes::Enum r; r << v; return r;}
|
||||
if (_type == PIVariant::pivStringList) {PIStringList v; ba >> v; PIVariantTypes::Enum r; r << v; return r;}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PIVariantTypes::Enum>(*this);}
|
||||
if (_type == PIVariant::pivEnum) {
|
||||
PIVariantTypes::Enum r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString v;
|
||||
ba >> v;
|
||||
return PIVariantTypes::Enum::fromString(v);
|
||||
}
|
||||
if (_type == PIVariant::pivStringList) {
|
||||
PIStringList v;
|
||||
ba >> v;
|
||||
PIVariantTypes::Enum r;
|
||||
r << v;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PIVariantTypes::Enum>(*this);
|
||||
}
|
||||
return PIVariantTypes::Enum();
|
||||
}
|
||||
|
||||
@@ -942,9 +1580,21 @@ PIVariantTypes::Enum PIVariant::toEnum() const {
|
||||
//!
|
||||
PIVariantTypes::File PIVariant::toFile() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivFile) {PIVariantTypes::File r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivString) {PIString v; ba >> v; PIVariantTypes::File r; r.file = v; return r;}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PIVariantTypes::File>(*this);}
|
||||
if (_type == PIVariant::pivFile) {
|
||||
PIVariantTypes::File r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString v;
|
||||
ba >> v;
|
||||
PIVariantTypes::File r;
|
||||
r.file = v;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PIVariantTypes::File>(*this);
|
||||
}
|
||||
return PIVariantTypes::File();
|
||||
}
|
||||
|
||||
@@ -966,9 +1616,21 @@ PIVariantTypes::File PIVariant::toFile() const {
|
||||
//!
|
||||
PIVariantTypes::Dir PIVariant::toDir() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivDir) {PIVariantTypes::Dir r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivString) {PIString v; ba >> v; PIVariantTypes::Dir r; r.dir = v; return r;}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PIVariantTypes::Dir>(*this);}
|
||||
if (_type == PIVariant::pivDir) {
|
||||
PIVariantTypes::Dir r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString v;
|
||||
ba >> v;
|
||||
PIVariantTypes::Dir r;
|
||||
r.dir = v;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PIVariantTypes::Dir>(*this);
|
||||
}
|
||||
return PIVariantTypes::Dir();
|
||||
}
|
||||
|
||||
@@ -990,10 +1652,24 @@ PIVariantTypes::Dir PIVariant::toDir() const {
|
||||
//!
|
||||
PIVariantTypes::Color PIVariant::toColor() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivString) {PIString r; ba >> r; return PIVariantTypes::Color::fromString(r);}
|
||||
if (_type == PIVariant::pivColor) {PIVariantTypes::Color r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivInt) {int v; ba >> v; return PIVariantTypes::Color(v);}
|
||||
if (_type == PIVariant::pivCustom) {return getAsValue<PIVariantTypes::Color>(*this);}
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return PIVariantTypes::Color::fromString(r);
|
||||
}
|
||||
if (_type == PIVariant::pivColor) {
|
||||
PIVariantTypes::Color r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
if (_type == PIVariant::pivInt) {
|
||||
int v;
|
||||
ba >> v;
|
||||
return PIVariantTypes::Color(v);
|
||||
}
|
||||
if (_type == PIVariant::pivCustom) {
|
||||
return getAsValue<PIVariantTypes::Color>(*this);
|
||||
}
|
||||
return PIVariantTypes::Color();
|
||||
}
|
||||
|
||||
@@ -1013,7 +1689,11 @@ PIVariantTypes::Color PIVariant::toColor() const {
|
||||
//!
|
||||
PIVariantTypes::IODevice PIVariant::toIODevice() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivIODevice) {PIVariantTypes::IODevice r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivIODevice) {
|
||||
PIVariantTypes::IODevice r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
return PIVariantTypes::IODevice();
|
||||
}
|
||||
|
||||
@@ -1033,8 +1713,17 @@ PIVariantTypes::IODevice PIVariant::toIODevice() const {
|
||||
//!
|
||||
PIPointd PIVariant::toPoint() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivString) {PIString r; ba >> r; PIStringList l = r.split(';'); if (l.size() >= 2) return PIPointd(l[0].toDouble(), l[1].toDouble());}
|
||||
if (_type == PIVariant::pivPoint) {PIPointd r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
PIStringList l = r.split(';');
|
||||
if (l.size() >= 2) return PIPointd(l[0].toDouble(), l[1].toDouble());
|
||||
}
|
||||
if (_type == PIVariant::pivPoint) {
|
||||
PIPointd r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
return PIPointd();
|
||||
}
|
||||
|
||||
@@ -1054,8 +1743,17 @@ PIPointd PIVariant::toPoint() const {
|
||||
//!
|
||||
PIRectd PIVariant::toRect() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivString) {PIString r; ba >> r; PIStringList l = r.split(';'); if (l.size() >= 4) return PIRectd(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble());}
|
||||
if (_type == PIVariant::pivRect) {PIRectd r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
PIStringList l = r.split(';');
|
||||
if (l.size() >= 4) return PIRectd(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble());
|
||||
}
|
||||
if (_type == PIVariant::pivRect) {
|
||||
PIRectd r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
return PIRectd();
|
||||
}
|
||||
|
||||
@@ -1075,8 +1773,17 @@ PIRectd PIVariant::toRect() const {
|
||||
//!
|
||||
PILined PIVariant::toLine() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivString) {PIString r; ba >> r; PIStringList l = r.split(';'); if (l.size() >= 4) return PILined(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble());}
|
||||
if (_type == PIVariant::pivLine) {PILined r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
PIStringList l = r.split(';');
|
||||
if (l.size() >= 4) return PILined(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble());
|
||||
}
|
||||
if (_type == PIVariant::pivLine) {
|
||||
PILined r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
return PILined();
|
||||
}
|
||||
|
||||
@@ -1096,7 +1803,11 @@ PILined PIVariant::toLine() const {
|
||||
//!
|
||||
PIMathVectord PIVariant::toMathVector() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivMathVector) {PIMathVectord r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivMathVector) {
|
||||
PIMathVectord r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
return PIMathVectord();
|
||||
}
|
||||
|
||||
@@ -1116,7 +1827,10 @@ PIMathVectord PIVariant::toMathVector() const {
|
||||
//!
|
||||
PIMathMatrixd PIVariant::toMathMatrix() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivMathMatrix) {PIMathMatrixd r; ba >> r; return r;}
|
||||
if (_type == PIVariant::pivMathMatrix) {
|
||||
PIMathMatrixd r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
return PIMathMatrixd();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,13 @@
|
||||
#ifndef PIVARIANT_H
|
||||
#define PIVARIANT_H
|
||||
|
||||
#include "pivarianttypes.h"
|
||||
#include "piconstchars.h"
|
||||
#include "pitime.h"
|
||||
#include "pigeometry.h"
|
||||
#include "pidatetime.h"
|
||||
#include "piline.h"
|
||||
#include "pimathmatrix.h"
|
||||
#include "pipoint.h"
|
||||
#include "pirect.h"
|
||||
#include "pivarianttypes.h"
|
||||
|
||||
|
||||
#ifdef DOXYGEN
|
||||
@@ -64,8 +66,14 @@ public:
|
||||
static uint typeIDHelper() { return 0; }
|
||||
|
||||
static bool isSimpleHelper() { return false; }
|
||||
template<typename C> static PIByteArray castHelper(PIByteArray ba) {return PIByteArray();}
|
||||
template<typename C> static C castVariant(const T & v) {return C();}
|
||||
template<typename C>
|
||||
static PIByteArray castHelper(PIByteArray ba) {
|
||||
return PIByteArray();
|
||||
}
|
||||
template<typename C>
|
||||
static C castVariant(const T & v) {
|
||||
return C();
|
||||
}
|
||||
};
|
||||
|
||||
struct PIP_EXPORT __PIVariantInfo__ {
|
||||
@@ -93,7 +101,8 @@ struct __PIVariantTypeInfo__ {
|
||||
};
|
||||
|
||||
# define __TYPEINFO_SINGLE(PT, T) \
|
||||
template<> struct __PIVariantTypeInfo__<T> { \
|
||||
template<> \
|
||||
struct __PIVariantTypeInfo__<T> { \
|
||||
typedef PT PureType; \
|
||||
typedef const PT ConstPureType; \
|
||||
typedef PT * PointerType; \
|
||||
@@ -110,46 +119,68 @@ struct __PIVariantTypeInfo__ {
|
||||
|
||||
class PIP_EXPORT __PIVariantInfoStorage__ {
|
||||
public:
|
||||
__PIVariantInfoStorage__() {if (!map) map = new PIMap<uint, __PIVariantInfo__ * >();}
|
||||
static __PIVariantInfoStorage__ * get() {static __PIVariantInfoStorage__ * r = new __PIVariantInfoStorage__(); return r;}
|
||||
__PIVariantInfoStorage__() {
|
||||
if (!map) map = new PIMap<uint, __PIVariantInfo__ *>();
|
||||
}
|
||||
static __PIVariantInfoStorage__ * get() {
|
||||
static __PIVariantInfoStorage__ * r = new __PIVariantInfoStorage__();
|
||||
return r;
|
||||
}
|
||||
static PIMap<uint, __PIVariantInfo__ *> * map;
|
||||
};
|
||||
|
||||
|
||||
# define REGISTER_VARIANT(classname) \
|
||||
template<> inline PIString __PIVariantFunctions__< classname >::typeNameHelper() {static PIString tn = PIStringAscii(#classname); return tn;} \
|
||||
template<> inline uint __PIVariantFunctions__< classname >::typeIDHelper() {static uint ret = PIStringAscii(#classname).hash(); return ret;} \
|
||||
template<> \
|
||||
inline PIString __PIVariantFunctions__<classname>::typeNameHelper() { \
|
||||
static PIString tn = PIStringAscii(#classname); \
|
||||
return tn; \
|
||||
} \
|
||||
template<> \
|
||||
inline uint __PIVariantFunctions__<classname>::typeIDHelper() { \
|
||||
static uint ret = PIStringAscii(#classname).hash(); \
|
||||
return ret; \
|
||||
} \
|
||||
REGISTER_VARIANT_TYPEINFO(classname) \
|
||||
STATIC_INITIALIZER_BEGIN \
|
||||
uint type_id = __PIVariantFunctions__<classname>::typeIDHelper(); \
|
||||
PIString type_name = __PIVariantFunctions__<classname>::typeNameHelper(); \
|
||||
if (__PIVariantInfoStorage__::get()->map->contains(type_id)) return; \
|
||||
PIByteArray empty; empty << classname(); \
|
||||
PIByteArray empty; \
|
||||
empty << classname(); \
|
||||
(*(__PIVariantInfoStorage__::get()->map))[type_id] = new __PIVariantInfo__(type_name, empty); \
|
||||
STATIC_INITIALIZER_END
|
||||
|
||||
|
||||
# define REGISTER_VARIANT_CAST_H(classname_from, classname_to) \
|
||||
template<> template<> inline \
|
||||
classname_to __PIVariantFunctions__<classname_from>::castVariant<classname_to>(const classname_from & v);
|
||||
template<> \
|
||||
template<> \
|
||||
inline classname_to __PIVariantFunctions__<classname_from>::castVariant<classname_to>(const classname_from & v);
|
||||
|
||||
# define REGISTER_VARIANT_CAST_CPP(classname_from, classname_to) \
|
||||
template<> template<> inline \
|
||||
PIByteArray __PIVariantFunctions__<classname_from>::castHelper<classname_to>(PIByteArray v) { \
|
||||
classname_from f; v >> f; \
|
||||
template<> \
|
||||
template<> \
|
||||
inline PIByteArray __PIVariantFunctions__<classname_from>::castHelper<classname_to>(PIByteArray v) { \
|
||||
classname_from f; \
|
||||
v >> f; \
|
||||
classname_to t = __PIVariantFunctions__<classname_from>::castVariant<classname_to>(f); \
|
||||
PIByteArray ret; ret << t; \
|
||||
PIByteArray ret; \
|
||||
ret << t; \
|
||||
return ret; \
|
||||
} \
|
||||
STATIC_INITIALIZER_BEGIN \
|
||||
__PIVariantInfo__ * vi(__PIVariantInfoStorage__::get()->map->value(__PIVariantFunctions__< classname_from >::typeIDHelper(), nullptr)); \
|
||||
__PIVariantInfo__ * vi( \
|
||||
__PIVariantInfoStorage__::get()->map->value(__PIVariantFunctions__<classname_from>::typeIDHelper(), nullptr)); \
|
||||
if (!vi) { \
|
||||
piCout << "Warning! Using REGISTER_VARIANT_CAST("#classname_from", "#classname_to") before REGISTER_VARIANT("#classname_from"), ignore."; \
|
||||
piCout << "Warning! Using REGISTER_VARIANT_CAST(" #classname_from ", " #classname_to \
|
||||
") before REGISTER_VARIANT(" #classname_from "), ignore."; \
|
||||
return; \
|
||||
} \
|
||||
vi->cast[__PIVariantFunctions__< classname_to >::typeIDHelper()] = __PIVariantFunctions__<classname_from>::castHelper<classname_to>; \
|
||||
vi->cast[__PIVariantFunctions__<classname_to>::typeIDHelper()] = \
|
||||
__PIVariantFunctions__<classname_from>::castHelper<classname_to>; \
|
||||
STATIC_INITIALIZER_END \
|
||||
template<> template<> \
|
||||
template<> \
|
||||
template<> \
|
||||
classname_to __PIVariantFunctions__<classname_from>::castVariant<classname_to>(const classname_from & v)
|
||||
|
||||
# define REGISTER_VARIANT_CAST(classname_from, classname_to) \
|
||||
@@ -157,9 +188,15 @@ public:
|
||||
REGISTER_VARIANT_CAST_CPP(classname_from, classname_to)
|
||||
|
||||
|
||||
#define REGISTER_VARIANT_CAST_SIMPLE(classname_from, classname_to) REGISTER_VARIANT_CAST(classname_from, classname_to) {return classname_to(v);}
|
||||
# define REGISTER_VARIANT_CAST_SIMPLE(classname_from, classname_to) \
|
||||
REGISTER_VARIANT_CAST(classname_from, classname_to) { \
|
||||
return classname_to(v); \
|
||||
}
|
||||
# define REGISTER_VARIANT_CAST_SIMPLE_H(classname_from, classname_to) REGISTER_VARIANT_CAST_H(classname_from, classname_to)
|
||||
#define REGISTER_VARIANT_CAST_SIMPLE_CPP(classname_from, classname_to) REGISTER_VARIANT_CAST_CPP(classname_from, classname_to) {return classname_to(v);}
|
||||
# define REGISTER_VARIANT_CAST_SIMPLE_CPP(classname_from, classname_to) \
|
||||
REGISTER_VARIANT_CAST_CPP(classname_from, classname_to) { \
|
||||
return classname_to(v); \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -188,12 +225,14 @@ public:
|
||||
class PIP_EXPORT PIVariant {
|
||||
friend PICout operator<<(PICout s, const PIVariant & v);
|
||||
BINARY_STREAM_FRIEND(PIVariant);
|
||||
public:
|
||||
|
||||
public:
|
||||
//! \~english Type of %PIVariant content
|
||||
//! \~russian Тип содержимого %PIVariant
|
||||
enum Type {
|
||||
pivInvalid /** \~english Invalid type, default type of empty contructor \~russian Недействительный тип, также конструированный по умолчанию */ = 0 ,
|
||||
pivInvalid /** \~english Invalid type, default type of empty contructor \~russian Недействительный тип, также конструированный по
|
||||
умолчанию */
|
||||
= 0,
|
||||
pivBool /** bool */,
|
||||
pivChar /** char */,
|
||||
pivUChar /** uchar */,
|
||||
@@ -534,7 +573,9 @@ public:
|
||||
//! Для стандартных типов эквиваленстно методу \a to<Type>. \n
|
||||
//! Для других возвращает тип T только если он был установлен ранее.
|
||||
template<typename T>
|
||||
T value() const {return getAsValue<T>(*this);}
|
||||
T value() const {
|
||||
return getAsValue<T>(*this);
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
@@ -546,127 +587,220 @@ public:
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const char * v) {setValue(PIString(v)); return *this;}
|
||||
PIVariant & operator=(const char * v) {
|
||||
setValue(PIString(v));
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const bool v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const bool v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const char v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const char v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const uchar v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const uchar v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const short v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const short v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const ushort v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const ushort v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const int & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const int & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const uint & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const uint & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const llong & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const llong & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const ullong & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const ullong & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const float & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const float & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const double & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const double & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const ldouble & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const ldouble & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIBitArray & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIBitArray & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIByteArray & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIByteArray & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIString & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIString & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIStringList & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIStringList & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PITime & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PITime & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIDate & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIDate & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIDateTime & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIDateTime & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PISystemTime & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PISystemTime & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIVariantTypes::Enum & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIVariantTypes::Enum & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIVariantTypes::File & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIVariantTypes::File & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIVariantTypes::Dir & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIVariantTypes::Dir & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIVariantTypes::Color & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIVariantTypes::Color & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIVariantTypes::IODevice & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIVariantTypes::IODevice & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIPointd & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIPointd & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIRectd & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIRectd & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PILined & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PILined & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIMathVectord & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIMathVectord & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator =(const PIMathMatrixd & v) {setValue(v); return *this;}
|
||||
PIVariant & operator=(const PIMathMatrixd & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//! \~english Compare operator. Check type and content.
|
||||
@@ -773,10 +907,20 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
//! \~english Returns all registered type ID.
|
||||
//! \~russian Возвращает все зарегистрированные ID типов.
|
||||
static PIVector<uint> knownTypeIDs();
|
||||
|
||||
static int knownTypeIDsCount();
|
||||
|
||||
private:
|
||||
void destroy() { _content.clear(); }
|
||||
template <typename T> inline static Type getType() {return pivCustom;}
|
||||
template <typename T> inline void initType(const T & v) {
|
||||
template<typename T>
|
||||
inline static Type getType() {
|
||||
return pivCustom;
|
||||
}
|
||||
template<typename T>
|
||||
inline void initType(const T & v) {
|
||||
_content.clear();
|
||||
_content << v;
|
||||
_type = getType<T>();
|
||||
@@ -792,7 +936,8 @@ private:
|
||||
_info = 0;
|
||||
#endif
|
||||
}
|
||||
template<typename T> inline static T getAsValue(const PIVariant & v) {
|
||||
template<typename T>
|
||||
inline static T getAsValue(const PIVariant & v) {
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
if (v._content.isEmpty() || !v._info) return T();
|
||||
uint cnid = __PIVariantFunctions__<T>::typeIDHelper();
|
||||
@@ -806,7 +951,8 @@ private:
|
||||
if (!cf) return T();
|
||||
ba = cf(v._content);
|
||||
}
|
||||
T ret; ba >> ret;
|
||||
T ret;
|
||||
ba >> ret;
|
||||
return ret;
|
||||
#else
|
||||
return T();
|
||||
@@ -819,12 +965,12 @@ private:
|
||||
__PIVariantInfo__ * _info = nullptr;
|
||||
#endif
|
||||
uint _typeID = 0;
|
||||
|
||||
};
|
||||
|
||||
typedef PIMap<PIString, PIVariant> PIVariantMap;
|
||||
typedef PIVector<PIVariant> PIVariantVector;
|
||||
|
||||
// clang-format off
|
||||
template<> inline bool PIVariant::value() const {return toBool();}
|
||||
template<> inline char PIVariant::value() const {return (char)toInt();}
|
||||
template<> inline uchar PIVariant::value() const {return (uchar)toInt();}
|
||||
@@ -918,6 +1064,7 @@ template<> inline PIVariant::Type PIVariant::getType<PIRectd>() {return PIVarian
|
||||
template<> inline PIVariant::Type PIVariant::getType<PILined>() {return PIVariant::pivLine;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIMathVectord>() {return PIVariant::pivMathVector;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIMathMatrixd>() {return PIVariant::pivMathMatrix;}
|
||||
// clang-format on
|
||||
|
||||
REGISTER_VARIANT(bool)
|
||||
REGISTER_VARIANT(char)
|
||||
@@ -994,12 +1141,13 @@ BINARY_STREAM_READ(PIVariant) {
|
||||
//! \~english Output operator to \a PICout
|
||||
//! \~russian Оператор вывода в \a PICout
|
||||
inline PICout operator<<(PICout s, const PIVariant & v) {
|
||||
s.space(); s.saveAndSetControls(0);
|
||||
s.space();
|
||||
s.saveAndSetControls(0);
|
||||
s << "PIVariant(" << v.typeName();
|
||||
if (v.isValid())
|
||||
s << ", " << v.toString();
|
||||
if (v.isValid()) s << ", " << v.toString();
|
||||
s << ")";
|
||||
s.restoreControls(); return s;
|
||||
s.restoreControls();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
*/
|
||||
|
||||
#include "pivarianttypes.h"
|
||||
#include "pipropertystorage.h"
|
||||
|
||||
#include "colors_p.h"
|
||||
#include "pipropertystorage.h"
|
||||
#ifndef MICRO_PIP
|
||||
# include "piiodevice.h"
|
||||
#endif
|
||||
@@ -27,8 +28,7 @@
|
||||
|
||||
int PIVariantTypes::Enum::selectedValue() const {
|
||||
for (const auto & e: enum_list)
|
||||
if (e.name == selected)
|
||||
return e.value;
|
||||
if (e.name == selected) return e.value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -55,16 +55,14 @@ bool PIVariantTypes::Enum::selectName(const PIString & n) {
|
||||
|
||||
int PIVariantTypes::Enum::value(const PIString & n) const {
|
||||
for (const auto & e: enum_list)
|
||||
if (e.name == n)
|
||||
return e.value;
|
||||
if (e.name == n) return e.value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
PIString PIVariantTypes::Enum::name(int v) const {
|
||||
for (const auto & e: enum_list)
|
||||
if (e.value == v)
|
||||
return e.name;
|
||||
if (e.value == v) return e.name;
|
||||
return PIString();
|
||||
}
|
||||
|
||||
@@ -85,7 +83,6 @@ PIStringList PIVariantTypes::Enum::names() const {
|
||||
}
|
||||
|
||||
|
||||
|
||||
PIVariantTypes::IODevice::IODevice() {
|
||||
#ifndef MICRO_PIP
|
||||
mode = PIIODevice::ReadWrite;
|
||||
@@ -114,16 +111,20 @@ PIString PIVariantTypes::IODevice::toPICout() const {
|
||||
PIString s;
|
||||
s += "IODevice(" + prefix + ", mode=";
|
||||
int rwc = 0;
|
||||
if (mode & 1) {s += "r"; ++rwc;}
|
||||
if (mode & 2) {s += "w"; ++rwc;}
|
||||
if (mode & 1) {
|
||||
s += "r";
|
||||
++rwc;
|
||||
}
|
||||
if (mode & 2) {
|
||||
s += "w";
|
||||
++rwc;
|
||||
}
|
||||
if (rwc == 1) s += "o";
|
||||
s += ", flags=";
|
||||
#ifndef MICRO_PIP // TODO: PIIODevice for MICRO PIP
|
||||
if (options != 0) {
|
||||
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingRead])
|
||||
s += " br";
|
||||
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingWrite])
|
||||
s += " bw";
|
||||
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingRead]) s += " br";
|
||||
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingWrite]) s += " bw";
|
||||
}
|
||||
#endif // MICRO_PIP
|
||||
PIPropertyStorage ps = get();
|
||||
@@ -135,13 +136,53 @@ PIString PIVariantTypes::IODevice::toPICout() const {
|
||||
}
|
||||
|
||||
|
||||
|
||||
PIVariantTypes::Enum & PIVariantTypes::Enum::operator<<(const PIVariantTypes::Enumerator & v) {
|
||||
enum_list << v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIString PIVariantTypes::Enum::toString() {
|
||||
static PIString masks = "\"";
|
||||
PIString ret;
|
||||
ret += "\"" + enum_name.masked(masks) + "\":(";
|
||||
bool comma = false;
|
||||
for (const auto & i: enum_list) {
|
||||
if (comma) ret += ';';
|
||||
comma = true;
|
||||
ret += "\"" + i.name.masked(masks) + "\":";
|
||||
ret += PIString::fromNumber(i.value);
|
||||
}
|
||||
ret += "):" + PIString::fromNumber(selectedValue());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIVariantTypes::Enum PIVariantTypes::Enum::fromString(PIString str) {
|
||||
static PIString masks = "\"";
|
||||
Enum ret;
|
||||
if (str.size() < 3) return ret;
|
||||
ret.enum_name = str.takeRange('"', '"').unmask(masks);
|
||||
str.trim();
|
||||
if (str.startsWith(":")) str.cutLeft(1).trim();
|
||||
PIString el = str.takeRange('(', ')');
|
||||
while (el.isNotEmpty()) {
|
||||
Enumerator e;
|
||||
e.name = el.takeRange('"', '"').unmask(masks);
|
||||
el.trim();
|
||||
if (el.startsWith(":")) el.cutLeft(1).trim();
|
||||
e.value = el.takeInteger().toInt();
|
||||
el.trim();
|
||||
if (el.startsWith(";")) el.cutLeft(1).trim();
|
||||
ret.enum_list << e;
|
||||
}
|
||||
str.trim();
|
||||
if (str.startsWith(":")) str.cutLeft(1).trim();
|
||||
ret.selectValue(str.toInt());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIVariantTypes::Enum & PIVariantTypes::Enum::operator<<(const PIString & v) {
|
||||
if (enum_list.isEmpty()) {
|
||||
enum_list << Enumerator(0, v);
|
||||
@@ -159,7 +200,6 @@ PIVariantTypes::Enum & PIVariantTypes::Enum::operator <<(const PIStringList & v)
|
||||
}
|
||||
|
||||
|
||||
|
||||
PIVariantTypes::Color PIVariantTypes::Color::fromString(const PIString & str) {
|
||||
if (str.size_s() < 2) return Color();
|
||||
PIString cn = str.toLowerCase().trim();
|
||||
|
||||
@@ -150,6 +150,14 @@ struct PIP_EXPORT Enum {
|
||||
//! \~russian Возвращает пустой ли Enum.
|
||||
bool isEmpty() const {return enum_list.isEmpty();}
|
||||
|
||||
//! \~english Returns string full representation.
|
||||
//! \~russian Возвращает полное строковое представление.
|
||||
PIString toString();
|
||||
|
||||
//! \~english Returns Enum from string full representation.
|
||||
//! \~russian Возвращает Enum из полного строкового представления.
|
||||
static Enum fromString(PIString str);
|
||||
|
||||
|
||||
//! \~english Name of Enum.
|
||||
//! \~russian Имя Enum.
|
||||
|
||||
18
main.cpp
18
main.cpp
@@ -59,14 +59,16 @@ int main(int argc, char * argv[]) {
|
||||
v.setValueFromString("0xFF00FFff");
|
||||
piCout << v;*/
|
||||
|
||||
PIJSON j;
|
||||
j["123"] = "str";
|
||||
j[PIString::fromUTF8("ключ")] = PIString::fromUTF8("str_значение");
|
||||
piCout << j;
|
||||
piCout << PIJSON::fromJSON(j.toJSON(PIJSON::Compact, true));
|
||||
piCout << PIJSON::fromJSON(j.toJSON(PIJSON::Compact, false));
|
||||
piCout << PIJSON::fromJSON(j.toJSON(PIJSON::Tree, true));
|
||||
piCout << PIJSON::fromJSON(j.toJSON(PIJSON::Tree, false));
|
||||
PIVariantTypes::Enum e;
|
||||
e.enum_name = "MyEnum";
|
||||
e << PIVariantTypes::Enumerator(10105, "Null")
|
||||
<< PIVariantTypes::Enumerator(20, "Sec")
|
||||
<< PIVariantTypes::Enumerator(100, "Fir");
|
||||
e.selectValue(20);
|
||||
|
||||
piCout << e.toString();
|
||||
piCout << PIVariantTypes::Enum::fromString(e.toString()).toString();
|
||||
piCout << PIVariantTypes::Enum::fromString("\"MyEnum\"(\"Null\":10105 \"Sec\":20 \"Fir\":100) 20").toString();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "picli.h"
|
||||
#include "picodeparser.h"
|
||||
#include "piiostream.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
@@ -102,6 +103,10 @@ void help() {
|
||||
piCout << help_string;
|
||||
}
|
||||
|
||||
void printError(const PIString & msg) {
|
||||
std::cerr << msg.data() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
PIString toCName(const PIString &s) {
|
||||
PIString ret(s.trimmed());
|
||||
@@ -231,13 +236,14 @@ void makeEnumInfo(PIIOTextStream & ts, const PICodeParser::Enum * e) {
|
||||
}
|
||||
|
||||
|
||||
void writeClassStreamMembersOut(PIIOTextStream & ts, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
bool writeClassStreamMembersOut(PIIOTextStream & ts, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
for (const PICodeParser::Member & m: e->members) {
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
ml << m;
|
||||
}
|
||||
bool is_union = e->type == "union";
|
||||
PISet<int> used_id;
|
||||
for (const PICodeParser::Member & m: ml) {
|
||||
if (is_union && m.isBitfield())
|
||||
continue;
|
||||
@@ -245,6 +251,10 @@ void writeClassStreamMembersOut(PIIOTextStream & ts, const PICodeParser::Entity
|
||||
++cnt;
|
||||
if (m.meta.contains("id"))
|
||||
cnt = m.meta.value("id").toInt();
|
||||
if (used_id[cnt]) {
|
||||
printError("Error with \"" + e->name + "\" stream operator: ID " + PIString::fromNumber(cnt) + " already used");
|
||||
return false;
|
||||
}
|
||||
if (m.dims.isEmpty()) {
|
||||
if (simple) {
|
||||
ts << "\ts << ";
|
||||
@@ -275,21 +285,23 @@ void writeClassStreamMembersOut(PIIOTextStream & ts, const PICodeParser::Entity
|
||||
if (is_union)
|
||||
break;
|
||||
}
|
||||
if (is_union) return;
|
||||
if (is_union) return true;
|
||||
for (const PICodeParser::Entity * ce: e->children) {
|
||||
if (ce->has_name) continue;
|
||||
writeClassStreamMembersOut(ts, ce, cnt, simple);
|
||||
if (!writeClassStreamMembersOut(ts, ce, cnt, simple)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
bool writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
for (const PICodeParser::Member & m: e->members) {
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
ml << m;
|
||||
}
|
||||
bool is_union = e->type == "union";
|
||||
PISet<int> used_id;
|
||||
for (const PICodeParser::Member & m: ml) {
|
||||
if (is_union && m.isBitfield())
|
||||
continue;
|
||||
@@ -297,6 +309,11 @@ void writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity *
|
||||
++cnt;
|
||||
if (m.meta.contains("id"))
|
||||
cnt = m.meta.value("id").toInt();
|
||||
if (used_id[cnt]) {
|
||||
printError("Error with \"" + e->name + "\" stream operator: ID " + PIString::fromNumber(cnt) + " already used");
|
||||
return false;
|
||||
}
|
||||
used_id << cnt;
|
||||
if (m.dims.isEmpty()) {
|
||||
bool is_enum = parser.isEnum(m.type);
|
||||
if (simple) {
|
||||
@@ -339,11 +356,12 @@ void writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity *
|
||||
if (is_union)
|
||||
break;
|
||||
}
|
||||
if (is_union) return;
|
||||
if (is_union) return true;
|
||||
for (const PICodeParser::Entity * ce: e->children) {
|
||||
if (ce->has_name) continue;
|
||||
writeClassStreamMembersIn(ts, ce, cnt, simple);
|
||||
if (!writeClassStreamMembersIn(ts, ce, cnt, simple)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -359,14 +377,14 @@ bool needClassStream(const PICodeParser::Entity * e) {
|
||||
}
|
||||
|
||||
|
||||
void makeClassStream(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
bool makeClassStream(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return true;
|
||||
bool simple = e->meta.contains("simple-stream");
|
||||
ts << "\nBINARY_STREAM_WRITE(" << e->name << ") {\n";
|
||||
if (!simple)
|
||||
ts << "\tPIChunkStream cs;\n";
|
||||
int cnt = 0;
|
||||
writeClassStreamMembersOut(ts, e, cnt, simple);
|
||||
if (!writeClassStreamMembersOut(ts, e, cnt, simple)) return false;
|
||||
if (!simple)
|
||||
ts << "\ts << cs.data();\n";
|
||||
ts << "\treturn s;\n}\n";
|
||||
@@ -379,10 +397,11 @@ void makeClassStream(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
ts << "\t\tswitch (cs.read()) {\n";
|
||||
}
|
||||
cnt = 0;
|
||||
writeClassStreamMembersIn(ts, e, cnt, simple);
|
||||
if (!writeClassStreamMembersIn(ts, e, cnt, simple)) return false;
|
||||
if (!simple)
|
||||
ts << "\t\t}\n\t}\n";
|
||||
ts << "\treturn s;\n}\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -507,7 +526,8 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
for (const PICodeParser::Entity * e: parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI") ||
|
||||
!(e->visibility == PICodeParser::Global || e->visibility == PICodeParser::Public)) continue;
|
||||
makeClassStream(ts, e);
|
||||
if (!makeClassStream(ts, e))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (meta || enums || getters) {
|
||||
|
||||
Reference in New Issue
Block a user