Merge remote-tracking branch 'origin/master' into concurrent
# Conflicts: # lib/main/thread/pithreadpoolexecutor.cpp # lib/main/thread/pithreadpoolexecutor.h # tests/concurrent/ExecutorIntegrationTest.cpp # tests/concurrent/ExecutorUnitTest.cpp # tests/concurrent/testutil.h
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
add_executable(piterminal "main.cpp")
|
||||
target_link_libraries(piterminal pip pip_console)
|
||||
if (DEFINED LIB)
|
||||
install(TARGETS piterminal DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
endif ()
|
||||
@@ -1,280 +0,0 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Terminal client for windows, used by PITerminal and pisd
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
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"
|
||||
#ifndef WINDOWS
|
||||
int main (int argc, char * argv[]) {
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
# include "piscreentypes.h"
|
||||
# include "pisharedmemory.h"
|
||||
# include "../../lib/console/piterminal.cpp"
|
||||
# include "pifile.h"
|
||||
# include <wincon.h>
|
||||
|
||||
|
||||
PIVector<PIVector<PIScreenTypes::Cell> > cells;
|
||||
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||
CHAR_INFO * chars = 0;
|
||||
HANDLE console = 0, cstdin = 0, pipe = 0, cmd_proc = 0;
|
||||
PITerminalAuxData data_out;
|
||||
PIMutex con_mutex;
|
||||
int con_w = -1, con_h = -1;
|
||||
|
||||
|
||||
PIScreenTypes::Cell CharInfo2Cell(const CHAR_INFO & c) {
|
||||
PIScreenTypes::Cell ret;
|
||||
ret.symbol = PIChar::fromConsole(c.Char.AsciiChar);
|
||||
ret.format.color_char = PIScreenTypes::Black;
|
||||
if ((c.Attributes & (FOREGROUND_RED)) == FOREGROUND_RED) ret.format.color_char = PIScreenTypes::Red;
|
||||
if ((c.Attributes & (FOREGROUND_GREEN)) == FOREGROUND_GREEN) ret.format.color_char = PIScreenTypes::Green;
|
||||
if ((c.Attributes & (FOREGROUND_BLUE)) == FOREGROUND_BLUE) ret.format.color_char = PIScreenTypes::Blue;
|
||||
if ((c.Attributes & (FOREGROUND_GREEN | FOREGROUND_BLUE)) == (FOREGROUND_GREEN | FOREGROUND_BLUE)) ret.format.color_char = PIScreenTypes::Cyan;
|
||||
if ((c.Attributes & (FOREGROUND_RED | FOREGROUND_BLUE)) == (FOREGROUND_RED | FOREGROUND_BLUE)) ret.format.color_char = PIScreenTypes::Magenta;
|
||||
if ((c.Attributes & (FOREGROUND_RED | FOREGROUND_GREEN)) == (FOREGROUND_RED | FOREGROUND_GREEN)) ret.format.color_char = PIScreenTypes::Yellow;
|
||||
if ((c.Attributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)) == (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)) ret.format.color_char = PIScreenTypes::White;
|
||||
ret.format.color_back = PIScreenTypes::Black;
|
||||
if ((c.Attributes & (BACKGROUND_RED)) == (BACKGROUND_RED)) ret.format.color_back = PIScreenTypes::Red;
|
||||
if ((c.Attributes & (BACKGROUND_GREEN)) == (BACKGROUND_GREEN)) ret.format.color_back = PIScreenTypes::Green;
|
||||
if ((c.Attributes & (BACKGROUND_BLUE)) == (BACKGROUND_BLUE)) ret.format.color_back = PIScreenTypes::Blue;
|
||||
if ((c.Attributes & (BACKGROUND_GREEN | BACKGROUND_BLUE)) == (BACKGROUND_GREEN | BACKGROUND_BLUE)) ret.format.color_back = PIScreenTypes::Cyan;
|
||||
if ((c.Attributes & (BACKGROUND_RED | BACKGROUND_BLUE)) == (BACKGROUND_RED | BACKGROUND_BLUE)) ret.format.color_back = PIScreenTypes::Magenta;
|
||||
if ((c.Attributes & (BACKGROUND_RED | BACKGROUND_GREEN)) == (BACKGROUND_RED | BACKGROUND_GREEN)) ret.format.color_back = PIScreenTypes::Yellow;
|
||||
if ((c.Attributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)) == (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)) ret.format.color_back = PIScreenTypes::White;
|
||||
if ((c.Attributes & (FOREGROUND_INTENSITY)) > 0) ret.format.flags |= PIScreenTypes::Bold;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int SpecialKey2VirtualKeyCode(PIKbdListener::SpecialKey k) {
|
||||
switch (k) {
|
||||
case PIKbdListener::Tab : return '\t'; break;
|
||||
case PIKbdListener::Return : return '\n'; break;
|
||||
case PIKbdListener::Space : return ' '; break;
|
||||
case PIKbdListener::Backspace : return 8 ;
|
||||
case PIKbdListener::PageUp : return 33 ;
|
||||
case PIKbdListener::PageDown : return 34 ;
|
||||
case PIKbdListener::End : return 35 ;
|
||||
case PIKbdListener::Home : return 36 ;
|
||||
case PIKbdListener::LeftArrow : return 37 ;
|
||||
case PIKbdListener::UpArrow : return 38 ;
|
||||
case PIKbdListener::RightArrow: return 39 ;
|
||||
case PIKbdListener::DownArrow : return 40 ;
|
||||
case PIKbdListener::Insert : return 45 ;
|
||||
case PIKbdListener::Delete : return 46 ;
|
||||
case PIKbdListener::F1 : return 112;
|
||||
case PIKbdListener::F2 : return 113;
|
||||
case PIKbdListener::F3 : return 114;
|
||||
case PIKbdListener::F4 : return 115;
|
||||
case PIKbdListener::F5 : return 116;
|
||||
case PIKbdListener::F6 : return 117;
|
||||
case PIKbdListener::F7 : return 118;
|
||||
case PIKbdListener::F8 : return 119;
|
||||
case PIKbdListener::F9 : return 120;
|
||||
case PIKbdListener::F10 : return 121;
|
||||
case PIKbdListener::F11 : return 122;
|
||||
case PIKbdListener::F12 : return 123;
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int KeyModifiers2ControlKeyState(PIKbdListener::KeyModifiers m) {
|
||||
int ret(0);
|
||||
if (m[PIKbdListener::Ctrl]) ret |= LEFT_CTRL_PRESSED;
|
||||
if (m[PIKbdListener::Shift]) ret |= SHIFT_PRESSED;
|
||||
if (m[PIKbdListener::Alt]) ret |= LEFT_ALT_PRESSED;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void readConsole(int x, int y, int w, int h) {
|
||||
GetConsoleScreenBufferInfo(console, &sbi);
|
||||
COORD bs, bc;
|
||||
bs.X = w;
|
||||
bs.Y = h;
|
||||
bc.X = bc.Y = 0;
|
||||
memset(chars, 0, w * h * sizeof(CHAR_INFO));
|
||||
ReadConsoleOutput(console, chars, bs, bc, &(sbi.srWindow));
|
||||
for (int i = 0; i < h; ++i)
|
||||
for (int j = 0; j < w; ++j)
|
||||
cells[i][j] = CharInfo2Cell(chars[i * w + j]);
|
||||
}
|
||||
|
||||
|
||||
void resizeCells(int w, int h) {
|
||||
if (chars) delete[] chars;
|
||||
chars = new CHAR_INFO[w * h];
|
||||
cells.resize(h);
|
||||
for (int i = 0; i < h; ++i)
|
||||
cells[i].resize(w);
|
||||
}
|
||||
|
||||
|
||||
void resizeConsole(int w, int h) {
|
||||
if (con_w == w && con_h == h) return;
|
||||
con_w = w;
|
||||
con_h = h;
|
||||
GetConsoleScreenBufferInfo(console, &sbi);
|
||||
sbi.srWindow.Left = 0;
|
||||
sbi.srWindow.Right = sbi.srWindow.Left + w - 1;
|
||||
sbi.srWindow.Bottom = sbi.srWindow.Top + h - 1;
|
||||
COORD sz; sz.X = w; sz.Y = h;
|
||||
SetConsoleScreenBufferSize(console, sz);
|
||||
SetConsoleWindowInfo(console, TRUE, &(sbi.srWindow));
|
||||
//system(("mode CON: COLS=" + PIString::fromNumber(w) + " LINES=" + PIString::fromNumber(h)).dataAscii());
|
||||
resizeCells(w, h);
|
||||
}
|
||||
|
||||
|
||||
class PipeReader: public PIThread {
|
||||
public:
|
||||
PipeReader(): PIThread() {
|
||||
wrote = readed = 0;
|
||||
msg_size = 0;
|
||||
start(1);
|
||||
}
|
||||
~PipeReader() {
|
||||
stop();
|
||||
}
|
||||
void run() {
|
||||
in.resize(PIPE_BUFFER_SIZE);
|
||||
ReadFile(pipe, in.data(), in.size_s(), &readed, 0);
|
||||
if (GetLastError() == ERROR_BROKEN_PIPE) {
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
//piCout << errorString();
|
||||
if (readed > 0) {
|
||||
in.resize(readed);
|
||||
stream.append(in);
|
||||
if (msg_size == 0) {
|
||||
if (stream.size_s() < 4) return;
|
||||
stream >> msg_size;
|
||||
}
|
||||
if (stream.size_s() >= msg_size) {
|
||||
msg = PIByteArray(stream.data(), msg_size);
|
||||
stream.remove(0, msg_size);
|
||||
msg_size = 0;
|
||||
parseMessage();
|
||||
}
|
||||
if (msg_size == 0 && stream.size_s() < 4) return;
|
||||
}
|
||||
}
|
||||
void parseMessage() {
|
||||
if (msg.size_s() < 4) return;
|
||||
PIMutexLocker _ml(con_mutex);
|
||||
int type; msg >> type;
|
||||
//piCout << "msg" << type;
|
||||
switch ((PITerminalAuxMessageType)type) {
|
||||
case mtKey: {
|
||||
PIVector<PIKbdListener::KeyEvent> ke;
|
||||
msg >> ke;
|
||||
PIVector<INPUT_RECORD> ir(ke.size() * 2);
|
||||
for (int i = 0; i < ke.size_s(); ++i) {
|
||||
PIKbdListener::KeyEvent k(ke[i]);
|
||||
int j = i+i, z = j+1;
|
||||
ir[j].EventType = KEY_EVENT;
|
||||
ir[j].Event.KeyEvent.wRepeatCount = 1;
|
||||
ir[j].Event.KeyEvent.dwControlKeyState = KeyModifiers2ControlKeyState(k.modifiers);
|
||||
if (PITerminal::isSpecialKey(k.key)) {
|
||||
ir[j].Event.KeyEvent.wVirtualKeyCode = SpecialKey2VirtualKeyCode((PIKbdListener::SpecialKey)k.key);
|
||||
ir[j].Event.KeyEvent.uChar.AsciiChar = PIChar(piMaxi(k.key, 0)).toAscii();
|
||||
} else
|
||||
ir[j].Event.KeyEvent.uChar.UnicodeChar = PIChar(piMaxi(k.key, 0)).toWChar();
|
||||
//piCout << ir[j].Event.KeyEvent.wVirtualKeyCode << int(ir[j].Event.KeyEvent.uChar.AsciiChar);
|
||||
ir[j].Event.KeyEvent.bKeyDown = true;
|
||||
ir[z] = ir[j];
|
||||
ir[z].Event.KeyEvent.bKeyDown = false;
|
||||
}
|
||||
WriteConsoleInput(cstdin, ir.data(), ir.size_s(), &wrote);
|
||||
} break;
|
||||
case mtResize: {
|
||||
int rw, rh;
|
||||
msg >> rw >> rh;
|
||||
resizeConsole(rw, rh);
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
DWORD wrote, readed;
|
||||
int msg_size;
|
||||
PIByteArray in, stream, msg;
|
||||
};
|
||||
|
||||
|
||||
void getCursor(int & x, int & y) {
|
||||
GetConsoleScreenBufferInfo(console, &sbi);
|
||||
x = sbi.dwCursorPosition.X - sbi.srWindow.Left;
|
||||
y = sbi.dwCursorPosition.Y - sbi.srWindow.Top;
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
//piCout << "start";
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
memset(&si, 0, sizeof(si));
|
||||
memset(&pi, 0, sizeof(pi));
|
||||
memset(&sbi, 0, sizeof(sbi));
|
||||
PIString shmh, pname;
|
||||
if (argc > 1) shmh = argv[1];
|
||||
if (argc > 2) pname = argv[2];
|
||||
if(!CreateProcessA(0, (LPSTR)"cmd", 0, 0, true, 0, 0, 0, &si, &pi)) {
|
||||
return 1;
|
||||
}
|
||||
PISharedMemory shm("piterm_aux" + shmh, 1024*1024);
|
||||
pipe = CreateFile((LPSTR)pname.dataAscii(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
|
||||
if (pipe == INVALID_HANDLE_VALUE) {
|
||||
return 1;
|
||||
}
|
||||
CloseHandle(pi.hThread);
|
||||
cmd_proc = pi.hProcess;
|
||||
console = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
cstdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
resizeConsole(80, 24);
|
||||
PipeReader pipe_reader;
|
||||
pipe_reader.waitForStart();
|
||||
PIByteArray scr;
|
||||
while (true) {
|
||||
//piCout << "loop";
|
||||
if (!pipe_reader.isRunning()) break;
|
||||
con_mutex.lock();
|
||||
getCursor(data_out.cursor_x, data_out.cursor_y);
|
||||
readConsole(0, 0, con_w, con_h);
|
||||
scr.clear();
|
||||
scr << cells;
|
||||
data_out.size_x = con_w;
|
||||
data_out.size_y = con_h;
|
||||
data_out.cells_size = scr.size_s();
|
||||
con_mutex.unlock();
|
||||
shm.write(&data_out, sizeof(data_out));
|
||||
shm.write(scr, sizeof(data_out));
|
||||
piMSleep(25);
|
||||
}
|
||||
//piCout << "exit";
|
||||
TerminateProcess(pi.hProcess, 0);
|
||||
CloseHandle(pi.hProcess);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -23,16 +23,26 @@
|
||||
#ifndef PICCLOUDCLIENT_H
|
||||
#define PICCLOUDCLIENT_H
|
||||
|
||||
#include "pip_cloud_export.h"
|
||||
#include "piiodevice.h"
|
||||
|
||||
class PIEthernet;
|
||||
|
||||
class PIP_EXPORT PICloudClient {
|
||||
|
||||
class PIP_CLOUD_EXPORT PICloudClient : public PIIODevice
|
||||
{
|
||||
PIIODEVICE(PICloudClient)
|
||||
public:
|
||||
//!
|
||||
explicit PICloudClient();
|
||||
virtual ~PICloudClient();
|
||||
|
||||
protected:
|
||||
bool openDevice();
|
||||
bool closeDevice();
|
||||
|
||||
private:
|
||||
|
||||
PIEthernet * eth;
|
||||
};
|
||||
|
||||
#endif // PICCLOUDCLIENT_H
|
||||
|
||||
@@ -23,10 +23,11 @@
|
||||
#ifndef PICCLOUDSERVER_H
|
||||
#define PICCLOUDSERVER_H
|
||||
|
||||
#include "pip_cloud_export.h"
|
||||
#include "piiodevice.h"
|
||||
|
||||
|
||||
class PIP_EXPORT PICloudServer {
|
||||
class PIP_CLOUD_EXPORT PICloudServer {
|
||||
public:
|
||||
//!
|
||||
explicit PICloudServer();
|
||||
|
||||
@@ -23,9 +23,10 @@
|
||||
#ifndef PICCLOUDTCP_H
|
||||
#define PICCLOUDTCP_H
|
||||
|
||||
#include "pip_cloud_export.h"
|
||||
#include "pistring.h"
|
||||
|
||||
class PIP_EXPORT PICloudTCP {
|
||||
class PIP_CLOUD_EXPORT PICloudTCP {
|
||||
public:
|
||||
//!
|
||||
PICloudTCP();
|
||||
|
||||
@@ -30,7 +30,7 @@ class PIVariant;
|
||||
|
||||
namespace PICodeInfo {
|
||||
|
||||
enum PIP_EXPORT TypeFlag {
|
||||
enum TypeFlag {
|
||||
NoFlag,
|
||||
Const = 0x01,
|
||||
Static = 0x02,
|
||||
@@ -153,10 +153,10 @@ inline PICout operator <<(PICout s, const PICodeInfo::EnumInfo & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
extern PIMap<PIString, PICodeInfo::ClassInfo * > * classesInfo;
|
||||
extern PIMap<PIString, PICodeInfo::EnumInfo * > * enumsInfo;
|
||||
extern PIMap<PIString, PICodeInfo::AccessValueFunction> * accessValueFunctions;
|
||||
extern PIMap<PIString, PICodeInfo::AccessTypeFunction> * accessTypeFunctions;
|
||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::ClassInfo * > * classesInfo;
|
||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::EnumInfo * > * enumsInfo;
|
||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::AccessValueFunction> * accessValueFunctions;
|
||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::AccessTypeFunction> * accessTypeFunctions;
|
||||
|
||||
inline PIByteArray getMemberValue(const void * p, const char * class_name, const char * member_name) {
|
||||
if (!p || !class_name || !member_name || !accessValueFunctions) return PIByteArray();
|
||||
@@ -172,11 +172,11 @@ inline const char * getMemberType(const char * class_name, const char * member_n
|
||||
return af(member_name);
|
||||
}
|
||||
|
||||
PIVariant getMemberAsVariant(const void * p, const char * class_name, const char * member_name);
|
||||
PIP_EXPORT PIVariant getMemberAsVariant(const void * p, const char * class_name, const char * member_name);
|
||||
|
||||
}
|
||||
|
||||
class __PICodeInfoInitializer__ {
|
||||
class PIP_EXPORT __PICodeInfoInitializer__ {
|
||||
public:
|
||||
__PICodeInfoInitializer__() {
|
||||
if (_inited_) return;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
|
||||
PIStringList arg_vals;
|
||||
while (!args_.isEmpty()) {
|
||||
int ci = args_.find(","), bi = args_.find("(");
|
||||
int ci = args_.find(','), bi = args_.find('(');
|
||||
if (ci < 0) {
|
||||
arg_vals << args_;
|
||||
break;
|
||||
@@ -33,7 +33,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
|
||||
if (bi >= 0 && bi < ci) {
|
||||
ca = args_.left(args_.takeLeft(bi).toInt());
|
||||
ci -= ca.size_s(); bi -= ca.size_s();
|
||||
ca += "(" + args_.takeRange("(", ")") + ")";
|
||||
ca += '(' + args_.takeRange('(', ')') + ')';
|
||||
} else {
|
||||
ca = args_.takeLeft(ci);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
|
||||
args_.trim(); args_.takeLeft(1); args_.trim();
|
||||
}
|
||||
if (args.size() != arg_vals.size()) {
|
||||
piCout << ("Error: in expansion of macro \"" + name + "(" + args.join(", ") + ")\": expect")
|
||||
piCout << ("Error: in expansion of macro \"" + name + '(' + args.join(", ") + ")\": expect")
|
||||
<< args.size() << "arguments but takes" << arg_vals.size() << "!";
|
||||
if (ok != 0) *ok = false;
|
||||
return PIString();
|
||||
@@ -57,7 +57,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
|
||||
if (ind + an.size_s() < ret.size_s()) nc = ret.mid(ind + an.size_s(),1)[0];
|
||||
if (ppc != '#' && pc == '#' && !_isCChar(nc)) { // to chars
|
||||
ind--;
|
||||
ret.replace(ind, an.size_s() + 1, "\"" + av + "\"");
|
||||
ret.replace(ind, an.size_s() + 1, '\"' + av + '\"');
|
||||
ind -= an.size_s() - av.size_s() - 1;
|
||||
continue;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
|
||||
ind -= an.size_s() - av.size_s();
|
||||
}
|
||||
}
|
||||
ret.replaceAll("##", "");
|
||||
ret.replaceAll(PIStringAscii("##"), "");
|
||||
if (ok != 0) *ok = true;
|
||||
return ret;
|
||||
}
|
||||
@@ -99,42 +99,42 @@ void PICodeParser::parseFile(const PIString & file, bool follow_includes) {
|
||||
}
|
||||
piCout << "\n\nDefines:";
|
||||
piForeachC (Define & m, defines)
|
||||
piCout << "define" << m.first << m.second;
|
||||
piCout << PIStringAscii("define") << m.first << m.second;
|
||||
piCout << "\n\nMacros:";
|
||||
piForeachC (Macro & m, macros)
|
||||
piCout << "Macro:" << m.name << m.args << m.value;
|
||||
piCout << "\n\nClasses:";
|
||||
piCout << "\n\nEnums:";
|
||||
piForeachC (Enum & c, enums) {
|
||||
piCout << "enum" << c.name << c.meta;
|
||||
piCout << PIStringAscii("enum") << c.name << c.meta;
|
||||
piForeachC (EnumeratorInfo & e, c.members)
|
||||
piCout << " " << e.name << "=" << e.value << e.meta;
|
||||
piCout << " " << e.name << '=' << e.value << e.meta;
|
||||
}
|
||||
piCout << "\n\nTypedefs:";
|
||||
piForeachC (Typedef & c, typedefs)
|
||||
piCout << "typedef" << c;*/
|
||||
piCout << PIStringAscii("typedef") << c;*/
|
||||
}
|
||||
|
||||
|
||||
void PICodeParser::parseFiles(const PIStringList & files, bool follow_includes) {
|
||||
clear();
|
||||
piForeachC (PIString & f, files)
|
||||
parseFileInternal(f, follow_includes);
|
||||
parseFileInternal(f, follow_includes);
|
||||
/*piCout << "\n\nDefines:";
|
||||
piForeachC (Define & m, defines)
|
||||
piCout << "define" << m.first << m.second;
|
||||
piCout << PIStringAscii("define") << m.first << m.second;
|
||||
piCout << "\n\nMacros:";
|
||||
piForeachC (Macro & m, macros)
|
||||
piCout << "Macro:" << m.name << m.args << m.value;
|
||||
piCout << "\n\nClasses:";
|
||||
piForeachC (Entity * c, entities)
|
||||
piCout << "class" << c->name << c->parents;
|
||||
piCout << PIStringAscii("class") << c->name << c->parents;
|
||||
piCout << "\n\nEnums:";
|
||||
piForeachC (Enum & c, enums)
|
||||
piCout << "enum" << c.name << c.members;
|
||||
piCout << PIStringAscii("enum") << c.name << c.members;
|
||||
piCout << "\n\nTypedefs:";
|
||||
piForeachC (Typedef & c, typedefs)
|
||||
piCout << "typedef" << c;*/
|
||||
piCout << PIStringAscii("typedef") << c;*/
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ bool PICodeParser::parseFileInternal(const PIString & file, bool follow_includes
|
||||
PIFile f(file, PIIODevice::ReadOnly);
|
||||
int ii = 0;
|
||||
while (!f.isOpened() && ii < (includes.size_s() - 1)) {
|
||||
f.setPath(includes[++ii] + "/" + file);
|
||||
f.setPath(includes[++ii] + '/' + file);
|
||||
//piCout << "try" << f.path();
|
||||
f.open(PIIODevice::ReadOnly);
|
||||
}
|
||||
@@ -186,7 +186,10 @@ void PICodeParser::clear() {
|
||||
evaluator.clearCustomVariables();
|
||||
cur_def_vis = Global;
|
||||
anon_num = 0;
|
||||
defines << Define("PICODE", "") << custom_defines;
|
||||
PIStringList defs = PIStringAscii(PICODE_DEFINES).split(",");
|
||||
piForeachC (PIString & d, defs)
|
||||
defines << Define(d, "");
|
||||
defines << Define(PIStringAscii("PICODE"), "") << custom_defines;
|
||||
}
|
||||
|
||||
|
||||
@@ -197,9 +200,9 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
PIString pfc, line, ccmn, tmp;
|
||||
PIMap<PIString, PIString> cchars;
|
||||
|
||||
/// Remove comments, join multiline "*" and replace "*" to $n (cchars)
|
||||
fc.replaceAll("\r\n", "\n");
|
||||
fc.replaceAll("\r", "\n");
|
||||
/// Remove comments, join multiline '*' and replace '*' to $n (cchars)
|
||||
fc.replaceAll("\r\n", '\n');
|
||||
fc.replaceAll('\r', '\n');
|
||||
for (int i = 0; i < fc.size_s() - 1; ++i) {
|
||||
if (fc[i].unicode16Code() >= 255) continue;
|
||||
if (i > 0) pc = c;
|
||||
@@ -256,7 +259,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
if (ind + m.name.size_s() < pfc.size_s()) nc = pfc.mid(ind + m.name.size_s(),1)[0];
|
||||
if (_isCChar(pc) || _isCChar(nc) || nc.isDigit()) continue;
|
||||
PIString ret, range; bool ok(false);
|
||||
range = pfc.mid(ind + m.name.size_s()).takeRange("(", ")");
|
||||
range = pfc.mid(ind + m.name.size_s()).takeRange('(', ')');
|
||||
ret = m.expand(range, &ok);
|
||||
if (!ok) return false;
|
||||
int rlen = pfc.find(range, ind + m.name.size_s()) + range.size_s() + 1 - ind;
|
||||
@@ -274,46 +277,46 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
int nl = pfc.size_s();
|
||||
if (pl == nl) break;
|
||||
pl = nl;
|
||||
if (pfc.left(9) == "namespace") {
|
||||
pfc.cutLeft(pfc.find("{") + 1);
|
||||
if (pfc.left(9) == PIStringAscii("namespace")) {
|
||||
pfc.cutLeft(pfc.find('{') + 1);
|
||||
continue;
|
||||
}
|
||||
if (pfc.left(8) == "template") {
|
||||
if (pfc.left(8) == PIStringAscii("template")) {
|
||||
pfc.cutLeft(8);
|
||||
pfc.takeRange("<", ">");
|
||||
pfc.takeRange('<', '>');
|
||||
bool def = !isDeclaration(pfc, 0, &end);
|
||||
pfc.cutLeft(end);
|
||||
if (def) pfc.takeRange("{", "}");
|
||||
if (def) pfc.takeRange('{', '}');
|
||||
else pfc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
if (pfc.left(5) == "class" || pfc.left(6) == "struct" || pfc.left(5) == "union") {
|
||||
int dind = pfc.find("{", 0), find = pfc.find(";", 0);
|
||||
if (pfc.left(5) == PIStringAscii("class") || pfc.left(6) == PIStringAscii("struct") || pfc.left(5) == PIStringAscii("union")) {
|
||||
int dind = pfc.find('{', 0), find = pfc.find(';', 0);
|
||||
if (dind < 0 && find < 0) {pfc.cutLeft(6); continue;}
|
||||
if (dind < 0 || find < dind) {pfc.cutLeft(6); continue;}
|
||||
ccmn = pfc.left(dind) + "{\n" + pfc.mid(dind).takeRange('{', '}') + "\n}\n";
|
||||
ccmn = pfc.left(dind) + PIStringAscii("{\n") + pfc.mid(dind).takeRange('{', '}') + PIStringAscii("\n}\n");
|
||||
pfc.remove(0, ccmn.size());
|
||||
parseClass(0, ccmn);
|
||||
continue;
|
||||
}
|
||||
if (pfc.left(4) == "enum") {
|
||||
if (pfc.left(4) == PIStringAscii("enum")) {
|
||||
pfc.cutLeft(4);
|
||||
tmp = pfc.takeCWord();
|
||||
pfc.trim();
|
||||
MetaMap meta = maybeMeta(pfc);
|
||||
parseEnum(0, cur_namespace + tmp, pfc.takeRange("{", "}"), meta);
|
||||
parseEnum(0, cur_namespace + tmp, pfc.takeRange('{', '}'), meta);
|
||||
pfc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
if (pfc.left(7) == "typedef") {
|
||||
if (pfc.left(7) == PIStringAscii("typedef")) {
|
||||
pfc.cutLeft(7);
|
||||
typedefs << parseTypedef(pfc.takeLeft(pfc.find(";")));
|
||||
typedefs << parseTypedef(pfc.takeLeft(pfc.find(';')));
|
||||
if (typedefs.back().first.isEmpty()) typedefs.pop_back();
|
||||
else root_.typedefs << typedefs.back();
|
||||
pfc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
int sci = pfc.find(";", 0), obi = pfc.find("{", 0);
|
||||
int sci = pfc.find(';', 0), obi = pfc.find('{', 0);
|
||||
if (sci < 0 && obi < 0) {
|
||||
pfc.takeLeft(1);
|
||||
continue;
|
||||
@@ -323,7 +326,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
str = pfc.takeLeft(sci + 1);
|
||||
} else {
|
||||
str = pfc.takeLeft(obi);
|
||||
pfc.cutLeft(pfc.takeRange("{", "}").toInt());
|
||||
pfc.cutLeft(pfc.takeRange('{', '}').toInt());
|
||||
}
|
||||
parseMember(&root_, str);
|
||||
}
|
||||
@@ -333,22 +336,22 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
|
||||
|
||||
PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc) {
|
||||
PIString cd = fc.trimmed().removeAll('\n').replaceAll("\t", " ").replaceAll(" ", " "), pn;
|
||||
PIString cd = fc.trimmed().removeAll('\n').replaceAll('\t', ' ').replaceAll(PIStringAscii(" "), ' '), pn;
|
||||
MetaMap meta;
|
||||
int ind = cd.find("$M");
|
||||
int ind = cd.find(PIStringAscii("$M"));
|
||||
if (ind >= 0) {
|
||||
meta = tmp_meta.value(cd.takeMid(ind, 5));
|
||||
cd.replaceAll(" ", " ");
|
||||
cd.replaceAll(PIStringAscii(" "), ' ');
|
||||
}
|
||||
//piCout << "found class <****\n" << cd << "\n****>";
|
||||
ind = cd.find(":");
|
||||
ind = cd.find(':');
|
||||
PIVector<Entity * > parents;
|
||||
if (ind > 0) {
|
||||
PIStringList pl = cd.takeMid(ind + 1).trim().split(",");
|
||||
PIStringList pl = cd.takeMid(ind + 1).trim().split(',');
|
||||
cd.cutRight(1);
|
||||
Entity * pe = 0;
|
||||
piForeachC (PIString & p, pl) {
|
||||
if (p.contains(" ")) pn = p.mid(p.find(" ") + 1);
|
||||
if (p.contains(' ')) pn = p.mid(p.find(' ') + 1);
|
||||
else pn = p;
|
||||
pe = findEntityByName(pn);
|
||||
if (pe == 0) ;//{piCout << "Error: can`t find" << pn;}
|
||||
@@ -356,11 +359,11 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
|
||||
}
|
||||
}
|
||||
PIString typename_ = cd.left(6).trim();
|
||||
bool is_class = typename_ == "class";
|
||||
bool is_class = typename_ == PIStringAscii("class");
|
||||
cur_def_vis = (is_class ? Private : Public);
|
||||
PIString cn = cd.mid(6).trim();
|
||||
bool has_name = !cn.isEmpty();
|
||||
if (cn.isEmpty()) cn = "<unnamed_" + PIString::fromNumber(anon_num++) + ">";
|
||||
if (cn.isEmpty()) cn = PIStringAscii("<unnamed_") + PIString::fromNumber(anon_num++) + '>';
|
||||
//piCout << "found " << typename_ << cn;
|
||||
if (cn.isEmpty()) return 0;
|
||||
Entity * e = new Entity();
|
||||
@@ -377,7 +380,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
|
||||
|
||||
PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
Visibility prev_vis = cur_def_vis;
|
||||
int dind = fc.find("{"), find = fc.find(";"), end = 0;
|
||||
int dind = fc.find('{'), find = fc.find(';'), end = 0;
|
||||
if (dind < 0 && find < 0) return PIString();
|
||||
if (dind < 0 || find < dind) return fc.left(find);
|
||||
//piCout << "parse class <****\n" << fc.left(20) << "\n****>";
|
||||
@@ -390,43 +393,43 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
int ps = -1;
|
||||
bool def = false;
|
||||
PIString prev_namespace = cur_namespace, stmp;
|
||||
cur_namespace = ce->name + "::";
|
||||
cur_namespace = ce->name + PIStringAscii("::");
|
||||
//piCout << "parse class" << ce->name << "namespace" << cur_namespace;
|
||||
//piCout << "\nparse class" << ce->name << "namespace" << cur_namespace;
|
||||
while (!fc.isEmpty()) {
|
||||
PIString cw = fc.takeCWord(), tmp;
|
||||
//piCout << "\ntaked word" << cw;
|
||||
if (cw == "public") {cur_def_vis = Public; fc.cutLeft(1); continue;}
|
||||
if (cw == "protected") {cur_def_vis = Protected; fc.cutLeft(1); continue;}
|
||||
if (cw == "private") {cur_def_vis = Private; fc.cutLeft(1); continue;}
|
||||
if (cw == "class" || cw == "struct" || cw == "union") {
|
||||
if (cw == PIStringAscii("public" )) {cur_def_vis = Public; fc.cutLeft(1); continue;}
|
||||
if (cw == PIStringAscii("protected")) {cur_def_vis = Protected; fc.cutLeft(1); continue;}
|
||||
if (cw == PIStringAscii("private" )) {cur_def_vis = Private; fc.cutLeft(1); continue;}
|
||||
if (cw == PIStringAscii("class") || cw == PIStringAscii("struct") || cw == PIStringAscii("union")) {
|
||||
if (isDeclaration(fc, 0, &end)) {
|
||||
fc.cutLeft(end);
|
||||
fc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
tmp = fc.takeLeft(fc.find("{"));
|
||||
stmp = fc.takeRange("{", "}");
|
||||
tmp = fc.takeLeft(fc.find('{'));
|
||||
stmp = fc.takeRange('{', '}');
|
||||
fc.takeSymbol();
|
||||
stmp = cw + " " + tmp + "{" + stmp + "}";
|
||||
stmp = cw + ' ' + tmp + '{' + stmp + '}';
|
||||
parseClass(ce, stmp);
|
||||
continue;
|
||||
}
|
||||
if (cw == "enum") {
|
||||
if (cw == PIStringAscii("enum")) {
|
||||
tmp = fc.takeCWord();
|
||||
fc.trim();
|
||||
MetaMap meta = maybeMeta(fc);
|
||||
parseEnum(ce, cur_namespace + tmp, fc.takeRange("{", "}"), meta);
|
||||
parseEnum(ce, cur_namespace + tmp, fc.takeRange('{', '}'), meta);
|
||||
fc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
if (cw == "friend") {fc.cutLeft(fc.find(";") + 1); continue;}
|
||||
if (cw == "typedef") {ce->typedefs << parseTypedef(fc.takeLeft(fc.find(";"))); typedefs << ce->typedefs.back(); typedefs.back().first.insert(0, cur_namespace); if (ce->typedefs.back().first.isEmpty()) ce->typedefs.pop_back(); fc.takeSymbol(); continue;}
|
||||
if (cw == "template") {
|
||||
fc.takeRange("<", ">");
|
||||
if (cw == PIStringAscii("friend")) {fc.cutLeft(fc.find(';') + 1); continue;}
|
||||
if (cw == PIStringAscii("typedef")) {ce->typedefs << parseTypedef(fc.takeLeft(fc.find(';'))); typedefs << ce->typedefs.back(); typedefs.back().first.insert(0, cur_namespace); if (ce->typedefs.back().first.isEmpty()) ce->typedefs.pop_back(); fc.takeSymbol(); continue;}
|
||||
if (cw == PIStringAscii("template")) {
|
||||
fc.takeRange('<', '>');
|
||||
def = !isDeclaration(fc, 0, &end);
|
||||
fc.cutLeft(end);
|
||||
if (def) fc.takeRange("{", "}");
|
||||
if (def) fc.takeRange('{', '}');
|
||||
else fc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
@@ -434,7 +437,7 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
tmp = (cw + fc.takeLeft(end)).trim();
|
||||
if (!tmp.isEmpty())
|
||||
parseMember(ce, tmp);
|
||||
if (def) fc.takeRange("{", "}");
|
||||
if (def) fc.takeRange('{', '}');
|
||||
else fc.takeSymbol();
|
||||
if (ps == fc.size_s()) {fc.cutLeft(1);}
|
||||
ps = fc.size_s();
|
||||
@@ -448,13 +451,13 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
PICodeParser::MetaMap PICodeParser::parseMeta(PIString & fc) {
|
||||
PICodeParser::MetaMap ret;
|
||||
if (fc.isEmpty()) return ret;
|
||||
PIStringList ml = fc.split(",");
|
||||
PIStringList ml = fc.split(',');
|
||||
piForeachC (PIString & m, ml) {
|
||||
int i = m.find("=");
|
||||
int i = m.find('=');
|
||||
if (i < 0) continue;
|
||||
PIString mv = m.mid(i + 1).trim();
|
||||
if (mv.startsWith("\"")) mv.cutLeft(1);
|
||||
if (mv.endsWith("\"")) mv.cutRight(1);
|
||||
if (mv.startsWith('\"')) mv.cutLeft(1);
|
||||
if (mv.endsWith('\"')) mv.cutRight(1);
|
||||
ret[m.left(i).trim()] = mv;
|
||||
}
|
||||
//piCout << ms << ret;
|
||||
@@ -463,20 +466,22 @@ PICodeParser::MetaMap PICodeParser::parseMeta(PIString & fc) {
|
||||
|
||||
|
||||
bool PICodeParser::parseEnum(Entity * parent, const PIString & name, PIString fc, const MetaMap & meta) {
|
||||
//piCout << "enum" << name << fc;
|
||||
static const PIString s_ss = PIStringAscii(" ");
|
||||
static const PIString s_M = PIStringAscii("$M");
|
||||
//piCout << PIStringAscii("enum") << name << fc;
|
||||
Enum e(name);
|
||||
e.meta = meta;
|
||||
PIStringList vl(fc.split(","));
|
||||
PIStringList vl(fc.split(','));
|
||||
PIString vn;
|
||||
int cv = -1, ind = 0;
|
||||
piForeach (PIString & v, vl) {
|
||||
MetaMap meta;
|
||||
int mi = v.find("$M");
|
||||
int mi = v.find(s_M);
|
||||
if (mi >= 0) {
|
||||
meta = tmp_meta.value(v.takeMid(mi, 5));
|
||||
v.replaceAll(" ", " ");
|
||||
v.replaceAll(s_ss, ' ');
|
||||
}
|
||||
vn = v; ind = v.find("=");
|
||||
vn = v; ind = v.find('=');
|
||||
if (ind > 0) {cv = v.right(v.size_s() - ind - 1).toInt(); vn = v.left(ind);}
|
||||
if (ind < 0) ++cv;
|
||||
e.members << EnumeratorInfo(vn.trim(), cv, meta);
|
||||
@@ -492,15 +497,15 @@ bool PICodeParser::parseEnum(Entity * parent, const PIString & name, PIString fc
|
||||
PICodeParser::Typedef PICodeParser::parseTypedef(PIString fc) {
|
||||
//piCout << "parse typedef" << fc;
|
||||
Typedef td;
|
||||
fc.replaceAll("\t", " ");
|
||||
fc.replaceAll('\t', ' ');
|
||||
|
||||
if (fc.contains("(")) {
|
||||
int start = fc.find("("), end = fc.find(")");
|
||||
if (fc.contains('(')) {
|
||||
int start = fc.find('('), end = fc.find(')');
|
||||
td.first = fc.takeMid(start + 1, end - start - 1).trim();
|
||||
if (td.first.left(1) == "*") {td.first.cutLeft(1).trim(); fc.insert(start + 1, "*");}
|
||||
if (td.first.left(1) == PIChar('*')) {td.first.cutLeft(1).trim(); fc.insert(start + 1, '*');}
|
||||
td.second = fc.trim();
|
||||
} else {
|
||||
td.first = fc.takeMid(fc.findLast(" ")).trim();
|
||||
td.first = fc.takeMid(fc.findLast(' ')).trim();
|
||||
td.second = fc.trim();
|
||||
}
|
||||
//piCout << "found typedef" << td;
|
||||
@@ -509,34 +514,53 @@ PICodeParser::Typedef PICodeParser::parseTypedef(PIString fc) {
|
||||
|
||||
|
||||
bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
static const PIString s_operator = PIStringAscii("operator");
|
||||
static const PIString s_ss = PIStringAscii(" ");
|
||||
static const PIString s_cs = PIStringAscii(", ");
|
||||
static const PIString s_sb = PIStringAscii(" (");
|
||||
static const PIString s_sM = PIStringAscii(" $M");
|
||||
static const PIString s_M = PIStringAscii("$M");
|
||||
static const PIString s_T = PIStringAscii("$T");
|
||||
static const PIString s_inline_s = PIStringAscii("inline ");
|
||||
static const PIString s_static_s = PIStringAscii("static ");
|
||||
static const PIString s_virtual_s = PIStringAscii("virtual ");
|
||||
static const PIString s_void = PIStringAscii("void");
|
||||
static const PIString s_using = PIStringAscii("using");
|
||||
static const PIString s_s5 = PIStringAscii(" ");
|
||||
static const PIString s_s_const_s = PIStringAscii(" const ");
|
||||
static const PIString s_s_static_s = PIStringAscii(" static ");
|
||||
static const PIString s_s_mutable_s = PIStringAscii(" mutable ");
|
||||
static const PIString s_s_volatile_s = PIStringAscii(" volatile ");
|
||||
static const PIString s_s_extern_s = PIStringAscii(" extern ");
|
||||
|
||||
if (fc.trim().isEmpty()) return true;
|
||||
if (fc.find("operator") >= 0) return true;
|
||||
if (fc.find(s_operator) >= 0) return true;
|
||||
tmp_temp.clear();
|
||||
//piCout << "parse member" << fc;
|
||||
int ts = fc.find("<"), te = 0;
|
||||
int ts = fc.find('<'), te = 0;
|
||||
PIString ctemp, crepl;
|
||||
while (ts >= 0) {
|
||||
ctemp = fc.mid(ts).takeRange("<", ">");
|
||||
if (ctemp.isEmpty()) {te = ts + 1; ts = fc.find("<", te); continue;}
|
||||
crepl = "$T" + PIString::fromNumber(tmp_temp.size_s()).expandLeftTo(3, "0");
|
||||
ctemp = fc.mid(ts).takeRange('<', '>');
|
||||
if (ctemp.isEmpty()) {te = ts + 1; ts = fc.find('<', te); continue;}
|
||||
crepl = s_T + PIString::fromNumber(tmp_temp.size_s()).expandLeftTo(3, '0');
|
||||
fc.replace(ts, ctemp.size_s() + 2, crepl);
|
||||
tmp_temp[crepl] = "<" + ctemp + ">";
|
||||
ts = fc.find("<", te);
|
||||
tmp_temp[crepl] = '<' + ctemp + '>';
|
||||
ts = fc.find('<', te);
|
||||
}
|
||||
fc.replaceAll("\n", " ").replaceAll("\t", " ").replaceAll(" ", " ").replaceAll(", ", ",").replaceAll(" (", "(").replaceAll(" $M", "$M");
|
||||
fc.replaceAll('\n', ' ').replaceAll('\t', ' ').replaceAll(s_ss, ' ').replaceAll(s_cs, ',').replaceAll(s_sb, '(').replaceAll(s_sM, s_M);
|
||||
//piCout << "parse member" << fc;
|
||||
PIStringList tl, al;
|
||||
Member me;
|
||||
//piCout << fc;
|
||||
if (fc.contains("(")) {
|
||||
if (fc.contains('(')) {
|
||||
MetaMap meta;
|
||||
int ind = fc.find("$M");
|
||||
int ind = fc.find(s_M);
|
||||
if (ind >= 0) {
|
||||
meta = tmp_meta.value(fc.takeMid(ind, 5));
|
||||
fc.replaceAll(" ", " ").replaceAll(" (", "(");
|
||||
fc.replaceAll(s_ss, ' ').replaceAll(s_sb, '(');
|
||||
}
|
||||
fc.cutRight(fc.size_s() - fc.findLast(")") - 1);
|
||||
te = fc.find("(");
|
||||
fc.cutRight(fc.size_s() - fc.findLast(')') - 1);
|
||||
te = fc.find('(');
|
||||
//piCout << fc;
|
||||
for (ts = te - 1; ts >= 0; --ts)
|
||||
if (!_isCChar(fc[ts]) && !(fc[ts].isDigit())) break;
|
||||
@@ -544,37 +568,37 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
me.meta = meta;
|
||||
me.name = fc.takeMid(ts + 1, te - ts - 1);
|
||||
if (me.name == parent->name) return true;
|
||||
me.arguments_full = fc.takeMid(ts + 2).cutRight(1).split(",");
|
||||
me.arguments_full = fc.takeMid(ts + 2).cutRight(1).split(',');
|
||||
me.type = fc.cutRight(1).trim();
|
||||
me.visibility = cur_def_vis;
|
||||
if (me.type.find("inline ") >= 0) {
|
||||
if (me.type.find(s_inline_s) >= 0) {
|
||||
me.attributes |= Inline;
|
||||
me.type.removeAll("inline ");
|
||||
me.type.removeAll(s_inline_s);
|
||||
}
|
||||
if (me.type.find("static ") >= 0) {
|
||||
if (me.type.find(s_static_s) >= 0) {
|
||||
me.attributes |= Static;
|
||||
me.type.removeAll("static ");
|
||||
me.type.removeAll(s_static_s);
|
||||
}
|
||||
if (me.type.find("virtual ") >= 0) {
|
||||
if (me.type.find(s_virtual_s) >= 0) {
|
||||
me.attributes |= Virtual;
|
||||
me.type.removeAll("virtual ");
|
||||
me.type.removeAll(s_virtual_s);
|
||||
}
|
||||
normalizeEntityNamespace(me.type);
|
||||
int i = 0;
|
||||
//piCout << me.arguments_full;
|
||||
piForeach (PIString & a, me.arguments_full)
|
||||
if ((i = a.find("=")) > 0)
|
||||
if ((i = a.find('=')) > 0)
|
||||
a.cutRight(a.size_s() - i).trim();
|
||||
for (int j = 0; j < me.arguments_full.size_s(); ++j)
|
||||
if (me.arguments_full[j] == "void") {
|
||||
if (me.arguments_full[j] == s_void) {
|
||||
me.arguments_full.remove(j);
|
||||
--j;
|
||||
}
|
||||
me.arguments_type = me.arguments_full;
|
||||
piForeach (PIString & a, me.arguments_type) {
|
||||
crepl.clear();
|
||||
if (a.contains("["))
|
||||
crepl = a.takeMid(a.find("["), a.findLast("]") - a.find("[") + 1);
|
||||
if (a.contains('['))
|
||||
crepl = a.takeMid(a.find('['), a.findLast(']') - a.find('[') + 1);
|
||||
for (ts = a.size_s() - 1; ts >= 0; --ts)
|
||||
if (!_isCChar(a[ts]) && !(a[ts].isDigit())) break;
|
||||
a.cutRight(a.size_s() - ts - 1);
|
||||
@@ -586,18 +610,18 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
//piCout << "func" << me.type << me.name << me.arguments_full << me.arguments_type;
|
||||
parent->functions << me;
|
||||
} else {
|
||||
if (fc.endsWith(";")) fc.cutRight(1);
|
||||
if (fc.startsWith("using") || !(fc.contains(' ') || fc.contains('\t') || fc.contains('\n'))) return true;
|
||||
if (fc.endsWith(';')) fc.cutRight(1);
|
||||
if (fc.startsWith(s_using) || !(fc.contains(' ') || fc.contains('\t') || fc.contains('\n'))) return true;
|
||||
int bits = extractMemberBits(fc);
|
||||
tl = fc.split(",");
|
||||
tl = fc.split(',');
|
||||
//piCout << "member" << fc << tl;
|
||||
//piCout << "member after eb" << fc << ", bits =" << bits;
|
||||
if (tl.isEmpty()) return true;
|
||||
bool vn = true;
|
||||
ctemp = tl.front().trim();
|
||||
PIString meta_t;
|
||||
if (ctemp.contains("$M"))
|
||||
meta_t = ctemp.takeMid(ctemp.find("$M"));
|
||||
if (ctemp.contains(s_M))
|
||||
meta_t = ctemp.takeMid(ctemp.find(s_M));
|
||||
for (ts = ctemp.size_s() - 1; ts > 0; --ts) {
|
||||
if (vn) {if (!_isCChar(ctemp[ts]) && !ctemp[ts].isDigit() && ctemp[ts] != '[' && ctemp[ts] != ']') vn = false;}
|
||||
else {if (_isCChar(ctemp[ts]) || ctemp[ts].isDigit()) break;}
|
||||
@@ -606,26 +630,26 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
me.visibility = cur_def_vis;
|
||||
ctemp += meta_t;
|
||||
restoreTmpTemp(&me);
|
||||
PIString type = " " + me.type;
|
||||
if (type.find(" const ") >= 0) {
|
||||
PIString type = s_s5 + me.type;
|
||||
if (type.find(s_s_const_s) >= 0) {
|
||||
me.attributes |= Const;
|
||||
type.replaceAll(" const ", " ");
|
||||
type.replaceAll(s_s_const_s, ' ');
|
||||
}
|
||||
if (type.find(" static ") >= 0) {
|
||||
if (type.find(s_s_static_s) >= 0) {
|
||||
me.attributes |= Static;
|
||||
type.replaceAll(" static ", " ");
|
||||
type.replaceAll(s_s_static_s, ' ');
|
||||
}
|
||||
if (type.find(" mutable ") >= 0) {
|
||||
if (type.find(s_s_mutable_s) >= 0) {
|
||||
me.attributes |= Mutable;
|
||||
type.replaceAll(" mutable ", " ");
|
||||
type.replaceAll(s_s_mutable_s, ' ');
|
||||
}
|
||||
if (type.find(" volatile ") >= 0) {
|
||||
if (type.find(s_s_volatile_s) >= 0) {
|
||||
me.attributes |= Volatile;
|
||||
type.replaceAll(" volatile ", " ");
|
||||
type.replaceAll(s_s_volatile_s, ' ');
|
||||
}
|
||||
if (type.find(" extern ") >= 0) {
|
||||
if (type.find(s_s_extern_s) >= 0) {
|
||||
me.attributes |= Extern;
|
||||
type.replaceAll(" extern ", " ");
|
||||
type.replaceAll(s_s_extern_s, ' ');
|
||||
}
|
||||
type.trim();
|
||||
normalizeEntityNamespace(type);
|
||||
@@ -637,15 +661,15 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
me.type = type;
|
||||
restoreTmpMeta(&me);
|
||||
if (me.name.isEmpty()) continue;
|
||||
if (me.name.contains("["))
|
||||
crepl = me.name.takeMid(me.name.find("["), me.name.findLast("]") - me.name.find("[") + 1);
|
||||
if (me.name.contains('['))
|
||||
crepl = me.name.takeMid(me.name.find('['), me.name.findLast(']') - me.name.find('[') + 1);
|
||||
while (!me.name.isEmpty()) {
|
||||
if (me.name.front() == "*" || me.name.front() == "&") {
|
||||
if (me.name.front() == PIChar('*') || me.name.front() == PIChar('&')) {
|
||||
me.type += me.name.takeLeft(1);
|
||||
me.name.trim();
|
||||
} else break;
|
||||
}
|
||||
me.is_type_ptr = (me.type.right(1) == "]" || me.type.right(1) == "*");
|
||||
me.is_type_ptr = (me.type.right(1) == PIChar(']') || me.type.right(1) == PIChar('*'));
|
||||
me.type += crepl;
|
||||
me.bits = bits;
|
||||
while (!crepl.isEmpty()) {
|
||||
@@ -664,7 +688,7 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
|
||||
|
||||
int PICodeParser::extractMemberBits(PIString & fc) {
|
||||
int i = fc.findLast(":");
|
||||
int i = fc.findLast(':');
|
||||
if (i <= 0) return -1;
|
||||
if (fc[i - 1].toAscii() == ':') return -1;
|
||||
PIString bs = fc.takeMid(i).mid(1).trim();
|
||||
@@ -674,6 +698,14 @@ int PICodeParser::extractMemberBits(PIString & fc) {
|
||||
|
||||
|
||||
void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
static const PIString s_const_s = PIStringAscii("const ");
|
||||
static const PIString s_static_s = PIStringAscii("static ");
|
||||
static const PIString s_mutable_s = PIStringAscii("mutable ");
|
||||
static const PIString s_volatile_s = PIStringAscii("volatile ");
|
||||
static const PIString s_s_const_s = PIStringAscii(" const ");
|
||||
static const PIString s_s_static_s = PIStringAscii(" static ");
|
||||
static const PIString s_s_mutable_s = PIStringAscii(" mutable ");
|
||||
static const PIString s_s_volatile_s = PIStringAscii(" volatile ");
|
||||
PIString suff, pref;
|
||||
for (int i = n.size_s() - 1; i > 0; --i)
|
||||
if (_isCChar(n[i]) || n[i].isDigit()) {
|
||||
@@ -681,11 +713,11 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
n.cutRight(suff.size_s());
|
||||
break;
|
||||
}
|
||||
n.push_front(" ");
|
||||
if (n.find(" static ") >= 0) {n.replaceAll(" static ", ""); pref += "static ";}
|
||||
if (n.find(" const ") >= 0) {n.replaceAll(" const ", ""); pref += "const ";}
|
||||
if (n.find(" mutable ") >= 0) {n.replaceAll(" mutable ", ""); pref += "mutable ";}
|
||||
if (n.find(" volatile ") >= 0) {n.replaceAll(" volatile ", ""); pref += "volatile ";}
|
||||
n.push_front(' ');
|
||||
if (n.find(s_s_const_s) >= 0) {n.replaceAll(s_s_const_s, ""); pref += s_const_s;}
|
||||
if (n.find(s_s_static_s) >= 0) {n.replaceAll(s_s_static_s, ""); pref += s_static_s;}
|
||||
if (n.find(s_s_mutable_s) >= 0) {n.replaceAll(s_s_mutable_s, ""); pref += s_mutable_s;}
|
||||
if (n.find(s_s_volatile_s) >= 0) {n.replaceAll(s_s_volatile_s, ""); pref += s_volatile_s;}
|
||||
n.trim();
|
||||
int f = 0;
|
||||
piForeachC (Entity * e, entities) {
|
||||
@@ -694,27 +726,29 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
return;
|
||||
}
|
||||
if ((f = e->name.find(n)) >= 0)
|
||||
if (e->name.mid(f - 1, 1) == ":")
|
||||
if (e->name.at(f - 1) == PIChar(':'))
|
||||
if (e->name.find(cur_namespace) >= 0) {
|
||||
n = pref + e->name + suff;
|
||||
return;
|
||||
}
|
||||
}
|
||||
piForeachC (Enum & e, enums)
|
||||
if ((f = e.name.find(n)) >= 0)
|
||||
if (e.name.mid(f - 1, 1) == ":")
|
||||
if (e.name.find(cur_namespace) >= 0) {
|
||||
//piCout << "change" << n << "to" << e.name + suff;
|
||||
n = pref + e.name + suff;
|
||||
return;
|
||||
piForeachC (Enum & e, enums) {
|
||||
if ((f = e.name.find(n)) >= 0)
|
||||
if (e.name.at(f - 1) == PIChar(':'))
|
||||
if (e.name.find(cur_namespace) >= 0) {
|
||||
//piCout << "change" << n << "to" << e.name + suff;
|
||||
n = pref + e.name + suff;
|
||||
return;
|
||||
}
|
||||
}
|
||||
piForeachC (Typedef & e, typedefs)
|
||||
if ((f = e.first.find(n)) >= 0)
|
||||
if (e.first.mid(f - 1, 1) == ":")
|
||||
if (e.first.find(cur_namespace) >= 0) {
|
||||
//piCout << "change" << n << "to" << e.name + suff;
|
||||
n = pref + e.first + suff;
|
||||
return;
|
||||
piForeachC (Typedef & e, typedefs) {
|
||||
if ((f = e.first.find(n)) >= 0)
|
||||
if (e.first.at(f - 1) == PIChar(':'))
|
||||
if (e.first.find(cur_namespace) >= 0) {
|
||||
//piCout << "change" << n << "to" << e.name + suff;
|
||||
n = pref + e.first + suff;
|
||||
return;
|
||||
}
|
||||
}
|
||||
n = (pref + n + suff).trim();
|
||||
}
|
||||
@@ -723,20 +757,20 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
void PICodeParser::restoreTmpTemp(Member * e) {
|
||||
int i = 0;
|
||||
piForeach (PIString & a, e->arguments_full) {
|
||||
while ((i = a.find("$T")) >= 0)
|
||||
while ((i = a.find(PIStringAscii("$T"))) >= 0)
|
||||
a.replace(i, 5, tmp_temp[a.mid(i, 5)]);
|
||||
}
|
||||
piForeach (PIString & a, e->arguments_type) {
|
||||
while ((i = a.find("$T")) >= 0)
|
||||
while ((i = a.find(PIStringAscii("$T"))) >= 0)
|
||||
a.replace(i, 5, tmp_temp[a.mid(i, 5)]);
|
||||
}
|
||||
while ((i = e->type.find("$T")) >= 0)
|
||||
while ((i = e->type.find(PIStringAscii("$T"))) >= 0)
|
||||
e->type.replace(i, 5, tmp_temp[e->type.mid(i, 5)]);
|
||||
}
|
||||
|
||||
|
||||
void PICodeParser::restoreTmpMeta(PICodeParser::Member * e) {
|
||||
int i = e->name.find("$M");
|
||||
int i = e->name.find(PIStringAscii("$M"));
|
||||
if (i < 0) return;
|
||||
e->meta = tmp_meta[e->name.takeMid(i, 5)];
|
||||
}
|
||||
@@ -744,7 +778,7 @@ void PICodeParser::restoreTmpMeta(PICodeParser::Member * e) {
|
||||
|
||||
PICodeParser::MetaMap PICodeParser::maybeMeta(PIString & fc) {
|
||||
PICodeParser::MetaMap ret;
|
||||
if (fc.left(2) == "$M") {
|
||||
if (fc.left(2) == PIStringAscii("$M")) {
|
||||
ret = tmp_meta.value(fc.takeLeft(5));
|
||||
fc.trim();
|
||||
}
|
||||
@@ -754,10 +788,10 @@ PICodeParser::MetaMap PICodeParser::maybeMeta(PIString & fc) {
|
||||
|
||||
bool PICodeParser::macroCondition(const PIString & mif, PIString mifcond) {
|
||||
//piCout << "macroCondition" << mif << mifcond;
|
||||
if (mif == "ifdef") return isDefineExists(mifcond);
|
||||
if (mif == "ifndef") return !isDefineExists(mifcond);
|
||||
if (mif == "if" || mif == "elif") {
|
||||
mifcond.removeAll(" ").removeAll("\t");
|
||||
if (mif == PIStringAscii("ifdef")) return isDefineExists(mifcond);
|
||||
if (mif == PIStringAscii("ifndef")) return !isDefineExists(mifcond);
|
||||
if (mif == PIStringAscii("if") || mif == PIStringAscii("elif")) {
|
||||
mifcond.removeAll(' ').removeAll('\t');
|
||||
return procMacrosCond(mifcond) > 0.;
|
||||
}
|
||||
return false;
|
||||
@@ -770,7 +804,7 @@ double PICodeParser::procMacrosCond(PIString fc) {
|
||||
int oper = 0, ps = -1;
|
||||
char cc, nc;
|
||||
PIString ce;
|
||||
fc.removeAll("defined");
|
||||
fc.removeAll(PIStringAscii("defined"));
|
||||
//piCout << "procMacrosCond" << fc;
|
||||
while (!fc.isEmpty()) {
|
||||
cc = fc[0].toAscii();
|
||||
@@ -825,17 +859,17 @@ double PICodeParser::defineValue(const PIString & dn) {
|
||||
void PICodeParser::replaceMeta(PIString & dn) {
|
||||
tmp_meta.clear();
|
||||
if (dn.isEmpty()) return;
|
||||
int s = dn.find("PIMETA");
|
||||
int s = dn.find(PIStringAscii("PIMETA"));
|
||||
while (s >= 0) {
|
||||
int ms = 0, ml = 0;
|
||||
ms = dn.findRange('(', ')', '\\', s + 6, &ml);
|
||||
if (ms < 0) return;
|
||||
PIString meta = dn.mid(ms, ml).trim();
|
||||
PIString rm = "$M" + PIString::fromNumber(tmp_meta.size_s()).expandLeftTo(3, "0");
|
||||
PIString rm = PIStringAscii("$M") + PIString::fromNumber(tmp_meta.size_s()).expandLeftTo(3, '0');
|
||||
dn.replace(s, ms + ml + 1 - s, rm);
|
||||
//piCout << "FOUND META \"" << meta << "\"";
|
||||
//piCout << "FOUND META \"" << meta << '\"';
|
||||
tmp_meta[rm] = parseMeta(meta);
|
||||
s = dn.find("PIMETA");
|
||||
s = dn.find(PIStringAscii("PIMETA"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -849,7 +883,7 @@ PICodeParser::Entity * PICodeParser::findEntityByName(const PIString & en) {
|
||||
|
||||
|
||||
bool PICodeParser::isDeclaration(const PIString & fc, int start, int * end) {
|
||||
int dind = fc.find("{", start), find = fc.find(";", start);
|
||||
int dind = fc.find('{', start), find = fc.find(';', start);
|
||||
//piCout << "isDeclaration" << dind << find << fc.left(10);
|
||||
if (dind < 0 && find < 0) {if (end) *end = -1; return true;}
|
||||
if (dind < 0 || find < dind) {if (end) *end = find; return true;}
|
||||
@@ -861,17 +895,17 @@ bool PICodeParser::isDeclaration(const PIString & fc, int start, int * end) {
|
||||
bool PICodeParser::isMainFile(const PIString & fc) {
|
||||
int si = 0;
|
||||
while (si >= 0) {
|
||||
int csi = fc.find(" main", si);
|
||||
if (csi < 0) csi = fc.find("\tmain", si);
|
||||
if (csi < 0) csi = fc.find("\nmain", si);
|
||||
int csi = fc.find(PIStringAscii(" main"), si);
|
||||
if (csi < 0) csi = fc.find(PIStringAscii("\tmain"), si);
|
||||
if (csi < 0) csi = fc.find(PIStringAscii("\nmain"), si);
|
||||
if (csi < 0) return false;
|
||||
si = csi;
|
||||
int fi = fc.find("(", si + 5);
|
||||
int fi = fc.find('(', si + 5);
|
||||
if (fi < 0) return false;
|
||||
if (fi - si < 10) {
|
||||
PIString ms(fc.mid(si, fi - si + 1));
|
||||
ms.removeAll(" ").removeAll("\t").removeAll("\n");
|
||||
if (ms == "main(") return true;
|
||||
ms.removeAll(' ').removeAll('\t').removeAll('\n');
|
||||
if (ms == PIStringAscii("main(")) return true;
|
||||
}
|
||||
si += 5;
|
||||
}
|
||||
@@ -885,17 +919,17 @@ PIString PICodeParser::procMacros(PIString fc) {
|
||||
bool grab = false, skip = false, cond_ok = false;
|
||||
PIString pfc, nfc, line, mif, mifcond;
|
||||
//piCout << "procMacros\n<******" << fc << "\n******>";
|
||||
fc += "\n";
|
||||
fc += '\n';
|
||||
while (!fc.isEmpty()) {
|
||||
line = fc.takeLine().trimmed();
|
||||
if (line.left(1) == "#") {
|
||||
if (line.left(1) == PIChar('#')) {
|
||||
mifcond = line.mid(1);
|
||||
mif = mifcond.takeCWord();
|
||||
//piCout << mif;
|
||||
//piCout << "mif mifcond" << mif << mifcond << ifcnt;
|
||||
if (skip || grab) {
|
||||
if (mif.left(2) == "if") ifcnt++;
|
||||
if (mif.left(5) == "endif") {
|
||||
if (mif.left(2) == PIStringAscii("if")) ifcnt++;
|
||||
if (mif.left(5) == PIStringAscii("endif")) {
|
||||
if (ifcnt > 0) ifcnt--;
|
||||
else {
|
||||
//piCout << "main endif" << skip << grab;
|
||||
@@ -904,7 +938,7 @@ PIString PICodeParser::procMacros(PIString fc) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (mif.left(4) == "elif" && ifcnt == 0) {
|
||||
if (mif.left(4) == PIStringAscii("elif") && ifcnt == 0) {
|
||||
//piCout << "main elif" << skip << grab << cond_ok;
|
||||
if (cond_ok) {
|
||||
if (grab) {
|
||||
@@ -922,17 +956,17 @@ PIString PICodeParser::procMacros(PIString fc) {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (mif.left(4) == "else" && ifcnt == 0) {
|
||||
if (mif.left(4) == PIStringAscii("else") && ifcnt == 0) {
|
||||
//piCout << "main else" << skip << grab;
|
||||
if (grab) pfc << procMacros(nfc);
|
||||
if (skip && !cond_ok) {skip = false; grab = true;}
|
||||
else {skip = true; grab = false;}
|
||||
continue;
|
||||
}
|
||||
if (grab) nfc << line << "\n";
|
||||
if (grab) nfc << line << '\n';
|
||||
continue;
|
||||
}
|
||||
if (mif.left(2) == "if") {
|
||||
if (mif.left(2) == PIStringAscii("if")) {
|
||||
//piCout << "main if";
|
||||
skip = grab = cond_ok = false;
|
||||
if (macroCondition(mif, mifcond.trimmed())) grab = cond_ok = true;
|
||||
@@ -944,8 +978,8 @@ PIString PICodeParser::procMacros(PIString fc) {
|
||||
//return false; /// WARNING: now skip errors
|
||||
}
|
||||
} else {
|
||||
if (grab) nfc << line << "\n";
|
||||
else if (!skip) pfc << line << "\n";
|
||||
if (grab) nfc << line << '\n';
|
||||
else if (!skip) pfc << line << '\n';
|
||||
}
|
||||
}
|
||||
return pfc;
|
||||
@@ -956,21 +990,21 @@ bool PICodeParser::parseDirective(PIString d) {
|
||||
if (d.isEmpty()) return true;
|
||||
PIString dname = d.takeCWord();
|
||||
//piCout << "parseDirective" << d;
|
||||
if (dname == "include") {
|
||||
d.replaceAll("<", "\"").replaceAll(">", "\"");
|
||||
PIString cf = cur_file, ifc = d.takeRange("\"", "\"");
|
||||
if (dname == PIStringAscii("include")) {
|
||||
d.replaceAll('<', '\"').replaceAll('>', '\"');
|
||||
PIString cf = cur_file, ifc = d.takeRange('\"', '\"');
|
||||
if (with_includes) {
|
||||
bool ret = parseFileInternal(ifc, with_includes);
|
||||
cur_file = cf;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (dname == "define") {
|
||||
if (dname == PIStringAscii("define")) {
|
||||
PIString mname = d.takeCWord();
|
||||
//piCout << mname;
|
||||
if (mname == "PIMETA") return true;
|
||||
if (d.left(1) == "(") { // macro
|
||||
PIStringList args = d.takeRange("(", ")").split(",").trim();
|
||||
if (mname == PIStringAscii("PIMETA")) return true;
|
||||
if (d.left(1) == PIChar('(')) { // macro
|
||||
PIStringList args = d.takeRange('(', ')').split(',').trim();
|
||||
macros << Macro(mname, d.trim(), args);
|
||||
} else { // define
|
||||
d.trim();
|
||||
@@ -979,7 +1013,7 @@ bool PICodeParser::parseDirective(PIString d) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (dname == "undef") {
|
||||
if (dname == PIStringAscii("undef")) {
|
||||
PIString mname = d.takeCWord();
|
||||
for (int i = 0; i < defines.size_s(); ++i)
|
||||
if (defines[i].first == mname) {defines.remove(i); --i;}
|
||||
|
||||
@@ -33,8 +33,8 @@ class PIP_EXPORT PICodeParser {
|
||||
public:
|
||||
PICodeParser();
|
||||
|
||||
enum PIP_EXPORT Visibility {Global, Public, Protected, Private};
|
||||
enum PIP_EXPORT Attribute {
|
||||
enum Visibility {Global, Public, Protected, Private};
|
||||
enum Attribute {
|
||||
NoAttributes = 0x0,
|
||||
Const = 0x01,
|
||||
Static = 0x02,
|
||||
|
||||
@@ -23,10 +23,11 @@
|
||||
#ifndef PICOMPRESS_H
|
||||
#define PICOMPRESS_H
|
||||
|
||||
#include "pip_compress_export.h"
|
||||
#include "pibytearray.h"
|
||||
|
||||
PIByteArray piCompress(const PIByteArray & ba, int level = 6);
|
||||
PIP_COMPRESS_EXPORT PIByteArray piCompress(const PIByteArray & ba, int level = 6);
|
||||
|
||||
PIByteArray piDecompress(const PIByteArray & zba);
|
||||
PIP_COMPRESS_EXPORT PIByteArray piDecompress(const PIByteArray & zba);
|
||||
|
||||
#endif // PICOMPRESS_H
|
||||
@@ -1,461 +0,0 @@
|
||||
/*! \file piconsole.h
|
||||
* \brief Console output class
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Console output/input
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PICONSOLE_H
|
||||
#define PICONSOLE_H
|
||||
|
||||
#include "pikbdlistener.h"
|
||||
|
||||
class PIProtocol;
|
||||
class PIDiagnostics;
|
||||
class PISystemMonitor;
|
||||
class PIPeer;
|
||||
class PITimer;
|
||||
|
||||
class PIP_EXPORT PIConsole: public PIThread
|
||||
{
|
||||
PIOBJECT_SUBCLASS(PIConsole, PIThread)
|
||||
public:
|
||||
|
||||
//! Constructs %PIConsole with key handler "slot" and if "startNow" start it
|
||||
explicit PIConsole(bool startNow = true, PIKbdListener::KBFunc slot = 0);
|
||||
|
||||
~PIConsole();
|
||||
|
||||
|
||||
//! Variables output format
|
||||
enum Format {
|
||||
Normal /** Default console format */ = 0x01,
|
||||
Bold /** Bold text */ = 0x02,
|
||||
Faint = 0x04,
|
||||
Italic = 0x08,
|
||||
Underline /** Underlined text */ = 0x10,
|
||||
Blink /** Blinked text */ = 0x20,
|
||||
Inverse /** Swap text and background colors */ = 0x40,
|
||||
Black /** Black text */ = 0x100,
|
||||
Red /** Red text */ = 0x200,
|
||||
Green /** Green text */ = 0x400,
|
||||
Yellow /** Yellow text */ = 0x800,
|
||||
Blue /** Blue text */ = 0x1000,
|
||||
Magenta /** Magenta text */ = 0x2000,
|
||||
Cyan /** Cyan text */ = 0x4000,
|
||||
White /** White text */ = 0x8000,
|
||||
BackBlack /** Black background */ = 0x10000,
|
||||
BackRed /** Red background */ = 0x20000,
|
||||
BackGreen /** Green background */ = 0x40000,
|
||||
BackYellow /** Yellow background */ = 0x80000,
|
||||
BackBlue /** Blue background */ = 0x100000,
|
||||
BackMagenta /** Magenta background */ = 0x200000,
|
||||
BackCyan /** Cyan background */ = 0x400000,
|
||||
BackWhite /** White background */ = 0x800000,
|
||||
Dec /** Decimal base for integers */ = 0x1000000,
|
||||
Hex /** Hexadecimal base for integers */ = 0x2000000,
|
||||
Oct /** Octal base for integers */ = 0x4000000,
|
||||
Bin /** Binary base for integers */ = 0x8000000,
|
||||
Scientific /** Scientific representation of floats */ = 0x10000000,
|
||||
SystemTimeSplit /** PISystemTime split representation (* s, * ns) */ = 0x20000000,
|
||||
SystemTimeSeconds /** PISystemTime seconds representation (*.* s) */ = 0x40000000
|
||||
};
|
||||
|
||||
//! Column labels alignment
|
||||
enum Alignment {
|
||||
Nothing /** No alignment */ ,
|
||||
Left /** Labels align left and variables align left */ ,
|
||||
Right /** Labels align right and variables align left */
|
||||
};
|
||||
|
||||
typedef PIFlags<PIConsole::Format> FormatFlags;
|
||||
|
||||
//! Add to current tab to column "column" string "name" with format "format"
|
||||
void addString(const PIString & name, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const PIString * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const char * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const bool * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const short * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const int * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const long * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const llong * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const uchar * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const ushort * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const uint * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const ulong * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const ullong * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const float * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const double * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" variable with label "name", pointer "ptr" and format "format"
|
||||
void addVariable(const PIString & name, const PISystemTime * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
void addVariable(const PIString & name, const PIDiagnostics * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
void addVariable(const PIString & name, const PISystemMonitor * ptr, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" bits field with label "name", pointer "ptr" and format "format"
|
||||
void addBitVariable(const PIString & name, const void * ptr, int fromBit, int bitsCount, int column = 1, FormatFlags format = PIConsole::Normal);
|
||||
|
||||
//! Add to current tab to column "column" "count" empty lines
|
||||
void addEmptyLine(int column = 1, uint count = 1);
|
||||
|
||||
PIString getString(int x, int y);
|
||||
short getShort(int x, int y) {return getString(x, y).toShort();}
|
||||
int getInt(int x, int y) {return getString(x, y).toInt();}
|
||||
float getFloat(int x, int y) {return getString(x, y).toFloat();}
|
||||
double getDouble(int x, int y) {return getString(x, y).toDouble();}
|
||||
PIString getString(const PIString & name);
|
||||
short getShort(const PIString & name) {return getString(name).toShort();}
|
||||
int getInt(const PIString & name) {return getString(name).toInt();}
|
||||
float getFloat(const PIString & name) {return getString(name).toFloat();}
|
||||
double getDouble(const PIString & name) {return getString(name).toDouble();}
|
||||
|
||||
|
||||
//! Returns tabs count
|
||||
uint tabsCount() const {return tabs.size();}
|
||||
|
||||
//! Returns current tab name
|
||||
PIString currentTab() const {return tabs[cur_tab].name;}
|
||||
|
||||
//! Returns current tab index
|
||||
int currentTabIndex() const {return cur_tab;}
|
||||
|
||||
//! Add new tab with name "name", bind key "bind_key" and returns this tab index
|
||||
int addTab(const PIString & name, char bind_key = 0);
|
||||
|
||||
//! Remove tab with index "index"
|
||||
void removeTab(uint index);
|
||||
|
||||
//! Remove tab with name "name"
|
||||
void removeTab(const PIString & name);
|
||||
|
||||
//! Clear content of tab with index "index"
|
||||
void clearTab(uint index);
|
||||
|
||||
//! Clear content of tab with name "name"
|
||||
void clearTab(const PIString & name);
|
||||
|
||||
//! Set current tab to tab with index "index", returns if tab exists
|
||||
bool setTab(uint index);
|
||||
|
||||
//! Set current tab to tab with name "name", returns if tab exists
|
||||
bool setTab(const PIString & name);
|
||||
|
||||
//! Set tab with index "index" bind key to "bind_key", returns if tab exists
|
||||
bool setTabBindKey(uint index, char bind_key);
|
||||
|
||||
//! Set tab with name "name" bind key to "bind_key", returns if tab exists
|
||||
bool setTabBindKey(const PIString & name, char bind_key);
|
||||
|
||||
//! Remove all tabs and if "clearScreen" clear the screen
|
||||
void clearTabs(bool clearScreen = true) {if (clearScreen && isRunning()) {toUpperLeft(); clearScreenLower();} tabs.clear();}
|
||||
|
||||
|
||||
//! Set custom status text of current tab to "str"
|
||||
void addCustomStatus(const PIString & str) {tabs[cur_tab].status = str;}
|
||||
|
||||
//! Clear custom status text of current tab
|
||||
void clearCustomStatus() {tabs[cur_tab].status.clear();}
|
||||
|
||||
//! Returns default alignment
|
||||
Alignment defaultAlignment() const {return def_align;}
|
||||
|
||||
//! Set default alignment to "align"
|
||||
void setDefaultAlignment(Alignment align) {def_align = align;}
|
||||
|
||||
//! Set column "col" alignment to "align"
|
||||
void setColumnAlignment(int col, Alignment align) {if (col < 0 || col >= columns().size_s()) return; column(col).alignment = align;}
|
||||
|
||||
//! Set all columns of all tabs alignment to "align"
|
||||
void setColumnAlignmentToAll(Alignment align) {piForeach (Tab & i, tabs) piForeach (Column & j, i.columns) j.alignment = align; fillLabels();}
|
||||
|
||||
|
||||
//! Directly call function from \a PIKbdListener
|
||||
void enableExitCapture(char key = 'Q') {listener->enableExitCapture(key);}
|
||||
|
||||
//! Directly call function from \a PIKbdListener
|
||||
void disableExitCapture() {listener->disableExitCapture();}
|
||||
|
||||
//! Directly call function from \a PIKbdListener
|
||||
bool exitCaptured() const {return listener->exitCaptured();}
|
||||
|
||||
//! Directly call function from \a PIKbdListener
|
||||
char exitKey() const {return listener->exitKey();}
|
||||
|
||||
|
||||
int windowWidth() const {return width;}
|
||||
int windowHeight() const {return height;}
|
||||
|
||||
PIString fstr(FormatFlags f);
|
||||
void update();
|
||||
void pause(bool yes) {pause_ = yes;}
|
||||
|
||||
// Server functions
|
||||
void startServer(const PIString & name);
|
||||
void stopPeer();
|
||||
bool isServerStarted() const {return peer != 0;}
|
||||
PIStringList clients() const;
|
||||
|
||||
// Client functions
|
||||
void listenServers();
|
||||
PIStringList availableServers() const;
|
||||
PIString selectedServer() const {return server_name;}
|
||||
void connectToServer(const PIString & name);
|
||||
void disconnect();
|
||||
bool isConnected() const {return state == Connected;}
|
||||
|
||||
void toUpperLeft();
|
||||
void moveRight(int n = 1);
|
||||
void moveLeft(int n = 1);
|
||||
void moveTo(int x = 0, int y = 0);
|
||||
void clearScreen();
|
||||
void clearScreenLower();
|
||||
void clearLine();
|
||||
void newLine();
|
||||
void hideCursor();
|
||||
void showCursor();
|
||||
|
||||
EVENT_HANDLER0(void, clearVariables) {clearVariables(true);}
|
||||
EVENT_HANDLER1(void, clearVariables, bool, clearScreen);
|
||||
|
||||
EVENT_HANDLER0(void, waitForFinish) {WAIT_FOR_EXIT}
|
||||
EVENT_HANDLER0(void, start) {start(false);}
|
||||
EVENT_HANDLER1(void, start, bool, wait) {PIThread::start(40); if (wait) waitForFinish();}
|
||||
EVENT_HANDLER0(void, stop) {stop(false);}
|
||||
EVENT_HANDLER1(void, stop, bool, clear);
|
||||
|
||||
EVENT2(keyPressed, PIKbdListener::KeyEvent, key, void * , data)
|
||||
|
||||
//! \handlers
|
||||
//! \{
|
||||
|
||||
//! \fn void waitForFinish()
|
||||
//! \brief block until finished (exit key will be pressed)
|
||||
|
||||
//! \fn void clearVariables(bool clearScreen = true)
|
||||
//! \brief Remove all columns at current tab and if "clearScreen" clear the screen
|
||||
|
||||
//! \fn void start(bool wait = false)
|
||||
//! \brief Start console output and if "wait" block until finished (exit key will be pressed)
|
||||
|
||||
//! \fn void stop(bool clear = false)
|
||||
//! \brief Stop console output and if "clear" clear the screen
|
||||
|
||||
//! \}
|
||||
//! \events
|
||||
//! \{
|
||||
|
||||
//! \fn void keyPressed(PIKbdListener::KeyEvent key, void * data)
|
||||
//! \brief Raise on key "key" pressed, "data" is pointer to %PIConsole object
|
||||
|
||||
//! \}
|
||||
|
||||
private:
|
||||
void begin();
|
||||
void run();
|
||||
void fillLabels();
|
||||
void status();
|
||||
void checkColumn(uint col) {while (columns().size() < col) columns().push_back(Column(def_align));}
|
||||
int bitsValue(const void * src, int offset, int count) const;
|
||||
const char * toBin(const void * d, int s);
|
||||
inline void printLine(const PIString & str, int dx = 0, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const PIString & str, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const char * str, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const bool value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const int value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const long value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const llong value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const float value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const double value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const char value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const short value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const uchar value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const ushort value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const uint value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const ulong value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const ullong value, FormatFlags format = PIConsole::Normal);
|
||||
inline int printValue(const PISystemTime & value, FormatFlags format = PIConsole::Normal);
|
||||
static void key_event(PIKbdListener::KeyEvent key, void * t);
|
||||
|
||||
struct Variable {
|
||||
Variable() {nx = ny = type = offset = bitFrom = bitCount = size = 0; format = Normal; remote = false; ptr = 0; id = 1;}
|
||||
Variable(const Variable & src) {remote = src.remote; name = src.name; format = src.format; type = src.type; offset = src.offset; size = src.size;
|
||||
bitFrom = src.bitFrom; bitCount = src.bitCount; ptr = src.ptr; nx = src.nx; ny = src.ny; rdata = src.rdata; id = src.id;}
|
||||
bool isEmpty() const {return (remote ? false : ptr == 0);}
|
||||
const void * data() {return (remote ? rdata.data() : ptr);}
|
||||
void writeData(PIByteArray & ba) {
|
||||
if (remote) ba << rdata;
|
||||
else {
|
||||
if (type == 0) ba << (*(PIString * )ptr);
|
||||
else ba << PIByteArray::RawData(ptr, size);
|
||||
}
|
||||
}
|
||||
PIString name;
|
||||
FormatFlags format;
|
||||
int nx;
|
||||
int ny;
|
||||
int type;
|
||||
int offset;
|
||||
int bitFrom;
|
||||
int bitCount;
|
||||
int size;
|
||||
int id;
|
||||
bool remote;
|
||||
const void * ptr;
|
||||
PIByteArray rdata;
|
||||
void operator =(const Variable & src) {remote = src.remote; name = src.name; format = src.format; type = src.type; offset = src.offset; size = src.size;
|
||||
bitFrom = src.bitFrom; bitCount = src.bitCount; ptr = src.ptr; nx = src.nx; ny = src.ny; rdata = src.rdata; id = src.id;}
|
||||
};
|
||||
|
||||
struct VariableContent {
|
||||
int id;
|
||||
PIByteArray rdata;
|
||||
};
|
||||
|
||||
struct Column {
|
||||
Column(Alignment align = PIConsole::Right) {variables.reserve(32); alignment = align;}
|
||||
PIVector<Variable> variables;
|
||||
Alignment alignment;
|
||||
uint size() const {return variables.size();}
|
||||
Variable & operator [](int index) {return variables[index];}
|
||||
const Variable & operator [](int index) const {return variables[index];}
|
||||
void push_back(const Variable & v) {variables.push_back(v);}
|
||||
void operator =(const Column & src) {variables = src.variables; alignment = src.alignment;}
|
||||
};
|
||||
|
||||
struct Tab {
|
||||
Tab(PIString n = "", char k = 0) {columns.reserve(8); name = n; key = k;}
|
||||
PIVector<Column> columns;
|
||||
PIString name;
|
||||
PIString status;
|
||||
char key;
|
||||
};
|
||||
|
||||
enum ConnectedState {Disconnected, FetchingData, Committing, Connected};
|
||||
|
||||
friend PIByteArray & operator <<(PIByteArray & ba, const PIConsole::VariableContent & v);
|
||||
friend PIByteArray & operator >>(PIByteArray & ba, PIConsole::VariableContent & v);
|
||||
|
||||
friend PIByteArray & operator <<(PIByteArray & ba, const PIConsole::Variable & v);
|
||||
friend PIByteArray & operator >>(PIByteArray & ba, PIConsole::Variable & v);
|
||||
|
||||
friend PIByteArray & operator <<(PIByteArray & ba, const PIConsole::Column & v);
|
||||
friend PIByteArray & operator >>(PIByteArray & ba, PIConsole::Column & v);
|
||||
|
||||
friend PIByteArray & operator <<(PIByteArray & ba, const PIConsole::Tab & v);
|
||||
friend PIByteArray & operator >>(PIByteArray & ba, PIConsole::Tab & v);
|
||||
|
||||
PIVector<Column> & columns() {return tabs[cur_tab].columns;}
|
||||
Column & column(int index) {return tabs[cur_tab].columns[index - 1];}
|
||||
int couts(const PIString & v);
|
||||
int couts(const char * v);
|
||||
int couts(const bool v);
|
||||
int couts(const char v);
|
||||
int couts(const short v);
|
||||
int couts(const int v);
|
||||
int couts(const long v);
|
||||
int couts(const llong v);
|
||||
int couts(const uchar v);
|
||||
int couts(const ushort v);
|
||||
int couts(const uint v);
|
||||
int couts(const ulong v);
|
||||
int couts(const ullong v);
|
||||
int couts(const float v);
|
||||
int couts(const double v);
|
||||
int couts(const PISystemTime & v);
|
||||
|
||||
struct RemoteClient;
|
||||
|
||||
void serverSendInfo();
|
||||
void serverSendData();
|
||||
RemoteClient & remoteClient(const PIString & fname);
|
||||
EVENT_HANDLER2(void, peerReceived, const PIString &, from, const PIByteArray &, data);
|
||||
EVENT_HANDLER2(void, peerTimer, void * , data, int, delim);
|
||||
EVENT_HANDLER1(void, peerDisconnectedEvent, const PIString &, name);
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PIVector<Tab> tabs;
|
||||
PIString binstr, rstr;
|
||||
PIByteArray rba;
|
||||
Variable tv;
|
||||
PIKbdListener * listener;
|
||||
Alignment def_align;
|
||||
PIKbdListener::KBFunc ret_func;
|
||||
int width, height, pwidth, pheight, col_wid, num_format, systime_format;
|
||||
uint max_y;
|
||||
int vid;
|
||||
uint cur_tab, col_cnt;
|
||||
|
||||
PIPeer * peer;
|
||||
PITimer * peer_timer;
|
||||
PITimeMeasurer peer_tm;
|
||||
PIString server_name;
|
||||
bool server_mode, pause_;
|
||||
ConnectedState state;
|
||||
|
||||
struct RemoteClient {
|
||||
RemoteClient(const PIString & n = "") {name = n; state = Disconnected;}
|
||||
PIString name;
|
||||
ConnectedState state;
|
||||
};
|
||||
|
||||
PIVector<RemoteClient> remote_clients;
|
||||
|
||||
};
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & ba, const PIConsole::VariableContent & v) {ba << v.id << v.rdata; return ba;}
|
||||
inline PIByteArray & operator >>(PIByteArray & ba, PIConsole::VariableContent & v) {ba >> v.id; ba >> v.rdata; return ba;}
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & ba, const PIConsole::Variable & v) {ba << v.name << v.id << (int)v.format << v.type << v.size << v.bitFrom << v.bitCount; return ba;}
|
||||
inline PIByteArray & operator >>(PIByteArray & ba, PIConsole::Variable & v) {ba >> v.name >> v.id >> (int & )v.format >> v.type >> v.size >> v.bitFrom >> v.bitCount; return ba;}
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & ba, const PIConsole::Column & v) {ba << (int)v.alignment << v.variables; return ba;}
|
||||
inline PIByteArray & operator >>(PIByteArray & ba, PIConsole::Column & v) {int a; ba >> a >> v.variables; v.alignment = (PIConsole::Alignment)a; return ba;}
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & ba, const PIConsole::Tab & v) {ba << v.name << v.status << (uchar)v.key << v.columns; return ba;}
|
||||
inline PIByteArray & operator >>(PIByteArray & ba, PIConsole::Tab & v) {ba >> v.name >> v.status >> (uchar&)v.key >> v.columns; return ba;}
|
||||
|
||||
#endif // PICONSOLE_H
|
||||
@@ -21,7 +21,6 @@
|
||||
#define PICONSOLEMODULE_H
|
||||
|
||||
#include "pikbdlistener.h"
|
||||
#include "piconsole.h"
|
||||
#include "piscreen.h"
|
||||
#include "piscreentiles.h"
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
typedef PIFlags<KeyModifier> KeyModifiers;
|
||||
|
||||
//! This struct contains information about pressed keyboard key
|
||||
struct KeyEvent {
|
||||
struct PIP_EXPORT KeyEvent {
|
||||
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)
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
typedef PIFlags<MouseButton> MouseButtons;
|
||||
|
||||
//! This struct contains information about mouse action
|
||||
struct MouseEvent {
|
||||
struct PIP_EXPORT MouseEvent {
|
||||
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
|
||||
@@ -126,18 +126,14 @@ public:
|
||||
};
|
||||
|
||||
//! This struct contains information about mouse wheel action
|
||||
struct WheelEvent: public MouseEvent {
|
||||
struct PIP_EXPORT WheelEvent: public MouseEvent {
|
||||
WheelEvent(): MouseEvent() {direction = false;}
|
||||
|
||||
//! Wheel direction, /b true - up, /b fasle - down
|
||||
bool direction;
|
||||
};
|
||||
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
typedef std::function<void(KeyEvent, void *)> KBFunc;
|
||||
#else
|
||||
typedef void (*KBFunc)(KeyEvent, void * );
|
||||
#endif
|
||||
|
||||
//! Constructs keyboard listener with external function "slot" and custom data "data"
|
||||
explicit PIKbdListener(KBFunc slot = 0, void * data = 0, bool startNow = true);
|
||||
@@ -154,10 +150,8 @@ public:
|
||||
//! Set external function to "slot"
|
||||
void setSlot(KBFunc slot) {ret_func = slot;}
|
||||
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
//! Set external function to "slot"
|
||||
void setSlot(std::function<void(KeyEvent)> slot) {ret_func = [slot](KeyEvent e, void *){slot(e);};}
|
||||
#endif
|
||||
|
||||
//! Returns if exit key if awaiting
|
||||
bool exitCaptured() const {return exit_enabled;}
|
||||
@@ -213,7 +207,7 @@ private:
|
||||
void end();
|
||||
|
||||
#ifndef WINDOWS
|
||||
struct EscSeq {
|
||||
struct PIP_EXPORT EscSeq {
|
||||
const char * seq;
|
||||
int key;
|
||||
int mod;
|
||||
@@ -234,7 +228,7 @@ private:
|
||||
static const EscSeq esc_seq[];
|
||||
#endif
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
KBFunc ret_func;
|
||||
int exit_key;
|
||||
bool exit_enabled, is_active;
|
||||
|
||||
@@ -23,11 +23,12 @@
|
||||
#ifndef PISCREEN_H
|
||||
#define PISCREEN_H
|
||||
|
||||
#include "pip_console_export.h"
|
||||
#include "piscreentile.h"
|
||||
#include "piscreendrawer.h"
|
||||
|
||||
|
||||
class PIP_EXPORT PIScreen: public PIThread, public PIScreenTypes::PIScreenBase
|
||||
class PIP_CONSOLE_EXPORT PIScreen: public PIThread, public PIScreenTypes::PIScreenBase
|
||||
{
|
||||
PIOBJECT_SUBCLASS(PIScreen, PIThread)
|
||||
class SystemConsole;
|
||||
@@ -100,7 +101,7 @@ public:
|
||||
//! \}
|
||||
|
||||
private:
|
||||
class SystemConsole {
|
||||
class PIP_CONSOLE_EXPORT SystemConsole {
|
||||
public:
|
||||
SystemConsole();
|
||||
~SystemConsole();
|
||||
@@ -124,7 +125,7 @@ private:
|
||||
#else
|
||||
PIString formatString(const PIScreenTypes::Cell & c);
|
||||
#endif
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_CONSOLE_EXPORT)
|
||||
int width, height, pwidth, pheight;
|
||||
int mouse_x, mouse_y;
|
||||
PIVector<PIVector<PIScreenTypes::Cell> > cells, pcells;
|
||||
|
||||
@@ -25,16 +25,17 @@
|
||||
#ifndef PISCREENCONSOLE_H
|
||||
#define PISCREENCONSOLE_H
|
||||
|
||||
#include "pip_console_export.h"
|
||||
#include "piscreentiles.h"
|
||||
|
||||
/// NOTE: incomplete class
|
||||
/// TODO: write TileVars
|
||||
|
||||
class PIP_EXPORT TileVars: public PIScreenTile {
|
||||
class PIP_CONSOLE_EXPORT TileVars: public PIScreenTile {
|
||||
public:
|
||||
TileVars(const PIString & n = PIString());
|
||||
protected:
|
||||
struct Variable {
|
||||
struct PIP_CONSOLE_EXPORT Variable {
|
||||
Variable() {nx = ny = type = offset = bitFrom = bitCount = size = 0; format = PIScreenTypes::CellFormat(); ptr = 0;}
|
||||
bool isEmpty() const {return (ptr == 0);}
|
||||
PIString name;
|
||||
@@ -68,7 +69,7 @@ protected:
|
||||
|
||||
|
||||
|
||||
class PIP_EXPORT PIScreenConsoleTile : public PIScreenTile
|
||||
class PIP_CONSOLE_EXPORT PIScreenConsoleTile : public PIScreenTile
|
||||
{
|
||||
public:
|
||||
PIScreenConsoleTile();
|
||||
|
||||
@@ -23,10 +23,11 @@
|
||||
#ifndef PISCREENDRAWER_H
|
||||
#define PISCREENDRAWER_H
|
||||
|
||||
#include "pip_console_export.h"
|
||||
#include "piscreentypes.h"
|
||||
#include "pistring.h"
|
||||
|
||||
class PIP_EXPORT PIScreenDrawer
|
||||
class PIP_CONSOLE_EXPORT PIScreenDrawer
|
||||
{
|
||||
friend class PIScreen;
|
||||
PIScreenDrawer(PIVector<PIVector<PIScreenTypes::Cell> > & c);
|
||||
|
||||
@@ -23,12 +23,13 @@
|
||||
#ifndef PISCREENTILE_H
|
||||
#define PISCREENTILE_H
|
||||
|
||||
#include "pip_console_export.h"
|
||||
#include "piscreentypes.h"
|
||||
#include "pikbdlistener.h"
|
||||
|
||||
class PIScreenDrawer;
|
||||
|
||||
class PIP_EXPORT PIScreenTile: public PIObject {
|
||||
class PIP_CONSOLE_EXPORT PIScreenTile: public PIObject {
|
||||
friend class PIScreen;
|
||||
PIOBJECT_SUBCLASS(PIScreenTile, PIObject)
|
||||
public:
|
||||
|
||||
@@ -23,10 +23,11 @@
|
||||
#ifndef PISCREENTILES_H
|
||||
#define PISCREENTILES_H
|
||||
|
||||
#include "pip_console_export.h"
|
||||
#include "piscreentile.h"
|
||||
|
||||
|
||||
class PIP_EXPORT TileSimple: public PIScreenTile {
|
||||
class PIP_CONSOLE_EXPORT TileSimple: public PIScreenTile {
|
||||
PIOBJECT_SUBCLASS(TileSimple, PIScreenTile)
|
||||
public:
|
||||
typedef PIPair<PIString, PIScreenTypes::CellFormat> Row;
|
||||
@@ -43,7 +44,7 @@ protected:
|
||||
|
||||
class TileList;
|
||||
|
||||
class PIP_EXPORT TileScrollBar: public PIScreenTile {
|
||||
class PIP_CONSOLE_EXPORT TileScrollBar: public PIScreenTile {
|
||||
PIOBJECT_SUBCLASS(TileScrollBar, PIScreenTile)
|
||||
friend class TileList;
|
||||
public:
|
||||
@@ -66,7 +67,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class PIP_EXPORT TileList: public PIScreenTile {
|
||||
class PIP_CONSOLE_EXPORT TileList: public PIScreenTile {
|
||||
PIOBJECT_SUBCLASS(TileList, PIScreenTile)
|
||||
public:
|
||||
TileList(const PIString & n = PIString());
|
||||
@@ -98,7 +99,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class PIP_EXPORT TileButton: public PIScreenTile {
|
||||
class PIP_CONSOLE_EXPORT TileButton: public PIScreenTile {
|
||||
PIOBJECT_SUBCLASS(TileButton, PIScreenTile)
|
||||
public:
|
||||
TileButton(const PIString & n = PIString());
|
||||
@@ -118,7 +119,7 @@ protected:
|
||||
|
||||
|
||||
|
||||
class PIP_EXPORT TileButtons: public PIScreenTile {
|
||||
class PIP_CONSOLE_EXPORT TileButtons: public PIScreenTile {
|
||||
PIOBJECT_SUBCLASS(TileButtons, PIScreenTile)
|
||||
public:
|
||||
TileButtons(const PIString & n = PIString());
|
||||
@@ -143,7 +144,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class PIP_EXPORT TileCheck: public PIScreenTile {
|
||||
class PIP_CONSOLE_EXPORT TileCheck: public PIScreenTile {
|
||||
PIOBJECT_SUBCLASS(TileCheck, PIScreenTile)
|
||||
public:
|
||||
TileCheck(const PIString & n = PIString());
|
||||
@@ -162,7 +163,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class PIP_EXPORT TileProgress: public PIScreenTile {
|
||||
class PIP_CONSOLE_EXPORT TileProgress: public PIScreenTile {
|
||||
PIOBJECT_SUBCLASS(TileProgress, PIScreenTile)
|
||||
public:
|
||||
TileProgress(const PIString & n = PIString());
|
||||
@@ -178,7 +179,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class PIP_EXPORT TilePICout: public TileList {
|
||||
class PIP_CONSOLE_EXPORT TilePICout: public TileList {
|
||||
PIOBJECT_SUBCLASS(TilePICout, PIScreenTile)
|
||||
public:
|
||||
TilePICout(const PIString & n = PIString());
|
||||
@@ -191,7 +192,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class PIP_EXPORT TileInput: public PIScreenTile {
|
||||
class PIP_CONSOLE_EXPORT TileInput: public PIScreenTile {
|
||||
PIOBJECT_SUBCLASS(TileInput, PIScreenTile)
|
||||
public:
|
||||
TileInput(const PIString & n = PIString());
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#ifndef PISCREENTYPES_H
|
||||
#define PISCREENTYPES_H
|
||||
|
||||
#include "pip_console_export.h"
|
||||
#include "pivariant.h"
|
||||
|
||||
class PIScreenTile;
|
||||
@@ -30,7 +31,7 @@ class PIScreenTile;
|
||||
namespace PIScreenTypes {
|
||||
|
||||
//! Color for chars or background
|
||||
enum PIP_EXPORT Color {
|
||||
enum Color {
|
||||
Default /** Default */,
|
||||
Black /** Black */,
|
||||
Red /** Red */,
|
||||
@@ -44,7 +45,7 @@ namespace PIScreenTypes {
|
||||
};
|
||||
|
||||
//! Flags for chars
|
||||
enum PIP_EXPORT CharFlag {
|
||||
enum CharFlag {
|
||||
Bold /** Bold or bright */ = 0x1,
|
||||
Blink /** Blink text */ = 0x2,
|
||||
Underline /** Underline text */ = 0x4,
|
||||
@@ -52,14 +53,14 @@ namespace PIScreenTypes {
|
||||
};
|
||||
|
||||
//! Alignment
|
||||
enum PIP_EXPORT Alignment {
|
||||
enum Alignment {
|
||||
Left /** Left */ ,
|
||||
Center /** Center */ ,
|
||||
Right /** Right */
|
||||
};
|
||||
|
||||
//! Size policy
|
||||
enum PIP_EXPORT SizePolicy {
|
||||
enum SizePolicy {
|
||||
Fixed /** Fixed size */ ,
|
||||
Preferred /** Preferred size */ ,
|
||||
Expanding /** Maximum available size */ ,
|
||||
@@ -67,13 +68,13 @@ namespace PIScreenTypes {
|
||||
};
|
||||
|
||||
//! Direction
|
||||
enum PIP_EXPORT Direction {
|
||||
enum Direction {
|
||||
Horizontal /** Horizontal */ ,
|
||||
Vertical /** Vertical */
|
||||
};
|
||||
|
||||
//! Focus flags
|
||||
enum PIP_EXPORT FocusFlag {
|
||||
enum FocusFlag {
|
||||
CanHasFocus /** Tile can has focus */ = 0x1,
|
||||
NextByTab /** Focus passed to next tile by tab key */ = 0x2,
|
||||
NextByArrowsHorizontal /** Focus passed to next tile by arrow keys left or right */ = 0x4,
|
||||
@@ -87,7 +88,7 @@ namespace PIScreenTypes {
|
||||
typedef PIFlags<CharFlag> CharFlags;
|
||||
typedef PIFlags<FocusFlag> FocusFlags;
|
||||
|
||||
union PIP_EXPORT CellFormat {
|
||||
union PIP_CONSOLE_EXPORT CellFormat {
|
||||
CellFormat(ushort f = 0) {raw_format = f;}
|
||||
CellFormat(Color col_char, Color col_back = Default, CharFlags flags_ = 0) {
|
||||
color_char = col_char;
|
||||
@@ -104,7 +105,7 @@ namespace PIScreenTypes {
|
||||
bool operator !=(const CellFormat & c) const {return raw_format != c.raw_format;}
|
||||
};
|
||||
|
||||
struct PIP_EXPORT Cell {
|
||||
struct PIP_CONSOLE_EXPORT Cell {
|
||||
Cell(PIChar c = PIChar(' '), CellFormat f = CellFormat()) {symbol = c; format = f;}
|
||||
CellFormat format;
|
||||
PIChar symbol;
|
||||
@@ -120,13 +121,13 @@ namespace PIScreenTypes {
|
||||
}
|
||||
};
|
||||
|
||||
struct PIP_EXPORT TileEvent {
|
||||
struct PIP_CONSOLE_EXPORT TileEvent {
|
||||
TileEvent(int t = -1, const PIVariant & d = PIVariant()): type(t), data(d) {}
|
||||
int type;
|
||||
PIVariant data;
|
||||
};
|
||||
|
||||
class PIScreenBase {
|
||||
class PIP_CONSOLE_EXPORT PIScreenBase {
|
||||
public:
|
||||
PIScreenBase() {}
|
||||
virtual ~PIScreenBase() {}
|
||||
|
||||
@@ -23,11 +23,12 @@
|
||||
#ifndef PITERMINAL_H
|
||||
#define PITERMINAL_H
|
||||
|
||||
#include "pip_console_export.h"
|
||||
#include "pikbdlistener.h"
|
||||
#include "piscreentypes.h"
|
||||
|
||||
|
||||
class PIP_EXPORT PITerminal: public PIThread
|
||||
class PIP_CONSOLE_EXPORT PITerminal: public PIThread
|
||||
{
|
||||
PIOBJECT_SUBCLASS(PITerminal, PIThread)
|
||||
public:
|
||||
@@ -63,7 +64,7 @@ private:
|
||||
int termType(const PIString & t);
|
||||
#endif
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_CONSOLE_EXPORT)
|
||||
int dsize_x, dsize_y;
|
||||
int size_x, size_y, cursor_x, cursor_y;
|
||||
bool cursor_blink, cursor_visible;
|
||||
|
||||
@@ -28,147 +28,347 @@
|
||||
* \fn PIVector::PIVector();
|
||||
* Contructs an empty vector
|
||||
|
||||
* \fn PIVector::PIVector(ullong size, const Type & value = Type());
|
||||
* \fn PIVector::PIVector(size_t size, const T & value = T());
|
||||
* \brief Contructs vector with size "size" filled elements "value"
|
||||
* \details Example: \snippet picontainers.cpp PIVector::PIVector
|
||||
|
||||
* \fn const Type & PIVector::at(ullong index) const;
|
||||
* \fn const T & PIVector::at(size_t index) const;
|
||||
* \brief Read-only access to element by index "index"
|
||||
* \details Example: \snippet picontainers.cpp PIVector::at_c
|
||||
* \sa \a operator[]
|
||||
|
||||
* \fn Type & PIVector::at(ullong index);
|
||||
* \fn T & PIVector::at(size_t index);
|
||||
* \brief Full access to element by index "index"
|
||||
* \details Example: \snippet picontainers.cpp PIVector::at
|
||||
* \sa \a operator[]
|
||||
|
||||
* \fn const Type * PIVector::data(ullong index = 0) const;
|
||||
* \fn const T * PIVector::data(size_t index = 0) const;
|
||||
* \brief Read-only pointer to element by index "index"
|
||||
* \details Example: \snippet picontainers.cpp PIVector::data_c
|
||||
|
||||
* \fn Type * PIVector::data(ullong index = 0);
|
||||
* \fn T * PIVector::data(size_t index = 0);
|
||||
* \brief Pointer to element by index "index"
|
||||
* \details Example: \snippet picontainers.cpp PIVector::data
|
||||
|
||||
* \fn ullong PIVector::size() const;
|
||||
* \fn size_t PIVector::size() const;
|
||||
* \brief Elements count
|
||||
|
||||
* \fn int PIVector::size_s() const;
|
||||
* \fn ssize_t PIVector::size_s() const;
|
||||
* \brief Elements count
|
||||
|
||||
* \fn bool PIVector::isEmpty() const;
|
||||
* \brief Return \c "true" if vector is empty, i.e. size = 0
|
||||
|
||||
* \fn bool PIVector::has(const Type & t) const;
|
||||
* \fn bool PIVector::has(const T & t) const;
|
||||
|
||||
* \fn bool PIVector::contains(const Type & v) const;
|
||||
* \fn bool PIVector::contains(const T & v) const;
|
||||
* \brief Return \c "true" if vector has at least one element equal "t"
|
||||
|
||||
* \fn int PIVector::etries(const Type & t) const;
|
||||
* \fn int PIVector::etries(const T & t) const;
|
||||
* \brief Return how many times element "t" appears in vector
|
||||
|
||||
* \fn static int PIVector::compare_func(const Type * t0, const Type * t1);
|
||||
* \brief Standard compare function for type "Type". Return 0 if t0 = t1, -1 if t0 < t1 and 1 if t0 > t1.
|
||||
* \fn ssize_t PIVector::indexOf(const T & t) const;
|
||||
* \brief Return index of first element equal "t" or -1 if there is no such element
|
||||
|
||||
* \fn void PIVector::resize(ullong size, const Type & new_type = Type());
|
||||
* \fn ssize_t PIVector::lastIndexOf(const T & t) const;
|
||||
* \brief Return index of last element equal "t" or -1 if there is no such element
|
||||
|
||||
* \fn static int PIVector::compare_func(const T * t0, const T * t1);
|
||||
* \brief Standard compare function for type "T". Return 0 if t0 = t1, -1 if t0 < t1 and 1 if t0 > t1.
|
||||
|
||||
* \fn void PIVector::resize(size_t size, const T & new_type = T());
|
||||
* \brief Resize vector to size "size"
|
||||
* \details Elements removed from end of vector if new size < old size, or added new elements = "new_type" if new size > old size.\n
|
||||
* Example: \snippet picontainers.cpp PIVector::resize
|
||||
* \sa \a size(), \a clear()
|
||||
|
||||
* \fn PIVector<T> & PIVector::enlarge(ullong size);
|
||||
* \fn PIVector & PIVector::enlarge(size_t size);
|
||||
* \brief Increase vector size with "size" elements
|
||||
|
||||
* \fn void PIVector::clear();
|
||||
* \brief Clear vector. Equivalent to call <tt>"resize(0)"</tt>
|
||||
|
||||
* \fn PIVector<T> & PIVector::sort(CompareFunc compare = compare_func);
|
||||
* \fn PIVector & PIVector::sort(CompareFunc compare = compare_func);
|
||||
* \brief Sort vector using quick sort algorithm and standard compare function
|
||||
* \details Example: \snippet picontainers.cpp PIVector::sort_0
|
||||
* With custom compare function: \snippet picontainers.cpp PIVector::sort_1
|
||||
|
||||
* \fn PIVector<T> & PIVector::fill(const Type & t);
|
||||
* \fn PIVector & PIVector::fill(const T & t);
|
||||
* \brief Fill vector with elements "t" leave size is unchanged and return reference to vector
|
||||
* \details Example: \snippet picontainers.cpp PIVector::fill
|
||||
|
||||
* \fn Type & PIVector::back();
|
||||
* \fn PIVector & PIVector::assign(const T & t = T());
|
||||
* \brief Synonym of \a fill(t)
|
||||
|
||||
* \fn PIVector & PIVector::assign(size_t new_size, const T & t);
|
||||
* \brief Resize to "new_size", then fill with "t"
|
||||
|
||||
* \fn T & PIVector::back();
|
||||
* \brief Last element of the vector
|
||||
|
||||
* \fn const Type & PIVector::back() const;
|
||||
* \fn const T & PIVector::back() const;
|
||||
* \brief Last element of the vector
|
||||
|
||||
* \fn Type & PIVector::front();
|
||||
* \fn T & PIVector::front();
|
||||
* \brief First element of the vector
|
||||
|
||||
* \fn const Type & PIVector::front() const;
|
||||
* \fn const T & PIVector::front() const;
|
||||
* \brief First element of the vector
|
||||
|
||||
* \fn PIVector<T> & PIVector::push_back(const Type & t);
|
||||
* \fn PIVector & PIVector::push_back(const T & t);
|
||||
* \brief Add new element "t" at the end of vector and return reference to vector
|
||||
|
||||
* \fn PIVector<T> & PIVector::push_front(const Type & t);
|
||||
* \fn PIVector & PIVector::push_front(const T & t);
|
||||
* \brief Add new element "t" at the beginning of vector and return reference to vector
|
||||
|
||||
* \fn PIVector<T> & PIVector::pop_back();
|
||||
* \fn PIVector & PIVector::pop_back();
|
||||
* \brief Remove one element from the end of vector and return reference to vector
|
||||
|
||||
* \fn PIVector<T> & PIVector::pop_front();
|
||||
* \fn PIVector & PIVector::pop_front();
|
||||
* \brief Remove one element from the beginning of vector and return reference to vector
|
||||
|
||||
* \fn Type PIVector::take_back();
|
||||
* \fn T PIVector::take_back();
|
||||
* \brief Remove one element from the end of vector and return it
|
||||
|
||||
* \fn Type PIVector::take_front();
|
||||
* \fn T PIVector::take_front();
|
||||
* \brief Remove one element from the beginning of vector and return it
|
||||
|
||||
* \fn PIVector<T> & PIVector::remove(uint index);
|
||||
* \fn PIVector & PIVector::remove(size_t index);
|
||||
* \brief Remove one element by index "index" and return reference to vector
|
||||
* \details Example: \snippet picontainers.cpp PIVector::remove_0
|
||||
* \sa \a removeOne(), \a removeAll()
|
||||
|
||||
* \fn PIVector<T> & PIVector::remove(uint index, uint count);
|
||||
* \fn PIVector & PIVector::remove(size_t index, size_t count);
|
||||
* \brief Remove "count" elements by first index "index" and return reference to vector
|
||||
* \details Example: \snippet picontainers.cpp PIVector::remove_1
|
||||
* \sa \a removeOne(), \a removeAll()
|
||||
|
||||
* \fn PIVector<T> & PIVector::removeOne(const Type & v);
|
||||
* \fn PIVector & PIVector::removeOne(const T & v);
|
||||
* \brief Remove no more than one element equal "v" and return reference to vector
|
||||
* \details Example: \snippet picontainers.cpp PIVector::removeOne
|
||||
* \sa \a remove(), \a removeAll()
|
||||
|
||||
* \fn PIVector<T> & PIVector::removeAll(const Type & v);
|
||||
* \fn PIVector & PIVector::removeAll(const T & v);
|
||||
* \brief Remove all elements equal "v" and return reference to vector
|
||||
* \details Example: \snippet picontainers.cpp PIVector::removeAll
|
||||
* \sa \a remove(), \a removeOne()
|
||||
|
||||
* \fn PIVector<T> & PIVector::insert(uint pos, const Type & t);
|
||||
* \fn PIVector & PIVector::insert(size_t pos, const T & t);
|
||||
* \brief Insert element "t" after index "pos" and return reference to vector
|
||||
* \details Example: \snippet picontainers.cpp PIVector::insert_0
|
||||
|
||||
* \fn PIVector<T> & PIVector::insert(uint pos, const PIVector<T> & t);
|
||||
* \fn PIVector & PIVector::insert(size_t pos, const PIVector & t);
|
||||
* \brief Insert other vector "t" after index "pos" and return reference to vector
|
||||
* \details Example: \snippet picontainers.cpp PIVector::insert_1
|
||||
|
||||
* \fn Type & PIVector::operator [](uint index);
|
||||
* \fn T & PIVector::operator [](size_t index);
|
||||
* \brief Full access to element by index "index"
|
||||
* \details Example: \snippet picontainers.cpp PIVector::()
|
||||
* \sa \a at()
|
||||
|
||||
* \fn const Type & PIVector::operator [](uint index) const;
|
||||
* \fn const T & PIVector::operator [](size_t index) const;
|
||||
* \brief Read-only access to element by index "index"
|
||||
* \details Example: \snippet picontainers.cpp PIVector::()_c
|
||||
* \sa \a at()
|
||||
|
||||
* \fn PIVector<T> & PIVector::operator <<(const Type & t);
|
||||
* \fn PIVector & PIVector::operator <<(const T & t);
|
||||
* \brief Add new element "t" at the end of vector and return reference to vector
|
||||
|
||||
* \fn PIVector<T> & PIVector::operator <<(const PIVector<T> & t);
|
||||
* \fn PIVector & PIVector::operator <<(const PIVector & t);
|
||||
* \brief Add vector "t" at the end of vector and return reference to vector
|
||||
|
||||
* \fn bool PIVector::operator ==(const PIVector<T> & t);
|
||||
* \fn bool PIVector::operator ==(const PIVector & t);
|
||||
* \brief Compare with vector "t"
|
||||
|
||||
* \fn bool PIVector::operator !=(const PIVector<T> & t);
|
||||
* \fn bool PIVector::operator !=(const PIVector & t);
|
||||
* \brief Compare with vector "t"
|
||||
|
||||
* */
|
||||
|
||||
|
||||
|
||||
|
||||
/** \class PIMap
|
||||
* \brief Associative array
|
||||
* \details This class used to store Key = Value array of any
|
||||
* type of data. \a value() returns value for key and leave map
|
||||
* unchaged in any case. \a operator [] create entry in map if
|
||||
* there is no entry for given key. You can retrieve all
|
||||
* keys by method \a keys() and all values by methos \a values().
|
||||
* To iterate all entries use class PIMapIterator, or methods
|
||||
* \a makeIterator() and \a makeReverseIterator().
|
||||
|
||||
* \fn PIMap::PIMap();
|
||||
* \brief Contructs an empty map
|
||||
|
||||
* \fn PIMap::PIMap(const PIMap & other);
|
||||
* \brief Contructs a copy of "other"
|
||||
|
||||
* \fn PIMap & PIMap::operator =(const PIMap & other);
|
||||
* \brief Copy operator
|
||||
|
||||
* \fn PIMap::PIMap(const PIMap & other);
|
||||
* \brief Contructs a copy of "other"
|
||||
|
||||
* \fn PIMapIterator PIMap::makeIterator() const
|
||||
* \brief Returns PIMapIterator for this map
|
||||
|
||||
* \fn PIMapIterator PIMap::makeReverseIterator() const
|
||||
* \brief Returns reverse PIMapIterator for this map
|
||||
|
||||
|
||||
* \fn size_t PIMap::size() const
|
||||
* \brief Returns entries count
|
||||
|
||||
* \fn int PIMap::size_s() const
|
||||
* \brief Returns entries count
|
||||
|
||||
* \fn size_t PIMap::length() const
|
||||
* \brief Returns entries count
|
||||
|
||||
* \fn bool PIMap::isEmpty() const
|
||||
* \brief Returns if map is empty
|
||||
|
||||
|
||||
* \fn T & PIMap::operator [](const Key & key)
|
||||
* \brief Returns value for key "key". If there is no key in map, create one.
|
||||
|
||||
* \fn const T PIMap::operator [](const Key & key) const
|
||||
* \brief Returns value for key "key". If there is no key in map, returns default T().
|
||||
|
||||
* \fn T & PIMap::at(const Key & key)
|
||||
* \brief Equivalent to operator []
|
||||
|
||||
* \fn const T PIMap::at(const Key & key) const
|
||||
* \brief Equivalent to operator []
|
||||
|
||||
|
||||
* \fn PIMap & PIMap::operator <<(const PIMap & other)
|
||||
* \brief Insert all etries of "other" to this map. Override existing values.
|
||||
|
||||
* \fn bool PIMap::operator ==(const PIMap & t) const
|
||||
* \brief Compare operator
|
||||
|
||||
* \fn bool PIMap::operator !=(const PIMap & t) const
|
||||
* \brief Compare operator
|
||||
|
||||
* \fn bool PIMap::contains(const Key & key) const
|
||||
* \brief Returns "true" if map contains entry with key "key"
|
||||
|
||||
|
||||
* \fn PIMap & PIMap::reserve(size_t new_size)
|
||||
* \brief Reserve space for "new_size" entries
|
||||
|
||||
* \fn PIMap & PIMap::removeOne(const Key & key)
|
||||
* \brief Remove entry with key "key"
|
||||
|
||||
* \fn PIMap & PIMap::remove(const Key & key)
|
||||
* \brief Equivalent \a removeOne(key)
|
||||
|
||||
* \fn PIMap & PIMap::erase(const Key & key)
|
||||
* \brief Equivalent \a removeOne(key)
|
||||
|
||||
* \fn PIMap & PIMap::clear()
|
||||
* \brief Clear map
|
||||
|
||||
|
||||
* \fn void PIMap::swap(PIMap & other)
|
||||
* \brief Swap map with "other"
|
||||
|
||||
|
||||
* \fn PIMap & PIMap::insert(const Key & key, const T & value)
|
||||
* \brief Insert or rewrite entry with key "key" and value "value"
|
||||
|
||||
* \fn const T PIMap::value(const Key & key, const T & default = T())
|
||||
* \brief Returns value for key "key". If there is no key in map, returns "default".
|
||||
|
||||
* \fn PIVector<T> PIMap::values() const
|
||||
* \brief Returns all values as PIVector
|
||||
|
||||
* \fn Key PIMap::key(const T & value, const Key & default = Key()) const
|
||||
* \brief Returns key for first founded value "value". If there is no such value in map, returns "default".
|
||||
|
||||
* \fn PIVector<Key> PIMap::keys() const
|
||||
* \brief Returns all keys as PIVector
|
||||
|
||||
* */
|
||||
|
||||
|
||||
|
||||
|
||||
/** \class PIMapIterator
|
||||
* \brief Helper class to iterate over PIMap
|
||||
* \details This class used to access keys and values in PIMap.
|
||||
* You can use constructor to create iterator, or use \a PIMap::makeIterator()
|
||||
* and \a PIMap::makeReverseIterator() methods.
|
||||
*
|
||||
* First usage variant:
|
||||
* \code
|
||||
* PIMap<int, PIString> m;
|
||||
* m[1] = "one";
|
||||
* m[2] = "two";
|
||||
* m[4] = "four";
|
||||
*
|
||||
* auto it = m.makeIterator();
|
||||
* while (it.next()) {
|
||||
* piCout << it.key() << it.value();
|
||||
* }
|
||||
* // 1 one
|
||||
* // 2 two
|
||||
* // 4 four
|
||||
* \endcode
|
||||
*
|
||||
* Using hasNext():
|
||||
* \code
|
||||
* while (it.hasNext()) {
|
||||
* it.next();
|
||||
* \endcode
|
||||
*
|
||||
* Using constructor:
|
||||
* \code
|
||||
* PIMapIterator<int, PIString> it(m);
|
||||
* \endcode
|
||||
*
|
||||
* Write access:
|
||||
* \code
|
||||
* while (it.next()) {
|
||||
* it.valueRef().append("_!");
|
||||
* piCout << it.key() << it.value();
|
||||
* }
|
||||
*
|
||||
* // 1 one_!
|
||||
* // 2 two_!
|
||||
* // 4 four_!
|
||||
* \endcode
|
||||
*
|
||||
* Reverse iterator:
|
||||
* \code
|
||||
* auto it = m.makeReverseIterator();
|
||||
* while (it.next()) {
|
||||
* piCout << it.key() << it.value();
|
||||
* }
|
||||
*
|
||||
* // 4 four
|
||||
* // 2 two
|
||||
* // 1 one
|
||||
* \endcode
|
||||
|
||||
* \fn PIMapIterator(const PIMap & map, bool reverse = false)
|
||||
* \brief Contructs iterator for "map". Current position is invalid.
|
||||
|
||||
* \fn const Key & PIMapIterator::key() const
|
||||
* \brief Returns current entry key
|
||||
|
||||
* \fn const T & PIMapIterator::value() const
|
||||
* \brief Returns current entry value
|
||||
|
||||
* \fn T & PIMapIterator::valueRef() const
|
||||
* \brief Returns reference to current entry value
|
||||
|
||||
* \fn bool PIMapIterator::hasNext()
|
||||
* \brief Returns if iterator can jump to next entry
|
||||
|
||||
* \fn bool PIMapIterator::next()
|
||||
* \brief Jump to next entry and return if new position is valid.
|
||||
|
||||
* */
|
||||
|
||||
@@ -97,141 +97,32 @@
|
||||
*/
|
||||
# define piForeachCR(i,c)
|
||||
|
||||
/*!\brief Macro for break from any piForeach* loop
|
||||
* \details \warning C++ ordinary "break" doesn`t work inside piForeach*
|
||||
* loops! Always use "piBreak" instead!
|
||||
*/
|
||||
# define piBreak
|
||||
|
||||
#else
|
||||
|
||||
# define piBreak {_for._end = true; break;}
|
||||
|
||||
template <typename C>
|
||||
struct _reverse_wrapper {
|
||||
C & c_;
|
||||
_reverse_wrapper(C & c): c_(c) {}
|
||||
_reverse_wrapper(const C & c): c_(const_cast<C&>(c)) {}
|
||||
typename C::reverse_iterator begin() {return c_.rbegin();}
|
||||
typename C::reverse_iterator end() {return c_.rend(); }
|
||||
typename C::const_reverse_iterator begin() const {return c_.rbegin();}
|
||||
typename C::const_reverse_iterator end() const {return c_.rend(); }
|
||||
};
|
||||
|
||||
template <typename C> _reverse_wrapper<C> _reverse_wrap(C & c) {return _reverse_wrapper<C>(c);}
|
||||
template <typename C> _reverse_wrapper<C> _reverse_wrap(const C & c) {return _reverse_wrapper<C>(c);}
|
||||
|
||||
|
||||
# define piForTimes(c) for(int _i##c = 0; _i##c < c; ++_i##c)
|
||||
|
||||
#ifdef CC_GCC
|
||||
# define piForeach(i,c) for(i : c)
|
||||
# define piForeachC(i,c) for(const i : c)
|
||||
# define piForeachR(i,c) for(i : _reverse_wrap(c))
|
||||
# define piForeachRC(i,c) for(const i : _reverse_wrap(c))
|
||||
|
||||
template<typename Type>
|
||||
class _PIForeach {
|
||||
public:
|
||||
_PIForeach(Type & t): _t(t), _break(false), _end(false) {_it = _t.begin();}
|
||||
typename Type::value_type _var;
|
||||
typename Type::iterator _it;
|
||||
Type & _t;
|
||||
bool _break, _end;
|
||||
inline bool isEnd() {return _it == _t.end();}
|
||||
inline void operator ++() {if (_end) _it = _t.end(); else _it++; _break = false;}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class _PIForeachR {
|
||||
public:
|
||||
_PIForeachR(Type & t): _t(t), _break(false), _end(false) {_rit = _t.rbegin();}
|
||||
typename Type::value_type _var;
|
||||
typename Type::reverse_iterator _rit;
|
||||
Type & _t;
|
||||
bool _break, _end;
|
||||
inline bool isEnd() {return _rit == _t.rend();}
|
||||
inline void operator ++() {if (_end) _rit = _t.rend(); else _rit++; _break = false;}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class _PIForeachC {
|
||||
public:
|
||||
_PIForeachC(const Type & t): _t(t), _break(false), _end(false) {_it = _t.begin();}
|
||||
typename Type::value_type _var;
|
||||
typename Type::const_iterator _it;
|
||||
const Type & _t;
|
||||
bool _break, _end;
|
||||
inline bool isEnd() {return _it == _t.end();}
|
||||
inline void operator ++() {if (_end) _it = _t.end(); else _it++; _break = false;}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class _PIForeachCR {
|
||||
public:
|
||||
_PIForeachCR(const Type & t): _t(t), _break(false), _end(false) {_rit = _t.rbegin();}
|
||||
typename Type::value_type _var;
|
||||
typename Type::const_reverse_iterator _rit;
|
||||
const Type & _t;
|
||||
bool _break, _end;
|
||||
inline bool isEnd() {return _rit == _t.rend();}
|
||||
inline void operator ++() {if (_end) _rit = _t.rend(); else _rit++; _break = false;}
|
||||
};
|
||||
|
||||
#define piForeach(i,c) for(_PIForeach<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
|
||||
for(i(*_for._it); !_for._break; _for._break = true)
|
||||
#define piForeachR(i,c) for(_PIForeachR<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
|
||||
for(i(*_for._rit); !_for._break; _for._break = true)
|
||||
#define piForeachA(i,c) for(_PIForeach<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
|
||||
for(typeof(_for._var) & i(*_for._it); !_for._break; _for._break = true)
|
||||
#define piForeachAR(i,c) for(_PIForeachR<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
|
||||
for(typeof(_for._var) & i(*_for._rit); !_for._break; _for._break = true)
|
||||
#define piForeachC(i,c) for(_PIForeachC<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
|
||||
for(const i(*_for._it); !_for._break; _for._break = true)
|
||||
#define piForeachCR(i,c) for(_PIForeachCR<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
|
||||
for(const i(*_for._rit); !_for._break; _for._break = true)
|
||||
#define piForeachCA(i,c) for(_PIForeachC<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
|
||||
for(const typeof(_for._var) & i(*_for._it); !_for._break; _for._break = true)
|
||||
#define piForeachCAR(i,c) for(_PIForeachCR<typeof(c)> _for(c); !_for.isEnd(); ++_for) \
|
||||
for(const typeof(_for._var) & i(*_for._rit); !_for._break; _for._break = true)
|
||||
|
||||
#define piForeachRA piForeachAR
|
||||
#define piForeachAC piForeachCA
|
||||
#define piForeachCRA piForeachCAR
|
||||
#define piForeachARC piForeachCAR
|
||||
#define piForeachACR piForeachCAR
|
||||
#define piForeachRCA piForeachCAR
|
||||
#define piForeachRAC piForeachCAR
|
||||
|
||||
#else
|
||||
|
||||
class _PIForeachBase {public: mutable bool _break, _end; };
|
||||
|
||||
template<typename Type>
|
||||
class _PIForeach: public _PIForeachBase {
|
||||
public:
|
||||
_PIForeach(Type & t, bool i = false): _t(t), _inv(i) {_break = _end = false; if (_inv) _rit = _t.rbegin(); else _it = _t.begin();}
|
||||
mutable typename Type::value_type _var;
|
||||
mutable typename Type::iterator _it;
|
||||
mutable typename Type::reverse_iterator _rit;
|
||||
Type & _t;
|
||||
bool _inv;
|
||||
bool isEnd() {if (_inv) return _rit == _t.rend(); else return _it == _t.end();}
|
||||
void operator ++() {if (_inv) {if (_end) _rit = _t.rend(); else _rit++;} else {if (_end) _it = _t.end(); else _it++;} _break = false;}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class _PIForeachC: public _PIForeachBase {
|
||||
public:
|
||||
_PIForeachC(const Type & t, bool i = false): _t(t), _inv(i) {_break = _end = false; if (_inv) _rit = _t.rbegin(); else _it = _t.begin();}
|
||||
mutable typename Type::value_type _var;
|
||||
mutable typename Type::const_iterator _it;
|
||||
mutable typename Type::const_reverse_iterator _rit;
|
||||
const Type & _t;
|
||||
bool _inv;
|
||||
bool isEnd() {if (_inv) return _rit == _t.rend(); else return _it == _t.end();}
|
||||
void operator ++() {if (_inv) {if (_end) _rit = _t.rend(); else _rit++;} else {if (_end) _it = _t.end(); else _it++;} _break = false;}
|
||||
};
|
||||
|
||||
template <typename T> inline _PIForeach<T> _PIForeachNew(T & t, bool i = false) {return _PIForeach<T>(t, i);}
|
||||
template <typename T> inline _PIForeach<T> * _PIForeachCast(_PIForeachBase & c, T & ) {return static_cast<_PIForeach<T> * >(&c);}
|
||||
|
||||
template <typename T> inline _PIForeachC<T> _PIForeachNewC(const T & t, bool i = false) {return _PIForeachC<T>(t, i);}
|
||||
template <typename T> inline _PIForeachC<T> * _PIForeachCastC(_PIForeachBase & c, const T & ) {return static_cast<_PIForeachC<T> * >(&c);}
|
||||
|
||||
#define piForeach(i,c) for(_PIForeachBase & _for = _PIForeachNew(c); !_PIForeachCast(_for, c)->isEnd(); ++(*_PIForeachCast(_for, c))) \
|
||||
for(i = *(_PIForeachCast(_for, c)->_it); !_for._break; _for._break = true)
|
||||
#define piForeachR(i,c) for(_PIForeachBase & _for = _PIForeachNew(c, true); !_PIForeachCast(_for, c)->isEnd(); ++(*_PIForeachCast(_for, c))) \
|
||||
for(i = *(_PIForeachCast(_for, c)->_rit); !_for._break; _for._break = true)
|
||||
#define piForeachC(i,c) for(_PIForeachBase & _for = _PIForeachNewC(c); !_PIForeachCastC(_for, c)->isEnd(); ++(*_PIForeachCastC(_for, c))) \
|
||||
for(const i = *(_PIForeachCastC(_for, c)->_it); !_for._break; _for._break = true)
|
||||
#define piForeachCR(i,c) for(_PIForeachBase & _for = _PIForeachNewC(c, false); !_PIForeachCastC(_for, c)->isEnd(); ++(*_PIForeachCastC(_for, c))) \
|
||||
for(const i = *(_PIForeachCastC(_for, c)->_rit); !_for._break; _for._break = true)
|
||||
|
||||
#endif
|
||||
|
||||
#define piForeachRC piForeachCR
|
||||
# define piForeachCR piForeachRC
|
||||
|
||||
#endif // DOXYGEN
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ template <typename T>
|
||||
class PIDeque {
|
||||
public:
|
||||
inline PIDeque(): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||
//piCout << "PIDeque";
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
}
|
||||
inline PIDeque(const PIDeque<T> & other): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||
@@ -49,8 +48,10 @@ public:
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
resize(pid_size, f);
|
||||
}
|
||||
inline PIDeque(PIDeque<T> && other): pid_data(other.pid_data), pid_size(other.pid_size), pid_rsize(other.pid_rsize), pid_start(other.pid_start) {
|
||||
other._reset();
|
||||
}
|
||||
inline virtual ~PIDeque() {
|
||||
//piCout << "~PIDeque";
|
||||
PIINTROSPECTION_CONTAINER_DELETE(T)
|
||||
PIINTROSPECTION_CONTAINER_FREE(T, (pid_rsize))
|
||||
deleteT(pid_data + pid_start, pid_size);
|
||||
@@ -66,6 +67,11 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PIDeque<T> & operator =(PIDeque<T> && other) {
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
typedef T value_type;
|
||||
|
||||
class iterator {
|
||||
@@ -256,6 +262,23 @@ public:
|
||||
elementNew(pid_data + pid_start + index, v);
|
||||
return *this;
|
||||
}
|
||||
inline PIDeque<T> & insert(size_t index, T && v) {
|
||||
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
||||
if (dir) {
|
||||
alloc(pid_size + 1, true);
|
||||
if (index < pid_size - 1) {
|
||||
size_t os = pid_size - index - 1;
|
||||
memmove((void*)(&(pid_data[index + pid_start + 1])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc(pid_size + 1, false, -1);
|
||||
if (index > 0)
|
||||
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + 1])), index * sizeof(T));
|
||||
}
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
||||
elementNew(pid_data + pid_start + index, std::move(v));
|
||||
return *this;
|
||||
}
|
||||
inline PIDeque<T> & insert(size_t index, const PIDeque<T> & other) {
|
||||
if (other.isEmpty()) return *this;
|
||||
assert(&other != this);
|
||||
@@ -336,7 +359,14 @@ public:
|
||||
elementNew(pid_data + pid_start + pid_size - 1, v);
|
||||
return *this;
|
||||
}
|
||||
inline PIDeque<T> & push_back(T && v) {
|
||||
alloc(pid_size + 1, true);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1);
|
||||
elementNew(pid_data + pid_start + pid_size - 1, std::move(v));
|
||||
return *this;
|
||||
}
|
||||
inline PIDeque<T> & append(const T & v) {return push_back(v);}
|
||||
inline PIDeque<T> & append(T && v) {return push_back(std::move(v));}
|
||||
inline PIDeque<T> & append(const PIDeque<T> & t) {
|
||||
assert(&t != this);
|
||||
size_t ps = pid_size;
|
||||
@@ -345,10 +375,13 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline PIDeque<T> & operator <<(const T & v) {return push_back(v);}
|
||||
inline PIDeque<T> & operator <<(T && v) {return push_back(std::move(v));}
|
||||
inline PIDeque<T> & operator <<(const PIDeque<T> & t) {return append(t);}
|
||||
|
||||
inline PIDeque<T> & push_front(const T & v) {insert(0, v); return *this;}
|
||||
inline PIDeque<T> & push_front(T && v) {insert(0, std::move(v)); return *this;}
|
||||
inline PIDeque<T> & prepend(const T & v) {return push_front(v);}
|
||||
inline PIDeque<T> & prepend(T && v) {return push_front(std::move(v));}
|
||||
|
||||
inline PIDeque<T> & pop_back() {if (pid_size == 0) return *this; resize(pid_size - 1); return *this;}
|
||||
inline PIDeque<T> & pop_front() {if (pid_size == 0) return *this; remove(0); return *this;}
|
||||
@@ -364,7 +397,6 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
const PIDeque<T> & forEach(std::function<void(const T &)> f) const {
|
||||
for (uint i = 0; i < pid_size; ++i)
|
||||
f(pid_data[i + pid_start]);
|
||||
@@ -388,7 +420,6 @@ public:
|
||||
ret << f(pid_data[i + pid_start]);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
inline void _reset() {pid_size = pid_rsize = pid_start = 0; pid_data = 0;}
|
||||
@@ -414,6 +445,7 @@ private:
|
||||
}
|
||||
}
|
||||
inline void elementNew(T * to, const T & from) {new(to)T(from);}
|
||||
inline void elementNew(T * to, T && from) {new(to)T(std::move(from));}
|
||||
inline void elementDelete(T & from) {from.~T();}
|
||||
inline void dealloc() {
|
||||
if ((uchar*)pid_data != 0) free((uchar*)pid_data);
|
||||
@@ -487,6 +519,7 @@ private:
|
||||
template<> inline void PIDeque<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(T, s); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
|
||||
template<> inline void PIDeque<T>::deleteT(T *, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz);} \
|
||||
template<> inline void PIDeque<T>::elementNew(T * to, const T & from) {(*to) = from;} \
|
||||
template<> inline void PIDeque<T>::elementNew(T * to, T && from) {(*to) = std::move(from);} \
|
||||
template<> inline void PIDeque<T>::elementDelete(T &) {;} \
|
||||
template<> inline PIDeque<T> & PIDeque<T>::_resizeRaw(size_t new_size) { \
|
||||
if (new_size > pid_size) { \
|
||||
@@ -538,5 +571,7 @@ inline PICout operator <<(PICout s, const PIDeque<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T> inline void piSwap(PIDeque<T> & f, PIDeque<T> & s) {f.swap(s);}
|
||||
|
||||
|
||||
#endif // PIDEQUE_H
|
||||
|
||||
@@ -57,7 +57,7 @@ void piQuickSort(T * a, ssize_t N) {
|
||||
if (i <= j) {
|
||||
if (i != j) {
|
||||
//piCout << "swap" << i << j << a[i] << a[j];
|
||||
piSwapBinary<T>(a[i], a[j]);
|
||||
piSwap<T>(a[i], a[j]);
|
||||
}
|
||||
i++; j--;
|
||||
}
|
||||
@@ -67,13 +67,20 @@ void piQuickSort(T * a, ssize_t N) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename Key, typename T>
|
||||
class PIMapIterator;
|
||||
|
||||
|
||||
template <typename Key, typename T>
|
||||
class PIMap {
|
||||
template <typename Key1, typename T1> friend PIByteArray & operator >>(PIByteArray & s, PIMap<Key1, T1> & v);
|
||||
template <typename Key1, typename T1> friend PIByteArray & operator <<(PIByteArray & s, const PIMap<Key1, T1> & v);
|
||||
template <typename Key1, typename T1> friend class PIMapIterator;
|
||||
public:
|
||||
PIMap() {;}
|
||||
PIMap(const PIMap<Key, T> & other) {*this = other;}
|
||||
PIMap(PIMap<Key, T> && other) : pim_content(std::move(other.pim_content)), pim_index(std::move(other.pim_index)) {}
|
||||
virtual ~PIMap() {;}
|
||||
|
||||
PIMap<Key, T> & operator =(const PIMap<Key, T> & other) {
|
||||
@@ -84,6 +91,11 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
PIMap<Key, T> & operator =(PIMap<Key, T> && other) {
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
typedef T mapped_type;
|
||||
typedef Key key_type;
|
||||
typedef PIPair<Key, T> value_type;
|
||||
@@ -177,6 +189,9 @@ public:
|
||||
const_reverse_iterator constRbegin() const {return const_reverse_iterator(this, size() - 1);}
|
||||
const_reverse_iterator constRend() const {return const_reverse_iterator(this, -1);}
|
||||
|
||||
PIMapIterator<Key, T> makeIterator() const {return PIMapIterator<Key, T>(*this);}
|
||||
PIMapIterator<Key, T> makeReverseIterator() const {return PIMapIterator<Key, T>(*this, true);}
|
||||
|
||||
size_t size() const {return pim_content.size();}
|
||||
int size_s() const {return pim_content.size_s();}
|
||||
size_t length() const {return pim_content.size();}
|
||||
@@ -216,8 +231,8 @@ public:
|
||||
PIMap<Key, T> & clear() {pim_content.clear(); pim_index.clear(); return *this;}
|
||||
|
||||
void swap(PIMap<Key, T> & other) {
|
||||
piSwapBinary<PIVector<T> >(pim_content, other.pim_content);
|
||||
piSwapBinary<PIDeque<MapIndex> >(pim_index, other.pim_index);
|
||||
pim_content.swap(other.pim_content);
|
||||
pim_index.swap(other.pim_index);
|
||||
}
|
||||
|
||||
PIMap<Key, T> & insert(const Key & key, const T & value) {
|
||||
@@ -232,6 +247,18 @@ public:
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
PIMap<Key, T> & insert(const Key & key, T && value) {
|
||||
bool f(false);
|
||||
ssize_t i = _find(key, f);
|
||||
//piCout << "insert key=" << key << "found=" << f << "index=" << i << "value=" << value;
|
||||
if (f) {
|
||||
pim_content[pim_index[i].index] = std::move(value);
|
||||
} else {
|
||||
pim_content.push_back(std::move(value));
|
||||
pim_index.insert(i, MapIndex(key, pim_content.size() - 1));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
const T value(const Key & key, const T & default_ = T()) const {bool f(false); ssize_t i = _find(key, f); if (!f) return default_; return pim_content[pim_index[i].index];}
|
||||
PIVector<T> values() const {return pim_content;}
|
||||
Key key(const T & value_, const Key & default_ = Key()) const {for (int i = 0; i < pim_index.size_s(); ++i) if (pim_content[pim_index[i].index] == value_) return pim_index[i].key; return default_;}
|
||||
@@ -292,7 +319,7 @@ protected:
|
||||
pim_index[i].index = ci;
|
||||
break;
|
||||
}
|
||||
piSwapBinary<T>(pim_content[ci], pim_content.back());
|
||||
piSwap<T>(pim_content[ci], pim_content.back());
|
||||
pim_content.resize(pim_index.size());
|
||||
}
|
||||
const value_type _pair(ssize_t index) const {
|
||||
@@ -309,6 +336,41 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
template <typename Key, typename T>
|
||||
class PIMapIterator {
|
||||
typedef PIMap<Key, T> MapType;
|
||||
public:
|
||||
PIMapIterator(const PIMap<Key, T> & map, bool reverse = false): m(map), pos(-1), rev(reverse) {
|
||||
if (rev) pos = m.size_s();
|
||||
}
|
||||
const Key & key() const {return const_cast<MapType & >(m)._key(pos);}
|
||||
const T & value() const {return const_cast<MapType & >(m)._value(pos);}
|
||||
T & valueRef() const {return const_cast<MapType & >(m)._value(pos);}
|
||||
inline bool hasNext() const {
|
||||
if (rev) {
|
||||
return pos > 0;
|
||||
} else {
|
||||
return pos < (m.size_s() - 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
inline bool next() {
|
||||
if (rev) {
|
||||
--pos;
|
||||
return pos >= 0;
|
||||
} else {
|
||||
++pos;
|
||||
return pos < m.size_s();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
const MapType & m;
|
||||
ssize_t pos;
|
||||
bool rev;
|
||||
};
|
||||
|
||||
|
||||
#ifdef PIP_STD_IOSTREAM
|
||||
template<typename Key, typename Type>
|
||||
inline std::ostream & operator <<(std::ostream & s, const PIMap<Key, Type> & v) {
|
||||
@@ -342,5 +404,7 @@ inline PICout operator <<(PICout s, const PIMap<Key, Type> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename Key, typename Type> inline void piSwap(PIMap<Key, Type> & f, PIMap<Key, Type> & s) {f.swap(s);}
|
||||
|
||||
|
||||
#endif // PIMAP_H
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
class PICout;
|
||||
|
||||
template<typename Type0, typename Type1>
|
||||
class PIP_EXPORT PIPair {
|
||||
class PIPair {
|
||||
public:
|
||||
PIPair() {first = Type0(); second = Type1();}
|
||||
PIPair(const Type0 & value0, const Type1 & value1) {first = value0; second = value1;}
|
||||
|
||||
@@ -30,18 +30,20 @@
|
||||
|
||||
|
||||
template<typename T>
|
||||
class PIP_EXPORT PIQueue: public PIDeque<T> {
|
||||
class PIQueue: public PIDeque<T> {
|
||||
public:
|
||||
PIQueue() {}
|
||||
virtual ~PIQueue() {}
|
||||
PIDeque<T> & enqueue(const T & v) {PIDeque<T>::push_front(v); return *this;}
|
||||
PIDeque<T> & enqueue(T && v) {PIDeque<T>::push_front(std::move(v)); return *this;}
|
||||
T dequeue() {return PIDeque<T>::take_back();}
|
||||
T & head() {return PIDeque<T>::back();}
|
||||
const T & head() const {return PIDeque<T>::back();}
|
||||
PIVector<T> toVector() {
|
||||
PIVector<T> v(PIDeque<T>::size());
|
||||
PIVector<T> v;
|
||||
v.reserve(PIDeque<T>::size());
|
||||
for (uint i = 0; i < PIDeque<T>::size(); ++i)
|
||||
v[i] = PIDeque<T>::at(i);
|
||||
v.push_back(PIDeque<T>::at(i));
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
* has logarithmic complexity.
|
||||
*/
|
||||
template <typename T>
|
||||
class PIP_EXPORT PISet: public PIMap<T, uchar> {
|
||||
class PISet: public PIMap<T, uchar> {
|
||||
typedef PIMap<T, uchar> _CSet;
|
||||
public:
|
||||
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
typedef T key_type;
|
||||
|
||||
PISet<T> & operator <<(const T & t) {_CSet::insert(t, 0); return *this;}
|
||||
PISet<T> & operator <<(T && t) {_CSet::insert(std::move(t), 0); return *this;}
|
||||
PISet<T> & operator <<(const PISet<T> & other) {(*(_CSet*)this) << *((_CSet*)&other); return *this;}
|
||||
|
||||
//! Returns if element "t" exists in this set
|
||||
|
||||
@@ -28,15 +28,22 @@
|
||||
#include "pivector.h"
|
||||
|
||||
template<typename T>
|
||||
class PIP_EXPORT PIStack: public PIVector<T> {
|
||||
class PIStack: public PIVector<T> {
|
||||
public:
|
||||
PIStack() {;}
|
||||
virtual ~PIStack() {;}
|
||||
PIVector<T> & push(const T & v) {PIVector<T>::push_back(v); return *this;}
|
||||
PIVector<T> & push(T && v) {PIVector<T>::push_back(std::move(v)); return *this;}
|
||||
T pop() {return PIVector<T>::take_back();}
|
||||
T & top() {return PIVector<T>::back();}
|
||||
const T & top() const {return PIVector<T>::back();}
|
||||
PIVector<T> toVector() {PIVector<T> v(PIVector<T>::size()); for (uint i = 0; i < PIVector<T>::size(); ++i) v[i] = PIVector<T>::at(i); return v;}
|
||||
PIVector<T> toVector() {
|
||||
PIVector<T> v;
|
||||
v.reserve(PIVector<T>::size());
|
||||
for (uint i = 0; i < PIVector<T>::size(); ++i)
|
||||
v.push_back(PIVector<T>::at(i));
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PISTACK_H
|
||||
|
||||
@@ -48,6 +48,9 @@ public:
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
resize(piv_size, f);
|
||||
}
|
||||
inline PIVector(PIVector<T> && other): piv_data(other.piv_data), piv_size(other.piv_size), piv_rsize(other.piv_rsize) {
|
||||
other._reset();
|
||||
}
|
||||
inline virtual ~PIVector() {
|
||||
PIINTROSPECTION_CONTAINER_DELETE(T)
|
||||
PIINTROSPECTION_CONTAINER_FREE(T, (piv_rsize))
|
||||
@@ -65,6 +68,11 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PIVector<T> & operator =(PIVector<T> && other) {
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
typedef T value_type;
|
||||
|
||||
class iterator {
|
||||
@@ -253,6 +261,16 @@ public:
|
||||
elementNew(piv_data + index, v);
|
||||
return *this;
|
||||
}
|
||||
inline PIVector<T> & insert(size_t index, T && v) {
|
||||
alloc(piv_size + 1);
|
||||
if (index < piv_size - 1) {
|
||||
size_t os = piv_size - index - 1;
|
||||
memmove((void*)(&(piv_data[index + 1])), (const void*)(&(piv_data[index])), os * sizeof(T));
|
||||
}
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
||||
elementNew(piv_data + index, std::move(v));
|
||||
return *this;
|
||||
}
|
||||
inline PIVector<T> & insert(size_t index, const PIVector<T> & other) {
|
||||
if (other.isEmpty()) return *this;
|
||||
assert(&other != this);
|
||||
@@ -320,7 +338,14 @@ public:
|
||||
elementNew(piv_data + piv_size - 1, v);
|
||||
return *this;
|
||||
}
|
||||
inline PIVector<T> & push_back(T && v) {
|
||||
alloc(piv_size + 1);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1);
|
||||
elementNew(piv_data + piv_size - 1, std::move(v));
|
||||
return *this;
|
||||
}
|
||||
inline PIVector<T> & append(const T & v) {return push_back(v);}
|
||||
inline PIVector<T> & append(T && v) {return push_back(std::move(v));}
|
||||
inline PIVector<T> & append(const PIVector<T> & other) {
|
||||
assert(&other != this);
|
||||
size_t ps = piv_size;
|
||||
@@ -329,10 +354,13 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline PIVector<T> & operator <<(const T & v) {return push_back(v);}
|
||||
inline PIVector<T> & operator <<(T && v) {return push_back(std::move(v));}
|
||||
inline PIVector<T> & operator <<(const PIVector<T> & other) {return append(other);}
|
||||
|
||||
inline PIVector<T> & push_front(const T & v) {insert(0, v); return *this;}
|
||||
inline PIVector<T> & push_front(T && v) {insert(0, std::move(v)); return *this;}
|
||||
inline PIVector<T> & prepend(const T & v) {return push_front(v);}
|
||||
inline PIVector<T> & prepend(T && v) {return push_front(std::move(v));}
|
||||
|
||||
inline PIVector<T> & pop_back() {
|
||||
if (piv_size == 0)
|
||||
@@ -358,7 +386,6 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
const PIVector<T> & forEach(std::function<void(const T &)> f) const {
|
||||
for (uint i = 0; i < piv_size; ++i)
|
||||
f(piv_data[i]);
|
||||
@@ -382,7 +409,6 @@ public:
|
||||
ret << f(piv_data[i]);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
inline void _reset() {piv_size = piv_rsize = 0; piv_data = 0;}
|
||||
@@ -407,6 +433,7 @@ private:
|
||||
}
|
||||
}
|
||||
inline void elementNew(T * to, const T & from) {new(to)T(from);}
|
||||
inline void elementNew(T * to, T && from) {new(to)T(std::move(from));}
|
||||
inline void elementDelete(T & from) {from.~T();}
|
||||
inline void dealloc() {
|
||||
if ((uchar*)piv_data != 0) free((uchar*)piv_data);
|
||||
@@ -436,6 +463,7 @@ private:
|
||||
template<> inline void PIVector<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(T, s); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
|
||||
template<> inline void PIVector<T>::deleteT(T *, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz);} \
|
||||
template<> inline void PIVector<T>::elementNew(T * to, const T & from) {(*to) = from;} \
|
||||
template<> inline void PIVector<T>::elementNew(T * to, T && from) {(*to) = std::move(from);} \
|
||||
template<> inline void PIVector<T>::elementDelete(T &) {;} \
|
||||
template<> inline PIVector<T> & PIVector<T>::_resizeRaw(size_t new_size) { \
|
||||
if (new_size > piv_size) { \
|
||||
@@ -487,5 +515,7 @@ inline PICout operator <<(PICout s, const PIVector<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T> inline void piSwap(PIVector<T> & f, PIVector<T> & s) {f.swap(s);}
|
||||
|
||||
|
||||
#endif // PIVECTOR_H
|
||||
|
||||
@@ -44,10 +44,10 @@ public:
|
||||
cols_ = cols;
|
||||
mat.resize(rows*cols, f);
|
||||
}
|
||||
inline PIVector2D(size_t rows, size_t cols, const PIVector<T> & v) {
|
||||
mat = v;
|
||||
rows_ = rows;
|
||||
cols_ = cols;
|
||||
inline PIVector2D(size_t rows, size_t cols, const PIVector<T> & v) : rows_(rows), cols_(cols), mat(v) {
|
||||
mat.resize(rows*cols);
|
||||
}
|
||||
inline PIVector2D(size_t rows, size_t cols, PIVector<T> && v) : rows_(rows), cols_(cols), mat(std::move(v)) {
|
||||
mat.resize(rows*cols);
|
||||
}
|
||||
inline PIVector2D(const PIVector<PIVector<T> > & v) {
|
||||
@@ -236,6 +236,7 @@ public:
|
||||
|
||||
PIVector<PIVector<T> > toVectors() const {
|
||||
PIVector<PIVector<T> > ret;
|
||||
ret.reserve(rows_);
|
||||
for(size_t i = 0; i < rows_; ++i)
|
||||
ret << PIVector<T>(mat.data(i*cols_), cols_);
|
||||
return ret;
|
||||
|
||||
@@ -96,9 +96,7 @@
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
# include <functional>
|
||||
#endif
|
||||
#include <functional>
|
||||
|
||||
#include <cstddef>
|
||||
#ifdef WINDOWS
|
||||
@@ -194,10 +192,10 @@
|
||||
|
||||
// Private data macros
|
||||
|
||||
#define PRIVATE_DECLARATION \
|
||||
#define PRIVATE_DECLARATION(e) \
|
||||
struct __Private__; \
|
||||
friend struct __Private__; \
|
||||
struct __PrivateInitializer__ { \
|
||||
struct e __PrivateInitializer__ { \
|
||||
__PrivateInitializer__(); \
|
||||
__PrivateInitializer__(const __PrivateInitializer__ & o); \
|
||||
~__PrivateInitializer__(); \
|
||||
@@ -220,8 +218,8 @@
|
||||
#define PRIVATEWB __privateinitializer__.p
|
||||
|
||||
#define NO_COPY_CLASS(name) \
|
||||
explicit name(const name & ); \
|
||||
void operator =(const name & );
|
||||
name(const name&) = delete; \
|
||||
name& operator=(const name&) = delete;
|
||||
|
||||
#ifdef FREERTOS
|
||||
# define PIP_MIN_MSLEEP 10.
|
||||
@@ -257,7 +255,7 @@ typedef long double ldouble;
|
||||
|
||||
/*! \brief Templated function for swap two values
|
||||
* \details Example:\n \snippet piincludes.cpp swap */
|
||||
template<typename T> inline void piSwap(T & f, T & s) {T t = f; f = s; s = t;}
|
||||
template<typename T> inline void piSwap(T & f, T & s) {T t(std::move(f)); f = std::move(s); s = std::move(t);}
|
||||
|
||||
/*! \brief Templated function for swap two values without "="
|
||||
* \details Example:\n \snippet piincludes.cpp swapBinary */
|
||||
@@ -294,6 +292,14 @@ template<> inline void piSwapBinary(const void *& f, const void *& s) {
|
||||
}
|
||||
}
|
||||
|
||||
template<> inline void piSwap(double & f, double & s) {piSwapBinary<double>(f, s);}
|
||||
template<> inline void piSwap(ldouble & f, ldouble & s) {piSwapBinary<ldouble>(f, s);}
|
||||
#ifdef ARCH_BITS_32
|
||||
template<> inline void piSwap(float & f, float & s) {piSwapBinary<float>(f, s);}
|
||||
template<> inline void piSwap(llong & f, llong & s) {piSwapBinary<llong>(f, s);}
|
||||
template<> inline void piSwap(ullong & f, ullong & s) {piSwapBinary<ullong>(f, s);}
|
||||
#endif
|
||||
|
||||
/*! \brief Function for compare two values without "=" by raw content
|
||||
* \details Example:\n \snippet piincludes.cpp compareBinary */
|
||||
inline bool piCompareBinary(const void * f, const void * s, size_t size) {
|
||||
|
||||
@@ -56,6 +56,10 @@ public:
|
||||
//! Constructs an empty byte array
|
||||
PIByteArray() {;}
|
||||
|
||||
PIByteArray(const PIByteArray & o): PIDeque<uchar>(o) {}
|
||||
|
||||
PIByteArray(PIByteArray && o): PIDeque<uchar>(std::move(o)) {}
|
||||
|
||||
//! Constructs 0-filled byte array with size "size"
|
||||
PIByteArray(const uint size) {resize(size);}
|
||||
|
||||
@@ -124,6 +128,10 @@ public:
|
||||
|
||||
void operator =(const PIDeque<uchar> & d) {resize(d.size()); memcpy(data(), d.data(), d.size());}
|
||||
|
||||
PIByteArray & operator =(const PIByteArray & o) {if (this == &o) return *this; clear(); append(o); return *this;}
|
||||
|
||||
PIByteArray & operator =(PIByteArray && o) {swap(o); return *this;}
|
||||
|
||||
static PIByteArray fromUserInput(PIString str);
|
||||
static PIByteArray fromHex(PIString str);
|
||||
static PIByteArray fromBase64(const PIByteArray & base64);
|
||||
@@ -138,7 +146,7 @@ inline std::ostream & operator <<(std::ostream & s, const PIByteArray & ba);
|
||||
#endif
|
||||
|
||||
//! \relatesalso PIByteArray \brief Output to PICout operator
|
||||
PICout operator <<(PICout s, const PIByteArray & ba);
|
||||
PIP_EXPORT PICout operator <<(PICout s, const PIByteArray & ba);
|
||||
|
||||
#define PBA_OPERATOR_TO int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v));
|
||||
|
||||
@@ -212,7 +220,7 @@ inline PIByteArray & operator >>(PIByteArray & s, ldouble & v) {assert(s.size()
|
||||
//! \relatesalso PIByteArray \brief Restore operator
|
||||
template<typename T> inline PIByteArray & operator >>(PIByteArray & s, PIFlags<T> & v) {PBA_OPERATOR_FROM return s;}
|
||||
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details
|
||||
PIByteArray & operator >>(PIByteArray & s, PIByteArray & v);
|
||||
PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIByteArray & v);
|
||||
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) {assert(s.size_s() >= v.s); if (v.s > 0) memcpy((void*)(v.d), s.data(), v.s); s.remove(0, v.s); return s;}
|
||||
|
||||
@@ -316,6 +324,7 @@ __PIBYTEARRAY_SIMPLE_TYPE__(PIChar)
|
||||
|
||||
|
||||
template<> inline uint piHash(const PIByteArray & ba) {return ba.hash();}
|
||||
template<> inline void piSwap(PIByteArray & f, PIByteArray & s) {f.swap(s);}
|
||||
|
||||
|
||||
#endif // PIBYTEARRAY_H
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
|
||||
#include "piincludes.h"
|
||||
|
||||
extern char * __syslocname__;
|
||||
extern char * __sysoemname__;
|
||||
extern char * __utf8name__;
|
||||
extern PIP_EXPORT char * __syslocname__;
|
||||
extern PIP_EXPORT char * __sysoemname__;
|
||||
extern PIP_EXPORT char * __utf8name__;
|
||||
|
||||
class PIP_EXPORT PIChar
|
||||
{
|
||||
|
||||
@@ -54,12 +54,18 @@ public:
|
||||
int id;
|
||||
T data;
|
||||
};
|
||||
template <typename T>
|
||||
struct ChunkConst {
|
||||
ChunkConst(int i, const T & d): id(i), data(d) {}
|
||||
int id;
|
||||
const T & data;
|
||||
};
|
||||
|
||||
//! Returns chunk with ID "id" and value "data" for write to stream
|
||||
template <typename T> static Chunk<T> chunk(int id, const T & data) {return Chunk<T>(id, data);}
|
||||
template <typename T> static ChunkConst<T> chunk(int id, const T & data) {return ChunkConst<T>(id, data);}
|
||||
|
||||
//! Add data to this chunk strean with ID "id" and value "data"
|
||||
template <typename T> PIChunkStream & add(int id, const T & data) {*this << Chunk<T>(id, data); return *this;}
|
||||
template <typename T> PIChunkStream & add(int id, const T & data) {*this << ChunkConst<T>(id, data); return *this;}
|
||||
|
||||
void setSource(const PIByteArray & data);
|
||||
void setSource(PIByteArray * data);
|
||||
@@ -112,6 +118,7 @@ private:
|
||||
PIMap<int, PIByteArray> data_map;
|
||||
|
||||
template <typename T> friend PIChunkStream & operator <<(PIChunkStream & s, const PIChunkStream::Chunk<T> & c);
|
||||
template <typename T> friend PIChunkStream & operator <<(PIChunkStream & s, const PIChunkStream::ChunkConst<T> & c);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -133,5 +140,24 @@ PIChunkStream & operator <<(PIChunkStream & s, const PIChunkStream::Chunk<T> & c
|
||||
}
|
||||
return s;
|
||||
}
|
||||
template <typename T>
|
||||
PIChunkStream & operator <<(PIChunkStream & s, const PIChunkStream::ChunkConst<T> & c) {
|
||||
PIByteArray ba;
|
||||
ba << c.data;
|
||||
switch (s.version_) {
|
||||
case PIChunkStream::Version_1:
|
||||
(*(s.data_)) << c.id << ba;
|
||||
break;
|
||||
case PIChunkStream::Version_2:
|
||||
if (s.data_->isEmpty())
|
||||
(*(s.data_)) << uchar(uchar(s.version_) | 0x80);
|
||||
PIChunkStream::writeVInt(*(s.data_), c.id);
|
||||
PIChunkStream::writeVInt(*(s.data_), ba.size());
|
||||
s.data_->append(ba);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // PICHUNKSTREAM_H
|
||||
|
||||
@@ -64,13 +64,13 @@ public:
|
||||
|
||||
static bool addToGroup(const PIString & group, const PIObject * element);
|
||||
|
||||
class CollectionAdder {
|
||||
class PIP_EXPORT CollectionAdder {
|
||||
public:
|
||||
CollectionAdder(const PIString & group, const PIObject * element, const PIString & name = PIString(), bool own = false);
|
||||
};
|
||||
|
||||
protected:
|
||||
struct Group {
|
||||
struct PIP_EXPORT Group {
|
||||
Group(const PIString & name_ = PIString()) {name = name_;}
|
||||
PIString name;
|
||||
PIVector<const PIObject * > elements;
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
#include "piincludes_p.h"
|
||||
#include "picout.h"
|
||||
#include "piconsole.h"
|
||||
#include "pibytearray.h"
|
||||
#include "pistack.h"
|
||||
#include "piobject.h"
|
||||
#include "pistring_std.h"
|
||||
#ifdef WINDOWS
|
||||
# include <windows.h>
|
||||
|
||||
@@ -46,7 +46,7 @@ class PIObject;
|
||||
namespace PICoutManipulators {
|
||||
|
||||
//! \brief Enum contains special characters
|
||||
enum PIP_EXPORT PICoutSpecialChar {
|
||||
enum PICoutSpecialChar {
|
||||
Null /*! Null-character, '\\0' */,
|
||||
NewLine /*! New line character, '\\n' */,
|
||||
Tab /*! Tab character, '\\t' */,
|
||||
@@ -55,7 +55,7 @@ namespace PICoutManipulators {
|
||||
};
|
||||
|
||||
//! \brief Enum contains immediate action
|
||||
enum PIP_EXPORT PICoutAction {
|
||||
enum PICoutAction {
|
||||
Flush /*! Flush the output */,
|
||||
Backspace /*! Remove last symbol */,
|
||||
ShowCursor /*! Show cursor */,
|
||||
@@ -67,7 +67,7 @@ namespace PICoutManipulators {
|
||||
};
|
||||
|
||||
//! \brief Enum contains control of PICout
|
||||
enum PIP_EXPORT PICoutControl {
|
||||
enum PICoutControl {
|
||||
AddNone /*! No controls */ = 0x0,
|
||||
AddSpaces /*! Spaces will be appear after each output */ = 0x1,
|
||||
AddNewLine /*! New line will be appear after all output */ = 0x2,
|
||||
@@ -78,7 +78,7 @@ namespace PICoutManipulators {
|
||||
};
|
||||
|
||||
//! \brief Enum contains output format
|
||||
enum PIP_EXPORT PICoutFormat {
|
||||
enum PICoutFormat {
|
||||
Bin /*! Binary representation of integers */ = 0x01,
|
||||
Oct /*! Octal representation of integers */ = 0x02,
|
||||
Dec /*! Decimal representation of integers */ = 0x04,
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
|
||||
~PICout();
|
||||
|
||||
class Notifier {
|
||||
class PIP_EXPORT Notifier {
|
||||
public:
|
||||
static Notifier * instance();
|
||||
static PIObject * object();
|
||||
@@ -291,7 +291,7 @@ private:
|
||||
void applyFormat(PICoutManipulators::PICoutFormat f);
|
||||
|
||||
static OutputDevices devs;
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
bool fo_, cc_, fc_, act_;
|
||||
int cnb_, attr_, id_;
|
||||
PIString * buffer_;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
* \snippet piincludes.cpp flags
|
||||
*/
|
||||
template<typename Enum>
|
||||
class PIP_EXPORT PIFlags {
|
||||
class PIFlags {
|
||||
public:
|
||||
//! Constructor with flags = 0
|
||||
PIFlags(): flags(0) {;}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "piincludes.h"
|
||||
#include "piincludes_p.h"
|
||||
#include "piconsole.h"
|
||||
#include "pitime.h"
|
||||
#ifndef QNX
|
||||
# include <clocale>
|
||||
|
||||
@@ -26,9 +26,11 @@
|
||||
#ifdef PIP_STD_IOSTREAM
|
||||
# include <iostream>
|
||||
#endif
|
||||
#include <atomic>
|
||||
|
||||
class PIObject;
|
||||
class PIMutex;
|
||||
class PIMutexLocker;
|
||||
class PIObject;
|
||||
class PIString;
|
||||
class PIByteArray;
|
||||
class PIInit;
|
||||
@@ -37,7 +39,7 @@ class PICout;
|
||||
|
||||
struct lconv;
|
||||
|
||||
extern lconv * currentLocale;
|
||||
extern PIP_EXPORT lconv * currentLocale;
|
||||
|
||||
/*! \fn errorString()
|
||||
* \brief Return readable error description in format "code <number> - <description>" */
|
||||
|
||||
@@ -125,7 +125,7 @@ PIInit::PIInit() {
|
||||
piForeachC (PIString & i, ifpathes) {
|
||||
if (fileExists(i)) {
|
||||
sinfo->ifconfigPath = i;
|
||||
piBreak;
|
||||
break;
|
||||
}
|
||||
}
|
||||
# else
|
||||
|
||||
@@ -63,7 +63,7 @@ private:
|
||||
explicit PIInit();
|
||||
void setFileCharset(const char *charset);
|
||||
bool fileExists(const PIString & p);
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
char * file_charset;
|
||||
};
|
||||
|
||||
|
||||
@@ -190,39 +190,42 @@ PIStringList PIObject::scopeList() const {
|
||||
PIStringList PIObject::methodsEH() const {
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
PIStringList ret;
|
||||
__MetaData & ehd(__meta_data()[classNameID()]);
|
||||
piForeachC (__EHPair & eh, ehd.eh_func)
|
||||
ret << eh.second.fullFormat();
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++)
|
||||
ret << eh.value().fullFormat();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool PIObject::isMethodEHContains(const PIString & name) const {
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
__MetaData & ehd(__meta_data()[classNameID()]);
|
||||
piForeachC (__EHPair & eh, ehd.eh_func)
|
||||
if (eh.second.func_name == name)
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) {
|
||||
if (eh.value().func_name == name)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
PIString PIObject::methodEHArguments(const PIString & name) const {
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
__MetaData & ehd(__meta_data()[classNameID()]);
|
||||
piForeachC (__EHPair & eh, ehd.eh_func)
|
||||
if (eh.second.func_name == name)
|
||||
return eh.second.arguments();
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) {
|
||||
if (eh.value().func_name == name)
|
||||
return eh.value().arguments();
|
||||
}
|
||||
return PIString();
|
||||
}
|
||||
|
||||
|
||||
PIString PIObject::methodEHFullFormat(const PIString & name) const {
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
__MetaData & ehd(__meta_data()[classNameID()]);
|
||||
piForeachC (__EHPair & eh, ehd.eh_func)
|
||||
if (eh.second.func_name == name)
|
||||
return eh.second.fullFormat();
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) {
|
||||
if (eh.value().func_name == name)
|
||||
return eh.value().fullFormat();
|
||||
}
|
||||
return PIString();
|
||||
}
|
||||
|
||||
@@ -234,10 +237,11 @@ PIString PIObject::methodEHFromAddr(const void * addr) const {
|
||||
|
||||
PIVector<PIObject::__MetaFunc> PIObject::findEH(const PIString & name) const {
|
||||
PIVector<__MetaFunc> ret;
|
||||
__MetaData & ehd(__meta_data()[classNameID()]);
|
||||
piForeachC (__EHPair & eh, ehd.eh_func)
|
||||
if (eh.second.func_name == name)
|
||||
ret << eh.second;
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) {
|
||||
if (eh.value().func_name == name)
|
||||
ret << eh.value();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -313,7 +317,6 @@ bool PIObject::piConnectU(PIObject * src, const PIString & sig, PIObject * dest_
|
||||
}
|
||||
|
||||
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
bool PIObject::piConnectLS(PIObject * src, const PIString & sig, std::function<void()> * f, const char * loc) {
|
||||
if (src == 0) {
|
||||
delete f;
|
||||
@@ -345,7 +348,6 @@ bool PIObject::piConnectLS(PIObject * src, const PIString & sig, std::function<v
|
||||
//piCout << "finished";
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void PIObject::piDisconnect(PIObject * src, const PIString & sig, PIObject * dest, void * ev_h) {
|
||||
@@ -584,11 +586,11 @@ void PIObject::dump(const PIString & line_prefix) const {
|
||||
//printf("dump %d properties ok\n", properties_.size());
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {";
|
||||
__MetaData & ehd(__meta_data()[classNameID()]);
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s();
|
||||
//printf("dump %d methods\n", ehd.eh_func.size());
|
||||
piForeachC (__EHPair & eh, ehd.eh_func) {
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << eh.second.fullFormat();
|
||||
for (auto eh = ehd.eh_func.constBegin(); eh != ehd.eh_func.constEnd(); eh++) {
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << eh.value().fullFormat();
|
||||
}
|
||||
//printf("dump %d methods ok\n", ehd.eh_func.size());
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||
@@ -669,8 +671,6 @@ void PIObject::__MetaData::addScope(const PIString & s, uint shash) {
|
||||
|
||||
|
||||
void PIObject::__Connection::destroy() {
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
if (functor) delete functor;
|
||||
functor = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -459,9 +459,7 @@
|
||||
|
||||
#define CONNECTU(src, event, dest, handler) PIObject::piConnectU(src, PIStringAscii(#event), dest, dest, PIStringAscii(#handler), LOCATION);
|
||||
#define CONNECTU_QUEUED(src, event, dest, handler, performer) PIObject::piConnectU(src, PIStringAscii(#event), dest, dest, PIStringAscii(#handler), LOCATION, performer);
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
# define CONNECTL(src, event, functor) PIObject::piConnectLS(src, PIStringAscii(#event), PIObject::__newFunctor(&(src)->__stat_eh_##event##__, functor), LOCATION);
|
||||
#endif
|
||||
#define CONNECTL(src, event, functor) PIObject::piConnectLS(src, PIStringAscii(#event), PIObject::__newFunctor(&(src)->__stat_eh_##event##__, functor), LOCATION);
|
||||
|
||||
#define CONNECT0(ret, src, event, dest, handler) PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*))(&(dest)->__stat_eh_##handler##__), (void*)(void(*)(void*))(&(src)->__stat_eh_##event##__), 0, LOCATION);
|
||||
#define CONNECT1(ret, a0, src, event, dest, handler) PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0))(&(dest)->__stat_eh_##handler##__), (void*)(void(*)(void*, a0))(&(src)->__stat_eh_##event##__), 1, LOCATION);
|
||||
@@ -499,18 +497,16 @@ class PIP_EXPORT PIObject {
|
||||
typedef void __Parent__;
|
||||
friend class PIIntrospection;
|
||||
public:
|
||||
|
||||
NO_COPY_CLASS(PIObject)
|
||||
|
||||
//! Contructs PIObject with name "name"
|
||||
explicit PIObject(const PIString & name = PIString());
|
||||
|
||||
virtual ~PIObject();
|
||||
|
||||
private:
|
||||
explicit PIObject(const PIObject & );
|
||||
void operator =(const PIObject & );
|
||||
|
||||
private:
|
||||
uint _signature_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//! Returns object name
|
||||
@@ -601,13 +597,11 @@ public:
|
||||
// / Direct connect
|
||||
static void piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc);
|
||||
static bool piConnectU(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, const PIString & hname, const char * loc, PIObject * performer = 0);
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
static bool piConnectLS(PIObject * src, const PIString & sig, std::function<void()> * f, const char * loc);
|
||||
template <typename INPUT, typename... TYPES>
|
||||
static std::function<void()> * __newFunctor(void(*stat_handler)(void*,TYPES...), INPUT functor) {
|
||||
return (std::function<void()>*)(new std::function<void(TYPES...)>(functor));
|
||||
}
|
||||
#endif
|
||||
|
||||
// / Through names and mixed
|
||||
static void piConnect(const PIString & src, const PIString & sig, void * dest, void * ev_h);
|
||||
@@ -629,11 +623,9 @@ public:
|
||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||
__Connection i(sender->connections[j]);
|
||||
if (i.eventID != eventID) continue;
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
if (i.functor) {
|
||||
(*(i.functor))();
|
||||
} else {
|
||||
#endif
|
||||
if (i.performer) {
|
||||
i.performer->postQueuedEvent(__QueuedEvent(i.slot, i.dest, i.dest_o, sender));
|
||||
} else {
|
||||
@@ -646,9 +638,7 @@ public:
|
||||
if (ts) i.dest_o->mutex_.unlock();
|
||||
}
|
||||
}
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
}
|
||||
#endif
|
||||
if (!sender->isPIObject()) break;
|
||||
}
|
||||
}
|
||||
@@ -658,11 +648,9 @@ public:
|
||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||
__Connection i(sender->connections[j]);
|
||||
if (i.eventID != eventID) continue;
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
if (i.functor) {
|
||||
(*((std::function<void(T0)>*)i.functor))(v0);
|
||||
} else {
|
||||
#endif
|
||||
if (i.performer) {
|
||||
PIVector<PIVariant> vl;
|
||||
if (i.args_count > 0) vl << PIVariant::fromValue(v0);
|
||||
@@ -678,9 +666,7 @@ public:
|
||||
if (ts) i.dest_o->mutex_.unlock();
|
||||
}
|
||||
}
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
}
|
||||
#endif
|
||||
if (!sender->isPIObject()) break;
|
||||
}
|
||||
}
|
||||
@@ -689,11 +675,9 @@ public:
|
||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||
__Connection i(sender->connections[j]);
|
||||
if (i.eventID != eventID) continue;
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
if (i.functor) {
|
||||
(*((std::function<void(T0, T1)>*)i.functor))(v0, v1);
|
||||
} else {
|
||||
#endif
|
||||
if (i.performer) {
|
||||
PIVector<PIVariant> vl;
|
||||
if (i.args_count > 0) vl << PIVariant::fromValue(v0);
|
||||
@@ -713,9 +697,7 @@ public:
|
||||
if (ts) i.dest_o->mutex_.unlock();
|
||||
}
|
||||
}
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
}
|
||||
#endif
|
||||
if (!sender->isPIObject()) break;
|
||||
}
|
||||
}
|
||||
@@ -724,11 +706,9 @@ public:
|
||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||
__Connection i(sender->connections[j]);
|
||||
if (i.eventID != eventID) continue;
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
if (i.functor) {
|
||||
(*((std::function<void(T0, T1, T2)>*)i.functor))(v0, v1, v2);
|
||||
} else {
|
||||
#endif
|
||||
if (i.performer) {
|
||||
PIVector<PIVariant> vl;
|
||||
if (i.args_count > 0) vl << PIVariant::fromValue(v0);
|
||||
@@ -750,9 +730,7 @@ public:
|
||||
if (ts) i.dest_o->mutex_.unlock();
|
||||
}
|
||||
}
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
}
|
||||
#endif
|
||||
if (!sender->isPIObject()) break;
|
||||
}
|
||||
}
|
||||
@@ -761,11 +739,9 @@ public:
|
||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||
__Connection i(sender->connections[j]);
|
||||
if (i.eventID != eventID) continue;
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
if (i.functor) {
|
||||
(*((std::function<void(T0, T1, T2, T3)>*)i.functor))(v0, v1, v2, v3);
|
||||
} else {
|
||||
#endif
|
||||
if (i.performer) {
|
||||
PIVector<PIVariant> vl;
|
||||
if (i.args_count > 0) vl << PIVariant::fromValue(v0);
|
||||
@@ -789,9 +765,7 @@ public:
|
||||
if (ts) i.dest_o->mutex_.unlock();
|
||||
}
|
||||
}
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
}
|
||||
#endif
|
||||
if (!sender->isPIObject()) break;
|
||||
}
|
||||
}
|
||||
@@ -826,7 +800,7 @@ public:
|
||||
static bool isTypeOf(const void * o) {return isTypeOf<T>((PIObject*)o);}
|
||||
static PIString simplifyType(const char * a);
|
||||
|
||||
struct __MetaFunc {
|
||||
struct PIP_EXPORT __MetaFunc {
|
||||
__MetaFunc(): addr(0), addrV(0) {;}
|
||||
bool isNull() const {return addr == 0;}
|
||||
PIString arguments() const;
|
||||
@@ -839,7 +813,7 @@ public:
|
||||
PIStringList types;
|
||||
PIStringList names;
|
||||
};
|
||||
struct __MetaData {
|
||||
struct PIP_EXPORT __MetaData {
|
||||
__MetaData() {scope_list << PIStringAscii("PIObject"); scope_id << PIStringAscii("PIObject").hash();}
|
||||
void addScope(const PIString & s, uint shash);
|
||||
PIStringList scope_list;
|
||||
@@ -891,16 +865,12 @@ private:
|
||||
dest = d;
|
||||
args_count = ac;
|
||||
performer = p;
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
functor = 0;
|
||||
#endif
|
||||
}
|
||||
void destroy();
|
||||
void * slot;
|
||||
void * signal;
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
std::function<void()> * functor;
|
||||
#endif
|
||||
PIString event;
|
||||
uint eventID;
|
||||
PIObject * dest_o;
|
||||
@@ -949,7 +919,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
void dumpApplication();
|
||||
bool dumpApplicationToFile(const PIString & path);
|
||||
PIP_EXPORT void dumpApplication();
|
||||
PIP_EXPORT bool dumpApplicationToFile(const PIString & path);
|
||||
|
||||
#endif // PIOBJECT_H
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
* contains unique name and you can identify property by name with propertyValueByName(), propertyByName().
|
||||
* You can add property using addProperty(const Property&), addProperty(const PIString&, const PIVariant&, const PIString&, int).
|
||||
*/
|
||||
class PIPropertyStorage {
|
||||
class PIP_EXPORT PIPropertyStorage {
|
||||
public:
|
||||
PIPropertyStorage() {}
|
||||
|
||||
/**
|
||||
* @brief PIPropertyStorage element.
|
||||
*/
|
||||
struct Property {
|
||||
struct PIP_EXPORT Property {
|
||||
Property(const PIString & n = PIString(), const PIString & c = PIString(), const PIVariant & v = PIVariant(), int f = 0):
|
||||
name(n), comment(c), value(v), flags(f) {}
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ PIString PIString::dtos(const double num, char format, int precision) {
|
||||
|
||||
|
||||
PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) {
|
||||
if (value == 0LL) return PIString("0");
|
||||
if (value == 0LL) return PIString('0');
|
||||
if (base < 2 || base > 40) {if (ok != 0) *ok = false; return PIString();}
|
||||
if (ok != 0) *ok = true;
|
||||
if (base == 10) return lltos(value);
|
||||
@@ -192,7 +192,7 @@ PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) {
|
||||
}
|
||||
|
||||
PIString PIString::fromNumberBaseU(const ullong value, int base, bool * ok) {
|
||||
if (value == 0ULL) return PIString("0");
|
||||
if (value == 0ULL) return PIString('0');
|
||||
if (base < 2 || base > 40) {if (ok != 0) *ok = false; return PIString();}
|
||||
if (ok != 0) *ok = true;
|
||||
if (base == 10) return ulltos(value);
|
||||
@@ -211,9 +211,10 @@ PIString PIString::fromNumberBaseU(const ullong value, int base, bool * ok) {
|
||||
|
||||
|
||||
llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
|
||||
static const PIString s_0x = PIStringAscii("0x");
|
||||
PIString v = value.trimmed();
|
||||
if (base < 0) {
|
||||
int ind = v.find("0x");
|
||||
int ind = v.find(s_0x);
|
||||
if (ind == 0 || ind == 1) {v.remove(ind, 2); base = 16;}
|
||||
else base = 10;
|
||||
} else
|
||||
@@ -254,6 +255,7 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
||||
int sz = ucnv_toUChars(cc, ucs, s, c, s, &e);
|
||||
//printf("appendFromChars %d -> %d\n", s, sz);
|
||||
//printf("PIString %d -> %d\n", c[0], ucs[0]);
|
||||
reserve(size_s() + sz);
|
||||
for (int i = 0; i < sz; ++i)
|
||||
push_back(PIChar(ucs[i]));
|
||||
delete[] ucs;
|
||||
@@ -264,11 +266,9 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
||||
# ifdef WINDOWS
|
||||
sz = MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, 0, 0);
|
||||
if (sz <= 0) return;
|
||||
wchar_t * buffer = new wchar_t[sz];
|
||||
MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, buffer, sz);
|
||||
for (int i = 0; i < sz; ++i)
|
||||
push_back(PIChar((ushort)buffer[i]));
|
||||
delete[] buffer;
|
||||
int old_sz = size_s();
|
||||
enlarge(sz);
|
||||
MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, (LPWSTR)PIDeque<PIChar>::data(old_sz), sz);
|
||||
return;
|
||||
//printf("request %d\n", sz);
|
||||
# else
|
||||
@@ -330,9 +330,14 @@ PIString PIString::fromAscii(const char * s) {
|
||||
PIString ret;
|
||||
int l = 0;
|
||||
while (s[l] != '\0') {
|
||||
ret.push_back(PIChar(short(s[l])));
|
||||
ret.push_back(PIChar(s[l]));
|
||||
++l;
|
||||
}
|
||||
/*while (s[l] != '\0') ++l;
|
||||
PIString ret;
|
||||
ret.resize(l);
|
||||
for (int i = 0; i < l; ++i)
|
||||
ret[i] = s[i];*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -369,6 +374,7 @@ void PIString::buildData(const char * cp) const {
|
||||
UConverter * cc = ucnv_open(cp, &e);
|
||||
if (cc) {
|
||||
char uc[8];
|
||||
data_.reserve(size_s());
|
||||
for (int i = 0; i < size_s(); ++i) {
|
||||
if (at(i).isAscii())
|
||||
data_.push_back(uchar(at(i).unicode16Code()));
|
||||
@@ -605,16 +611,18 @@ PIString PIString::trimmed() const {
|
||||
|
||||
|
||||
PIString & PIString::replace(int from, int count, const PIString & with) {
|
||||
if (count < length() - from) remove(from, count);
|
||||
else remove(from, length() - from);
|
||||
uint c = with.length();
|
||||
for (uint i = 0; i < c; ++i) insert(from + i, with[i]);
|
||||
count = piMini(count, length() - from);
|
||||
if (count == with.size_s())
|
||||
memcpy(&(at(from)), &(with.at(0)), count * sizeof(PIChar));
|
||||
else {
|
||||
remove(from, count);
|
||||
PIDeque<PIChar>::insert(from, with);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIString & PIString::replace(const PIString & what, const PIString & with, bool * ok) {
|
||||
//piCout << "replace" << what << with;
|
||||
if (what.isEmpty()) {
|
||||
if (ok != 0) *ok = false;
|
||||
return *this;
|
||||
@@ -628,8 +636,73 @@ PIString & PIString::replace(const PIString & what, const PIString & with, bool
|
||||
|
||||
PIString & PIString::replaceAll(const PIString & what, const PIString & with) {
|
||||
if (what.isEmpty() || what == with) return *this;
|
||||
bool ok = true;
|
||||
while (ok) replace(what, with, &ok);
|
||||
if (with.isEmpty()) removeAll(what);
|
||||
else {
|
||||
int l = what.length(), dl = with.length() - what.length();
|
||||
for (int i = 0; i < length() - l + 1; ++i) {
|
||||
bool match = true;
|
||||
for (int j = 0; j < l; ++j) {
|
||||
if (at(j + i) != what[j]) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!match) continue;
|
||||
if (dl > 0) PIDeque<PIChar>::insert(i, PIDeque<PIChar>((size_t)dl));
|
||||
if (dl < 0) PIDeque<PIChar>::remove(i, -dl);
|
||||
memcpy(PIDeque<PIChar>::data(i), &(with.at(0)), with.length() * sizeof(PIChar));
|
||||
//i -= l;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIString & PIString::replaceAll(const PIString & what, const char with) {
|
||||
if (what.isEmpty()) return *this;
|
||||
int l = what.length(), dl = what.length() - 1;
|
||||
for (int i = 0; i < length() - l + 1; ++i) {
|
||||
bool match = true;
|
||||
for (int j = 0; j < l; ++j) {
|
||||
if (at(j + i) != what[j]) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!match) continue;
|
||||
if (dl > 0) PIDeque<PIChar>::remove(i, dl);
|
||||
at(i) = PIChar(with);
|
||||
//i -= l;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIString & PIString::replaceAll(const char what, const char with) {
|
||||
int l = length();
|
||||
for (int i = 0; i < l; ++i) {
|
||||
if (at(i) == what)
|
||||
at(i) = with;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIString & PIString::removeAll(const PIString & str) {
|
||||
if (str.isEmpty()) return *this;
|
||||
int l = str.length();
|
||||
for (int i = 0; i < length() - l + 1; ++i) {
|
||||
bool match = true;
|
||||
for (int j = 0; j < l; ++j) {
|
||||
if (at(j + i) != str[j]) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!match) continue;
|
||||
PIDeque<PIChar>::remove(i, l);
|
||||
i -= l;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -641,16 +714,17 @@ PIString & PIString::insert(int index, const PIString & str) {
|
||||
|
||||
|
||||
PIString & PIString::elide(int size, float pos) {
|
||||
static const PIString s_dotdot = PIStringAscii("..");
|
||||
if (length() <= size) return *this;
|
||||
if (length() <= 2) {
|
||||
fill(".");
|
||||
fill('.');
|
||||
return *this;
|
||||
}
|
||||
pos = piClampf(pos, 0.f, 1.f);
|
||||
int ns = size - 2;
|
||||
int ls = piRoundf(ns * pos);
|
||||
remove(ls, length() - ns);
|
||||
insert(ls, "..");
|
||||
insert(ls, s_dotdot);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -670,9 +744,9 @@ PIStringList PIString::split(const PIString & delim) const {
|
||||
}
|
||||
|
||||
|
||||
int PIString::find(const char str, const int start) const {
|
||||
int PIString::find(const char c, const int start) const {
|
||||
for (int i = start; i < length(); ++i)
|
||||
if (at(i) == str)
|
||||
if (at(i) == c)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
@@ -687,9 +761,9 @@ int PIString::find(const PIString & str, const int start) const {
|
||||
}
|
||||
|
||||
|
||||
int PIString::findLast(const char str, const int start) const {
|
||||
int PIString::findLast(const char c, const int start) const {
|
||||
for (int i = length() - 1; i >= start; --i)
|
||||
if (at(i) == str)
|
||||
if (at(i) == c)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
@@ -730,7 +804,7 @@ int PIString::findCWord(const PIString & word, const int start) const {
|
||||
}
|
||||
|
||||
|
||||
int PIString::findRange(const PIChar & start, const PIChar & end, const PIChar & shield, const int start_index, int * len) const {
|
||||
int PIString::findRange(const PIChar start, const PIChar end, const PIChar shield, const int start_index, int * len) const {
|
||||
if (len) *len = 0;
|
||||
bool trim_ = (start != ' ' && start != '\t' && start != '\n' && start != '\r'), eq = (start == end);
|
||||
int sz = size_s(), ls = -1, le = -1, cnt = 0;
|
||||
@@ -783,7 +857,7 @@ int PIString::findAnyLast(const PIString & str, const int start) const {
|
||||
}
|
||||
|
||||
|
||||
int PIString::entries(const PIChar & c) const {
|
||||
int PIString::entries(const PIChar c) const {
|
||||
int sz = size_s(), ret = 0;
|
||||
for (int i = 0; i < sz; ++i)
|
||||
if (at(i) == c) ++ret;
|
||||
@@ -804,9 +878,14 @@ bool PIString::endsWith(const PIString & str) const {
|
||||
|
||||
|
||||
bool PIString::toBool() const {
|
||||
static const PIString s_true = PIStringAscii("true");
|
||||
static const PIString s_yes = PIStringAscii("yes" );
|
||||
static const PIString s_on = PIStringAscii("on" );
|
||||
static const PIString s_ok = PIStringAscii("ok" );
|
||||
PIString s(*this);
|
||||
s = s.trimmed().toLowerCase();
|
||||
if ( atof(s.toNativeDecimalPoints().data()) > 0. || s == "true" || s == "yes" || s == "on" || s == "ok") return true;
|
||||
if (s == s_true || s == s_yes || s == s_on || s == s_ok) return true;
|
||||
if (atof(s.toNativeDecimalPoints().data()) > 0.) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -953,7 +1032,7 @@ PIString PIString::takeNumber() {
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::takeRange(const PIChar & start, const PIChar & end, const PIChar & shield) {
|
||||
PIString PIString::takeRange(const PIChar start, const PIChar end, const PIChar shield) {
|
||||
PIString ret;
|
||||
bool trim_ = (start != ' ' && start != '\t' && start != '\n' && start != '\r'), eq = (start == end);
|
||||
int sz = size_s(), ls = -1, le = -1, cnt = 0;
|
||||
@@ -991,7 +1070,7 @@ PIString PIString::takeRange(const PIChar & start, const PIChar & end, const PIC
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::inBrackets(const PIChar &start, const PIChar &end) const {
|
||||
PIString PIString::inBrackets(const PIChar start, const PIChar end) const {
|
||||
int slen = length();
|
||||
int st = -1, bcnt = 0;
|
||||
PIChar cc;
|
||||
@@ -1030,9 +1109,9 @@ PIString PIString::toNativeDecimalPoints() const {
|
||||
#ifdef HAS_LOCALE
|
||||
PIString s(*this);
|
||||
if (currentLocale == 0) return s;
|
||||
return s.replaceAll(".", currentLocale->decimal_point).replaceAll(",", currentLocale->decimal_point);
|
||||
return s.replaceAll('.', currentLocale->decimal_point).replaceAll(',', currentLocale->decimal_point);
|
||||
#else
|
||||
return PIString(*this).replaceAll(",", ".");
|
||||
return PIString(*this).replaceAll(',', '.');
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1062,27 +1141,27 @@ ldouble PIString::toLDouble() const {
|
||||
|
||||
PIString & PIString::setReadableSize(llong bytes) {
|
||||
clear();
|
||||
if (bytes < 1024) {*this += (PIString::fromNumber(bytes) + " B"); return *this;}
|
||||
if (bytes < 1024) {*this += (PIString::fromNumber(bytes) + PIStringAscii(" B")); return *this;}
|
||||
double fres = bytes / 1024.;
|
||||
llong res = bytes / 1024;
|
||||
fres -= res;
|
||||
if (res < 1024) {*this += (PIString::fromNumber(res) + "." + PIString::fromNumber(llong(fres * 10)).left(1) + " kB"); return *this;}
|
||||
if (res < 1024) {*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" kB")); return *this;}
|
||||
fres = res / 1024.;
|
||||
res /= 1024;
|
||||
fres -= res;
|
||||
if (res < 1024) {*this += (PIString::fromNumber(res) + "." + PIString::fromNumber(llong(fres * 10)).left(1) + " MB"); return *this;}
|
||||
if (res < 1024) {*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" MB")); return *this;}
|
||||
fres = res / 1024.;
|
||||
res /= 1024;
|
||||
fres -= res;
|
||||
if (res < 1024) {*this += (PIString::fromNumber(res) + "." + PIString::fromNumber(llong(fres * 10)).left(1) + " GB"); return *this;}
|
||||
if (res < 1024) {*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" GB")); return *this;}
|
||||
fres = res / 1024.;
|
||||
res /= 1024;
|
||||
fres -= res;
|
||||
if (res < 1024) {*this += (PIString::fromNumber(res) + "." + PIString::fromNumber(llong(fres * 10)).left(1) + " TB"); return *this;}
|
||||
if (res < 1024) {*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" TB")); return *this;}
|
||||
fres = res / 1024.;
|
||||
res /= 1024;
|
||||
fres -= res;
|
||||
*this += (PIString::fromNumber(res) + "." + PIString::fromNumber(llong(fres * 10)).left(1) + " PB");
|
||||
*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" PB"));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1110,14 +1189,14 @@ void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
|
||||
}
|
||||
int mccnt = 2 - s.entries('.');
|
||||
if (mccnt > 0) {
|
||||
int ind = s.findLast(".") + 1;
|
||||
int ind = s.findLast('.') + 1;
|
||||
while (!_versionDelims_.contains(s[ind])) {
|
||||
++ind;
|
||||
if (ind > s.size_s() - 1)
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < mccnt; ++i)
|
||||
s.insert(ind, ".0");
|
||||
s.insert(ind, PIStringAscii(".0"));
|
||||
}
|
||||
PIStringList comps;
|
||||
while (!s.isEmpty()) {
|
||||
@@ -1132,7 +1211,7 @@ void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
|
||||
}
|
||||
for (int i = 0; i < comps.size_s(); ++i) {
|
||||
if (comps[i].isEmpty())
|
||||
comps[i] = "0";
|
||||
comps[i] = '0';
|
||||
bool ok = false;
|
||||
int val = comps[i].toInt(-1, &ok);
|
||||
if (ok) {
|
||||
@@ -1148,20 +1227,20 @@ void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
|
||||
int versionLabelValue(PIString s) {
|
||||
int ret = -10000;
|
||||
if (s.isEmpty()) return 0;
|
||||
if (s.startsWith("pre")) {
|
||||
if (s.startsWith(PIStringAscii("pre"))) {
|
||||
s.cutLeft(3);
|
||||
ret -= 1;
|
||||
}
|
||||
if (s.startsWith("rc")) {
|
||||
if (s.startsWith(PIStringAscii("rc"))) {
|
||||
s.cutLeft(2);
|
||||
ret += s.toInt();
|
||||
}
|
||||
if (s.startsWith("r")) {
|
||||
if (s.startsWith(PIStringAscii("r"))) {
|
||||
s.cutLeft(1);
|
||||
ret += 10000 + s.toInt();
|
||||
}
|
||||
if (s == "alpha") ret -= 4;
|
||||
if (s == "beta" ) ret -= 2;
|
||||
if (s == PIStringAscii("alpha")) ret -= 4;
|
||||
if (s == PIStringAscii("beta" )) ret -= 2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1200,13 +1279,13 @@ PIString versionNormalize(const PIString & v) {
|
||||
PIString ret;
|
||||
for (int i = 0; i < codes.size_s(); ++i) {
|
||||
if (i > 0) {
|
||||
if (i < 3) ret += ".";
|
||||
else ret += "-";
|
||||
if (i < 3) ret += '.';
|
||||
else ret += '-';
|
||||
}
|
||||
ret += PIString::fromNumber(codes[i]);
|
||||
}
|
||||
for (int i = 0; i < strs.size_s(); ++i) {
|
||||
ret += "_";
|
||||
ret += '_';
|
||||
ret += strs[i];
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -43,17 +43,20 @@ public:
|
||||
static const float ElideCenter;
|
||||
static const float ElideRight ;
|
||||
|
||||
PIString & operator +=(const PIChar & c) {push_back(c); return *this;}
|
||||
PIString & operator +=(const PIChar c) {push_back(c); return *this;}
|
||||
PIString & operator +=(const char c) {push_back(PIChar(c)); return *this;}
|
||||
PIString & operator +=(const char * str);
|
||||
PIString & operator +=(const wchar_t * str);
|
||||
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;}
|
||||
PIString & operator +=(const PIString & str);
|
||||
|
||||
PIString(const PIString & o): PIDeque<PIChar>() {*this += o;}
|
||||
PIString(const PIString & o): PIDeque<PIChar>(o) {}
|
||||
|
||||
PIString(PIString && o): PIDeque<PIChar>(std::move(o)) {}
|
||||
|
||||
|
||||
//! Contructs string with single symbol "c"
|
||||
PIString(const PIChar & c): PIDeque<PIChar>() {*this += c;}
|
||||
PIString(const PIChar c): PIDeque<PIChar>() {*this += c;}
|
||||
PIString(const char c): PIDeque<PIChar>() {*this += PIChar(c);}
|
||||
|
||||
/*! \brief Contructs string from c-string "str"
|
||||
@@ -82,13 +85,15 @@ public:
|
||||
|
||||
/*! \brief Contructs string as sequence of symbols "c" of buffer with length "len"
|
||||
* \details Example: \snippet pistring.cpp PIString(int, PIChar) */
|
||||
PIString(const int len, const PIChar & c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) push_back(c);}
|
||||
PIString(const int len, const PIChar c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) push_back(c);}
|
||||
|
||||
~PIString() {}
|
||||
|
||||
|
||||
PIString & operator =(const PIString & o) {if (this == &o) return *this; clear(); *this += o; return *this;}
|
||||
|
||||
PIString & operator =(PIString && o) {swap(o); return *this;}
|
||||
|
||||
/*! \brief Return c-string representation of string
|
||||
* \details Converts content of string to c-string and return
|
||||
* pointer to first char. This buffer is valid until new convertion
|
||||
@@ -106,7 +111,7 @@ public:
|
||||
bool operator ==(const PIString & str) const;
|
||||
|
||||
//! Compare operator
|
||||
bool operator ==(const PIChar c) const {return *this == PIString(c);}
|
||||
bool operator ==(const PIChar c) const {if (size_s() != 1) return false; return at(0) == c;}
|
||||
|
||||
//! Compare operator
|
||||
bool operator ==(const char * str) const {return *this == PIString(str);}
|
||||
@@ -115,7 +120,7 @@ public:
|
||||
bool operator !=(const PIString & str) const;
|
||||
|
||||
//! Compare operator
|
||||
bool operator !=(const PIChar c) const {return *this != PIString(c);}
|
||||
bool operator !=(const PIChar c) const {if (size_s() != 1) return true; return at(0) != c;}
|
||||
|
||||
//! Compare operator
|
||||
bool operator !=(const char * str) const {return *this != PIString(str);}
|
||||
@@ -124,7 +129,7 @@ public:
|
||||
bool operator <(const PIString & str) const;
|
||||
|
||||
//! Compare operator
|
||||
bool operator <(const PIChar c) const {return *this < PIString(c);}
|
||||
bool operator <(const PIChar c) const {if (size_s() != 1) return size_s() < 1; return at(0) < c;}
|
||||
|
||||
//! Compare operator
|
||||
bool operator <(const char * str) const {return *this < PIString(str);}
|
||||
@@ -133,7 +138,7 @@ public:
|
||||
bool operator >(const PIString & str) const;
|
||||
|
||||
//! Compare operator
|
||||
bool operator >(const PIChar c) const {return *this > PIString(c);}
|
||||
bool operator >(const PIChar c) const {if (size_s() != 1) return size_s() > 1; return at(0) > c;}
|
||||
|
||||
//! Compare operator
|
||||
bool operator >(const char * str) const {return *this > PIString(str);}
|
||||
@@ -142,7 +147,7 @@ public:
|
||||
bool operator <=(const PIString & str) const {return !(*this > str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator <=(const PIChar c) const {return *this <= PIString(c);}
|
||||
bool operator <=(const PIChar c) const {return !(*this > c);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator <=(const char * str) const {return *this <= PIString(str);}
|
||||
@@ -151,7 +156,7 @@ public:
|
||||
bool operator >=(const PIString & str) const {return !(*this < str);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator >=(const PIChar c) const {return *this >= PIString(c);}
|
||||
bool operator >=(const PIChar c) const {return !(*this < c);}
|
||||
|
||||
//! Compare operator
|
||||
bool operator >=(const char * str) const {return *this >= PIString(str);}
|
||||
@@ -162,7 +167,11 @@ public:
|
||||
|
||||
/*! \brief Append symbol "c" at the end of string
|
||||
* \details Example: \snippet pistring.cpp PIString::<<(PIChar) */
|
||||
PIString & operator <<(const PIChar & c) {*this += c; return *this;}
|
||||
PIString & operator <<(const PIChar c) {*this += c; return *this;}
|
||||
|
||||
/*! \brief Append symbol "c" at the end of string
|
||||
* \details Example: \snippet pistring.cpp PIString::<<(PIChar) */
|
||||
PIString & operator <<(const char c) {*this += PIChar(c); return *this;}
|
||||
|
||||
/*! \brief Append c-string "str" at the end of string
|
||||
* \details Example: \snippet pistring.cpp PIString::<<(char * ) */
|
||||
@@ -177,11 +186,6 @@ public:
|
||||
PIString & operator <<(const int & num) {*this += PIString::fromNumber(num); return *this;}
|
||||
PIString & operator <<(const uint & num) {*this += PIString::fromNumber(num); return *this;}
|
||||
|
||||
/*! \brief Append string representation of "num" at the end of string
|
||||
* \details Example: \snippet pistring.cpp PIString::<<(int) */
|
||||
PIString & operator <<(const short & num) {*this += PIString::fromNumber(num); return *this;}
|
||||
PIString & operator <<(const ushort & num) {*this += PIString::fromNumber(num); return *this;}
|
||||
|
||||
/*! \brief Append string representation of "num" at the end of string
|
||||
* \details Example: \snippet pistring.cpp PIString::<<(int) */
|
||||
PIString & operator <<(const long & num) {*this += PIString::fromNumber(num); return *this;}
|
||||
@@ -278,8 +282,25 @@ public:
|
||||
* \details Example: \snippet pistring.cpp PIString::replaceAll
|
||||
* \sa \a replace(), \a replaced() */
|
||||
PIString & replaceAll(const PIString & what, const PIString & with);
|
||||
PIString replaceAll(const PIString & what, const PIString & with) const {PIString str(*this); str.replaceAll(what, with); return str;}
|
||||
|
||||
|
||||
/*! \brief Replace all founded substrings "what" with symbol "with" and return this string
|
||||
* \details Example: \snippet pistring.cpp PIString::replaceAll
|
||||
* \sa \a replace(), \a replaced() */
|
||||
PIString & replaceAll(const PIString & what, const char with);
|
||||
|
||||
/*! \brief Replace all founded symbols "what" with symbol "with" and return this string
|
||||
* \details Example: \snippet pistring.cpp PIString::replaceAll
|
||||
* \sa \a replace(), \a replaced() */
|
||||
PIString & replaceAll(const char what, const char with);
|
||||
|
||||
PIString replacedAll(const PIString & what, const PIString & with) const {PIString str(*this); str.replaceAll(what, with); return str;}
|
||||
|
||||
PIString replacedAll(const char what, const char with) const {PIString str(*this); str.replaceAll(what, with); return str;}
|
||||
|
||||
PIString & removeAll(const PIString & str);
|
||||
|
||||
PIString & removeAll(char c) {PIDeque<PIChar>::removeAll(PIChar(c)); return *this;}
|
||||
|
||||
/*! \brief Repeat content of string "times" times and return this string
|
||||
* \details Example: \snippet pistring.cpp PIString::repeat */
|
||||
PIString & repeat(int times) {PIString ss(*this); times--; piForTimes (times) *this += ss; return *this;}
|
||||
@@ -290,11 +311,11 @@ public:
|
||||
|
||||
/*! \brief Insert symbol "c" after index "index" and return this string
|
||||
* \details Example: \snippet pistring.cpp PIString::insert_0 */
|
||||
PIString & insert(const int index, const PIChar & c) {PIDeque<PIChar>::insert(index, c); return *this;}
|
||||
PIString & insert(const int index, const PIChar c) {PIDeque<PIChar>::insert(index, c); return *this;}
|
||||
|
||||
/*! \brief Insert symbol "c" after index "index" and return this string
|
||||
* \details Example: \snippet pistring.cpp PIString::insert_1 */
|
||||
PIString & insert(const int index, const char & c) {return insert(index, PIChar(c));}
|
||||
PIString & insert(const int index, const char c) {return insert(index, PIChar(c));}
|
||||
|
||||
/*! \brief Insert string "str" after index "index" and return this string
|
||||
* \details Example: \snippet pistring.cpp PIString::insert_2 */
|
||||
@@ -308,13 +329,13 @@ public:
|
||||
* "c" at the end of string, and return this string
|
||||
* \details Example: \snippet pistring.cpp PIString::expandRightTo
|
||||
* \sa \a expandLeftTo() */
|
||||
PIString & expandRightTo(const int len, const PIChar & c) {if (len > length()) resize(len, c); return *this;}
|
||||
PIString & expandRightTo(const int len, const PIChar c) {if (len > length()) resize(len, c); return *this;}
|
||||
|
||||
/*! \brief Enlarge string to length "len" by addition sequence of symbols
|
||||
* "c" at the beginning of string, and return this string
|
||||
* \details Example: \snippet pistring.cpp PIString::expandLeftTo
|
||||
* \sa \a expandRightTo() */
|
||||
PIString & expandLeftTo(const int len, const PIChar & c) {if (len > length()) insert(0, PIString(len - length(), c)); return *this;}
|
||||
PIString & expandLeftTo(const int len, const PIChar c) {if (len > length()) insert(0, PIString(len - length(), c)); return *this;}
|
||||
|
||||
/*! \brief Add "c" symbols at the beginning and end of the string, and return this string
|
||||
* \sa \a quoted() */
|
||||
@@ -327,7 +348,7 @@ public:
|
||||
/*! \brief Reverse string and return this string
|
||||
* \details Example: \snippet pistring.cpp PIString::reverse
|
||||
* \sa \a reversed() */
|
||||
PIString & reverse() {PIString str(*this); clear(); piForeachR (const PIChar & c, str) push_back(c); return *this;}
|
||||
PIString & reverse() {PIString str(*this); clear(); piForeachCR (PIChar c, str) push_back(c); return *this;}
|
||||
|
||||
/*! \brief Reverse copy of this string and return it
|
||||
* \details Example: \snippet pistring.cpp PIString::reversed
|
||||
@@ -390,13 +411,13 @@ public:
|
||||
* \details "Shield" symbol prevent analysis of the next symbol.
|
||||
* Example: \snippet pistring.cpp PIString::takeRange
|
||||
* \sa \a takeSymbol(), \a takeWord(), \a takeLine(), \a takeNumber() */
|
||||
PIString takeRange(const PIChar & start, const PIChar & end, const PIChar & shield = '\\');
|
||||
PIString takeRange(const PIChar start, const PIChar end, const PIChar shield = '\\');
|
||||
|
||||
|
||||
/*! \brief Return a string in brackets "start" and "end" symbols from the begin of this
|
||||
* string and return it.
|
||||
* \details Example: string = "a(b(c)d)e"; inBrackets('(', ')') = "b(c)d"; */
|
||||
PIString inBrackets(const PIChar & start, const PIChar & end) const;
|
||||
PIString inBrackets(const PIChar start, const PIChar end) const;
|
||||
|
||||
/*! \brief Return real bytes count of this string
|
||||
* \details It`s equivalent length of char sequence
|
||||
@@ -463,11 +484,8 @@ public:
|
||||
PIString toNativeDecimalPoints() const;
|
||||
|
||||
|
||||
//! \brief Returns if string contains "str"
|
||||
bool contains(const char str) const {return contains(PIString(str));}
|
||||
|
||||
//! \brief Returns if string contains "str"
|
||||
bool contains(const PIChar str) const {return contains(PIString(str));}
|
||||
//! \brief Returns if string contains "c"
|
||||
bool contains(const char c) const {return PIDeque<PIChar>::contains(PIChar(c));}
|
||||
|
||||
//! \brief Returns if string contains "str"
|
||||
bool contains(const char * str) const {return contains(PIString(str));}
|
||||
@@ -476,9 +494,9 @@ public:
|
||||
bool contains(const PIString & str) const {return find(str) >= 0;}
|
||||
|
||||
|
||||
//! \brief Search substring "str" from symbol at index "start" and return first occur position
|
||||
//! \brief Search symbol "c" from symbol at index "start" and return first occur position
|
||||
//! \details Example: \snippet pistring.cpp PIString::find
|
||||
int find(const char str, const int start = 0) const;
|
||||
int find(const char c, const int start = 0) const;
|
||||
|
||||
//! \brief Search substring "str" from symbol at index "start" and return first occur position
|
||||
//! \details Example: \snippet pistring.cpp PIString::find
|
||||
@@ -488,9 +506,9 @@ public:
|
||||
//! \details Example: \snippet pistring.cpp PIString::find
|
||||
int find(const char * str, const int start = 0) const {return find(PIString(str), start);}
|
||||
|
||||
//! \brief Search substring "str" from symbol at index "start" and return last occur position
|
||||
//! \brief Search symbol "c" from symbol at index "start" and return last occur position
|
||||
//! \details Example: \snippet pistring.cpp PIString::findLast
|
||||
int findLast(const char str, const int start = 0) const;
|
||||
int findLast(const char c, const int start = 0) const;
|
||||
|
||||
//! \brief Search substring "str" from symbol at index "start" and return last occur position
|
||||
//! \details Example: \snippet pistring.cpp PIString::findLast
|
||||
@@ -510,7 +528,7 @@ public:
|
||||
|
||||
//! \brief Search range between "start" and "end" symbols at index "start_index" and return first occur position.
|
||||
//! \details Example: \snippet pistring.cpp PIString::findRange
|
||||
int findRange(const PIChar & start, const PIChar & end, const PIChar & shield = '\\', const int start_index = 0, int * len = 0) const;
|
||||
int findRange(const PIChar start, const PIChar end, const PIChar shield = '\\', const int start_index = 0, int * len = 0) const;
|
||||
|
||||
//! \brief Search any symbol of "str" from symbol at index "start" and return first occur position
|
||||
//! \details Example: \snippet pistring.cpp PIString::findAny
|
||||
@@ -529,7 +547,7 @@ public:
|
||||
int findAnyLast(const char * str, const int start = 0) const {return findAnyLast(PIString(str), start);}
|
||||
|
||||
//! \brief Returns number of occurrences of symbol "c"
|
||||
int entries(const PIChar & c) const;
|
||||
int entries(const PIChar c) const;
|
||||
|
||||
//! \brief Returns number of occurrences of symbol "c"
|
||||
int entries(char c) const {return entries(PIChar(c));}
|
||||
@@ -714,9 +732,6 @@ public:
|
||||
//! \details Example: \snippet pistring.cpp PIString::readableSize
|
||||
static PIString readableSize(llong bytes);
|
||||
|
||||
PIString & removeAll(char v) {replaceAll(v, ""); return *this;}
|
||||
PIString & removeAll(const PIString & v) {replaceAll(v, ""); return *this;}
|
||||
|
||||
private:
|
||||
static const char toBaseN[];
|
||||
static const int fromBaseN[];
|
||||
@@ -759,6 +774,12 @@ inline PIString operator +(const PIString & f, const char * str) {PIString s(f);
|
||||
//! \relatesalso PIString \brief Return concatenated string
|
||||
inline PIString operator +(const char * str, const PIString & f) {return PIString(str) + f;}
|
||||
|
||||
//! \relatesalso PIString \brief Return concatenated string
|
||||
inline PIString operator +(const char c, const PIString & f) {return PIChar(c) + f;}
|
||||
|
||||
//! \relatesalso PIString \brief Return concatenated string
|
||||
inline PIString operator +(const PIString & f, const char c) {return f + PIChar(c);}
|
||||
|
||||
inline char chrUpr(char c);
|
||||
inline char chrLwr(char c);
|
||||
|
||||
@@ -770,5 +791,6 @@ PIString versionNormalize(const PIString & v);
|
||||
|
||||
|
||||
template<> inline uint piHash(const PIString & s) {return s.hash();}
|
||||
template<> inline void piSwap(PIString & f, PIString & s) {f.swap(s);}
|
||||
|
||||
#endif // PISTRING_H
|
||||
|
||||
@@ -37,17 +37,22 @@ public:
|
||||
|
||||
//! Contructs strings list with one string "str"
|
||||
PIStringList(const PIString & str) {push_back(str);}
|
||||
PIStringList(PIString && str) {push_back(std::move(str));}
|
||||
|
||||
//! Contructs empty strings list with strings "s0" and "s1"
|
||||
PIStringList(const PIString & s0, const PIString & s1) {push_back(s0); push_back(s1);}
|
||||
PIStringList(PIString && s0, PIString && s1) {push_back(std::move(s0)); push_back(std::move(s1));}
|
||||
|
||||
//! Contructs empty strings list with strings "s0", "s1" and "s2"
|
||||
PIStringList(const PIString & s0, const PIString & s1, const PIString & s2) {push_back(s0); push_back(s1); push_back(s2);}
|
||||
PIStringList(PIString && s0, PIString && s1, PIString && s2) {push_back(std::move(s0)); push_back(std::move(s1)); push_back(std::move(s2));}
|
||||
|
||||
//! Contructs empty strings list with strings "s0", "s1", "s2" and "s3"
|
||||
PIStringList(const PIString & s0, const PIString & s1, const PIString & s2, const PIString & s3) {push_back(s0); push_back(s1); push_back(s2); push_back(s3);}
|
||||
PIStringList(PIString && s0, PIString && s1, PIString && s2, PIString && s3) {push_back(std::move(s0)); push_back(std::move(s1)); push_back(std::move(s2)); push_back(std::move(s3));}
|
||||
|
||||
PIStringList(const PIStringList & o): PIDeque<PIString>() {resize(o.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = o[i];}
|
||||
PIStringList(const PIStringList & o): PIDeque<PIString>(o) {}
|
||||
PIStringList(PIStringList && o): PIDeque<PIString>(std::move(o)) {}
|
||||
PIStringList(const PIVector<PIString> & o): PIDeque<PIString>() {resize(o.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = o[i];}
|
||||
PIStringList(const PIDeque<PIString> & o): PIDeque<PIString>() {resize(o.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = o[i];}
|
||||
|
||||
@@ -83,6 +88,7 @@ public:
|
||||
PIStringList & operator =(const PIStringList & o) {PIDeque<PIString>::operator=(o); return *this;}
|
||||
|
||||
PIStringList & operator <<(const PIString & str) {append(str); return *this;}
|
||||
PIStringList & operator <<(PIString && str) {append(std::move(str)); return *this;}
|
||||
PIStringList & operator <<(const PIStringList & sl) {append(sl); return *this;}
|
||||
|
||||
};
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
template<typename T>
|
||||
class PIP_EXPORT __PIVariantFunctions__ {
|
||||
class __PIVariantFunctions__ {
|
||||
public:
|
||||
static PIString typeNameHelper() {return PIStringAscii("");}
|
||||
|
||||
@@ -59,7 +59,7 @@ struct PIP_EXPORT __PIVariantInfo__ {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct PIP_EXPORT __PIVariantTypeInfo__ {
|
||||
struct __PIVariantTypeInfo__ {
|
||||
typedef T PureType;
|
||||
typedef const T ConstPureType;
|
||||
typedef T * PointerType;
|
||||
@@ -102,7 +102,7 @@ REGISTER_VARIANT_TYPEINFO(ns::classname)
|
||||
|
||||
#define REGISTER_VARIANT_CPP(classname) \
|
||||
template <typename T> \
|
||||
class PIP_EXPORT __##classname##_PIVariantInitializer__ { \
|
||||
class __##classname##_PIVariantInitializer__ { \
|
||||
public: \
|
||||
__##classname##_PIVariantInitializer__(const PIString & name) { \
|
||||
if (__PIVariantInfoStorage__::get()->map->contains(name)) \
|
||||
@@ -115,7 +115,7 @@ public: \
|
||||
|
||||
#define REGISTER_NS_VARIANT_CPP(ns, classname) \
|
||||
template <typename T> \
|
||||
class PIP_EXPORT __##ns##classname##_PIVariantInitializer__ { \
|
||||
class __##ns##classname##_PIVariantInitializer__ { \
|
||||
public: \
|
||||
__##ns##classname##_PIVariantInitializer__(const PIString & name) { \
|
||||
if (__PIVariantInfoStorage__::get()->map->contains(name)) \
|
||||
@@ -155,7 +155,7 @@ PIByteArray __PIVariantFunctions__<classname_from>::castHelper<classname_to>(PIB
|
||||
PIByteArray ret; ret << t; \
|
||||
return ret;} \
|
||||
template <typename T, typename C> \
|
||||
class PIP_EXPORT __##classname_from##_##classname_to##_PIVariantCastInitializer__ { \
|
||||
class __##classname_from##_##classname_to##_PIVariantCastInitializer__ { \
|
||||
public: \
|
||||
__##classname_from##_##classname_to##_PIVariantCastInitializer__(const PIString & name, const PIString & cname) { \
|
||||
__PIVariantInfo__ * vi(__PIVariantInfoStorage__::get()->map->value(name, 0)); \
|
||||
@@ -206,7 +206,7 @@ class PIP_EXPORT PIVariant {
|
||||
public:
|
||||
|
||||
//! Type of %PIVariant content
|
||||
enum PIP_EXPORT Type {
|
||||
enum Type {
|
||||
pivInvalid /** Invalid type , default type of empty contructor */ = 0 ,
|
||||
pivBool /** bool */ ,
|
||||
pivChar /** char */ ,
|
||||
|
||||
@@ -23,11 +23,12 @@
|
||||
#ifndef PIAUTH_H
|
||||
#define PIAUTH_H
|
||||
|
||||
#include "pip_crypt_export.h"
|
||||
#include "piobject.h"
|
||||
#include "picrypt.h"
|
||||
|
||||
|
||||
class PIP_EXPORT PIAuth : public PIObject
|
||||
class PIP_CRYPT_EXPORT PIAuth : public PIObject
|
||||
{
|
||||
PIOBJECT(PIAuth)
|
||||
public:
|
||||
|
||||
@@ -23,9 +23,10 @@
|
||||
#ifndef PICRYPT_H
|
||||
#define PICRYPT_H
|
||||
|
||||
#include "pip_crypt_export.h"
|
||||
#include "pistring.h"
|
||||
|
||||
class PIP_EXPORT PICrypt {
|
||||
class PIP_CRYPT_EXPORT PICrypt {
|
||||
public:
|
||||
//! Construct and generate random key
|
||||
PICrypt();
|
||||
|
||||
@@ -30,8 +30,7 @@ class PIP_EXPORT PIGeoPosition : public PIMathVectorT3d
|
||||
{
|
||||
public:
|
||||
|
||||
enum CoordinateSystem
|
||||
{
|
||||
enum CoordinateSystem {
|
||||
Unknown=0, /// Unknown coordinate system
|
||||
Geodetic, /// Geodetic latitude, longitude, and height above ellipsoid
|
||||
Geocentric, /// Geocentric (regular spherical coordinates)
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "pibase.h"
|
||||
|
||||
class PIString;
|
||||
class PIMutex;
|
||||
class PIThread;
|
||||
class PITimer;
|
||||
class PIPeer;
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
PIVector<TypeInfo> getInfo() const;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct _Type {
|
||||
struct PIP_EXPORT _Type {
|
||||
_Type();
|
||||
uint id;
|
||||
uint count;
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
struct TypeInfo: _Type {
|
||||
struct PIP_EXPORT TypeInfo: _Type {
|
||||
PIString name;
|
||||
};
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
mutable PIMutex mutex;
|
||||
};
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::TypeInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::TypeInfo & v);
|
||||
PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::TypeInfo & v);
|
||||
PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::TypeInfo & v);
|
||||
|
||||
#endif // PIINTROSPECTION_CONTAINERS_P_H
|
||||
|
||||
@@ -214,9 +214,10 @@ PIByteArray PIIntrospection::packThreads() {
|
||||
if (p) {
|
||||
p->mutex.lock();
|
||||
PIMap<PIThread*, PIIntrospectionThreads::ThreadInfo> & tm(p->threads);
|
||||
for (PIMap<PIThread*, PIIntrospectionThreads::ThreadInfo>::iterator i = tm.begin(); i != tm.end(); ++i) {
|
||||
i.value().classname = PIStringAscii(i.key()->className());
|
||||
i.value().name = i.key()->name();
|
||||
auto it = tm.makeIterator();
|
||||
while (it.next()) {
|
||||
it.valueRef().classname = PIStringAscii(it.key()->className());
|
||||
it.valueRef().name = it.key()->name();
|
||||
}
|
||||
ret << tm.values();
|
||||
p->mutex.unlock();
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "pisystemmonitor.h"
|
||||
|
||||
|
||||
class PIIntrospection {
|
||||
class PIP_EXPORT PIIntrospection {
|
||||
public:
|
||||
|
||||
enum InfoTypes {
|
||||
@@ -38,12 +38,12 @@ public:
|
||||
itThreads = 0x10,
|
||||
};
|
||||
|
||||
struct RequiredInfo {
|
||||
struct PIP_EXPORT RequiredInfo {
|
||||
RequiredInfo();
|
||||
PIFlags<InfoTypes> types;
|
||||
};
|
||||
|
||||
struct ProcessInfo {
|
||||
struct PIP_EXPORT ProcessInfo {
|
||||
ProcessInfo();
|
||||
|
||||
PIString execCommand, hostname, user, OS_name, OS_version, architecture;
|
||||
@@ -53,14 +53,14 @@ public:
|
||||
PIStringList build_options;
|
||||
};
|
||||
|
||||
struct ProcessStat {
|
||||
struct PIP_EXPORT ProcessStat {
|
||||
ProcessStat() {}
|
||||
|
||||
PISystemMonitor::ProcessStats proc;
|
||||
PIVector<PISystemMonitor::ThreadStats> threads;
|
||||
};
|
||||
|
||||
struct ObjectInfo {
|
||||
struct PIP_EXPORT ObjectInfo {
|
||||
ObjectInfo();
|
||||
|
||||
PIString classname, name;
|
||||
@@ -91,13 +91,13 @@ public:
|
||||
|
||||
};
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::RequiredInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::RequiredInfo & v);
|
||||
PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::RequiredInfo & v);
|
||||
PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospection::RequiredInfo & v);
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ProcessInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ProcessInfo & v);
|
||||
PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ProcessInfo & v);
|
||||
PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ProcessInfo & v);
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v);
|
||||
PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v);
|
||||
PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v);
|
||||
|
||||
#endif // PIINTROSPECTION_SERVER_P_H
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
sWaiting,
|
||||
};
|
||||
|
||||
struct ThreadInfo {
|
||||
struct PIP_EXPORT ThreadInfo {
|
||||
ThreadInfo();
|
||||
PIString classname, name;
|
||||
int id, delay;
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v);
|
||||
PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v);
|
||||
PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v);
|
||||
PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v);
|
||||
|
||||
#endif // PIINTROSPECTION_THREADS_P_H
|
||||
|
||||
@@ -96,7 +96,7 @@ bool PIBinaryLog::openDevice() {
|
||||
piForeachC(PIFile::FileInfo &i, es) {
|
||||
if (i.extension() == "binlog" && i.isFile() && i.baseName().startsWith(filePrefix())) {
|
||||
setPath(i.path);
|
||||
piBreak;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
};
|
||||
|
||||
//! \brief Struct contains information about all records with same ID
|
||||
struct BinLogRecordInfo {
|
||||
struct PIP_EXPORT BinLogRecordInfo {
|
||||
BinLogRecordInfo() {
|
||||
id = count = 0;
|
||||
minimum_size = maximum_size = 0;
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
};
|
||||
|
||||
//! \brief Struct contains full information about Binary Log file and about all Records using map of \a BinLogRecordInfo
|
||||
struct BinLogInfo {
|
||||
struct PIP_EXPORT BinLogInfo {
|
||||
PIString path;
|
||||
int records_count;
|
||||
llong log_size;
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
};
|
||||
|
||||
//! \brief Struct contains position, ID and timestamp of record in file
|
||||
struct BinLogIndex {
|
||||
struct PIP_EXPORT BinLogIndex {
|
||||
int id;
|
||||
llong pos;
|
||||
PISystemTime timestamp;
|
||||
@@ -293,7 +293,7 @@ protected:
|
||||
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}
|
||||
|
||||
private:
|
||||
struct BinLogRecord {
|
||||
struct PIP_EXPORT BinLogRecord {
|
||||
int id;
|
||||
int size;
|
||||
PISystemTime timestamp;
|
||||
|
||||
@@ -505,8 +505,8 @@ private:
|
||||
|
||||
|
||||
#ifdef PIP_STD_IOSTREAM
|
||||
std::ostream & operator <<(std::ostream & s, const PIConfig::Branch & v);
|
||||
std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v);
|
||||
PIP_EXPORT std::ostream & operator <<(std::ostream & s, const PIConfig::Branch & v);
|
||||
PIP_EXPORT std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v);
|
||||
#endif
|
||||
|
||||
inline PICout operator <<(PICout s, const PIConfig::Branch & v) {s.setControl(0, true); v.piCoutt(s, ""); s.restoreControl(); return s;}
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
explicit PIEthernet();
|
||||
|
||||
//! \brief Type of %PIEthernet
|
||||
enum PIP_EXPORT Type {
|
||||
enum Type {
|
||||
UDP /** UDP - User Datagram Protocol */ ,
|
||||
TCP_Client /** TCP client - allow connection to TCP server */ ,
|
||||
TCP_Server /** TCP server - receive connections from TCP clients */ ,
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
};
|
||||
|
||||
//! \brief Parameters of %PIEthernet
|
||||
enum PIP_EXPORT Parameters {
|
||||
enum Parameters {
|
||||
ReuseAddress /** Rebind address if there is already binded. Enabled by default */ = 0x1,
|
||||
Broadcast /** Broadcast send. Disabled by default */ = 0x2,
|
||||
SeparateSockets /** If this parameter is set, %PIEthernet will initialize two different sockets,
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
|
||||
|
||||
//! \brief IPv4 network address, IP and port
|
||||
class Address {
|
||||
class PIP_EXPORT Address {
|
||||
friend class PIEthernet;
|
||||
friend inline PIByteArray & operator <<(PIByteArray & s, const PIEthernet::Address & v);
|
||||
friend inline PIByteArray & operator >>(PIByteArray & s, PIEthernet::Address & v);
|
||||
@@ -322,7 +322,7 @@ public:
|
||||
|
||||
|
||||
//! Flags of network interface
|
||||
enum PIP_EXPORT InterfaceFlag {
|
||||
enum InterfaceFlag {
|
||||
ifActive /** Is active */ = 0x1,
|
||||
ifRunning /** Is running */ = 0x2,
|
||||
ifBroadcast /** Support broadcast */ = 0x4,
|
||||
@@ -485,7 +485,7 @@ protected:
|
||||
void applyTimeout(int fd, int opt, double ms);
|
||||
void applyOptInt(int level, int opt, int val);
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
int sock, sock_s;
|
||||
bool connected_, connecting_, listen_threaded, server_bounded;
|
||||
mutable Address addr_r, addr_s, addr_lr;
|
||||
|
||||
@@ -235,7 +235,7 @@ PIByteArray PIFile::readAll(bool forceRead) {
|
||||
llong s = size();
|
||||
if (s < 0) return a;
|
||||
a.resize(s);
|
||||
s = readAll(a.data());
|
||||
fread(a.data(), 1, s, PRIVATE->fd);
|
||||
seek(cp);
|
||||
if (s >= 0) a.resize(s);
|
||||
return a;
|
||||
@@ -593,7 +593,7 @@ void PIFile::setDefaultCharset(const char * c) {
|
||||
PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
|
||||
FileInfo ret;
|
||||
if (path.isEmpty()) return ret;
|
||||
ret.path = path.replaceAll("\\", PIDir::separator);
|
||||
ret.path = path.replacedAll("\\", PIDir::separator);
|
||||
PIString n = ret.name();
|
||||
//piCout << "open" << path;
|
||||
#ifdef WINDOWS
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
struct PIP_EXPORT FileInfo {
|
||||
FileInfo() {size = 0; id_group = id_user = 0;}
|
||||
|
||||
enum PIP_EXPORT Flag {
|
||||
enum Flag {
|
||||
File = 0x01,
|
||||
Dir = 0x02,
|
||||
Dot = 0x04,
|
||||
@@ -292,7 +292,7 @@ protected:
|
||||
private:
|
||||
PIString strType(const PIIODevice::DeviceMode type);
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
int ret, prec_, fdi;
|
||||
PIString prec_str;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "pithread.h"
|
||||
|
||||
|
||||
class PIGPIO: public PIThread
|
||||
class PIP_EXPORT PIGPIO: public PIThread
|
||||
{
|
||||
PIOBJECT_SUBCLASS(PIGPIO, PIThread)
|
||||
public:
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
//! \}
|
||||
|
||||
private:
|
||||
struct GPIOData {
|
||||
struct PIP_EXPORT GPIOData {
|
||||
GPIOData() {dir = PIGPIO::In; num = fd = -1;}
|
||||
PIString name;
|
||||
int dir;
|
||||
|
||||
@@ -382,7 +382,7 @@ void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode *
|
||||
int dm = 0;
|
||||
DeviceOptions op = 0;
|
||||
if (fpwm.find("(") > 0 && fpwm.find(")") > 0) {
|
||||
PIString dms(fpwm.right(fpwm.length() - fpwm.findLast("(")).takeRange("(", ")").trim().toLowerCase().removeAll(" "));
|
||||
PIString dms(fpwm.right(fpwm.length() - fpwm.findLast("(")).takeRange("(", ")").trim().toLowerCase().removeAll(' '));
|
||||
PIStringList opts(dms.split(","));
|
||||
piForeachC (PIString & o, opts) {
|
||||
//piCout << dms;
|
||||
|
||||
@@ -54,6 +54,7 @@ class PIP_EXPORT PIIODevice: public PIThread
|
||||
PIOBJECT_SUBCLASS(PIIODevice, PIThread)
|
||||
friend void __DevicePool_threadReadDP(void * ddp);
|
||||
public:
|
||||
NO_COPY_CLASS(PIIODevice)
|
||||
|
||||
//! Constructs a empty PIIODevice
|
||||
explicit PIIODevice();
|
||||
@@ -388,8 +389,6 @@ protected:
|
||||
void * ret_data_;
|
||||
|
||||
private:
|
||||
NO_COPY_CLASS(PIIODevice)
|
||||
|
||||
EVENT_HANDLER2(void, check_start, void * , data, int, delim);
|
||||
EVENT_HANDLER(void, write_func);
|
||||
|
||||
|
||||
@@ -491,7 +491,7 @@ bool PIPeer::dataRead(uchar * readed, int size) {
|
||||
if (p.name != from) continue;
|
||||
piForeach (PeerInfo::PeerAddress & a, p.addresses) {
|
||||
if (a.address != addr) continue;
|
||||
if (a.last_ping >= time) piBreak;
|
||||
if (a.last_ping >= time) break;
|
||||
ptime = ctime - time;
|
||||
a.last_ping = time;
|
||||
a.wait_ping = false;
|
||||
@@ -677,7 +677,7 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
|
||||
if (peer.name == pi.name) peer.sync = 0;
|
||||
ch = true;
|
||||
}
|
||||
piBreak;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (exist || isRemoved(rpeer)) continue;
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
explicit PIPeer(const PIString & name = PIString());
|
||||
virtual ~PIPeer();
|
||||
|
||||
class PeerInfo {
|
||||
class PIP_EXPORT PeerInfo {
|
||||
friend class PIPeer;
|
||||
friend PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo & v);
|
||||
friend PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo & v);
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
PeerInfo() {dist = sync = cnt = 0; trace = -1; was_update = false; _data = 0;}
|
||||
~PeerInfo() {}
|
||||
|
||||
struct PeerAddress {
|
||||
struct PIP_EXPORT PeerAddress {
|
||||
PeerAddress(const PIEthernet::Address & a = PIEthernet::Address(), const PIEthernet::Address & m = PIEthernet::Address("255.255.255.0"));
|
||||
bool isAvailable() const {return ping > 0;}
|
||||
PIEthernet::Address address;
|
||||
@@ -120,11 +120,11 @@ public:
|
||||
EVENT1(peerConnectedEvent, const PIString &, name)
|
||||
EVENT1(peerDisconnectedEvent, const PIString &, name)
|
||||
|
||||
bool lockedEth() const {return eth_mutex.isLocked();}
|
||||
bool lockedPeers() const {return peers_mutex.isLocked();}
|
||||
bool lockedMBcasts() const {return mc_mutex.isLocked();}
|
||||
bool lockedSends() const {return send_mutex.isLocked();}
|
||||
bool lockedMCSends() const {return send_mc_mutex.isLocked();}
|
||||
// bool lockedEth() const {return eth_mutex.isLocked();}
|
||||
// bool lockedPeers() const {return peers_mutex.isLocked();}
|
||||
// bool lockedMBcasts() const {return mc_mutex.isLocked();}
|
||||
// bool lockedSends() const {return send_mutex.isLocked();}
|
||||
// bool lockedMCSends() const {return send_mc_mutex.isLocked();}
|
||||
|
||||
protected:
|
||||
virtual void dataReceived(const PIString & from, const PIByteArray & data) {;}
|
||||
|
||||
@@ -544,7 +544,7 @@ bool PISerial::openDevice() {
|
||||
piForeachC (DeviceInfo & d, devs) {
|
||||
if (d.id() == pl) {
|
||||
p = d.path;
|
||||
piBreak;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p.isEmpty()) {
|
||||
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
};
|
||||
|
||||
//! \brief Information about serial device
|
||||
struct DeviceInfo {
|
||||
struct PIP_EXPORT DeviceInfo {
|
||||
DeviceInfo();
|
||||
|
||||
//! \brief String representation of USB ID in format \"xxxx:xxxx\"
|
||||
@@ -246,7 +246,7 @@ protected:
|
||||
bool openDevice();
|
||||
bool closeDevice();
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
int fd, vtime;
|
||||
bool sending;
|
||||
PITimeMeasurer tm_;
|
||||
|
||||
@@ -86,7 +86,7 @@ private:
|
||||
void initPrivate();
|
||||
|
||||
int dsize;
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ private:
|
||||
uchar spi_bits;
|
||||
PIByteArray tx_buf, rx_buf;
|
||||
PIByteArray recv_buf;
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
};
|
||||
|
||||
#endif // PISPI_H
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
explicit PIUSB(ushort vid = 0, ushort pid = 0);
|
||||
~PIUSB() {closeDevice();}
|
||||
|
||||
struct Endpoint {
|
||||
struct PIP_EXPORT Endpoint {
|
||||
Endpoint(uchar a = 0, uchar at = 0, ushort mps = 0) {address = a; attributes = at; max_packet_size = mps; parse();}
|
||||
|
||||
enum Direction {Write = 0, Read = 1};
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
UsageType usage_type;
|
||||
};
|
||||
|
||||
struct Interface {
|
||||
struct PIP_EXPORT Interface {
|
||||
Interface() {index = value_to_select = class_code = subclass_code = protocol_code = 0;}
|
||||
uchar index;
|
||||
uchar value_to_select;
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
PIVector<PIUSB::Endpoint> endpoints;
|
||||
};
|
||||
|
||||
struct Configuration {
|
||||
struct PIP_EXPORT Configuration {
|
||||
Configuration() {index = value_to_select = attributes = max_power = 0; self_powered = remote_wakeup = false;}
|
||||
uchar index;
|
||||
uchar value_to_select;
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
PIVector<PIUSB::Interface> interfaces;
|
||||
};
|
||||
|
||||
struct Descriptor {
|
||||
struct PIP_EXPORT Descriptor {
|
||||
Descriptor() {usb_spec_number = 0; device_class = device_subclass = device_protocol = max_packet_size = 0; id_vendor = id_product = id_device_release = 0; index_manufacturer = index_product = index_serial = 0;}
|
||||
ushort usb_spec_number;
|
||||
uchar device_class;
|
||||
@@ -148,6 +148,6 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
PICout operator <<(PICout s, const PIUSB::Endpoint & v);
|
||||
PIP_EXPORT PICout operator <<(PICout s, const PIUSB::Endpoint & v);
|
||||
|
||||
#endif // PIUSB_H
|
||||
|
||||
@@ -102,7 +102,7 @@ protected:
|
||||
llong bytes_all, bytes_cur;
|
||||
|
||||
private:
|
||||
enum PIP_EXPORT PacketType {pt_Unknown, pt_Data, pt_ReplySuccess, pt_ReplyInvalid, pt_Break, pt_Start, pt_Pause};
|
||||
enum PacketType {pt_Unknown, pt_Data, pt_ReplySuccess, pt_ReplyInvalid, pt_Break, pt_Start, pt_Pause};
|
||||
|
||||
# pragma pack(push,1)
|
||||
struct PIP_EXPORT StartRequest {
|
||||
|
||||
@@ -23,11 +23,12 @@
|
||||
#ifndef PIBROADCAST_H
|
||||
#define PIBROADCAST_H
|
||||
|
||||
#include "pip_io_utils_export.h"
|
||||
#include "piethutilbase.h"
|
||||
#include "piethernet.h"
|
||||
|
||||
|
||||
class PIBroadcast: public PIThread, public PIEthUtilBase {
|
||||
class PIP_IO_UTILS_EXPORT PIBroadcast: public PIThread, public PIEthUtilBase {
|
||||
PIOBJECT_SUBCLASS(PIBroadcast, PIThread)
|
||||
public:
|
||||
|
||||
|
||||
@@ -375,21 +375,22 @@ bool PIConnection::removeDevice(const PIString & full_path) {
|
||||
PIStringList dntd(deviceNames(dev));
|
||||
piForeachC (PIString & n, dntd)
|
||||
device_names.removeOne(n);
|
||||
piForeachC (SPair & s, senders) {
|
||||
if (s.second == 0) continue;
|
||||
s.second->lock();
|
||||
s.second->devices.removeAll(dev);
|
||||
s.second->unlock();
|
||||
for (auto s = senders.constBegin(); s != senders.constEnd(); s++) {
|
||||
if (s.value() == 0) continue;
|
||||
s.value()->lock();
|
||||
s.value()->devices.removeAll(dev);
|
||||
s.value()->unlock();
|
||||
}
|
||||
device_modes.remove(dev);
|
||||
piForeachC (PEPair & i, extractors) {
|
||||
if (i.second == 0) continue;
|
||||
i.second->devices.removeAll(dev);
|
||||
for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
|
||||
if (i.value() == 0) continue;
|
||||
i.value()->devices.removeAll(dev);
|
||||
}
|
||||
bounded_extractors.remove(dev);
|
||||
channels_.remove(dev);
|
||||
for (PIMap<PIIODevice * , PIVector<PIIODevice * > >::iterator it = channels_.begin(); it != channels_.end(); ++it)
|
||||
it.value().removeAll(dev);
|
||||
auto it = channels_.makeIterator();
|
||||
while (it.next())
|
||||
it.valueRef().removeAll(dev);
|
||||
__device_pool__->lock();
|
||||
if (diags_.value(dev, 0) != 0)
|
||||
delete diags_.value(dev);
|
||||
@@ -404,15 +405,16 @@ void PIConnection::removeAllDevices() {
|
||||
PIVector<PIIODevice * > bdevs(__device_pool__->boundedDevices(this));
|
||||
__device_pool__->lock();
|
||||
piForeach (PIIODevice * d, bdevs) {
|
||||
piForeachC (SPair & s, senders) {
|
||||
if (s.second == 0) continue;
|
||||
s.second->lock();
|
||||
s.second->devices.removeAll(d);
|
||||
s.second->unlock();
|
||||
for (auto s = senders.constBegin(); s != senders.constEnd(); s++) {
|
||||
if (s.value() == 0) continue;
|
||||
s.value()->lock();
|
||||
s.value()->devices.removeAll(d);
|
||||
s.value()->unlock();
|
||||
}
|
||||
channels_.remove(d);
|
||||
for (PIMap<PIIODevice * , PIVector<PIIODevice * > >::iterator it = channels_.begin(); it != channels_.end(); ++it)
|
||||
it.value().removeAll(d);
|
||||
auto it = channels_.makeIterator();
|
||||
while (it.next())
|
||||
it.valueRef().removeAll(d);
|
||||
if (diags_.value(d, 0) != 0)
|
||||
delete diags_.value(d);
|
||||
diags_.remove(d);
|
||||
@@ -421,9 +423,9 @@ void PIConnection::removeAllDevices() {
|
||||
__device_pool__->unlock();
|
||||
device_modes.clear();
|
||||
bounded_extractors.clear();
|
||||
piForeachC (PEPair & i, extractors) {
|
||||
if (i.second == 0) continue;
|
||||
i.second->devices.clear();
|
||||
for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
|
||||
if (i.value() == 0) continue;
|
||||
i.value()->devices.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -563,15 +565,16 @@ bool PIConnection::removeFilter(const PIString & name_) {
|
||||
|
||||
void PIConnection::removeAllFilters() {
|
||||
__device_pool__->lock();
|
||||
piForeachC (PEPair & i, extractors) {
|
||||
if (i.second == 0) continue;
|
||||
channels_.remove(i.second->extractor);
|
||||
for (PIMap<PIIODevice * , PIVector<PIIODevice * > >::iterator it = channels_.begin(); it != channels_.end(); ++it)
|
||||
it.value().removeAll(i.second->extractor);
|
||||
if (diags_.value(i.second->extractor, 0) != 0)
|
||||
delete diags_.value(i.second->extractor);
|
||||
diags_.remove(i.second->extractor);
|
||||
delete i.second;
|
||||
for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
|
||||
if (i.value() == 0) continue;
|
||||
channels_.remove(i.value()->extractor);
|
||||
auto it = channels_.makeIterator();
|
||||
while (it.next())
|
||||
it.valueRef().removeAll(i.value()->extractor);
|
||||
if (diags_.value(i.value()->extractor, 0) != 0)
|
||||
delete diags_.value(i.value()->extractor);
|
||||
diags_.remove(i.value()->extractor);
|
||||
delete i.value();
|
||||
}
|
||||
extractors.clear();
|
||||
bounded_extractors.clear();
|
||||
@@ -581,28 +584,31 @@ void PIConnection::removeAllFilters() {
|
||||
|
||||
PIVector<PIPacketExtractor * > PIConnection::filters() const {
|
||||
PIVector<PIPacketExtractor * > ret;
|
||||
piForeachC (PEPair & i, extractors)
|
||||
if (i.second != 0)
|
||||
if (i.second->extractor != 0) ret << i.second->extractor;
|
||||
for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
|
||||
if (i.value() != 0)
|
||||
if (i.value()->extractor != 0) ret << i.value()->extractor;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIStringList PIConnection::filterNames() const {
|
||||
PIStringList ret;
|
||||
piForeachC (PEPair & i, extractors)
|
||||
if (i.second != 0)
|
||||
if (i.second->extractor != 0) ret << i.first;
|
||||
for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
|
||||
if (i.value() != 0)
|
||||
if (i.value()->extractor != 0) ret << i.key();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIPacketExtractor * PIConnection::filter(const PIString & name_) const {
|
||||
PIString fname_ = name_.trimmed();
|
||||
piForeachC (PEPair & i, extractors)
|
||||
if (i.second != 0)
|
||||
if (i.second->extractor != 0 && i.first == fname_)
|
||||
return i.second->extractor;
|
||||
for (auto i = extractors.constBegin(); i != extractors.constEnd(); i++) {
|
||||
if (i.value() != 0)
|
||||
if (i.value()->extractor != 0 && i.key() == fname_)
|
||||
return i.value()->extractor;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -655,8 +661,9 @@ bool PIConnection::removeChannel(const PIString & name0) {
|
||||
if (pe0 != 0) dev0 = pe0;
|
||||
if (dev0 == 0) return false;
|
||||
channels_.remove(dev0);
|
||||
for (PIMap<PIIODevice * , PIVector<PIIODevice * > >::iterator it = channels_.begin(); it != channels_.end(); ++it)
|
||||
it.value().removeAll(dev0);
|
||||
auto it = channels_.makeIterator();
|
||||
while (it.next())
|
||||
it.valueRef().removeAll(dev0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -784,9 +791,10 @@ float PIConnection::senderFrequency(const PIString & name) const {
|
||||
|
||||
|
||||
void PIConnection::removeAllSenders() {
|
||||
piForeachC (SPair & s, senders)
|
||||
if (s.second != 0)
|
||||
delete s.second;
|
||||
for (auto s = senders.constBegin(); s != senders.constEnd(); s++) {
|
||||
if (s.value() != 0)
|
||||
delete s.value();
|
||||
}
|
||||
senders.clear();
|
||||
}
|
||||
|
||||
@@ -802,8 +810,8 @@ void PIConnection::startThreadedRead(const PIString & full_path_name) {
|
||||
|
||||
|
||||
void PIConnection::startAllThreadedReads() {
|
||||
piForeachC (DevicePool::DDPair & d, __device_pool__->devices)
|
||||
startThreadedRead(d.first);
|
||||
for (auto d = __device_pool__->devices.constBegin(); d != __device_pool__->devices.constEnd(); d++)
|
||||
startThreadedRead(d.key());
|
||||
}
|
||||
|
||||
|
||||
@@ -816,10 +824,10 @@ void PIConnection::startSender(const PIString & name) {
|
||||
|
||||
|
||||
void PIConnection::startAllSenders() {
|
||||
piForeachC (SPair & s, senders) {
|
||||
if (s.second == 0) continue;
|
||||
if (!s.second->isRunning() && !__device_pool__->fake)
|
||||
s.second->start(s.second->int_);
|
||||
for (auto s = senders.constBegin(); s != senders.constEnd(); s++) {
|
||||
if (s.value() == 0) continue;
|
||||
if (!s.value()->isRunning() && !__device_pool__->fake)
|
||||
s.value()->start(s.value()->int_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -835,8 +843,8 @@ void PIConnection::stopThreadedRead(const PIString & full_path_name) {
|
||||
|
||||
|
||||
void PIConnection::stopAllThreadedReads() {
|
||||
piForeachC (DevicePool::DDPair & d, __device_pool__->devices)
|
||||
stopThreadedRead(d.first);
|
||||
for (auto d = __device_pool__->devices.constBegin(); d != __device_pool__->devices.constEnd(); d++)
|
||||
stopThreadedRead(d.key());
|
||||
}
|
||||
|
||||
|
||||
@@ -848,10 +856,10 @@ void PIConnection::stopSender(const PIString & name) {
|
||||
|
||||
|
||||
void PIConnection::stopAllSenders() {
|
||||
piForeachC (SPair & s, senders) {
|
||||
if (s.second == 0) continue;
|
||||
if (s.second->isRunning())
|
||||
s.second->stop();
|
||||
for (auto s = senders.constBegin(); s != senders.constEnd(); s++) {
|
||||
if (s.value() == 0) continue;
|
||||
if (s.value()->isRunning())
|
||||
s.value()->stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1012,14 +1020,14 @@ bool PIConnection::DevicePool::removeDevice(PIConnection * parent, const PIStrin
|
||||
|
||||
void PIConnection::DevicePool::unboundConnection(PIConnection * parent) {
|
||||
PIStringList rem;
|
||||
piForeachC (DDPair & i, devices) {
|
||||
if (i.second == 0) {
|
||||
rem << i.first;
|
||||
for (auto i = devices.constBegin(); i != devices.constEnd(); i++) {
|
||||
if (i.value() == 0) {
|
||||
rem << i.key();
|
||||
continue;
|
||||
}
|
||||
i.second->listeners.removeAll(parent);
|
||||
if (i.second->listeners.isEmpty())
|
||||
rem << i.first;
|
||||
i.value()->listeners.removeAll(parent);
|
||||
if (i.value()->listeners.isEmpty())
|
||||
rem << i.key();
|
||||
}
|
||||
piForeachC (PIString & i, rem) {
|
||||
DeviceData * dd = devices.value(i);
|
||||
@@ -1105,9 +1113,9 @@ PIConnection::DevicePool::DeviceData::~DeviceData() {
|
||||
void PIConnection::DevicePool::run() {
|
||||
PIVector<PIConnection * > conns(PIConnection::allConnections());
|
||||
piForeach (PIConnection * c, conns) {
|
||||
piForeachC (PIConnection::DPair & d, c->diags_) {
|
||||
if (d.second == 0) continue;
|
||||
d.second->tick(0, 1);
|
||||
for (auto d = c->diags_.constBegin(); d != c->diags_.constEnd(); d++) {
|
||||
if (d.value() == 0) continue;
|
||||
d.value()->tick(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1236,8 +1244,9 @@ void PIConnection::Sender::tick(void * , int) {
|
||||
void PIConnection::unboundExtractor(PIPacketExtractor * pe) {
|
||||
if (pe == 0) return;
|
||||
channels_.remove(pe);
|
||||
for (PIMap<PIIODevice * , PIVector<PIIODevice * > >::iterator it = channels_.begin(); it != channels_.end(); ++it)
|
||||
it.value().removeAll(pe);
|
||||
auto it = channels_.makeIterator();
|
||||
while (it.next())
|
||||
it.valueRef().removeAll(pe);
|
||||
bounded_extractors.remove(pe);
|
||||
PIVector<PIIODevice * > k = bounded_extractors.keys();
|
||||
piForeach (PIIODevice * i, k) {
|
||||
|
||||
@@ -404,7 +404,7 @@ private:
|
||||
void __DevicePool_threadReadDP(void * ddp);
|
||||
|
||||
|
||||
extern PIConnection::DevicePool * __device_pool__;
|
||||
extern PIP_EXPORT PIConnection::DevicePool * __device_pool__;
|
||||
|
||||
class PIP_EXPORT __DevicePoolContainer__ {
|
||||
public:
|
||||
|
||||
@@ -32,12 +32,13 @@ class PIP_EXPORT PIDiagnostics: public PITimer
|
||||
PIOBJECT_SUBCLASS(PIDiagnostics, PITimer)
|
||||
friend class PIConnection;
|
||||
public:
|
||||
NO_COPY_CLASS(PIDiagnostics)
|
||||
|
||||
//! Constructs an empty diagnostics and if "start_" start it
|
||||
PIDiagnostics(bool start_ = true);
|
||||
|
||||
virtual ~PIDiagnostics();
|
||||
|
||||
|
||||
//! Connection quality
|
||||
enum Quality {
|
||||
Unknown /** Unknown, no one packet received yet */ = 1,
|
||||
@@ -48,7 +49,7 @@ public:
|
||||
};
|
||||
|
||||
//! Information about current diagnostics state
|
||||
struct State {
|
||||
struct PIP_EXPORT State {
|
||||
State();
|
||||
float immediate_freq;
|
||||
float integral_freq;
|
||||
@@ -122,9 +123,7 @@ public:
|
||||
//! \}
|
||||
|
||||
private:
|
||||
NO_COPY_CLASS(PIDiagnostics)
|
||||
|
||||
struct Entry {
|
||||
struct PIP_EXPORT Entry {
|
||||
Entry() {bytes_ok = bytes_fail = 0; cnt_ok = cnt_fail = 0; empty = true;}
|
||||
ullong bytes_ok;
|
||||
ullong bytes_fail;
|
||||
|
||||
@@ -23,9 +23,10 @@
|
||||
#ifndef PIETHUTILBASE_H
|
||||
#define PIETHUTILBASE_H
|
||||
|
||||
#include "pip_io_utils_export.h"
|
||||
#include "pibytearray.h"
|
||||
|
||||
class PIEthUtilBase {
|
||||
class PIP_IO_UTILS_EXPORT PIEthUtilBase {
|
||||
public:
|
||||
PIEthUtilBase();
|
||||
~PIEthUtilBase();
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
PIFileTransfer();
|
||||
~PIFileTransfer();
|
||||
|
||||
enum PIP_EXPORT StepType {pft_None, pft_Description, pft_Data};
|
||||
enum StepType {pft_None, pft_Description, pft_Data};
|
||||
|
||||
struct PIP_EXPORT PFTFileInfo: public PIFile::FileInfo {
|
||||
PFTFileInfo(const PIFile::FileInfo &fi = PIFile::FileInfo()): PIFile::FileInfo(fi) {}
|
||||
|
||||
@@ -23,20 +23,21 @@
|
||||
#ifndef PISTREAMPACKER_H
|
||||
#define PISTREAMPACKER_H
|
||||
|
||||
#include "pip_io_utils_export.h"
|
||||
#include "piobject.h"
|
||||
#include "piethutilbase.h"
|
||||
|
||||
|
||||
class PIIODevice;
|
||||
|
||||
class PIP_EXPORT PIStreamPacker: public PIObject, public PIEthUtilBase {
|
||||
class PIP_IO_UTILS_EXPORT PIStreamPacker: public PIObject, public PIEthUtilBase {
|
||||
PIOBJECT(PIStreamPacker)
|
||||
public:
|
||||
//! Contructs packer and try to assign \"dev\"
|
||||
PIStreamPacker(PIIODevice * dev = 0);
|
||||
|
||||
//! Progress info
|
||||
struct Progress {
|
||||
struct PIP_IO_UTILS_EXPORT Progress {
|
||||
Progress();
|
||||
|
||||
//! Is send/receive in progress
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
/*! \file piluaprogram.h
|
||||
* \brief Lua Program
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
|
||||
Stephan Fomenko
|
||||
PILuaProgram
|
||||
Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -17,35 +20,32 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PICONDITIONLOCK_H
|
||||
#define PICONDITIONLOCK_H
|
||||
#ifndef PILUAPROGRAM_H
|
||||
#define PILUAPROGRAM_H
|
||||
|
||||
#include "pimutex.h"
|
||||
#include "pip_lua_export.h"
|
||||
#include "pip_lua.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Continued
|
||||
*/
|
||||
class PIP_EXPORT PIConditionLock {
|
||||
class PIP_LUA_EXPORT PILuaProgram
|
||||
{
|
||||
public:
|
||||
explicit PIConditionLock();
|
||||
~PIConditionLock();
|
||||
//! Constructs an empty PILuaProgram, initialize Lua context
|
||||
PILuaProgram();
|
||||
|
||||
//! \brief lock
|
||||
void lock();
|
||||
//! Load Lua script from PIString
|
||||
bool load(const PIString & script);
|
||||
|
||||
//! \brief unlock
|
||||
void unlock();
|
||||
//! Execute script
|
||||
bool prepare();
|
||||
|
||||
//! \brief tryLock
|
||||
bool tryLock();
|
||||
//! Get Lua Object or Function
|
||||
luabridge::LuaRef getGlobal(const PIString & name);
|
||||
|
||||
void * handle();
|
||||
//! Return Lua global namespace
|
||||
luabridge::Namespace getGlobalNamespace();
|
||||
|
||||
private:
|
||||
NO_COPY_CLASS(PIConditionLock)
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_LUA_EXPORT)
|
||||
};
|
||||
|
||||
|
||||
#endif // PICONDITIONLOCK_H
|
||||
#endif // PILUAPROGRAM_H
|
||||
58
lib/main/lua/pip_lua.h
Normal file
58
lib/main/lua/pip_lua.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*! \file pip_lua.h
|
||||
* \brief PIP Lua bindings
|
||||
*
|
||||
* This file declare conversions for PIP types via LuaBridge
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIP Lua bindings
|
||||
Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
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/>.
|
||||
*/
|
||||
#ifndef PIP_LUA_H
|
||||
#define PIP_LUA_H
|
||||
|
||||
#include "lua.hpp"
|
||||
#include <LuaBridge/LuaBridge.h>
|
||||
#include "pistring.h"
|
||||
|
||||
namespace luabridge {
|
||||
|
||||
template <>
|
||||
struct Stack <PIString> {
|
||||
static void push (lua_State* L, PIString const& str) {
|
||||
lua_pushstring(L, str.dataUTF8());
|
||||
}
|
||||
|
||||
static PIString get (lua_State* L, int index) {
|
||||
if (lua_type(L, index) == LUA_TSTRING) {
|
||||
const char* str = lua_tostring(L, index);
|
||||
return PIString::fromUTF8(str);
|
||||
}
|
||||
|
||||
lua_pushvalue(L, index);
|
||||
const char* str = lua_tostring(L, -1);
|
||||
PIString string = PIString::fromUTF8(str);
|
||||
lua_pop(L, 1);
|
||||
return string;
|
||||
}
|
||||
|
||||
static bool isInstance (lua_State* L, int index) {
|
||||
return lua_type(L, index) == LUA_TSTRING;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif // PIP_LUA_H
|
||||
@@ -30,12 +30,12 @@ typedef complexd (*FuncFunc)(void * , int, complexd * );
|
||||
|
||||
namespace PIEvaluatorTypes {
|
||||
|
||||
enum PIP_EXPORT eType {etNumber, etOperator, etVariable, etFunction};
|
||||
enum PIP_EXPORT Operation {oNone, oAdd, oSubtract, oMultiply, oDivide, oResidue, oPower,
|
||||
enum eType {etNumber, etOperator, etVariable, etFunction};
|
||||
enum Operation {oNone, oAdd, oSubtract, oMultiply, oDivide, oResidue, oPower,
|
||||
oEqual, oNotEqual, oGreater, oSmaller, oGreaterEqual, oSmallerEqual,
|
||||
oAnd, oOr, oFunction
|
||||
};
|
||||
enum PIP_EXPORT BaseFunctions {bfUnknown, bfSin, bfCos, bfTg, bfCtg,
|
||||
enum BaseFunctions {bfUnknown, bfSin, bfCos, bfTg, bfCtg,
|
||||
bfArcsin, bfArccos, bfArctg, bfArcctg,
|
||||
bfExp, bfRandom, bfRandomn,
|
||||
bfSh, bfCh, bfTh, bfCth,
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#ifndef PIFFT_H
|
||||
#define PIFFT_H
|
||||
|
||||
#include "pip_fftw_export.h"
|
||||
#include "pimathcomplex.h"
|
||||
|
||||
class PIP_EXPORT PIFFT_double
|
||||
@@ -123,7 +124,7 @@ typedef PIFFT_float PIFFTf;
|
||||
|
||||
#ifndef CC_VC
|
||||
|
||||
#define _PIFFTW_H(type) class _PIFFTW_P_##type##_ { \
|
||||
#define _PIFFTW_H(type) class PIP_FFTW_EXPORT _PIFFTW_P_##type##_ { \
|
||||
public: \
|
||||
_PIFFTW_P_##type##_(); \
|
||||
~_PIFFTW_P_##type##_(); \
|
||||
@@ -138,7 +139,7 @@ _PIFFTW_H(double)
|
||||
_PIFFTW_H(ldouble)
|
||||
|
||||
template <typename T>
|
||||
class PIP_EXPORT PIFFTW
|
||||
class PIFFTW
|
||||
{
|
||||
public:
|
||||
explicit PIFFTW() {p = 0; newP(p);}
|
||||
|
||||
@@ -103,21 +103,21 @@ inline float sqr(const float & v) {return v * v;}
|
||||
inline double sqr(const double & v) {return v * v;}
|
||||
inline double sinc(const double & v) {if (v == 0.) return 1.; double t = M_PI * v; return sin(t) / t;}
|
||||
|
||||
double piJ0(const double & v);
|
||||
double piJ1(const double & v);
|
||||
double piJn(int n, const double & v);
|
||||
double piY0(const double & v);
|
||||
double piY1(const double & v);
|
||||
double piYn(int n, const double & v);
|
||||
PIP_EXPORT double piJ0(const double & v);
|
||||
PIP_EXPORT double piJ1(const double & v);
|
||||
PIP_EXPORT double piJn(int n, const double & v);
|
||||
PIP_EXPORT double piY0(const double & v);
|
||||
PIP_EXPORT double piY1(const double & v);
|
||||
PIP_EXPORT double piYn(int n, const double & v);
|
||||
inline double toDb(double val) {return 10. * log10(val);}
|
||||
inline double fromDb(double val) {return pow(10., val / 10.);}
|
||||
inline double toRad(double deg) {return deg * M_PI_180;}
|
||||
inline double toDeg(double rad) {return rad * M_180_PI;}
|
||||
|
||||
// [-1 ; 1]
|
||||
double randomd();
|
||||
PIP_EXPORT double randomd();
|
||||
// [-1 ; 1] normal
|
||||
double randomn(double dv = 0., double sv = 1.);
|
||||
PIP_EXPORT double randomn(double dv = 0., double sv = 1.);
|
||||
|
||||
|
||||
inline PIVector<double> abs(const PIVector<double> & v) {
|
||||
|
||||
@@ -68,15 +68,10 @@ inline complexd sign(const complexd & x) {return complexd(sign(x.real()), sign(x
|
||||
inline complexd round(const complexd & c) {return complexd(piRound<double>(c.real()), piRound<double>(c.imag()));}
|
||||
inline complexd floor(const complexd & c) {return complexd(floor(c.real()), floor(c.imag()));}
|
||||
inline complexd ceil (const complexd & c) {return complexd(ceil(c.real()), ceil(c.imag()));}
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
# define acosc acos
|
||||
# define asinc asin
|
||||
# define atanc atan
|
||||
#else
|
||||
inline complexd atanc(const complexd & c) {return complexd(0., 0.5) * log((complexd_1 - complexd_i * c) / (complexd_1 + complexd_i * c));}
|
||||
inline complexd asinc(const complexd & c) {return -complexd_i * log(complexd_i * c + sqrt(complexd_1 - c * c));}
|
||||
inline complexd acosc(const complexd & c) {return -complexd_i * log(c + complexd_i * sqrt(complexd_1 - c * c));}
|
||||
#endif
|
||||
|
||||
#define acosc acos
|
||||
#define asinc asin
|
||||
#define atanc atan
|
||||
|
||||
#ifdef CC_GCC
|
||||
# if CC_GCC_VERSION <= 0x025F
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
/// Differential evaluations
|
||||
|
||||
struct TransferFunction {
|
||||
struct PIP_EXPORT TransferFunction {
|
||||
PIVector<double> vector_Bm, vector_An;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "pimathmatrix.h"
|
||||
|
||||
class PIQuaternion
|
||||
class PIP_EXPORT PIQuaternion
|
||||
{
|
||||
friend PIQuaternion operator*(const PIQuaternion & q0, const PIQuaternion & q1);
|
||||
friend PIQuaternion operator*(const double & a, const PIQuaternion & q);
|
||||
@@ -57,8 +57,8 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
PIQuaternion operator *(const double & a, const PIQuaternion & q);
|
||||
PIQuaternion operator *(const PIQuaternion & q0, const PIQuaternion & q1);
|
||||
PIP_EXPORT PIQuaternion operator *(const double & a, const PIQuaternion & q);
|
||||
PIP_EXPORT PIQuaternion operator *(const PIQuaternion & q0, const PIQuaternion & q1);
|
||||
inline PIQuaternion operator +(const PIQuaternion & q0, const PIQuaternion & q1) {return PIQuaternion(q0.vector() + q1.vector(), q0.scalar() + q1.scalar());}
|
||||
inline PIQuaternion operator -(const PIQuaternion & q0, const PIQuaternion & q1) {return PIQuaternion(q0.vector() - q1.vector(), q0.scalar() - q1.scalar());}
|
||||
inline PIQuaternion operator -(const PIQuaternion & q0) {return PIQuaternion(-q0.vector(), -q0.scalar());}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "pimathbase.h"
|
||||
|
||||
template <typename T>
|
||||
class PIP_EXPORT PIStatistic {
|
||||
class PIStatistic {
|
||||
public:
|
||||
PIStatistic() {mean = variance = skewness = kurtosis = T();}
|
||||
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
#ifndef PIOPENCL_H
|
||||
#define PIOPENCL_H
|
||||
|
||||
#include "pip_opencl_export.h"
|
||||
#include "pivariant.h"
|
||||
|
||||
|
||||
class PIOpenCL {
|
||||
class PIP_OPENCL_EXPORT PIOpenCL {
|
||||
public:
|
||||
|
||||
struct KernelArg;
|
||||
@@ -69,7 +70,7 @@ public:
|
||||
Double,
|
||||
};
|
||||
|
||||
struct KernelArg {
|
||||
struct PIP_OPENCL_EXPORT KernelArg {
|
||||
KernelArg();
|
||||
AddressQualifier address_qualifier;
|
||||
AccessQualifier access_qualifier;
|
||||
@@ -85,7 +86,7 @@ public:
|
||||
void init(void * _k, uint index);
|
||||
};
|
||||
|
||||
struct Device {
|
||||
struct PIP_OPENCL_EXPORT Device {
|
||||
Device() {id = platform_id = 0; max_compute_units = max_clock_frequency = 0; max_memory_size = 0;}
|
||||
bool isValid() const {return id != 0;}
|
||||
PIString displayText() const {return name.trimmed() + " (" + device_version.trimmed() + ")";}
|
||||
@@ -100,7 +101,7 @@ public:
|
||||
ullong max_memory_size;
|
||||
};
|
||||
|
||||
struct Platform {
|
||||
struct PIP_OPENCL_EXPORT Platform {
|
||||
Platform() {id = 0;}
|
||||
bool isValid() const {return id != 0;}
|
||||
PIString displayText() const {return name.trimmed() + " (" + version.trimmed() + ", " + profile.trimmed() + ")";}
|
||||
@@ -113,7 +114,7 @@ public:
|
||||
PIVector<Device> devices;
|
||||
};
|
||||
|
||||
class Context {
|
||||
class PIP_OPENCL_EXPORT Context {
|
||||
friend class Program;
|
||||
public:
|
||||
~Context();
|
||||
@@ -125,10 +126,10 @@ public:
|
||||
void zero();
|
||||
void deletePrograms();
|
||||
PIVector<Program * > programs_;
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_OPENCL_EXPORT)
|
||||
};
|
||||
|
||||
class Program {
|
||||
class PIP_OPENCL_EXPORT Program {
|
||||
friend class Context;
|
||||
friend class Kernel;
|
||||
public:
|
||||
@@ -143,10 +144,10 @@ public:
|
||||
Context * context_;
|
||||
PIString source_;
|
||||
PIVector<Kernel * > kernels_;
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_OPENCL_EXPORT)
|
||||
};
|
||||
|
||||
class Kernel {
|
||||
class PIP_OPENCL_EXPORT Kernel {
|
||||
friend class Program;
|
||||
public:
|
||||
const PIString & name() const {return name_;}
|
||||
@@ -165,7 +166,7 @@ public:
|
||||
Program * program_;
|
||||
PIString name_;
|
||||
PIVector<KernelArg> args_;
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_OPENCL_EXPORT)
|
||||
};
|
||||
|
||||
static void init();
|
||||
@@ -177,7 +178,7 @@ public:
|
||||
private:
|
||||
static PIString prog_header;
|
||||
PIOpenCL() {;}
|
||||
class Initializer {
|
||||
class PIP_OPENCL_EXPORT Initializer {
|
||||
public:
|
||||
Initializer();
|
||||
static Initializer * instance();
|
||||
|
||||
@@ -20,17 +20,16 @@
|
||||
#ifndef PIPLATFORM_H
|
||||
#define PIPLATFORM_H
|
||||
|
||||
#if (__cplusplus >= 201103L) // стандарт C++ 11 или выше
|
||||
#define PIP_CXX11_SUPPORT
|
||||
#endif
|
||||
#include <pip_export.h>
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
# define WINDOWS
|
||||
# define ARCH_BITS_32
|
||||
#endif
|
||||
#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
|
||||
# define WINDOWS
|
||||
# define ARCH_BITS_64
|
||||
#else
|
||||
# if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
# define WINDOWS
|
||||
# define ARCH_BITS_32
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__QNX__) || defined(__QNXNTO__)
|
||||
# define QNX
|
||||
@@ -93,11 +92,5 @@
|
||||
# define typeof __typeof__
|
||||
#endif
|
||||
|
||||
#if defined(DOXYGEN) || defined(CC_GCC) || defined(PICODE)
|
||||
# undef PIP_EXPORT
|
||||
# define PIP_EXPORT
|
||||
# undef DEPRECATED
|
||||
# define DEPRECATED
|
||||
#endif
|
||||
|
||||
#endif // PIPLATFORM_H
|
||||
|
||||
@@ -36,13 +36,12 @@ PIByteArray PIResources::get(const PIString & name) {
|
||||
|
||||
|
||||
void PIResources::dump() {
|
||||
PIMap<PIString, PIResourcesStorage::Section * > & sm(PIResourcesStorage::instance()->sections);
|
||||
PIMap<PIString, PIResourcesStorage::Section * >::iterator si;
|
||||
for (si = sm.begin(); si != sm.end(); ++si) {
|
||||
auto si = PIResourcesStorage::instance()->sections.makeIterator();
|
||||
while (si.next()) {
|
||||
piCout << "Section [" << si.key() << "]";
|
||||
if (!si.value()) continue;
|
||||
PIMap<PIString, PIByteArray * >::iterator fi;
|
||||
for (fi = si.value()->entries.begin(); fi != si.value()->entries.end(); ++fi) {
|
||||
auto fi = si.value()->entries.makeIterator();
|
||||
while (fi.next()) {
|
||||
PIString s = fi.key() + ": ";
|
||||
s << (fi.value() ? fi.value()->size_s() : 0) << " b";
|
||||
piCout << " " << s;
|
||||
|
||||
@@ -31,8 +31,8 @@ PIResourcesStorage::Section::~Section() {
|
||||
|
||||
|
||||
void PIResourcesStorage::Section::add(const PIResourcesStorage::Section & s) {
|
||||
PIMap<PIString, PIByteArray * >::const_iterator i;
|
||||
for (i = s.entries.begin(); i != s.entries.end(); ++i) {
|
||||
auto i = s.entries.makeIterator();
|
||||
while (i.next()) {
|
||||
if (!i.value()) continue;
|
||||
if (entries.value(i.key(), 0)) continue;
|
||||
entries[i.key()] = i.value();
|
||||
@@ -83,10 +83,10 @@ void PIResourcesStorage::registerSection(const uchar * rc_data, const uchar * rc
|
||||
piForeachC (PIResourcesStorage::__RCEntry & e, el) {
|
||||
ebs[e.section] << e;
|
||||
}
|
||||
PIMap<PIString, PIVector<PIResourcesStorage::__RCEntry> >::iterator it;
|
||||
for (it = ebs.begin(); it != ebs.end(); ++it) {
|
||||
auto it = ebs.makeIterator();
|
||||
while (it.next()) {
|
||||
PIResourcesStorage::Section s;
|
||||
PIVector<PIResourcesStorage::__RCEntry> & itv(it.value());
|
||||
const PIVector<PIResourcesStorage::__RCEntry> & itv(it.value());
|
||||
piForeachC (PIResourcesStorage::__RCEntry & e, itv) {
|
||||
//piCout << "add" << e.name << e.alias << PIString::readableSize(e.size);
|
||||
PIByteArray * eba = new PIByteArray(&(rc_data[e.offset]), e.size);
|
||||
@@ -114,8 +114,8 @@ PIByteArray PIResourcesStorage::get(const PIString & section_name, const PIStrin
|
||||
|
||||
|
||||
PIByteArray PIResourcesStorage::get(const PIString & entry_name) const {
|
||||
PIMap<PIString, Section * >::const_iterator i;
|
||||
for (i = sections.begin(); i != sections.end(); ++i) {
|
||||
auto i = sections.makeIterator();
|
||||
while (i.next()) {
|
||||
if (!i.value()) continue;
|
||||
PIByteArray * ba = i.value()->entries.value(entry_name, 0);
|
||||
if (!ba) continue;
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Text codings coder, based on "iconv"
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PIP_FREERTOS
|
||||
|
||||
#include "picodec.h"
|
||||
|
||||
|
||||
PIStringList PICodec::availableCodecs() {
|
||||
exec("/usr/bin/iconv", "-l");
|
||||
waitForFinish();
|
||||
PIString str(readOutput());
|
||||
str.cutLeft(str.find("\n "));
|
||||
str.replaceAll("\n", "");
|
||||
return str.split("//");
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PICodec::exec_iconv(const PIString & from, const PIString & to, const PIByteArray & str) {
|
||||
tf.openTemporary(PIIODevice::ReadWrite);
|
||||
tf.clear();
|
||||
tf << str;
|
||||
tf.close();
|
||||
exec("/usr/bin/iconv", PIStringList() << ("-f=" + from) << ("-t=" + to) << tf.path());
|
||||
waitForFinish();
|
||||
return readOutput();
|
||||
}
|
||||
|
||||
#endif // PIP_FREERTOS
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Text codings coder, based on "iconv"
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PICODEC_H
|
||||
#define PICODEC_H
|
||||
|
||||
#ifndef PIP_FREERTOS
|
||||
|
||||
#include "piprocess.h"
|
||||
|
||||
class PIP_EXPORT PICodec: protected PIProcess
|
||||
{
|
||||
PIOBJECT(PICodec)
|
||||
public:
|
||||
PICodec(): PIProcess() {setGrabOutput(true);}
|
||||
PICodec(const PIString & from, const PIString & to): PIProcess() {setCodings(from, to);}
|
||||
~PICodec() {tf.remove();}
|
||||
|
||||
void setFromCoding(const PIString & from) {c_from = from;}
|
||||
void setToCoding(const PIString & to) {c_to = to;}
|
||||
void setCodings(const PIString & from, const PIString & to) {c_from = from; c_to = to;}
|
||||
|
||||
PIStringList availableCodecs();
|
||||
PIString encode(PIString & str) {return PIString(exec_iconv(c_from, c_to, str.toByteArray()));}
|
||||
PIString encode(const PIByteArray & str) {return PIString(exec_iconv(c_from, c_to, str));}
|
||||
PIString decode(PIString & str) {return PIString(exec_iconv(c_to, c_from, str.toByteArray()));}
|
||||
PIString decode(const PIByteArray & str) {return PIString(exec_iconv(c_to, c_from, str));}
|
||||
|
||||
private:
|
||||
PIByteArray exec_iconv(const PIString & from, const PIString & to, const PIByteArray & str);
|
||||
|
||||
PIString c_from, c_to;
|
||||
PIFile tf;
|
||||
|
||||
};
|
||||
|
||||
#endif // PIP_FREERTOS
|
||||
#endif // PICODEC_H
|
||||
@@ -42,7 +42,7 @@ private:
|
||||
bool loadInternal();
|
||||
void getLastError();
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
PIString libpath, liberror;
|
||||
|
||||
};
|
||||
|
||||
@@ -93,7 +93,7 @@ private:
|
||||
void exec_();
|
||||
void startProc(bool detached);
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
PIStringList args, env;
|
||||
PIString wd;
|
||||
PIByteArray out;
|
||||
|
||||
@@ -26,7 +26,7 @@ class PIP_EXPORT PISystemInfo {
|
||||
public:
|
||||
PISystemInfo();
|
||||
|
||||
struct MountInfo {
|
||||
struct PIP_EXPORT MountInfo {
|
||||
MountInfo();
|
||||
PIString mount_point;
|
||||
PIString device;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#ifndef PISYSTEMMODULE_H
|
||||
#define PISYSTEMMODULE_H
|
||||
|
||||
#include "picodec.h"
|
||||
#include "pisignals.h"
|
||||
#include "pilibrary.h"
|
||||
#include "pisysteminfo.h"
|
||||
|
||||
@@ -331,9 +331,10 @@ void PISystemMonitor::run() {
|
||||
tstat.cpu_load_system = piClampf(tstat.cpu_load_system, 0.f, 100.f);
|
||||
tstat.cpu_load_user = piClampf(tstat.cpu_load_user , 0.f, 100.f);
|
||||
|
||||
for (PIMap<llong, ThreadStats>::iterator i = cur_tm.begin(); i != cur_tm.end(); ++i) {
|
||||
auto i = cur_tm.makeIterator();
|
||||
while (i.next()) {
|
||||
if (!last_tm.contains(i.key())) continue;
|
||||
ThreadStats & ts_new(i.value());
|
||||
ThreadStats & ts_new(i.valueRef());
|
||||
ThreadStats & ts_old(last_tm[i.key()]);
|
||||
ts_new.cpu_load_kernel = calcThreadUsage(ts_new.kernel_time, ts_old.kernel_time);
|
||||
ts_new.cpu_load_user = calcThreadUsage(ts_new.user_time, ts_old.user_time);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user