04.11.2011 - adjust for Windows & QNX, multiprotocol, repeater, signals, process, codec, console input
This commit is contained in:
25
Makefile_qnx
25
Makefile_qnx
@@ -33,7 +33,11 @@ SOURCES = main.cpp \
|
||||
pistring.cpp \
|
||||
pithread.cpp \
|
||||
pitimer.cpp \
|
||||
pivariable.cpp
|
||||
pivariable.cpp \
|
||||
picli.cpp \
|
||||
piprocess.cpp \
|
||||
picodec.cpp \
|
||||
pisignals.cpp
|
||||
OBJECTS = main.o \
|
||||
pibytearray.o \
|
||||
piconfig.o \
|
||||
@@ -49,7 +53,11 @@ OBJECTS = main.o \
|
||||
pistring.o \
|
||||
pithread.o \
|
||||
pitimer.o \
|
||||
pivariable.o
|
||||
pivariable.o \
|
||||
picli.o \
|
||||
piprocess.o \
|
||||
picodec.o \
|
||||
pisignals.o
|
||||
|
||||
first: all
|
||||
####### Implicit rules
|
||||
@@ -230,6 +238,18 @@ pivariable.o: pivariable.cpp pivariable.h \
|
||||
pichar.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o pivariable.o pivariable.cpp
|
||||
|
||||
picli.o: picli.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o picli.o picli.cpp
|
||||
|
||||
piprocess.o: piprocess.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o piprocess.o piprocess.cpp
|
||||
|
||||
picodec.o: picodec.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o picodec.o picodec.cpp
|
||||
|
||||
pisignals.o: pisignals.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o pisignals.o pisignals.cpp
|
||||
|
||||
####### Install
|
||||
|
||||
install: FORCE
|
||||
@@ -237,4 +257,3 @@ install: FORCE
|
||||
uninstall: FORCE
|
||||
|
||||
FORCE:
|
||||
|
||||
|
||||
104
main.cpp
104
main.cpp
@@ -28,11 +28,107 @@ public:
|
||||
|
||||
};
|
||||
|
||||
PIConsole c(false);
|
||||
//Prot p;
|
||||
|
||||
struct BitsStruct {
|
||||
uchar b1: 1;
|
||||
uchar b2: 2;
|
||||
uchar b4: 4;
|
||||
};
|
||||
|
||||
int i = 1;
|
||||
BitsStruct bits;
|
||||
|
||||
void keyFunc(char key, void * );
|
||||
|
||||
PIConsole c(false, keyFunc);
|
||||
|
||||
void keyFunc(char key, void * ) {
|
||||
switch (key) {
|
||||
case '-': i--; break;
|
||||
case '+': i++; break;
|
||||
case '[': bits.b1--; break;
|
||||
case ']': bits.b1++; break;
|
||||
case ';': bits.b2--; break;
|
||||
case '\'': bits.b2++; break;
|
||||
case ',': bits.b4--; break;
|
||||
case '.': bits.b4++; break;
|
||||
case 'i': i = c.getInt(1, 2); break;
|
||||
}
|
||||
};
|
||||
|
||||
void signalFunc(PISignals::Signal signal) {
|
||||
if (signal == PISignals::Interrupt) cout << "Ctrl+C pressed" << endl;
|
||||
};
|
||||
|
||||
void timerEvent(void*, int delim) {
|
||||
cout << "tick " << delim << endl;
|
||||
};
|
||||
|
||||
PITimer timer(timerEvent);
|
||||
|
||||
void timerEvent2(void*, int delim) {
|
||||
cout << "tick2 " << delim << endl;
|
||||
};
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
MProt mp;
|
||||
/*PICLI cli(argc, argv);
|
||||
cli.addArgument("debug");
|
||||
cli.addArgument("value", "V", "Val", true);
|
||||
if (cli.hasArgument("debug"))
|
||||
cout << "has debug" << endl;
|
||||
if (cli.hasArgument("value"))
|
||||
cout << "value = " << cli.argumentValue("value") << endl;*/
|
||||
/*
|
||||
timer.start(100);
|
||||
timer.addDelimiter(2, timerEvent2);
|
||||
timer.addDelimiter(5, timerEvent2);
|
||||
FOREVER_WAIT
|
||||
*/
|
||||
/*PISignals::setSlot(signalFunc);
|
||||
PISignals::grabSignals(PISignals::Interrupt);
|
||||
FOREVER_WAIT*/
|
||||
|
||||
/*PIString ip;
|
||||
int port;
|
||||
PIConfig conf("protocols.conf~");
|
||||
ip = conf.getValue("mcp1.receiver.ip");
|
||||
port = conf.getValue("mcp1.receiver.port");
|
||||
cout << ip << ":" << port << endl;*/
|
||||
|
||||
c.addString("PIConsole example");
|
||||
c.addEmptyLine();
|
||||
|
||||
c.addTab("colors", '1');
|
||||
c.addString("Red string", 1, PIConsole::Red);
|
||||
c.addString("Blue on yellow", 1, PIConsole::Blue | PIConsole::BackYellow);
|
||||
c.addEmptyLine();
|
||||
|
||||
c.addTab("columns", '2');
|
||||
c.addString("column 1", 1, PIConsole::BackYellow);
|
||||
c.addString("column 2", 2, PIConsole::BackCyan);
|
||||
c.addString("column 3", 3, PIConsole::BackMagenta);
|
||||
c.addEmptyLine();
|
||||
|
||||
c.addTab("bits", '3');
|
||||
c.addBitVariable("b1", &bits, 0, 1);
|
||||
c.addBitVariable("b2", &bits, 1, 2);
|
||||
c.addBitVariable("b4", &bits, 3, 4);
|
||||
c.addCustomStatus("[] - -/+ b1, ;\' - -/+ b2, ,. - -/+ b4");
|
||||
c.addEmptyLine();
|
||||
|
||||
c.addTab("formats", '4');
|
||||
c.addVariable("our int", &i);
|
||||
c.addVariable("dec", &i);
|
||||
c.addVariable("oct", &i, 1, PIConsole::Oct);
|
||||
c.addVariable("hex", &i, 1, PIConsole::Hex);
|
||||
c.addCustomStatus("-+ - -/+ number");
|
||||
c.addEmptyLine();
|
||||
|
||||
c.setTab(0);
|
||||
c.enableExitCapture();
|
||||
c.start(true);
|
||||
|
||||
/*MProt mp;
|
||||
Prot p;
|
||||
PIRepeater r("protocols.conf", "r", 1024);
|
||||
mp.addProtocol(p);
|
||||
@@ -49,6 +145,6 @@ int main(int argc, char * argv[]) {
|
||||
c.addVariable(r.secondChannelName() + ", send", r.sendCount_ptr());
|
||||
c.enableExitCapture();
|
||||
mp.start();
|
||||
c.start(false);
|
||||
c.start(false);*/
|
||||
c.waitForFinish();
|
||||
};
|
||||
|
||||
80
pibitarray.h
80
pibitarray.h
@@ -5,26 +5,26 @@
|
||||
|
||||
class PIBitArray {
|
||||
public:
|
||||
inline PIBitArray(const int & size = 0) {resize(size);}
|
||||
inline PIBitArray(uchar val) {resize(sizeof(val) * 8); data_[0] = val;}
|
||||
inline PIBitArray(ushort val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
inline PIBitArray(uint val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
inline PIBitArray(ulong val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
inline PIBitArray(ullong val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
inline PIBitArray(uchar * bytes, uint size) {resize(size * 8); memcpy(data(), bytes, size);}
|
||||
PIBitArray(const int & size = 0) {resize(size);}
|
||||
PIBitArray(uchar val) {resize(sizeof(val) * 8); data_[0] = val;}
|
||||
PIBitArray(ushort val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
PIBitArray(uint val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
PIBitArray(ulong val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
PIBitArray(ullong val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
PIBitArray(uchar * bytes, uint size) {resize(size * 8); memcpy(data(), bytes, size);}
|
||||
|
||||
inline uint bitSize() const {return size_;}
|
||||
inline uint byteSize() const {return bytesInBits(size_);}
|
||||
inline PIBitArray & resize(const uint & size) {size_ = size; data_.resize(bytesInBits(size_)); return *this;}
|
||||
uint bitSize() const {return size_;}
|
||||
uint byteSize() const {return bytesInBits(size_);}
|
||||
PIBitArray & resize(const uint & size) {size_ = size; data_.resize(bytesInBits(size_)); return *this;}
|
||||
|
||||
inline PIBitArray & clearBit(const uint & index) {data_[index / 8] &= ~(1 << (index % 8)); return *this;}
|
||||
inline PIBitArray & setBit(const uint & index) {data_[index / 8] |= (1 << (index % 8)); return *this;}
|
||||
inline PIBitArray & writeBit(const uint & index, const bool & value) {if (value) setBit(index); else clearBit(index); return *this;}
|
||||
inline PIBitArray & writeBit(const uint & index, const uchar & value) {return writeBit(index, static_cast<bool>(value));}
|
||||
PIBitArray & clearBit(const uint & index) {data_[index / 8] &= ~(1 << (index % 8)); return *this;}
|
||||
PIBitArray & setBit(const uint & index) {data_[index / 8] |= (1 << (index % 8)); return *this;}
|
||||
PIBitArray & writeBit(const uint & index, const bool & value) {if (value) setBit(index); else clearBit(index); return *this;}
|
||||
PIBitArray & writeBit(const uint & index, const uchar & value) {return writeBit(index, value > 0);}
|
||||
|
||||
inline PIBitArray & push_back(const bool & value) {resize(size_ + 1); writeBit(size_ - 1, value); return *this;}
|
||||
inline PIBitArray & push_back(const uchar & value) {return push_back(static_cast<bool>(value));}
|
||||
inline PIBitArray & insert(const uint & index, const bool & value) {
|
||||
PIBitArray & push_back(const bool & value) {resize(size_ + 1); writeBit(size_ - 1, value); return *this;}
|
||||
PIBitArray & push_back(const uchar & value) {return push_back(value > 0);}
|
||||
PIBitArray & insert(const uint & index, const bool & value) {
|
||||
resize(size_ + 1);
|
||||
uint fi = byteSize() - 1, si = index / 8, ti = index % 8;
|
||||
uchar c = data_[si];
|
||||
@@ -37,11 +37,11 @@ public:
|
||||
if (value) data_[si] |= (1 << ti);
|
||||
else data_[si] &= ~(1 << ti);
|
||||
return *this;}
|
||||
inline PIBitArray & insert(const uint & index, const uchar & value) {return push_back(static_cast<bool>(value));}
|
||||
inline PIBitArray & push_front(const bool & value) {return insert(0, value);}
|
||||
inline PIBitArray & push_front(const uchar & value) {return push_front(static_cast<bool>(value));}
|
||||
inline PIBitArray & pop_back() {return resize(size_ - 1);}
|
||||
inline PIBitArray & pop_front() {
|
||||
PIBitArray & insert(const uint & index, const uchar & value) {return push_back(value > 0);}
|
||||
PIBitArray & push_front(const bool & value) {return insert(0, value);}
|
||||
PIBitArray & push_front(const uchar & value) {return push_front(value > 0);}
|
||||
PIBitArray & pop_back() {return resize(size_ - 1);}
|
||||
PIBitArray & pop_front() {
|
||||
if (size_ == 0) return *this;
|
||||
uint fi = byteSize() - 1;
|
||||
for (uint i = 0; i < fi; ++i) {
|
||||
@@ -51,28 +51,28 @@ public:
|
||||
data_[fi] >>= 1;
|
||||
resize(size_ - 1);
|
||||
return *this;}
|
||||
inline PIBitArray & append(const PIBitArray & ba) {for (uint i = 0; i < ba.bitSize(); ++i) push_back(ba[i]); return *this;}
|
||||
PIBitArray & append(const PIBitArray & ba) {for (uint i = 0; i < ba.bitSize(); ++i) push_back(ba[i]); return *this;}
|
||||
|
||||
inline uchar * data() {return data_.data();}
|
||||
inline uchar toUChar() {if (size_ == 0) return 0; return data_[0];}
|
||||
inline ushort toUShort() {ushort t = 0; memcpy(&t, data(), piMin<uint>(byteSize(), sizeof(t))); return t;}
|
||||
inline uint toUInt() {uint t = 0; memcpy(&t, data(), piMin<uint>(byteSize(), sizeof(t))); return t;}
|
||||
inline ulong toULong() {ulong t = 0; memcpy(&t, data(), piMin<uint>(byteSize(), sizeof(t))); return t;}
|
||||
inline ullong toULLong() {ullong t = 0; memcpy(&t, data(), piMin<uint>(byteSize(), sizeof(t))); return t;}
|
||||
uchar * data() {return data_.data();}
|
||||
uchar toUChar() {if (size_ == 0) return 0; return data_[0];}
|
||||
ushort toUShort() {ushort t = 0; memcpy(&t, data(), piMin<uint>(byteSize(), sizeof(t))); return t;}
|
||||
uint toUInt() {uint t = 0; memcpy(&t, data(), piMin<uint>(byteSize(), sizeof(t))); return t;}
|
||||
ulong toULong() {ulong t = 0; memcpy(&t, data(), piMin<uint>(byteSize(), sizeof(t))); return t;}
|
||||
ullong toULLong() {ullong t = 0; memcpy(&t, data(), piMin<uint>(byteSize(), sizeof(t))); return t;}
|
||||
|
||||
inline bool at(const uint & index) const {return (1 & (data_[index / 8] >> (index % 8))) == 1 ? true : false;}
|
||||
inline bool operator [](const uint & index) const {return at(index);}
|
||||
inline void operator +=(const PIBitArray & ba) {append(ba);}
|
||||
inline bool operator ==(const PIBitArray & ba) const {if (bitSize() != ba.bitSize()) return false; for (uint i = 0; i < bitSize(); ++i) if (at(i) != ba[i]) return false; return true;}
|
||||
inline bool operator !=(const PIBitArray & ba) const {return !(*this == ba);}
|
||||
inline void operator =(const uchar & val) {resize(sizeof(val) * 8); data_[0] = val;}
|
||||
inline void operator =(const ushort & val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
inline void operator =(const uint & val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
inline void operator =(const ulong & val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
inline void operator =(const ullong & val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
bool at(const uint & index) const {return (1 & (data_[index / 8] >> (index % 8))) == 1 ? true : false;}
|
||||
bool operator [](const uint & index) const {return at(index);}
|
||||
void operator +=(const PIBitArray & ba) {append(ba);}
|
||||
bool operator ==(const PIBitArray & ba) const {if (bitSize() != ba.bitSize()) return false; for (uint i = 0; i < bitSize(); ++i) if (at(i) != ba[i]) return false; return true;}
|
||||
bool operator !=(const PIBitArray & ba) const {return !(*this == ba);}
|
||||
void operator =(const uchar & val) {resize(sizeof(val) * 8); data_[0] = val;}
|
||||
void operator =(const ushort & val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
void operator =(const uint & val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
void operator =(const ulong & val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
void operator =(const ullong & val) {resize(sizeof(val) * 8); memcpy(data(), &val, sizeof(val));}
|
||||
|
||||
private:
|
||||
inline uint bytesInBits(const uint & bits) const {return (bits + 7) / 8;}
|
||||
uint bytesInBits(const uint & bits) const {return (bits + 7) / 8;}
|
||||
|
||||
PIVector<uchar> data_;
|
||||
uint size_;
|
||||
|
||||
@@ -82,14 +82,14 @@ public:
|
||||
PIByteArray & convertFromBase64();
|
||||
PIByteArray & compressRLE(uchar threshold = 192);
|
||||
PIByteArray & decompressRLE(uchar threshold = 192);
|
||||
inline PIByteArray & compressHuffman() {*this = huffman.compress(*this); return *this;}
|
||||
PIByteArray & compressHuffman() {*this = huffman.compress(*this); return *this;}
|
||||
|
||||
inline PIByteArray toBase64() {PIByteArray ba(*this); ba.convertToBase64(); return ba;}
|
||||
inline PIByteArray fromBase64() {PIByteArray ba(*this); ba.convertFromBase64(); return ba;}
|
||||
inline PIByteArray compressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.compressedRLE(threshold); return ba;}
|
||||
inline PIByteArray decompressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.decompressedRLE(threshold); return ba;}
|
||||
PIByteArray toBase64() {PIByteArray ba(*this); ba.convertToBase64(); return ba;}
|
||||
PIByteArray fromBase64() {PIByteArray ba(*this); ba.convertFromBase64(); return ba;}
|
||||
PIByteArray compressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.compressedRLE(threshold); return ba;}
|
||||
PIByteArray decompressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.decompressedRLE(threshold); return ba;}
|
||||
|
||||
inline void operator =(const PIVector<uchar> & d) {resize(d.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = d[i];}
|
||||
void operator =(const PIVector<uchar> & d) {resize(d.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = d[i];}
|
||||
|
||||
private:
|
||||
union base64HelpStruct {
|
||||
|
||||
50
pichar.h
50
pichar.h
@@ -18,14 +18,14 @@ public:
|
||||
//inline operator const int() {return static_cast<const int>(ch);}
|
||||
//inline operator const char() {return toAscii();}
|
||||
|
||||
inline PIChar & operator =(const char v) {ch = v; return *this;}
|
||||
PIChar & operator =(const char v) {ch = v; return *this;}
|
||||
/*inline PIChar & operator =(const short v) {ch = v; return *this;}
|
||||
inline PIChar & operator =(const int v) {ch = v; return *this;}
|
||||
inline PIChar & operator =(const uchar v) {ch = v; return *this;}
|
||||
inline PIChar & operator =(const ushort v) {ch = v; return *this;}
|
||||
inline PIChar & operator =(const uint v) {ch = v; return *this;}*/
|
||||
|
||||
inline bool operator ==(const PIChar & o) const {return strcmp(o.toCharPtr(), toCharPtr()) == 0;}
|
||||
bool operator ==(const PIChar & o) const {return strcmp(o.toCharPtr(), toCharPtr()) == 0;}
|
||||
/*inline bool operator ==(const PIChar & o) const {if (o.isAscii() ^ isAscii()) return false;
|
||||
if (isAscii()) return (o.toAscii() == toAscii());
|
||||
return (o.toInt() == toInt());}
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
inline bool operator ==(const ushort o) const {return (PIChar(o) == *this);}
|
||||
inline bool operator ==(const uint o) const {return (PIChar(o) == *this);}*/
|
||||
|
||||
inline bool operator !=(const PIChar & o) const {return !(o == *this);}
|
||||
bool operator !=(const PIChar & o) const {return !(o == *this);}
|
||||
/*inline bool operator !=(const char o) const {return (PIChar(o) != *this);}
|
||||
inline bool operator !=(const short o) const {return (PIChar(o) != *this);}
|
||||
inline bool operator !=(const int o) const {return (PIChar(o) != *this);}
|
||||
@@ -44,34 +44,34 @@ public:
|
||||
inline bool operator !=(const ushort o) const {return (PIChar(o) != *this);}
|
||||
inline bool operator !=(const uint o) const {return (PIChar(o) != *this);}*/
|
||||
|
||||
inline bool operator >(const PIChar & o) const {return strcmp(o.toCharPtr(), toCharPtr()) < 0;}
|
||||
inline bool operator <(const PIChar & o) const {return strcmp(o.toCharPtr(), toCharPtr()) > 0;}
|
||||
inline bool operator >=(const PIChar & o) const {return strcmp(o.toCharPtr(), toCharPtr()) <= 0;}
|
||||
inline bool operator <=(const PIChar & o) const {return strcmp(o.toCharPtr(), toCharPtr()) >= 0;}
|
||||
bool operator >(const PIChar & o) const {return strcmp(o.toCharPtr(), toCharPtr()) < 0;}
|
||||
bool operator <(const PIChar & o) const {return strcmp(o.toCharPtr(), toCharPtr()) > 0;}
|
||||
bool operator >=(const PIChar & o) const {return strcmp(o.toCharPtr(), toCharPtr()) <= 0;}
|
||||
bool operator <=(const PIChar & o) const {return strcmp(o.toCharPtr(), toCharPtr()) >= 0;}
|
||||
|
||||
inline bool isDigit() const {return isdigit(ch);}
|
||||
inline bool isHex() const {return isxdigit(ch);}
|
||||
inline bool isGraphical() const {return isgraph(ch);}
|
||||
inline bool isControl() const {return iscntrl(ch);}
|
||||
inline bool isLower() const {return islower(ch);}
|
||||
inline bool isUpper() const {return isupper(ch);}
|
||||
inline bool isPrint() const {return isprint(ch);}
|
||||
inline bool isSpace() const {return isspace(ch);}
|
||||
inline bool isAlpha() const {return isalpha(ch);}
|
||||
inline bool isAscii() const {return isascii(ch);}
|
||||
bool isDigit() const {return isdigit(ch) != 0;}
|
||||
bool isHex() const {return isxdigit(ch) != 0;}
|
||||
bool isGraphical() const {return isgraph(ch) != 0;}
|
||||
bool isControl() const {return iscntrl(ch) != 0;}
|
||||
bool isLower() const {return islower(ch) != 0;}
|
||||
bool isUpper() const {return isupper(ch) != 0;}
|
||||
bool isPrint() const {return isprint(ch) != 0;}
|
||||
bool isSpace() const {return isspace(ch) != 0;}
|
||||
bool isAlpha() const {return isalpha(ch) != 0;}
|
||||
bool isAscii() const {return isascii(ch) != 0;}
|
||||
|
||||
inline int toInt() const {return static_cast<const int>(ch);}
|
||||
inline const wchar_t * toWCharPtr() const {return &ch;}
|
||||
inline const char * toCharPtr() const {return reinterpret_cast<const char * >(&ch);}
|
||||
inline const wchar_t toWChar() const {return ch;}
|
||||
inline char toAscii() const {return ch % 256;}
|
||||
inline int unicode16Code() const {wchar_t wc; if (mbtowc(&wc, toCharPtr(), 4) > 0) return wc; return 0;}
|
||||
int toInt() const {return static_cast<const int>(ch);}
|
||||
const wchar_t * toWCharPtr() const {return &ch;}
|
||||
const char * toCharPtr() const {return reinterpret_cast<const char * >(&ch);}
|
||||
const wchar_t toWChar() const {return ch;}
|
||||
char toAscii() const {return ch % 256;}
|
||||
int unicode16Code() const {wchar_t wc; if (mbtowc(&wc, toCharPtr(), 4) > 0) return wc; return 0;}
|
||||
//#ifdef WINDOWS
|
||||
// inline PIChar toUpper() const __attribute__ ((optimize(0))) {return PIChar(toupper(ch));}
|
||||
// inline PIChar toLower() const __attribute__ ((optimize(0))) {return PIChar(tolower(ch));}
|
||||
//#else
|
||||
inline PIChar toUpper() const {return PIChar(toupper(ch));}
|
||||
inline PIChar toLower() const {return PIChar(tolower(ch));}
|
||||
PIChar toUpper() const {return PIChar(toupper(ch));}
|
||||
PIChar toLower() const {return PIChar(tolower(ch));}
|
||||
//#endif
|
||||
|
||||
private:
|
||||
|
||||
48
picli.h
48
picli.h
@@ -8,32 +8,32 @@ class PICLI
|
||||
public:
|
||||
PICLI(int argc, char * argv[]);
|
||||
|
||||
inline void addArgument(const PIString & name, bool value = false) {_args << Argument(name, name[0], name, value); needParse = true;}
|
||||
inline void addArgument(const PIString & name, const PIChar & shortKey, bool value = false) {_args << Argument(name, shortKey, name, value); needParse = true;}
|
||||
inline void addArgument(const PIString & name, const char * shortKey, bool value = false) {_args << Argument(name, PIChar(shortKey), name, value); needParse = true;}
|
||||
inline void addArgument(const PIString & name, const PIChar & shortKey, const PIString & fullKey, bool value = false) {_args << Argument(name, shortKey, fullKey, value); needParse = true;}
|
||||
inline void addArgument(const PIString & name, const char * shortKey, const PIString & fullKey, bool value = false) {_args << Argument(name, PIChar(shortKey), fullKey, value); needParse = true;}
|
||||
void addArgument(const PIString & name, bool value = false) {_args << Argument(name, name[0], name, value); needParse = true;}
|
||||
void addArgument(const PIString & name, const PIChar & shortKey, bool value = false) {_args << Argument(name, shortKey, name, value); needParse = true;}
|
||||
void addArgument(const PIString & name, const char * shortKey, bool value = false) {_args << Argument(name, PIChar(shortKey), name, value); needParse = true;}
|
||||
void addArgument(const PIString & name, const PIChar & shortKey, const PIString & fullKey, bool value = false) {_args << Argument(name, shortKey, fullKey, value); needParse = true;}
|
||||
void addArgument(const PIString & name, const char * shortKey, const PIString & fullKey, bool value = false) {_args << Argument(name, PIChar(shortKey), fullKey, value); needParse = true;}
|
||||
|
||||
inline PIString rawArgument(int index) {return _args_raw[index];}
|
||||
inline PIString mandatoryArgument(int index) {return _args_mand[index];}
|
||||
inline PIString optionalArgument(int index) {return _args_opt[index];}
|
||||
inline const PIStringList & rawArguments() const {return _args_raw;}
|
||||
inline const PIStringList & mandatoryArguments() const {return _args_mand;}
|
||||
inline const PIStringList & optionalArguments() const {return _args_opt;}
|
||||
inline const PIString programCommand() const {return _args_raw.size() > 0 ? _args_raw.front() : PIString();}
|
||||
inline bool hasArgument(const PIString & name) {parse(); piForeach (Argument & i, _args) if (i.name == name && i.found) return true; return false;}
|
||||
inline PIString argumentValue(const PIString & name) {parse(); piForeach (Argument &i, _args) if (i.name == name && i.found) return i.value; return PIString();}
|
||||
inline PIString argumentShortKey(const PIString & name) {piForeach (Argument &i, _args) if (i.name == name) return i.short_key; return PIString();}
|
||||
inline PIString argumentFullKey(const PIString & name) {piForeach (Argument &i, _args) if (i.name == name) return i.full_key; return PIString();}
|
||||
PIString rawArgument(int index) {return _args_raw[index];}
|
||||
PIString mandatoryArgument(int index) {return _args_mand[index];}
|
||||
PIString optionalArgument(int index) {return _args_opt[index];}
|
||||
const PIStringList & rawArguments() const {return _args_raw;}
|
||||
const PIStringList & mandatoryArguments() const {return _args_mand;}
|
||||
const PIStringList & optionalArguments() const {return _args_opt;}
|
||||
const PIString programCommand() const {return _args_raw.size() > 0 ? _args_raw.front() : PIString();}
|
||||
bool hasArgument(const PIString & name) {parse(); piForeach (Argument & i, _args) if (i.name == name && i.found) return true; return false;}
|
||||
PIString argumentValue(const PIString & name) {parse(); piForeach (Argument &i, _args) if (i.name == name && i.found) return i.value; return PIString();}
|
||||
PIString argumentShortKey(const PIString & name) {piForeach (Argument &i, _args) if (i.name == name) return i.short_key; return PIString();}
|
||||
PIString argumentFullKey(const PIString & name) {piForeach (Argument &i, _args) if (i.name == name) return i.full_key; return PIString();}
|
||||
|
||||
inline const PIString & shortKeyPrefix() const {return _prefix_short;}
|
||||
inline const PIString & fullKeyPrefix() const {return _prefix_full;}
|
||||
inline const int mandatoryArgumentsCount() const {return _count_mand;}
|
||||
inline const int optionalArgumentsCount() const {return _count_opt;}
|
||||
inline void setShortKeyPrefix(const PIString & prefix) {_prefix_short = prefix;}
|
||||
inline void setFullKeyPrefix(const PIString & prefix) {_prefix_full = prefix;}
|
||||
inline void setMandatoryArgumentsCount(const int count) {_count_mand = count;}
|
||||
inline void setOptionalArgumentsCount(const int count) {_count_opt = count;}
|
||||
const PIString & shortKeyPrefix() const {return _prefix_short;}
|
||||
const PIString & fullKeyPrefix() const {return _prefix_full;}
|
||||
const int mandatoryArgumentsCount() const {return _count_mand;}
|
||||
const int optionalArgumentsCount() const {return _count_opt;}
|
||||
void setShortKeyPrefix(const PIString & prefix) {_prefix_short = prefix;}
|
||||
void setFullKeyPrefix(const PIString & prefix) {_prefix_full = prefix;}
|
||||
void setMandatoryArgumentsCount(const int count) {_count_mand = count;}
|
||||
void setOptionalArgumentsCount(const int count) {_count_opt = count;}
|
||||
|
||||
private:
|
||||
struct Argument {
|
||||
|
||||
@@ -332,6 +332,7 @@ void PIConfig::removeEntry(uint number, bool write) {
|
||||
|
||||
void PIConfig::removeEntry(Branch & b, PIConfig::Entry * e) {
|
||||
bool leaf = true;
|
||||
if (e->isLeaf()) other.remove(e->_line);
|
||||
if (!e->isLeaf() && !e->_value.isEmpty()) {
|
||||
e->_value.clear();
|
||||
leaf = false;
|
||||
@@ -351,7 +352,6 @@ void PIConfig::removeEntry(Branch & b, PIConfig::Entry * e) {
|
||||
if (!leaf) return;
|
||||
e->_parent->_children.remove(e);
|
||||
b.remove(e);
|
||||
other.remove(e->_line);
|
||||
delete e;
|
||||
}
|
||||
|
||||
|
||||
@@ -156,6 +156,8 @@ PIString PIConsole::fstr(PIFlags<PIConsole::Format> f) {
|
||||
if (f[PIConsole::BackMagenta]) attr |= (FOREGROUND_RED | FOREGROUND_BLUE);
|
||||
if (f[PIConsole::BackCyan]) attr |= (FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
if (f[PIConsole::BackWhite]) attr |= (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
if ((attr & BACKGROUND_RED) + (attr & BACKGROUND_GREEN) + (attr & BACKGROUND_BLUE) == 0)
|
||||
attr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
} else {
|
||||
if (f[PIConsole::Red]) attr |= FOREGROUND_RED;
|
||||
if (f[PIConsole::Green]) attr |= FOREGROUND_GREEN;
|
||||
@@ -171,6 +173,8 @@ PIString PIConsole::fstr(PIFlags<PIConsole::Format> f) {
|
||||
if (f[PIConsole::BackMagenta]) attr |= (BACKGROUND_RED | BACKGROUND_BLUE);
|
||||
if (f[PIConsole::BackCyan]) attr |= (BACKGROUND_GREEN | BACKGROUND_BLUE);
|
||||
if (f[PIConsole::BackWhite]) attr |= (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
|
||||
if ((attr & FOREGROUND_RED) + (attr & FOREGROUND_GREEN) + (attr & FOREGROUND_BLUE) == 0)
|
||||
attr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
}
|
||||
if (f[PIConsole::Bold]) attr |= FOREGROUND_INTENSITY;
|
||||
|
||||
@@ -279,7 +283,7 @@ void PIConsole::run() {
|
||||
}
|
||||
moveRight(tv.offset);
|
||||
switch (tv.type) {
|
||||
case 0: clen = printValue(tv.s != 0 ? *tv.s : "", tv.format); break;
|
||||
case 0: clen = printValue(tv.s != 0 ? *tv.s : PIString(), tv.format); break;
|
||||
case 1: clen = printValue(tv.b != 0 ? *tv.b : false, tv.format); break;
|
||||
case 2: clen = printValue(tv.i != 0 ? *tv.i : 0, tv.format); break;
|
||||
case 3: clen = printValue(tv.l != 0 ? *tv.l : 0l, tv.format); break;
|
||||
@@ -296,7 +300,11 @@ void PIConsole::run() {
|
||||
case 14: clen = printValue(bitsValue(tv.ptr, tv.bitFrom, tv.bitCount), tv.format); break;
|
||||
}
|
||||
if (clen + tv.offset < (uint)col_wid) {
|
||||
#ifdef QNX
|
||||
string ts = PIString(col_wid - clen - tv.offset - 1, ' ').stdString();
|
||||
#else
|
||||
string ts = PIString(col_wid - clen - tv.offset, ' ').stdString();
|
||||
#endif
|
||||
printf("%s", ts.c_str());
|
||||
}
|
||||
newLine();
|
||||
@@ -444,10 +452,19 @@ PIString PIConsole::getString(int x, int y) {
|
||||
bool run = isRunning();
|
||||
if (run) PIThread::stop(true);
|
||||
listener->setActive(false);
|
||||
msleep(50);
|
||||
#ifdef WINDOWS
|
||||
moveTo(x - 1, y - 1);
|
||||
#else
|
||||
moveTo(x, y);
|
||||
#endif
|
||||
showCursor();
|
||||
PIByteArray ba(4096);
|
||||
#ifdef CC_VC
|
||||
int ret = scanf_s(" %s", ba.data());
|
||||
#else
|
||||
int ret = scanf(" %s", ba.data());
|
||||
#endif
|
||||
listener->setActive(true);
|
||||
if (run) start();
|
||||
if (ret >= 1) return PIString(ba);
|
||||
|
||||
228
picontainers.h
228
picontainers.h
@@ -63,27 +63,27 @@ struct _PIForeachBase {mutable bool _break;};
|
||||
template<typename Type>
|
||||
class _PIForeach: public _PIForeachBase {
|
||||
public:
|
||||
inline _PIForeach(Type & t, bool i = false): _t(t), _inv(i) {if (_inv) _rit = _t.rbegin(); else _it = _t.begin(); _break = false;}
|
||||
_PIForeach(Type & t, bool i = false): _t(t), _inv(i) {if (_inv) _rit = _t.rbegin(); else _it = _t.begin(); _break = false;}
|
||||
mutable typename Type::value_type _var;
|
||||
mutable typename Type::iterator _it;
|
||||
mutable typename Type::reverse_iterator _rit;
|
||||
Type & _t;
|
||||
bool _inv;
|
||||
inline bool isEnd() {if (_inv) return _rit == _t.rend(); else return _it == _t.end();}
|
||||
inline void operator ++() {if (_inv) _rit++; else _it++; _break = false;}
|
||||
bool isEnd() {if (_inv) return _rit == _t.rend(); else return _it == _t.end();}
|
||||
void operator ++() {if (_inv) _rit++; else _it++; _break = false;}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class _PIForeachC: public _PIForeachBase {
|
||||
public:
|
||||
inline _PIForeachC(const Type & t, bool i = false): _t(t), _inv(i) {if (_inv) _rit = _t.rbegin(); else _it = _t.begin(); _break = false;}
|
||||
_PIForeachC(const Type & t, bool i = false): _t(t), _inv(i) {if (_inv) _rit = _t.rbegin(); else _it = _t.begin(); _break = false;}
|
||||
mutable typename Type::value_type _var;
|
||||
mutable typename Type::const_iterator _it;
|
||||
mutable typename Type::const_reverse_iterator _rit;
|
||||
const Type & _t;
|
||||
bool _inv;
|
||||
inline bool isEnd() {if (_inv) return _rit == _t.rend(); else return _it == _t.end();}
|
||||
inline void operator ++() {if (_inv) _rit++; else _it++; _break = false;}
|
||||
bool isEnd() {if (_inv) return _rit == _t.rend(); else return _it == _t.end();}
|
||||
void operator ++() {if (_inv) _rit++; else _it++; _break = false;}
|
||||
};
|
||||
|
||||
template <typename T> inline _PIForeach<T> _PIForeachNew(T & t, bool i = false) {return _PIForeach<T>(t, i);}
|
||||
@@ -110,27 +110,27 @@ template <typename T> inline _PIForeachC<T> * _PIForeachCastC(_PIForeachBase & c
|
||||
template<typename Enum>
|
||||
class PIFlags {
|
||||
public:
|
||||
inline PIFlags(): flags(0) {;}
|
||||
inline PIFlags(Enum e): flags(e) {;}
|
||||
inline PIFlags(const PIFlags & f): flags(f.flags) {;}
|
||||
inline PIFlags(const int i): flags(i) {;}
|
||||
inline void operator =(const PIFlags & f) {flags = f.flags;}
|
||||
inline void operator =(const Enum & e) {flags = e;}
|
||||
inline void operator =(const int & i) {flags = i;}
|
||||
inline void operator |=(const PIFlags & f) {flags = flags | f.flags;}
|
||||
inline void operator |=(const Enum & e) {flags = flags | e;}
|
||||
inline void operator |=(const int i) {flags = flags | i;}
|
||||
inline void operator &=(const PIFlags & f) {flags = flags & f.flags;}
|
||||
inline void operator &=(const Enum & e) {flags = flags & e;}
|
||||
inline void operator &=(const int i) {flags = flags & i;}
|
||||
inline PIFlags & operator |(PIFlags f) const {PIFlags tf(flags | f.flags); return tf;}
|
||||
inline PIFlags & operator |(Enum e) const {PIFlags tf(flags | e); return tf;}
|
||||
inline PIFlags & operator |(int i) const {PIFlags tf(flags | i); return tf;}
|
||||
inline PIFlags & operator &(PIFlags f) const {PIFlags tf(flags & f.flags); return tf;}
|
||||
inline PIFlags & operator &(Enum e) const {PIFlags tf(flags & e); return tf;}
|
||||
inline PIFlags & operator &(int i) const {PIFlags tf(flags & i); return tf;}
|
||||
inline bool operator [](Enum e) {return (flags & e) == e;}
|
||||
inline operator int() const {return flags;}
|
||||
PIFlags(): flags(0) {;}
|
||||
PIFlags(Enum e): flags(e) {;}
|
||||
PIFlags(const PIFlags & f): flags(f.flags) {;}
|
||||
PIFlags(const int i): flags(i) {;}
|
||||
void operator =(const PIFlags & f) {flags = f.flags;}
|
||||
void operator =(const Enum & e) {flags = e;}
|
||||
void operator =(const int & i) {flags = i;}
|
||||
void operator |=(const PIFlags & f) {flags = flags | f.flags;}
|
||||
void operator |=(const Enum & e) {flags = flags | e;}
|
||||
void operator |=(const int i) {flags = flags | i;}
|
||||
void operator &=(const PIFlags & f) {flags = flags & f.flags;}
|
||||
void operator &=(const Enum & e) {flags = flags & e;}
|
||||
void operator &=(const int i) {flags = flags & i;}
|
||||
PIFlags & operator |(PIFlags f) const {PIFlags tf(flags | f.flags); return tf;}
|
||||
PIFlags & operator |(Enum e) const {PIFlags tf(flags | e); return tf;}
|
||||
PIFlags & operator |(int i) const {PIFlags tf(flags | i); return tf;}
|
||||
PIFlags & operator &(PIFlags f) const {PIFlags tf(flags & f.flags); return tf;}
|
||||
PIFlags & operator &(Enum e) const {PIFlags tf(flags & e); return tf;}
|
||||
PIFlags & operator &(int i) const {PIFlags tf(flags & i); return tf;}
|
||||
bool operator [](Enum e) {return (flags & e) == e;}
|
||||
operator int() const {return flags;}
|
||||
private:
|
||||
int flags;
|
||||
};
|
||||
@@ -140,28 +140,28 @@ class PIVector: public vector<Type, Allocator> {
|
||||
typedef PIVector<Type, Allocator> _CVector;
|
||||
typedef vector<Type, Allocator> _stlc;
|
||||
public:
|
||||
inline PIVector() {;}
|
||||
inline PIVector(const Type & value) {_stlc::push_back(value);}
|
||||
inline PIVector(const Type & v0, const Type & v1) {_stlc::push_back(v0); _stlc::push_back(v1);}
|
||||
inline PIVector(const Type & v0, const Type & v1, const Type & v2) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2);}
|
||||
inline PIVector(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);}
|
||||
inline PIVector(uint size, const Type & value = Type()) {_stlc::resize(size, value);}
|
||||
inline const Type & at(uint index) const {return (*this)[index];}
|
||||
inline Type & at(uint index) {return (*this)[index];}
|
||||
inline const Type * data(uint index = 0) const {return &(*this)[index];}
|
||||
inline Type * data(uint index = 0) {return &(*this)[index];}
|
||||
inline int size_s() const {return static_cast<int>(_stlc::size());}
|
||||
inline bool isEmpty() const {return _stlc::empty();}
|
||||
inline _CVector & fill(const Type & t) {_stlc::assign(_stlc::size(), t); return *this;}
|
||||
inline _CVector & pop_front() {_stlc::erase(_stlc::begin()); return *this;}
|
||||
inline _CVector & push_front(const Type & t) {_stlc::insert(_stlc::begin(), t); return *this;}
|
||||
inline _CVector & remove(uint num) {_stlc::erase(_stlc::begin() + num); return *this;}
|
||||
inline _CVector & remove(uint num, uint count) {_stlc::erase(_stlc::begin() + num, _stlc::begin() + num + count); return *this;}
|
||||
inline _CVector & remove(const Type & t) {for (typename _stlc::iterator i = _stlc::begin(); i != _stlc::end(); ++i) if (t == *i) {_stlc::erase(i); --i;} return *this;}
|
||||
inline _CVector & insert(uint pos, const Type & t) {_stlc::insert(_stlc::begin() + pos, t); return *this;}
|
||||
inline _CVector & operator <<(const Type & t) {_stlc::push_back(t); return *this;}
|
||||
inline _CVector & operator <<(const _CVector & t) {piForeachCA (i, t) _stlc::push_back(i); return *this;}
|
||||
inline bool contain(const Type & v) const {for (uint i = 0; i < _stlc::size(); ++i) if (v == at(i)) return true; return false;}
|
||||
PIVector() {;}
|
||||
PIVector(const Type & value) {_stlc::push_back(value);}
|
||||
PIVector(const Type & v0, const Type & v1) {_stlc::push_back(v0); _stlc::push_back(v1);}
|
||||
PIVector(const Type & v0, const Type & v1, const Type & v2) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2);}
|
||||
PIVector(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);}
|
||||
PIVector(uint size, const Type & value = Type()) {_stlc::resize(size, value);}
|
||||
const Type & at(uint index) const {return (*this)[index];}
|
||||
Type & at(uint index) {return (*this)[index];}
|
||||
const Type * data(uint index = 0) const {return &(*this)[index];}
|
||||
Type * data(uint index = 0) {return &(*this)[index];}
|
||||
int size_s() const {return static_cast<int>(_stlc::size());}
|
||||
bool isEmpty() const {return _stlc::empty();}
|
||||
_CVector & fill(const Type & t) {_stlc::assign(_stlc::size(), t); return *this;}
|
||||
_CVector & pop_front() {_stlc::erase(_stlc::begin()); return *this;}
|
||||
_CVector & push_front(const Type & t) {_stlc::insert(_stlc::begin(), t); return *this;}
|
||||
_CVector & remove(uint num) {_stlc::erase(_stlc::begin() + num); return *this;}
|
||||
_CVector & remove(uint num, uint count) {_stlc::erase(_stlc::begin() + num, _stlc::begin() + num + count); return *this;}
|
||||
_CVector & remove(const Type & t) {for (typename _stlc::iterator i = _stlc::begin(); i != _stlc::end(); ++i) if (t == *i) {_stlc::erase(i); --i;} return *this;}
|
||||
_CVector & insert(uint pos, const Type & t) {_stlc::insert(_stlc::begin() + pos, t); return *this;}
|
||||
_CVector & operator <<(const Type & t) {_stlc::push_back(t); return *this;}
|
||||
_CVector & operator <<(const _CVector & t) {for (typename _stlc::iterator i = t.begin(); i != t.end(); i++) _stlc::push_back(*i); return *this;}
|
||||
bool contain(const Type & v) const {for (uint i = 0; i < _stlc::size(); ++i) if (v == at(i)) return true; return false;}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
@@ -172,22 +172,24 @@ class PIList: public list<Type, Allocator> {
|
||||
typedef PIList<Type, Allocator> _CList;
|
||||
typedef list<Type, Allocator> _stlc;
|
||||
public:
|
||||
inline PIList() {;}
|
||||
inline PIList(const Type & value) {_stlc::resize(1, value);}
|
||||
inline PIList(const Type & v0, const Type & v1) {_stlc::push_back(v0); _stlc::push_back(v1);}
|
||||
inline PIList(const Type & v0, const Type & v1, const Type & v2) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2);}
|
||||
inline PIList(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);}
|
||||
inline PIList(uint size, const Type & value = Type()) {_stlc::resize(size, value);}
|
||||
inline const Type * data(uint index = 0) const {return &(*this)[index];}
|
||||
inline Type * data(uint index = 0) {return &(*this)[index];}
|
||||
inline int size_s() const {return static_cast<int>(_stlc::size());}
|
||||
inline bool isEmpty() const {return _stlc::empty();}
|
||||
inline _CList & fill(const Type & t) {_stlc::assign(_stlc::size(), t); return *this;}
|
||||
inline _CList & remove(uint num) {_stlc::erase(_stlc::begin() + num); return *this;}
|
||||
inline _CList & remove(uint num, uint count) {_stlc::erase(_stlc::begin() + num, _stlc::begin() + num + count); return *this;}
|
||||
inline _CList & insert(uint pos, const Type & t) {_stlc::insert(_stlc::begin() + pos, t); return *this;}
|
||||
inline _CList & operator <<(const Type & t) {_stlc::push_back(t); return *this;}
|
||||
inline PIVector<Type, Allocator> toVector() {PIVector<Type, Allocator> v; for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) v << *i; return v;}
|
||||
PIList() {;}
|
||||
PIList(const Type & value) {_stlc::resize(1, value);}
|
||||
PIList(const Type & v0, const Type & v1) {_stlc::push_back(v0); _stlc::push_back(v1);}
|
||||
PIList(const Type & v0, const Type & v1, const Type & v2) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2);}
|
||||
PIList(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);}
|
||||
PIList(uint size, const Type & value = Type()) {_stlc::resize(size, value);}
|
||||
Type & operator [](uint index) {return (*this)[index];}
|
||||
Type & operator [](uint index) const {return (*this)[index];}
|
||||
const Type * data(uint index = 0) const {return &(*this)[index];}
|
||||
Type * data(uint index = 0) {return &(*this)[index];}
|
||||
int size_s() const {return static_cast<int>(_stlc::size());}
|
||||
bool isEmpty() const {return _stlc::empty();}
|
||||
_CList & fill(const Type & t) {_stlc::assign(_stlc::size(), t); return *this;}
|
||||
_CList & remove(uint num) {_stlc::erase(_stlc::begin() + num); return *this;}
|
||||
_CList & remove(uint num, uint count) {_stlc::erase(_stlc::begin() + num, _stlc::begin() + num + count); return *this;}
|
||||
_CList & insert(uint pos, const Type & t) {_stlc::insert(_stlc::begin() + pos, t); return *this;}
|
||||
_CList & operator <<(const Type & t) {_stlc::push_back(t); return *this;}
|
||||
PIVector<Type, Allocator> toVector() {PIVector<Type, Allocator> v; for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) v << *i; return v;}
|
||||
};
|
||||
|
||||
template<typename Type, typename Compare = std::less<Type>, typename Allocator = std::allocator<Type> >
|
||||
@@ -195,34 +197,34 @@ class PISet: public set<Type, Compare, Allocator> {
|
||||
typedef PISet<Type, Compare, Allocator> _CSet;
|
||||
typedef set<Type, Compare, Allocator> _stlc;
|
||||
public:
|
||||
inline PISet() {;}
|
||||
inline PISet(const Type & value) {_stlc::resize(1, value);}
|
||||
inline PISet(const Type & v0, const Type & v1) {_stlc::insert(v0); _stlc::insert(v1);}
|
||||
inline PISet(const Type & v0, const Type & v1, const Type & v2) {_stlc::insert(v0); _stlc::insert(v1); _stlc::insert(v2);}
|
||||
inline PISet(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_stlc::insert(v0); _stlc::insert(v1); _stlc::insert(v2); _stlc::insert(v3);}
|
||||
inline int size_s() const {return static_cast<int>(_stlc::size());}
|
||||
inline bool isEmpty() const {return _stlc::empty();}
|
||||
inline _CSet & remove(uint num) {_stlc::erase(_stlc::begin() + num); return *this;}
|
||||
inline _CSet & remove(uint num, uint count) {_stlc::erase(_stlc::begin() + num, _stlc::begin() + num + count); return *this;}
|
||||
inline _CSet & operator <<(const Type & t) {_stlc::insert(t); return *this;}
|
||||
inline bool operator [](const Type & t) {return _stlc::find(t);}
|
||||
inline PIVector<Type, Allocator> toVector() {PIVector<Type, Allocator> v; for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) v << *i; return v;}
|
||||
PISet() {;}
|
||||
PISet(const Type & value) {_stlc::resize(1, value);}
|
||||
PISet(const Type & v0, const Type & v1) {_stlc::insert(v0); _stlc::insert(v1);}
|
||||
PISet(const Type & v0, const Type & v1, const Type & v2) {_stlc::insert(v0); _stlc::insert(v1); _stlc::insert(v2);}
|
||||
PISet(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_stlc::insert(v0); _stlc::insert(v1); _stlc::insert(v2); _stlc::insert(v3);}
|
||||
int size_s() const {return static_cast<int>(_stlc::size());}
|
||||
bool isEmpty() const {return _stlc::empty();}
|
||||
_CSet & remove(uint num) {_stlc::erase(_stlc::begin() + num); return *this;}
|
||||
_CSet & remove(uint num, uint count) {_stlc::erase(_stlc::begin() + num, _stlc::begin() + num + count); return *this;}
|
||||
_CSet & operator <<(const Type & t) {_stlc::insert(t); return *this;}
|
||||
bool operator [](const Type & t) {return _stlc::find(t);}
|
||||
PIVector<Type, Allocator> toVector() {PIVector<Type, Allocator> v; for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) v << *i; return v;}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class PIStack: public PIVector<Type> {
|
||||
typedef PIStack<Type> _CStack;
|
||||
public:
|
||||
inline PIStack() {;}
|
||||
inline PIStack(const Type & value) {_CStack::resize(1, value);}
|
||||
inline PIStack(const Type & v0, const Type & v1) {_CStack::push_back(v0); _CStack::push_back(v1);}
|
||||
inline PIStack(const Type & v0, const Type & v1, const Type & v2) {_CStack::push_back(v0); _CStack::push_back(v1); _CStack::push_back(v2);}
|
||||
inline PIStack(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_CStack::push_back(v0); _CStack::push_back(v1); _CStack::push_back(v2); _CStack::push_back(v3);}
|
||||
inline _CStack & push(const Type & v) {_CStack::push_back(v); return *this;}
|
||||
inline Type pop() {Type t = Type(); if (_CStack::size() == 0) return t; t = _CStack::back(); _CStack::pop_back(); return t;}
|
||||
inline Type & top() {return _CStack::back();}
|
||||
inline const Type & top() const {return _CStack::back();}
|
||||
inline PIVector<Type> toVector() {PIVector<Type> v; for (typename _CStack::const_iterator i = _CStack::begin(); i != _CStack::end(); ++i) v << *i; return v;}
|
||||
PIStack() {;}
|
||||
PIStack(const Type & value) {_CStack::resize(1, value);}
|
||||
PIStack(const Type & v0, const Type & v1) {_CStack::push_back(v0); _CStack::push_back(v1);}
|
||||
PIStack(const Type & v0, const Type & v1, const Type & v2) {_CStack::push_back(v0); _CStack::push_back(v1); _CStack::push_back(v2);}
|
||||
PIStack(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_CStack::push_back(v0); _CStack::push_back(v1); _CStack::push_back(v2); _CStack::push_back(v3);}
|
||||
_CStack & push(const Type & v) {_CStack::push_back(v); return *this;}
|
||||
Type pop() {Type t = Type(); if (_CStack::size() == 0) return t; t = _CStack::back(); _CStack::pop_back(); return t;}
|
||||
Type & top() {return _CStack::back();}
|
||||
const Type & top() const {return _CStack::back();}
|
||||
PIVector<Type> toVector() {PIVector<Type> v; for (typename _CStack::const_iterator i = _CStack::begin(); i != _CStack::end(); ++i) v << *i; return v;}
|
||||
};
|
||||
|
||||
template<typename Type, typename Allocator = std::allocator<Type> >
|
||||
@@ -230,39 +232,39 @@ class PIDeque: public deque<Type, Allocator> {
|
||||
typedef PIDeque<Type, Allocator> _CDeque;
|
||||
typedef deque<Type, Allocator> _stlc;
|
||||
public:
|
||||
inline PIDeque() {;}
|
||||
inline PIDeque(const Type & value) {_stlc::resize(1, value);}
|
||||
inline PIDeque(const Type & v0, const Type & v1) {_stlc::push_back(v0); _stlc::push_back(v1);}
|
||||
inline PIDeque(const Type & v0, const Type & v1, const Type & v2) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2);}
|
||||
inline PIDeque(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);}
|
||||
inline int size_s() const {return static_cast<int>(_stlc::size());}
|
||||
inline bool isEmpty() const {return _stlc::empty();}
|
||||
inline _CDeque & operator <<(const Type & t) {_CDeque::push_back(t); return *this;}
|
||||
inline PIVector<Type, Allocator> toVector() {PIVector<Type, Allocator> v; for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) v << *i; return v;}
|
||||
PIDeque() {;}
|
||||
PIDeque(const Type & value) {_stlc::resize(1, value);}
|
||||
PIDeque(const Type & v0, const Type & v1) {_stlc::push_back(v0); _stlc::push_back(v1);}
|
||||
PIDeque(const Type & v0, const Type & v1, const Type & v2) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2);}
|
||||
PIDeque(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);}
|
||||
int size_s() const {return static_cast<int>(_stlc::size());}
|
||||
bool isEmpty() const {return _stlc::empty();}
|
||||
_CDeque & operator <<(const Type & t) {_CDeque::push_back(t); return *this;}
|
||||
PIVector<Type, Allocator> toVector() {PIVector<Type, Allocator> v; for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) v << *i; return v;}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class PIQueue: public PIDeque<Type> {
|
||||
typedef PIQueue<Type> _CQueue;
|
||||
public:
|
||||
inline PIQueue() {;}
|
||||
inline PIQueue(const Type & value) {_CQueue::resize(1, value);}
|
||||
inline PIQueue(const Type & v0, const Type & v1) {_CQueue::push_front(v0); _CQueue::push_front(v1);}
|
||||
inline PIQueue(const Type & v0, const Type & v1, const Type & v2) {_CQueue::push_front(v0); _CQueue::push_front(v1); _CQueue::push_front(v2);}
|
||||
inline PIQueue(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_CQueue::push_front(v0); _CQueue::push_front(v1); _CQueue::push_front(v2); _CQueue::push_front(v3);}
|
||||
inline _CQueue & enqueue(const Type & v) {_CQueue::push_front(v); return *this;}
|
||||
inline Type dequeue() {Type t = Type(); if (_CQueue::size() == 0) return t; t = _CQueue::back(); _CQueue::pop_back(); return t;}
|
||||
inline Type & head() {return _CQueue::back();}
|
||||
inline const Type & head() const {return _CQueue::back();}
|
||||
inline PIVector<Type> toVector() {PIVector<Type> v; for (typename _CQueue::const_iterator i = _CQueue::begin(); i != _CQueue::end(); ++i) v << *i; return v;}
|
||||
PIQueue() {;}
|
||||
PIQueue(const Type & value) {_CQueue::resize(1, value);}
|
||||
PIQueue(const Type & v0, const Type & v1) {_CQueue::push_front(v0); _CQueue::push_front(v1);}
|
||||
PIQueue(const Type & v0, const Type & v1, const Type & v2) {_CQueue::push_front(v0); _CQueue::push_front(v1); _CQueue::push_front(v2);}
|
||||
PIQueue(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {_CQueue::push_front(v0); _CQueue::push_front(v1); _CQueue::push_front(v2); _CQueue::push_front(v3);}
|
||||
_CQueue & enqueue(const Type & v) {_CQueue::push_front(v); return *this;}
|
||||
Type dequeue() {Type t = Type(); if (_CQueue::size() == 0) return t; t = _CQueue::back(); _CQueue::pop_back(); return t;}
|
||||
Type & head() {return _CQueue::back();}
|
||||
const Type & head() const {return _CQueue::back();}
|
||||
PIVector<Type> toVector() {PIVector<Type> v; for (typename _CQueue::const_iterator i = _CQueue::begin(); i != _CQueue::end(); ++i) v << *i; return v;}
|
||||
};
|
||||
|
||||
|
||||
template<typename Type0, typename Type1>
|
||||
class PIPair {
|
||||
public:
|
||||
inline PIPair() {first = Type0(); second = Type1();}
|
||||
inline PIPair(const Type0 & value0, const Type1 & value1) {first = value0; second = value1;}
|
||||
PIPair() {first = Type0(); second = Type1();}
|
||||
PIPair(const Type0 & value0, const Type1 & value1) {first = value0; second = value1;}
|
||||
Type0 first;
|
||||
Type1 second;
|
||||
};
|
||||
@@ -275,11 +277,11 @@ class PIHash: public PISet<PIPair<Key, Type> > {
|
||||
typedef PIHash<Type, Key> _CHash;
|
||||
typedef PISet<PIPair<Key, Type> > _CSet;
|
||||
public:
|
||||
inline PIHash() {;}
|
||||
inline PIHash(const Type & value, const Key & key) {insert(value, key);}
|
||||
inline _CHash & insert(const Type & value, const Key & key) {_CSet::insert(PIPair<Key, Type>(key, value));}
|
||||
inline Type value(Key key) {piForeachCA (i, *this) if (i.first == key) return i.second;; return Key();}
|
||||
inline Type operator[](Key key) {return value(key);}
|
||||
PIHash() {;}
|
||||
PIHash(const Type & value, const Key & key) {insert(value, key);}
|
||||
_CHash & insert(const Type & value, const Key & key) {_CSet::insert(PIPair<Key, Type>(key, value));}
|
||||
Type value(Key key) {for (typename _CHash::iterator i = _CHash::begin(); i != _CHash::end(); i++) if ((*i).first == key) return (*i).second; return Key();}
|
||||
Type operator[](Key key) {return value(key);}
|
||||
};
|
||||
|
||||
#endif // PICONTAINERS_H
|
||||
|
||||
@@ -53,7 +53,7 @@ bool PIEvaluatorContent::setVariableName(int index, const PIString & new_name) {
|
||||
|
||||
void PIEvaluatorContent::clearCustomVariables() {
|
||||
variables.clear();
|
||||
addVariable("i", complexd_1);
|
||||
addVariable("i", complexd_i);
|
||||
addVariable("pi", atan(1.) * 4.);
|
||||
addVariable("e", exp(1.));
|
||||
cv_count = variables.size();
|
||||
@@ -557,7 +557,7 @@ const PIString & PIEvaluator::preprocess(const PIString & string) {
|
||||
lind = parse(currentString);
|
||||
if (instructions.size() == 0) {
|
||||
variables.push_back(PIEvaluatorTypes::Variable());
|
||||
instructions.push_back(PIEvaluatorTypes::Instruction(PIEvaluatorTypes::oNone, PIVector<int>(1, lind), -variables.size()));
|
||||
instructions.push_back(PIEvaluatorTypes::Instruction(PIEvaluatorTypes::oNone, PIVector<int>(1, lind), -variables.size_s()));
|
||||
}
|
||||
kvars = &(content.variables);
|
||||
/*
|
||||
|
||||
16
pifile.cpp
16
pifile.cpp
@@ -22,8 +22,8 @@ PIString PIFile::readLine() {
|
||||
}
|
||||
|
||||
|
||||
int PIFile::readAll(void * data) {
|
||||
int cp = pos(), s = size();
|
||||
llong PIFile::readAll(void * data) {
|
||||
llong cp = pos(), s = size();
|
||||
stream.seekg(0);
|
||||
stream.read((char * )data, s);
|
||||
seek(cp);
|
||||
@@ -32,7 +32,7 @@ int PIFile::readAll(void * data) {
|
||||
|
||||
|
||||
PIByteArray PIFile::readAll() {
|
||||
int s = size();
|
||||
llong s = size();
|
||||
if (s < 0) return PIByteArray();
|
||||
PIByteArray a(s);
|
||||
s = readAll(a.data());
|
||||
@@ -41,9 +41,9 @@ PIByteArray PIFile::readAll() {
|
||||
}
|
||||
|
||||
|
||||
int PIFile::size() {
|
||||
llong PIFile::size() {
|
||||
if (!stream.is_open()) return -1;
|
||||
int s, cp = stream.tellg();
|
||||
llong s, cp = stream.tellg();
|
||||
stream.seekg(0, fstream::end);
|
||||
s = stream.tellg();
|
||||
stream.seekg(cp, fstream::beg);
|
||||
@@ -51,8 +51,8 @@ int PIFile::size() {
|
||||
}
|
||||
|
||||
|
||||
void PIFile::resize(int new_size, char fill_) {
|
||||
int ds = new_size - size();
|
||||
void PIFile::resize(llong new_size, char fill_) {
|
||||
llong ds = new_size - size();
|
||||
if (ds == 0) return;
|
||||
if (ds > 0) {
|
||||
char * buff = new char[ds];
|
||||
@@ -65,7 +65,7 @@ void PIFile::resize(int new_size, char fill_) {
|
||||
}
|
||||
|
||||
|
||||
int PIFile::pos() {
|
||||
llong PIFile::pos() {
|
||||
if (cmode[Read]) return stream.tellg();
|
||||
if (cmode[Write]) return stream.tellp();
|
||||
return -1;
|
||||
|
||||
12
pifile.h
12
pifile.h
@@ -25,23 +25,23 @@ public:
|
||||
bool open() {return open(cpath, cmode);}
|
||||
void close() {stream.close();}
|
||||
void clear() {string st = cpath.stdString(); close(); stream.open(st.c_str(), fstream::trunc | fstream::binary | (fstream::openmode)(int)cmode);}
|
||||
void seek(int position) {stream.clear(); stream.seekg(position); stream.seekp(position);}
|
||||
void seek(llong position) {stream.clear(); stream.seekg(position); stream.seekp(position);}
|
||||
void seekToBegin() {stream.clear(); stream.seekg(0, fstream::beg); stream.seekp(0, fstream::beg);}
|
||||
void seekToEnd() {stream.clear(); stream.seekg(0, fstream::end); stream.seekp(0, fstream::end);}
|
||||
void seekToLine(int line) {stream.clear(); seekToBegin(); piForTimes (line) readLine();} // line 0 - begin of file
|
||||
void resize(int new_size, char fill = 0);
|
||||
void seekToLine(llong line) {stream.clear(); seekToBegin(); piForTimes (line) readLine();} // line 0 - begin of file
|
||||
void resize(llong new_size, char fill = 0);
|
||||
void fill(char c) {stream.fill(c);}
|
||||
void flush() {stream.flush();}
|
||||
PIString readLine();
|
||||
int readAll(void * data);
|
||||
llong readAll(void * data);
|
||||
PIByteArray readAll();
|
||||
void remove() {if (isOpened()) close(); std::remove(cpath.data());}
|
||||
|
||||
PIString path() const {return cpath;}
|
||||
void setPath(const PIString & path) {cpath = path;}
|
||||
PIFlags<Mode> mode() const {return cmode;}
|
||||
int size();
|
||||
int pos();
|
||||
llong size();
|
||||
llong pos();
|
||||
bool isOpened() {return stream.is_open();}
|
||||
bool isEnd() {return stream.eof();}
|
||||
bool isEmpty() {return (size() <= 0);}
|
||||
|
||||
@@ -23,10 +23,8 @@ PIKbdListener::PIKbdListener(KBFunc slot, void * data_): PIThread() {
|
||||
void PIKbdListener::begin() {
|
||||
//cout << "list begin" << endl;
|
||||
#ifdef WINDOWS
|
||||
hIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
GetConsoleMode(hIn, &smode);
|
||||
tmode = smode;
|
||||
SetConsoleMode(hIn, ENABLE_PROCESSED_INPUT);
|
||||
GetConsoleMode(hIn, &tmode);
|
||||
#else
|
||||
struct termios term;
|
||||
tcgetattr(0, &term);
|
||||
|
||||
@@ -17,6 +17,8 @@ public:
|
||||
PIKbdListener(KBFunc slot = 0, void * data = 0);
|
||||
~PIKbdListener() {terminate(); end();}
|
||||
|
||||
void setData(void * data_) {data = data_;}
|
||||
void setSlot(KBFunc slot_) {ret_func = slot_;}
|
||||
void enableExitCapture(char key = 'Q') {exit_enabled = true; exit_key = key;}
|
||||
void disableExitCapture() {exit_enabled = false;}
|
||||
bool exitCaptured() const {return exit_enabled;}
|
||||
@@ -32,14 +34,15 @@ private:
|
||||
void end();
|
||||
|
||||
KBFunc ret_func;
|
||||
char rc, exit_key, is_active;
|
||||
bool exit_enabled;
|
||||
char exit_key;
|
||||
bool exit_enabled, is_active;
|
||||
void * data;
|
||||
#ifdef WINDOWS
|
||||
DWORD ret;
|
||||
DWORD ret, rc;
|
||||
void * hIn;
|
||||
DWORD smode, tmode;
|
||||
#else
|
||||
char rc;
|
||||
int ret;
|
||||
struct termios sterm, tterm;
|
||||
#endif
|
||||
|
||||
18
pimath.h
18
pimath.h
@@ -21,7 +21,7 @@ using std::complex;
|
||||
typedef complex<int> complexi;
|
||||
typedef complex<float> complexf;
|
||||
typedef complex<double> complexd;
|
||||
typedef complex<long double> complexld;
|
||||
typedef complex<ldouble> complexld;
|
||||
const complexld complexld_i(0., 1.);
|
||||
const complexld complexld_0(0.);
|
||||
const complexld complexld_1(1.);
|
||||
@@ -32,7 +32,7 @@ const complexd complexd_1(1.);
|
||||
const double deg2rad = atan(1.) / 45.;
|
||||
const double rad2deg = 45. / atan(1.);
|
||||
|
||||
inline int pow2(int p) {return 1 << p;}
|
||||
inline int pow2(const int p) {return 1 << p;}
|
||||
inline double sqr(const double & v) {return v * v;}
|
||||
inline double sinc(const double & v) {double t = M_PI * v; return sin(t) / t;}
|
||||
inline complexd atanc(const complexd & c) {return -complexd(-0.5, 1.) * log((complexd_1 + complexd_i * c) / (complexd_1 - complexd_i * c));}
|
||||
@@ -306,7 +306,7 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT<Cols, Ro
|
||||
/// Multiply matrices {CR x Rows0} on {Cols1 x CR}, result is {Cols1 x Rows0}
|
||||
template<uint CR, uint Rows0, uint Cols1, typename Type>
|
||||
inline PIMathMatrixT<Cols1, Rows0, Type> operator *(const PIMathMatrixT<CR, Rows0, Type> & fm,
|
||||
const PIMathMatrixT<Cols1, CR, Type> & sm) {
|
||||
const PIMathMatrixT<Cols1, CR, Type> & sm) {
|
||||
PIMathMatrixT<Cols1, Rows0, Type> tm;
|
||||
Type t;
|
||||
for (uint j = 0; j < Rows0; ++j) {
|
||||
@@ -323,7 +323,7 @@ inline PIMathMatrixT<Cols1, Rows0, Type> operator *(const PIMathMatrixT<CR, Rows
|
||||
/// Multiply matrix {Cols x Rows} on vector {Cols}, result is vector {Rows}
|
||||
template<uint Cols, uint Rows, typename Type>
|
||||
inline PIMathVectorT<Rows, Type> operator *(const PIMathMatrixT<Cols, Rows, Type> & fm,
|
||||
const PIMathVectorT<Cols, Type> & sv) {
|
||||
const PIMathVectorT<Cols, Type> & sv) {
|
||||
PIMathVectorT<Rows, Type> tv;
|
||||
Type t;
|
||||
for (uint i = 0; i < Rows; ++i) {
|
||||
@@ -459,8 +459,8 @@ public:
|
||||
inline _CMatrix & resize(const uint cols, const uint rows, const Type & new_value = Type()) {cols_ = cols; rows_ = rows; m.resize(cols); PIMM_FOR_C(i) m[i].resize(rows, new_value); return *this;}
|
||||
inline _CMatrix & setCol(uint index, const _CMCol & v) {PIMM_FOR_R(i) m[index][i] = v[i]; return *this;}
|
||||
inline _CMatrix & setRow(uint index, const _CMRow & v) {PIMM_FOR_C(i) m[i][index] = v[i]; return *this;}
|
||||
inline _CMatrix & swaprows_(uint r0, uint r1) {Type t; PIMM_FOR_C(i) {t = m[i][r0]; m[i][r0] = m[i][r1]; m[i][r1] = t;} return *this;}
|
||||
inline _CMatrix & swapcols_(uint c0, uint c1) {Type t; PIMM_FOR_R(i) {t = m[c0][i]; m[c0][i] = m[c1][i]; m[c1][i] = t;} return *this;}
|
||||
inline _CMatrix & swapRows(uint r0, uint r1) {Type t; PIMM_FOR_C(i) {t = m[i][r0]; m[i][r0] = m[i][r1]; m[i][r1] = t;} return *this;}
|
||||
inline _CMatrix & swapCols(uint c0, uint c1) {Type t; PIMM_FOR_R(i) {t = m[c0][i]; m[c0][i] = m[c1][i]; m[c1][i] = t;} return *this;}
|
||||
inline _CMatrix & fill(const Type & v) {PIMM_FOR_WB(c, r) m[c][r] = v; return *this;}
|
||||
//inline _CMatrix & set(Type fval, ...) {m[0] = fval; va_list vl; va_start(vl, fval); PIMV_FOR(i, 1) m[i] = va_arg(vl, Type); va_end(vl); return *this;}
|
||||
//inline void normalize() {Type tv = length(); if (tv == Type(1)) return; PIMV_FOR(i, 0) m[i] /= tv;}
|
||||
@@ -510,7 +510,7 @@ public:
|
||||
for (uint i = 0; i < cols_; ++i) {
|
||||
crow = i;
|
||||
while (smat.m[i][i] == Type(0))
|
||||
smat.swaprows_(i, ++crow);
|
||||
smat.swapRows(i, ++crow);
|
||||
for (uint j = i + 1; j < rows_; ++j) {
|
||||
mul = smat.m[i][j] / smat.m[i][i];
|
||||
for (uint k = i; k < cols_; ++k) smat.m[k][j] -= mul * smat.m[k][i];
|
||||
@@ -553,8 +553,8 @@ public:
|
||||
crow = i;
|
||||
while (smat.m[i][i] == Type(0)) {
|
||||
++crow;
|
||||
smat.swaprows_(i, crow);
|
||||
mtmp.swaprows_(i, crow);
|
||||
smat.swapRows(i, crow);
|
||||
mtmp.swapRows(i, crow);
|
||||
if (sv != 0) sv->swap(i, crow);
|
||||
}
|
||||
for (uint j = i + 1; j < rows_; ++j) {
|
||||
|
||||
@@ -43,8 +43,8 @@ private:
|
||||
class PIRepeater: public PIMultiProtocol {
|
||||
public:
|
||||
PIRepeater(const PIString & config, const PIString & name, int data_size) {
|
||||
ba_f.resize(data_size);
|
||||
ba_s.resize(data_size);
|
||||
ba_f = new PIByteArray(data_size);
|
||||
ba_s = new PIByteArray(data_size);
|
||||
PIConfig conf(config, PIFile::Read);
|
||||
if (!conf.isOpened()) {
|
||||
cout << "[PIRepeater \"" << name << "\"] Can`t open \"" << config << "\"!" << endl;
|
||||
@@ -55,8 +55,8 @@ public:
|
||||
cout << "[PIRepeater \"" << name << "\"] \"" << config << "\" should consist 2 nodes!" << endl;
|
||||
return;
|
||||
}
|
||||
addProtocol(config, b.child(0)->fullName(), 0, 0, ba_f.data(), data_size, ba_s.data(), data_size);
|
||||
addProtocol(config, b.child(1)->fullName(), 0, 0, ba_s.data(), data_size, ba_f.data(), data_size);
|
||||
addProtocol(config, b.child(0)->fullName(), 0, 0, ba_f->data(), data_size, ba_s->data(), data_size);
|
||||
addProtocol(config, b.child(1)->fullName(), 0, 0, ba_s->data(), data_size, ba_f->data(), data_size);
|
||||
start();
|
||||
}
|
||||
|
||||
@@ -68,11 +68,11 @@ public:
|
||||
ullong sendCount() {if (count() == 2) return protocol(0)->sendCount(); return 0;}
|
||||
ullong * sendCount_ptr() {if (count() == 2) return protocol(0)->sendCount_ptr(); return 0;}
|
||||
|
||||
PIByteArray * ba_f, * ba_s;
|
||||
|
||||
private:
|
||||
void received(PIProtocol * prot, bool , char * , int ) {if (prot == protocol(0)) protocol(1)->send(); else protocol(0)->send();}
|
||||
|
||||
PIByteArray ba_f, ba_s;
|
||||
|
||||
};
|
||||
|
||||
#endif // PIMULTIPROTOCOL_H
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
void unsetInputFile() {f_in.setPath("");}
|
||||
void unsetOutputFile() {f_out.setPath("");}
|
||||
void unsetErrorFile() {f_err.setPath("");}
|
||||
PIString workingDirectory() const {return wd;}
|
||||
void setWorkingDirectory(const PIString & path) {wd = path;}
|
||||
void resetWorkingDirectory() {wd.clear();}
|
||||
void exec(const PIString & program) {args.clear(); args << program; exec_();}
|
||||
|
||||
@@ -197,7 +197,7 @@ void PIProtocol::setSenderAddress(const PIString & ip, int port, bool force) {
|
||||
void PIProtocol::setExpectedFrequency(float frequency) {
|
||||
exp_freq = frequency;
|
||||
if (exp_freq < 10.f / 3.f) pckt_cnt_max = 10;
|
||||
else pckt_cnt_max = round(3.f * exp_freq);
|
||||
else pckt_cnt_max = uint(round(3.f * exp_freq));
|
||||
last_packets.resize(pckt_cnt_max);
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ bool PIProtocol::receiveEvent(void * t, char * data, int size) {
|
||||
}
|
||||
|
||||
|
||||
void PIProtocol::diagEvent(void * t) {
|
||||
void PIProtocol::diagEvent(void * t, int) {
|
||||
PIProtocol * p = (PIProtocol * )t;
|
||||
p->calc_freq();
|
||||
p->calc_diag();
|
||||
@@ -283,7 +283,7 @@ void PIProtocol::calc_diag() {
|
||||
|
||||
|
||||
void PIProtocol::calc_freq() {
|
||||
tf = 1000.f / diagTimer->elapsed_m();
|
||||
tf = float(1000.f / diagTimer->elapsed_m());
|
||||
diagTimer->reset();
|
||||
if (cur_pckt != 1) tf = 0.f;
|
||||
immediateFreq = tf;
|
||||
|
||||
@@ -84,6 +84,9 @@ public:
|
||||
PIString senderDeviceState() const {return devSenderState;}
|
||||
PIString * senderDeviceState_ptr() {return &devSenderState;}
|
||||
|
||||
void * receiveData() {return dataPtr;}
|
||||
void * sendData() {return sendDataPtr;}
|
||||
|
||||
protected:
|
||||
virtual bool receive(char * data, int size) {memcpy(dataPtr, data, size); return true;} // executed when raw data received, break if 'false' return
|
||||
virtual bool validate() {return true;} // function for validate algorithm and save data from dataPtr to external struct
|
||||
@@ -114,9 +117,9 @@ protected:
|
||||
uchar * dataPtr, * headerPtr, * sendDataPtr;
|
||||
|
||||
private:
|
||||
static void sendEvent(void * e) {((PIProtocol * )e)->send();}
|
||||
static void sendEvent(void * e, int) {((PIProtocol * )e)->send();}
|
||||
static bool receiveEvent(void * t, char * data, int size);
|
||||
static void diagEvent(void * t);
|
||||
static void diagEvent(void * t, int);
|
||||
|
||||
void setMultiProtocolOwner(PIMultiProtocolBase * mp) {mp_owner = mp;}
|
||||
PIMultiProtocolBase * multiProtocolOwner() const {return mp_owner;}
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
};
|
||||
|
||||
typedef void (*SignalEvent)(PISignals::Signal);
|
||||
|
||||
// slot is any function format "void <func>(PISignals::Signal)"
|
||||
static void setSlot(SignalEvent slot) {ret_func = slot;}
|
||||
static void grabSignals(PIFlags<PISignals::Signal> signals_);
|
||||
static void raiseSignal(PISignals::Signal signal) {raise(signalCode(signal));}
|
||||
|
||||
26
pistring.cpp
26
pistring.cpp
@@ -308,7 +308,7 @@ string PIString::convertToStd() const {
|
||||
char PIString::toChar() const {
|
||||
PIString s(toNativeDecimalPoints());
|
||||
char v;
|
||||
sscanf(s.data(), "%c", &v);
|
||||
sscanf(s.stdString().c_str(), "%c", &v);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -316,9 +316,9 @@ char PIString::toChar() const {
|
||||
short PIString::toShort() const {
|
||||
PIString s(trimmed().toLowerCase().toNativeDecimalPoints());
|
||||
short v;
|
||||
if (s.left(2) == "0x") {sscanf(s.data(), "%hx", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.data(), "%ho", &v); return v;}
|
||||
sscanf(s.data(), "%hd", &v);
|
||||
if (s.left(2) == "0x") {sscanf(s.stdString().c_str(), "%hx", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.stdString().c_str(), "%ho", &v); return v;}
|
||||
sscanf(s.stdString().c_str(), "%hd", &v);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -326,9 +326,9 @@ short PIString::toShort() const {
|
||||
int PIString::toInt() const {
|
||||
PIString s(trimmed().toLowerCase().toNativeDecimalPoints());
|
||||
int v;
|
||||
if (s.left(2) == "0x") {sscanf(s.data(), "%x", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.data(), "%o", &v); return v;}
|
||||
sscanf(s.data(), "%d", &v);
|
||||
if (s.left(2) == "0x") {sscanf(s.stdString().c_str(), "%x", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.stdString().c_str(), "%o", &v); return v;}
|
||||
sscanf(s.stdString().c_str(), "%d", &v);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -336,9 +336,9 @@ int PIString::toInt() const {
|
||||
long PIString::toLong() const {
|
||||
PIString s(trimmed().toLowerCase().toNativeDecimalPoints());
|
||||
long v;
|
||||
if (s.left(2) == "0x") {sscanf(s.data(), "%lx", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.data(), "%lo", &v); return v;}
|
||||
sscanf(s.data(), "%ld", &v);
|
||||
if (s.left(2) == "0x") {sscanf(s.stdString().c_str(), "%lx", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.stdString().c_str(), "%lo", &v); return v;}
|
||||
sscanf(s.stdString().c_str(), "%ld", &v);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -346,9 +346,9 @@ long PIString::toLong() const {
|
||||
llong PIString::toLLong() const {
|
||||
PIString s(trimmed().toLowerCase().toNativeDecimalPoints());
|
||||
llong v;
|
||||
if (s.left(2) == "0x") {sscanf(s.data(), "%llx", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.data(), "%llo", &v); return v;}
|
||||
sscanf(s.data(), "%lld", &v);
|
||||
if (s.left(2) == "0x") {sscanf(s.stdString().c_str(), "%llx", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.stdString().c_str(), "%llo", &v); return v;}
|
||||
sscanf(s.stdString().c_str(), "%lld", &v);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,15 +128,15 @@ public:
|
||||
int length() const {return size();}
|
||||
bool isEmpty() const {return (size() == 0 || *this == "");}
|
||||
|
||||
bool toBool() const {PIString s(*this); if (atof(s.toNativeDecimalPoints().data()) > 0. || s.trimmed().toLowerCase() == "true") return true; return false;}
|
||||
bool toBool() const {PIString s(*this); if (atof(s.toNativeDecimalPoints().stdString().c_str()) > 0. || s.trimmed().toLowerCase() == "true") return true; return false;}
|
||||
char toChar() const;
|
||||
short toShort() const;
|
||||
int toInt() const;
|
||||
long toLong() const;
|
||||
llong toLLong() const;
|
||||
float toFloat() const {PIString s(*this); return (float)atof(s.toNativeDecimalPoints().data());}
|
||||
double toDouble() const {PIString s(*this); return atof(s.toNativeDecimalPoints().data());}
|
||||
ldouble toLDouble() const {PIString s(*this); return atof(s.toNativeDecimalPoints().data());}
|
||||
float toFloat() const {PIString s(*this); return (float)atof(s.toNativeDecimalPoints().stdString().c_str());}
|
||||
double toDouble() const {PIString s(*this); return atof(s.toNativeDecimalPoints().stdString().c_str());}
|
||||
ldouble toLDouble() const {PIString s(*this); return atof(s.toNativeDecimalPoints().stdString().c_str());}
|
||||
|
||||
//inline PIString & setNumber(const char value) {clear(); *this += itos(value); return *this;}
|
||||
PIString & setNumber(const int value) {clear(); *this += itos(value); return *this;}
|
||||
|
||||
22
pitimer.cpp
22
pitimer.cpp
@@ -32,10 +32,30 @@ void PITimer::timer_event(sigval e) {
|
||||
PITimer * ct = (PITimer * )e.sival_ptr;
|
||||
if (ct->ret_func != 0) {
|
||||
if (ct->lockRun) ct->lock();
|
||||
ct->ret_func(ct->data);
|
||||
ct->ret_func(ct->data, 1);
|
||||
piForeach (TimerSlot & i, ct->ret_funcs) {
|
||||
if (i.delim > ++(i.tick)) continue;
|
||||
i.tick = 0;
|
||||
if (i.slot != 0) i.slot(ct->data, i.delim);
|
||||
else ct->ret_func(ct->data, i.delim);
|
||||
}
|
||||
if (ct->lockRun) ct->unlock();
|
||||
}
|
||||
}
|
||||
#else
|
||||
void PITimer::run() {
|
||||
if (ret_func != 0) {
|
||||
if (lockRun) lock();
|
||||
ret_func(data, 1);
|
||||
piForeach (TimerSlot & i, ret_funcs) {
|
||||
if (i.delim > ++(i.tick)) continue;
|
||||
i.tick = 0;
|
||||
if (i.slot != 0) i.slot(data, i.delim);
|
||||
else ret_func(data, i.delim);
|
||||
}
|
||||
if (lockRun) unlock();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
19
pitimer.h
19
pitimer.h
@@ -6,7 +6,7 @@
|
||||
#include "pithread.h"
|
||||
#include "pistring.h"
|
||||
|
||||
typedef void (*TimerEvent)(void * );
|
||||
typedef void (*TimerEvent)(void * , int );
|
||||
|
||||
struct PITime {
|
||||
int seconds;
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
~PITimer() {stop();}
|
||||
|
||||
void setData(void * data_) {data = data_;}
|
||||
void setSlot(TimerEvent slot_) {ret_func = slot_;}
|
||||
void setSlot(TimerEvent slot) {ret_func = slot;}
|
||||
#ifdef WINDOWS
|
||||
void reset() {t_st = GetCurrentTime();}
|
||||
#else
|
||||
@@ -42,6 +42,12 @@ public:
|
||||
void lock() {mutex_.lock();}
|
||||
void unlock() {mutex_.unlock();}
|
||||
#endif
|
||||
void addDelimiter(int delim, TimerEvent slot = 0) {ret_funcs << TimerSlot(slot, delim);}
|
||||
void removeDelimiter(int delim) {for (int i = 0; i < ret_funcs.size_s(); ++i) if (ret_funcs[i].delim == delim) {ret_funcs.remove(i); i--;}}
|
||||
void removeDelimiter(TimerEvent slot) {for (int i = 0; i < ret_funcs.size_s(); ++i) if (ret_funcs[i].slot == slot) {ret_funcs.remove(i); i--;}}
|
||||
void removeDelimiter(int delim, TimerEvent slot) {for (int i = 0; i < ret_funcs.size_s(); ++i) if (ret_funcs[i].slot == slot && ret_funcs[i].delim == delim) {ret_funcs.remove(i); i--;}}
|
||||
void clearDelimiters() {ret_funcs.clear();}
|
||||
|
||||
double elapsed_n(); // nanoseconds
|
||||
double elapsed_u(); // microseconds
|
||||
double elapsed_m(); // miliseconds
|
||||
@@ -49,7 +55,7 @@ public:
|
||||
|
||||
private:
|
||||
#ifdef WINDOWS
|
||||
void run() {if (ret_func != 0) ret_func(data);}
|
||||
void run();
|
||||
|
||||
long int t_st, t_cur;
|
||||
#else
|
||||
@@ -64,9 +70,16 @@ private:
|
||||
timer_t timer;
|
||||
sigevent se;
|
||||
#endif
|
||||
struct TimerSlot {
|
||||
TimerSlot(TimerEvent slot_ = 0, int delim_ = 1) {slot = slot_; delim = delim_; tick = 0;}
|
||||
TimerEvent slot;
|
||||
int delim;
|
||||
int tick;
|
||||
};
|
||||
|
||||
void * data;
|
||||
TimerEvent ret_func;
|
||||
PIVector<TimerSlot> ret_funcs;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -175,20 +175,20 @@ void PIVariable::setVariable(const PIString & str) {
|
||||
|
||||
void PIVariable::writeVariable(char * dest) {
|
||||
switch (type_) {
|
||||
case PIVariant::Bool: *((bool * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::Char: *((char * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::Short: *((short * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::Int: *((int * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::Long: *((long * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::LLong: *((llong * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::UChar: *((uchar * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::UShort: *((ushort * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::UInt: *((uint * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::ULong: *((ulong * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::ULLong: *((ullong * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::Float: *((float * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::Bool: *((bool * )((long)dest + offset)) = value_ > 0.; return;
|
||||
case PIVariant::Char: *((char * )((long)dest + offset)) = char(value_); return;
|
||||
case PIVariant::Short: *((short * )((long)dest + offset)) = short(value_); return;
|
||||
case PIVariant::Int: *((int * )((long)dest + offset)) = int(value_); return;
|
||||
case PIVariant::Long: *((long * )((long)dest + offset)) = long(value_); return;
|
||||
case PIVariant::LLong: *((llong * )((long)dest + offset)) = llong(value_); return;
|
||||
case PIVariant::UChar: *((uchar * )((long)dest + offset)) = uchar(value_); return;
|
||||
case PIVariant::UShort: *((ushort * )((long)dest + offset)) = ushort(value_); return;
|
||||
case PIVariant::UInt: *((uint * )((long)dest + offset)) = uint(value_); return;
|
||||
case PIVariant::ULong: *((ulong * )((long)dest + offset)) = ulong(value_); return;
|
||||
case PIVariant::ULLong: *((ullong * )((long)dest + offset)) = ullong(value_); return;
|
||||
case PIVariant::Float: *((float * )((long)dest + offset)) = float(value_); return;
|
||||
case PIVariant::Double: *((double * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::LDouble: *((ldouble * )((long)dest + offset)) = value_; return;
|
||||
case PIVariant::LDouble: *((ldouble * )((long)dest + offset)) = ldouble(value_); return;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
serial.odg
Normal file
BIN
serial.odg
Normal file
Binary file not shown.
BIN
serial_.emf
Normal file
BIN
serial_.emf
Normal file
Binary file not shown.
BIN
serial_.odg
Normal file
BIN
serial_.odg
Normal file
Binary file not shown.
2
serial_.svg
Normal file
2
serial_.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 42 KiB |
BIN
Описание.odt
BIN
Описание.odt
Binary file not shown.
BIN
Описание.pdf
Normal file
BIN
Описание.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user