BIG deep clean

This commit is contained in:
2020-06-10 13:14:16 +03:00
parent f579718e0b
commit c59579d5d5
222 changed files with 2392 additions and 11600 deletions

View File

@@ -1,3 +1,22 @@
/*
PIP - Platform Independent Primitives
Bit array
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 "pibitarray.h"
#include "picout.h"

View File

@@ -2,22 +2,22 @@
* \brief Bit array
*/
/*
PIP - Platform Independent Primitives
Bit array
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Bit array
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 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.
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/>.
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 PIBITARRAY_H

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Byte array
Ivan Pelipenko peri4ko@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, 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
@@ -18,7 +18,7 @@
*/
#include "pibytearray.h"
#include "pistring.h"
#include "pistringlist.h"
#include <iostream>
/*! \class PIByteArray

View File

@@ -301,7 +301,6 @@ inline bool operator !=(PIByteArray & f, PIByteArray & s) {if (f.size_s() != s.s
__PIBYTEARRAY_SIMPLE_TYPE__(bool)
__PIBYTEARRAY_SIMPLE_TYPE__(char)
//__PIBYTEARRAY_SIMPLE_TYPE__(uchar)
__PIBYTEARRAY_SIMPLE_TYPE__(short)
__PIBYTEARRAY_SIMPLE_TYPE__(ushort)
__PIBYTEARRAY_SIMPLE_TYPE__(int)

View File

@@ -2,22 +2,22 @@
* \brief Unicode char
*/
/*
PIP - Platform Independent Primitives
Unicode char
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Unicode char
Ivan Pelipenko peri4ko@yandex.ru, 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 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.
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/>.
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"
@@ -75,7 +75,6 @@ ushort charFromCodepage(const char * c, int size, const char * codepage, int * t
if (ret <= 0) return 0;
if (taken) *taken = ret;
return buffer;
//printf("request %d\n", sz);
# else
wchar_t wc(0);
mbtowc(0, 0, 0); // reset mbtowc
@@ -378,10 +377,7 @@ PICout operator <<(PICout s, const PIChar & v) {
} else
#endif
#ifdef WINDOWS
//if (PICout::isBufferActive())
s << v.toSystem();
//else
// s << v.toConsole1Byte();
#else
{
char tc[8];

View File

@@ -2,22 +2,22 @@
* \brief Unicode char
*/
/*
PIP - Platform Independent Primitives
Unicode char
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Unicode char
Ivan Pelipenko peri4ko@yandex.ru, 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 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.
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/>.
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 PICHAR_H
@@ -57,37 +57,14 @@ public:
//! Contructs symbol from no more than 4 bytes of string
PIChar(const char * c, int * bytes = 0);
//inline operator const int() {return static_cast<const int>(ch);}
//inline operator const char() {return toAscii();}
//! Copy operator
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;}*/
//! Compare operator
bool operator ==(const PIChar & o) const;
/*inline bool operator ==(const PIChar & o) const {if (o.isAscii() ^ isAscii()) return false;
if (isAscii()) return (o.toAscii() == toAscii());
return (o.toInt() == toInt());}
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);}
inline bool operator ==(const uchar o) const {return (PIChar(o) == *this);}
inline bool operator ==(const ushort o) const {return (PIChar(o) == *this);}
inline bool operator ==(const uint o) const {return (PIChar(o) == *this);}*/
//! Compare operator
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);}
inline bool operator !=(const uchar o) const {return (PIChar(o) != *this);}
inline bool operator !=(const ushort o) const {return (PIChar(o) != *this);}
inline bool operator !=(const uint o) const {return (PIChar(o) != *this);}*/
//! Compare operator
bool operator >(const PIChar & o) const;

View File

@@ -1,3 +1,22 @@
/*
PIP - Platform Independent Primitives
Binary markup serializator
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 "pichunkstream.h"
/*! \class PIChunkStream
@@ -99,7 +118,6 @@ uint PIChunkStream::readVInt(PIByteArray & s) {
for (abc = 0; abc < 3; ++abc) {
uchar mask = (0x80 >> abc);
if ((bytes[0] & mask) == mask) {
//if (s.isEmpty()) return 0;
bytes[0] &= (mask - 1);
s >> bytes[abc + 1];
} else break;

View File

@@ -2,22 +2,22 @@
* \brief Binary markup serializator
*/
/*
PIP - Platform Independent Primitives
PIP - Platform Independent Primitives
Binary markup serializator
Ivan Pelipenko peri4ko@yandex.ru
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 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.
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/>.
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 PICHUNKSTREAM_H

View File

@@ -1,20 +1,20 @@
/*
PIP - Platform Independent Primitives
Command-Line Parser
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Command-Line Parser
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 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.
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/>.
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 "picli.h"

View File

@@ -2,22 +2,22 @@
* \brief Command-Line parser
*/
/*
PIP - Platform Independent Primitives
Command-Line Parser
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Command-Line Parser
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 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.
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/>.
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 PICLI_H

View File

@@ -1,3 +1,22 @@
/*
PIP - Platform Independent Primitives
Peer - named I/O ethernet node, forming self-organized peering network
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 "picollection.h"

View File

@@ -2,22 +2,22 @@
* \brief Custom elements collection
*/
/*
PIP - Platform Independent Primitives
Peer - named I/O ethernet node, forming self-organized peering network
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Peer - named I/O ethernet node, forming self-organized peering network
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 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.
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/>.
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 PICOLLECTION_H
@@ -72,7 +72,6 @@ public:
protected:
struct Group {
Group(const PIString & name_ = PIString()) {name = name_;}
//~Group() {piCout << "delete group" << name << this; piForeach (const PIObject * o, elements) delete o; elements.clear();}
PIString name;
PIVector<const PIObject * > elements;
};

View File

@@ -1,20 +1,20 @@
/*
PIP - Platform Independent Primitives
Module includes
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Module includes
Ivan Pelipenko peri4ko@yandex.ru, 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 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.
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/>.
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 PICOREMODULE_H
@@ -22,7 +22,6 @@
#include "picollection.h"
#include "piobject.h"
#include "pistatemachine.h"
#include "pitime.h"
#include "picli.h"
#include "pichunkstream.h"

View File

@@ -226,13 +226,6 @@ PICout PICout::operator <<(const PICoutAction v) {
if (isOutputDeviceActive(StdOut)) {
#ifdef WINDOWS
/// TODO : wondows ClearScreen !!!
/*GetConsoleCursorInfo(__Private__::hOut, &curinfo);
curinfo.bVisible = false;
SetConsoleCursorInfo(__Private__::hOut, &curinfo);
SetConsoleCursorPosition(__Private__::hOut, ulcoord);
FillConsoleOutputAttribute(__Private__::hOut, __Private__::dattr, width * (height + 1), ulcoord, &written);
FillConsoleOutputCharacter(__Private__::hOut, ' ', width * (height + 1), ulcoord, &written);*/
#else
printf("\e[H\e[J");
#endif
@@ -262,14 +255,11 @@ PICout PICout::operator <<(const PICoutAction v) {
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v);\
}\
}
//#define PICOUTTOTARGETS(v) {if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v); else printf("%s", (v).dataConsole());}
#define PINUMERICCOUT if (cnb_ == 10) PICOUTTOTARGET(v) else PICOUTTOTARGETS(PIString::fromNumber(v, cnb_))
PICout PICout::operator <<(const char * v) {if (!act_) return *this; if (v[0] == '\0') return *this; space(); quote(); PICOUTTOTARGET(v) quote(); return *this;}
//PICout PICout::operator <<(const std::string & v) {space(); quote(); if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << StdString2PIString(v); else std::cout << (v); quote(); return *this;}
PICout PICout::operator <<(const bool v) {if (!act_) return *this; space(); if (v) PICOUTTOTARGET("true") else PICOUTTOTARGET("false") return *this;}
PICout PICout::operator <<(const char v) {if (!act_) return *this; space(); PICOUTTOTARGET(v) return *this;}

View File

@@ -2,22 +2,22 @@
* \brief General flags class
*/
/*
PIP - Platform Independent Primitives
General flags class
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
General flags class
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 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.
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/>.
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 PIFLAGS_H

View File

@@ -1,20 +1,20 @@
/*
PIP - Platform Independent Primitives
Global includes
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Global includes
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 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.
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/>.
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.h"

View File

@@ -1,20 +1,20 @@
/*
PIP - Platform Independent Primitives
Minimal PIP includes
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Minimal PIP includes
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 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.
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/>.
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 PIINCLUDES_H

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Private PIP includes
Ivan Pelipenko peri4ko@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, 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

View File

@@ -1,20 +1,20 @@
/*
PIP - Platform Independent Primitives
Initialization
PIP - Platform Independent Primitives
Initialization
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 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.
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/>.
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"
@@ -33,20 +33,20 @@
#endif
#ifdef WINDOWS
# include <winsock2.h>
extern FILETIME __pi_ftjan1970;
extern PINtQueryTimerResolution getTimerResolutionAddr;
extern PINtSetTimerResolution setTimerResolutionAddr;
void __PISetTimerResolution() {
if (setTimerResolutionAddr == NULL || getTimerResolutionAddr == NULL)
return;
ULONG _max(0), _min(0), _cur(0);
//printf("getTimerResolution ...\n");
LONG q = getTimerResolutionAddr(&_max, &_min, &_cur);
//printf("getTimerResolution %d %lu %lu %lu\n", q, _min, _max, _cur);
if (q == 0)
setTimerResolutionAddr(_min, TRUE, &_cur);
//printf("setTimerResolution %lu\n", cur);
}
extern FILETIME __pi_ftjan1970;
extern PINtQueryTimerResolution getTimerResolutionAddr;
extern PINtSetTimerResolution setTimerResolutionAddr;
void __PISetTimerResolution() {
if (setTimerResolutionAddr == NULL || getTimerResolutionAddr == NULL)
return;
ULONG _max(0), _min(0), _cur(0);
//printf("getTimerResolution ...\n");
LONG q = getTimerResolutionAddr(&_max, &_min, &_cur);
//printf("getTimerResolution %d %lu %lu %lu\n", q, _min, _max, _cur);
if (q == 0)
setTimerResolutionAddr(_min, TRUE, &_cur);
//printf("setTimerResolution %lu\n", cur);
}
#else
# include <pwd.h>
# ifndef FREERTOS
@@ -64,24 +64,13 @@
# include <mach/mach.h>
# include <mach/clock.h>
//# include <crt_externs.h>
extern clock_serv_t __pi_mac_clock;
extern clock_serv_t __pi_mac_clock;
#endif
#ifdef PIP_ICU
# define U_NOEXCEPT
# include <unicode/uclean.h>
# include <unicode/ucnv.h>
#endif
/*
#ifdef WINDOWS
# include <conio.h>
# include <io.h>
# include <windows.h>
# include <wincon.h>
#else
# include <fcntl.h>
# include <sys/ioctl.h>
# include <pthread.h>
#endif*/
#ifdef HAS_LOCALE
@@ -90,10 +79,10 @@ static locale_t currentLocale_t = 0;
PRIVATE_DEFINITION_START(PIInit)
#ifdef WINDOWS
HMODULE ntlib;
ULONG prev_res;
HMODULE ntlib;
ULONG prev_res;
#endif
bool delete_locs;
bool delete_locs;
PRIVATE_DEFINITION_END(PIInit)
#ifndef FREERTOS
@@ -133,12 +122,12 @@ PIInit::PIInit() {
signal(SIGPIPE, SIG_IGN);
PIStringList ifpathes;
ifpathes << PIStringAscii("/bin/ifconfig") << PIStringAscii("/sbin/ifconfig")
<< PIStringAscii("/usr/bin/ifconfig") << PIStringAscii("/usr/sbin/ifconfig");
<< PIStringAscii("/usr/bin/ifconfig") << PIStringAscii("/usr/sbin/ifconfig");
piForeachC (PIString & i, ifpathes)
if (fileExists(i)) {
sinfo->ifconfigPath = i;
piBreak;
}
if (fileExists(i)) {
sinfo->ifconfigPath = i;
piBreak;
}
# else
// OS version
DWORD dwVersion = GetVersion();
@@ -165,9 +154,7 @@ PIInit::PIInit() {
setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtSetTimerResolution");
__PISetTimerResolution();
}
/*if (setTimerResolution) setTimerResolutionAddr(1, TRUE, &(PRIVATE->prev_res));*/
# endif
//piDebug = true;
# ifdef HAS_LOCALE
//cout << "has locale" << endl;
if (currentLocale_t != 0) {
@@ -241,12 +228,12 @@ PIInit::PIInit() {
GetSystemInfo(&sysinfo);
sinfo->processorsCount = sysinfo.dwNumberOfProcessors;
switch (sysinfo.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_AMD64: sinfo->architecture = PIStringAscii("x86_64"); break;
case PROCESSOR_ARCHITECTURE_ARM: sinfo->architecture = PIStringAscii("arm"); break;
case PROCESSOR_ARCHITECTURE_IA64: sinfo->architecture = PIStringAscii("Intel Itanium-based"); break;
case PROCESSOR_ARCHITECTURE_INTEL: sinfo->architecture = PIStringAscii("x86"); break;
case PROCESSOR_ARCHITECTURE_UNKNOWN:
default: sinfo->architecture = PIStringAscii("unknown"); break;
case PROCESSOR_ARCHITECTURE_AMD64: sinfo->architecture = PIStringAscii("x86_64"); break;
case PROCESSOR_ARCHITECTURE_ARM: sinfo->architecture = PIStringAscii("arm"); break;
case PROCESSOR_ARCHITECTURE_IA64: sinfo->architecture = PIStringAscii("Intel Itanium-based"); break;
case PROCESSOR_ARCHITECTURE_INTEL: sinfo->architecture = PIStringAscii("x86"); break;
case PROCESSOR_ARCHITECTURE_UNKNOWN:
default: sinfo->architecture = PIStringAscii("unknown"); break;
}
int argc_(0);
wchar_t ** argv_ = CommandLineToArgvW(GetCommandLineW(), &argc_);
@@ -284,25 +271,25 @@ PIInit::PIInit() {
sinfo->OS_version = esp_get_idf_version();
#endif
sinfo->OS_name =
#ifdef WINDOWS
PIStringAscii("Windows");
#ifdef WINDOWS
PIStringAscii("Windows");
#else
# ifdef QNX
PIStringAscii("QNX");
# ifdef QNX
PIStringAscii("QNX");
# else
# ifdef MAC_OS
PIStringAscii("MacOS");
# ifdef MAC_OS
PIStringAscii("MacOS");
# else
# ifdef ANDROID
PIStringAscii("Android");
# ifdef ANDROID
PIStringAscii("Android");
# else
# ifdef FREE_BSD
PIStringAscii("FreeBSD");
# ifdef FREE_BSD
PIStringAscii("FreeBSD");
# else
# ifdef FREERTOS
PIStringAscii("FreeRTOS");
# ifdef FREERTOS
PIStringAscii("FreeRTOS");
# else
uns.sysname;
uns.sysname;
# endif
# endif
# endif
@@ -318,7 +305,6 @@ PIInit::~PIInit() {
PIResourcesStorage::instance()->clear();
#ifdef WINDOWS
WSACleanup();
//if (setTimerResolution) setTimerResolutionAddr(PRIVATE->prev_res, TRUE, &(PRIVATE->prev_res));
if (PRIVATE->ntlib) FreeLibrary(PRIVATE->ntlib);
PRIVATE->ntlib = 0;
#endif
@@ -332,67 +318,66 @@ PIInit::~PIInit() {
#ifdef PIP_ICU
u_cleanup();
#endif
//if (currentLocale_t != 0) freelocale(currentLocale_t);
}
bool PIInit::isBuildOptionEnabled(PIInit::BuildOption o) {
switch (o) {
case ICU: return
#ifdef PIP_ICU
case ICU: return
#ifdef PIP_ICU
true;
#else
false;
#endif
case USB: return
#ifdef PIP_USB
case USB: return
#ifdef PIP_USB
true;
#else
false;
#endif
case STL: return
#ifdef PIP_CONTAINERS_STL
case STL: return
#ifdef PIP_CONTAINERS_STL
true;
#else
false;
#endif
case Crypt: return
#ifdef PIP_CRYPT
case Crypt: return
#ifdef PIP_CRYPT
true;
#else
false;
#endif
case Introspection: return
#ifdef PIP_INTROSPECTION
case Introspection: return
#ifdef PIP_INTROSPECTION
true;
#else
false;
#endif
case FFTW: return
#ifdef PIP_FFTW
case FFTW: return
#ifdef PIP_FFTW
true;
#else
false;
#endif
case Compress: return
#ifdef PIP_COMPRESS
case Compress: return
#ifdef PIP_COMPRESS
true;
#else
false;
#endif
case OpenCL: return
#ifdef PIP_OPENCL
case OpenCL: return
#ifdef PIP_OPENCL
true;
#else
false;
#endif
case Cloud: return
#ifdef PIP_CLOUD
true;
case Cloud: return
#ifdef PIP_CLOUD
true;
#else
false;
false;
#endif
default: return false;
default: return false;
}
return false;
}

View File

@@ -2,22 +2,22 @@
* \brief Initialization
*/
/*
PIP - Platform Independent Primitives
Initialization
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Initialization
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 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.
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/>.
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 PIINIT_H

View File

@@ -1,20 +1,20 @@
/*
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
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 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.
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/>.
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 "piobject.h"
@@ -73,7 +73,6 @@ PIString PIObject::__MetaFunc::fullFormat() const {
PIObject::PIObject(const PIString & name): _signature_(__PIOBJECT_SIGNATURE__), emitter_(0), thread_safe_(false), proc_event_queue(false) {
//__PIVariantInitBuiltin__();
setName(name);
setDebug(true);
mutexObjects().lock();
@@ -181,14 +180,6 @@ void PIObject::piConnect(const PIString & src, const PIString & sig, const PIStr
d->connectors << s;
}
/*
PIStringList PIObject::events() {
PIStringList l;
for (PIMap<NamedFunction, PIString>::const_iterator i = signals_.begin(); i != signals_.end(); i++)
l << (*i).first;
return l;
}
*/
PIStringList PIObject::scopeList() const {
PIMutexLocker ml(__meta_mutex());
@@ -580,8 +571,6 @@ bool PIObject::isPIObject(const PIObject * o) {
}
void PIObject::dump(const PIString & line_prefix) const {
//printf("dump %s \"%s\"\n", className(), name().data());
PICout(PICoutManipulators::AddNewLine) << line_prefix << "class " << className() << " (" << (const void*)this << ", \"" << name() << "\") {";
@@ -627,8 +616,6 @@ void PIObject::dump(const PIString & line_prefix) const {
}
void dumpApplication() {
PIMutexLocker _ml(PIObject::mutexObjects());
//printf("dump application ...\n");
@@ -654,6 +641,7 @@ void dumpApplication() {
//printf("dump application done\n");
}
#ifndef FREERTOS
bool dumpApplicationToFile(const PIString & path) {
PIFile f(path + "_tmp");
@@ -672,8 +660,6 @@ bool dumpApplicationToFile(const PIString & path) {
#endif
void PIObject::__MetaData::addScope(const PIString & s, uint shash) {
if (!scope_id.contains(shash)) {
scope_list << s;
@@ -682,8 +668,6 @@ void PIObject::__MetaData::addScope(const PIString & s, uint shash) {
}
void PIObject::__Connection::destroy() {
#ifdef PIP_CXX11_SUPPORT
if (functor) delete functor;

View File

@@ -4,22 +4,22 @@
* This file declare PIObject class and associated macros
*/
/*
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
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 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.
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/>.
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 PIOBJECT_H

View File

@@ -1,3 +1,22 @@
/*
PIP - Platform Independent Primitives
Storage of properties for GUI usage
Ivan Pelipenko peri4ko@yandex.ru, 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/>.
*/
#include "pipropertystorage.h"

View File

@@ -1,334 +0,0 @@
/*! \file pistatemachine.h
* \brief Base class for custom state machine
*/
/*
PIP - Platform Independent Primitives
State machine
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 PISTATEMACHINE_H
#define PISTATEMACHINE_H
#include "piobject.h"
/*! \brief Base class for custom state machine
*
* \section PIStateMachine_synopsis Synopsis
* This class provide functionality of state machine.
* You should inherit from this class, implement \a execution()
* and \a transition() functions, set rules and periodically
* call \a tick() function to proper work of machine.
*
* \section PIStateMachine_prepare Prepare for work
* %State machine operates with "state", "rule" and "condition".
* * "State" is some class (by default \c int), associated name and
* optional "handler" - pointer to function executed on every \a tick();
* * "Rule" define rule of transition from one machine state to other.
* It is also has optional "handler";
* * "Condition" is a part of rule and define possibility of transition.
*
* First of all you should define states of your machine by function
* \a addState(). Then you should define transition rules for machine
* by function \a addRule(). Finally you can set initial state by function
* \a setInitialState() and provide periodically execution of function
* \a tick().
*
* \section PIStateMachine_principle Principle of work
* At any time the state machine is in some state. You can ask machine
* to enter in new state by function \a switchToState(). If all conditions
* done machine switch it state immediately, else machine remember request
* and will be try switch to the new state every tick. Successfull state
* switching execute function \a transition(), every tick execute
* function \a execution() with current state. On successfull transition
* if rule "handler" is not null it execute. Every \a tick() if current
* state "handler" is not null it execute.
*
* \section PIStateMachine_conditions Conditions
* Each rule has transition condition. Condition is array of pairs
* (string, number). It means that every condition by name "string"
* should be performed as least "number" times. Empty condition always
* permits transition.
*
* %State machine have current performed conditions. You can read this
* conditions by function \a currentConditions() and perform new
* conditions by functions \a performCondition() and \a performConditions().
* Currend conditions can de erased by function \a resetConditions().
*
* \section PIStateMachine_example Example
* This is simple example demonstrates all features:
* \snippet pistatemachine.cpp main
*/
template <typename Type = int>
class PIP_EXPORT PIStateMachine: public PIObject
{
PIOBJECT_SUBCLASS(PIStateMachine, PIObject)
public:
//! Constructs an empty state machine
PIStateMachine(void * _parent = 0) {if (_parent == 0) parent_ = this; else parent_ = _parent; resetConditions();}
~PIStateMachine() {;}
//! %Condition is a pair (string, number)
typedef PIPair<PIString, int> Condition;
//! %Rule of transition between states of machine
struct Rule {
//! Constuctor
Rule() {handler = 0; from = to = Type(); autoTransition = resetAllConditions = false;}
//! Constuctor
Rule(Type f, Type t, const PIStringList & c = PIStringList(), Handler h = 0, bool at = false, bool rac = false) {
from = f;
to = t;
for (int i = 0; i < c.size_s(); ++i)
conditions << Condition(c[i], 1);
autoTransition = at;
resetAllConditions = rac;
handler = h;
}
//! Source state
Type from;
//! Destination state
Type to;
//! %Conditions of transition
PIVector<Condition> conditions;
//! Automatic transition
bool autoTransition;
//! Reset or not all performed conditions of machine on transition
bool resetAllConditions;
//! Pointer to function executed on transition
Handler handler;
//! Add condition of transition
void addCondition(const PIString & name, int times = 1) {if (times > 0) conditions << Condition(name, times);}
bool operator ==(const Rule & other) const {return (from == other.from) && (to == other.to);}
bool operator !=(const Rule & other) const {return (from != other.from) || (to != other.to);}
};
//! %State of machine
struct State {
//! Constuctor
State() {handler = 0; value = Type();}
//! Constuctor
State(Type v, const PIString & n = "", Handler h = 0) {value = v; name = n; handler = h;}
//! %State value
Type value;
//! %State name
PIString name;
//! Pointer to function executed on tick
Handler handler;
bool operator ==(const State & other) const {return value == other.value;}
bool operator !=(const State & other) const {return value != other.value;}
};
void * parent() const {return parent_;}
void setParent(void * parent) {parent_ = parent;}
//! Add state of machine
void addState(Type value, const PIString & name = "", Handler handler = 0) {if (states_.contains(State(value, name))) return; states_ << State(value, name, handler);}
//! States count
int statesCount() const {return states_.size_s();}
//! Remove all states
void clearStates() {states_.clear();}
//! Add rule of transition
void addRule(Type from, Type to, const PIString & condition, Handler handler = 0, bool autoTransition = false, bool resetAllConditions = false) {if (rules_.contains(Rule(from, to))) return; rules_ << Rule(from, to, PIStringList(condition), handler, autoTransition, resetAllConditions);}
//! Add rule of transition
void addRule(Type from, Type to, Handler handler, bool autoTransition = false, bool resetAllConditions = false) {if (rules_.contains(Rule(from, to))) return; rules_ << Rule(from, to, PIStringList(), handler, autoTransition, resetAllConditions);}
//! Add rule of transition
void addRule(Type from, Type to, const PIStringList & conditions = PIStringList(), Handler handler = 0, bool autoTransition = false, bool resetAllConditions = false) {if (rules_.contains(Rule(from, to))) return; rules_ << Rule(from, to, conditions, handler, autoTransition, resetAllConditions);}
//! Add rule of transition
void addRule(const Rule & rule) {if (rules_.contains(rule)) return; rules_ << rule;}
//! Rules count
int rulesCount() const {return rules_.size_s();}
//! Remove all rules
void clearRules() {rules_.clear();}
//! Setup initial state. \a reset() will set machine state to "value"
void setInitialState(Type value) {
for (int i = 0; i < states_.size_s(); ++i)
if (states_[i].value == value) {
init_ = state_ = states_[i];
return;
}
}
/** \brief Try to switch machine state to state "to"
* \details If there is rule of transition exists and this rule conditions
* is performed then machine switched to new state immediately. Otherwise machine
* will be try to enter to new state every \a tick().
* \return \c true if state switched immediately, otherwise \c false */
bool switchToState(Type to) {
switch_to = to;
for (int i = 0; i < rules_.size_s(); ++i) {
Rule & r(rules_[i]);
if ((r.from != state_.value) || (r.to != to)) continue;
if (!checkConditions(r)) continue;
State ts = findState(to);
if (r.handler != 0 && parent_ != 0) r.handler(parent_);
transition(state_, ts);
state_ = ts;
resetConditions(r);
return true;
}
return false;
}
//! Reset machine state to initial and clear all conditions
void reset() {state_ = init_; resetConditions();}
//! Returns current state of machine
const State & currentState() const {return state_;}
//! Reset all performed conditions
void resetConditions() {cond.clear(); cond_count = 0;}
//! Reset performed condition with name "name"
void resetCondition(const PIString & name) {
for (int i = 0; i < cond.size_s(); ++i)
if (cond[i].first == name) {
cond.remove(i);
i--;
}
}
//! Perform condition with name "name" "times" times.
void performCondition(const PIString & name, int times = 1) {
if (times <= 0) return;
for (int i = 0; i < cond.size_s(); ++i)
if (cond[i].first == name) {
cond[i].second += times;
return;
}
cond << Condition(name, times);
}
//! Perform every condition with name from "names" one time.
void performConditions(const PIStringList & names) {
bool ok;
for (int n = 0; n < names.size_s(); ++n) {
ok = false;
for (int i = 0; i < cond.size_s(); ++i) {
if (cond[i].first == names[n]) {
cond[i].second++;
ok = true;
break;
}
}
if (ok) continue;
cond << Condition(names[n], 1);
}
}
//! Returns all current performed conditions
const PIVector<Condition> & currentConditions() const {return cond;}
Type * currentState_ptr() {return &state_.value;}
int * conditionsCount_ptr() {cond_count = cond.size_s(); return &cond_count;}
//! \handlers
//! \{
//! \fn void tick()
//! \brief Main function of machine. Execute \a execution() and check if need to switch state
//! \fn void tick(void * data, int delim)
//! \brief Main function of machine. Execute \a execution() and check if need to switch state
//! \}
EVENT_HANDLER(void, tick) {tick(0, 0);}
EVENT_HANDLER2(void, tick, void * , data, int, delim) {
execution(state_);
if (state_.handler != 0 && parent_ != 0) state_.handler(parent_);
if (switch_to != state_.value) switchToState(switch_to);
else {
piForeachC (Rule & r, rules_) {
if (!r.autoTransition || r.from != state_.value) continue;
if (checkConditions(r)) {
switchToState(r.to);
break;
}
}
}
}
protected:
//! Reimplement this function to process current state of machine
virtual void execution(const State & state) {;}
//! Reimplement this function to process switching current state of machine
virtual void transition(const State & from, const State & to) {;}
private:
State findState(Type value) {
for (int i = 0; i < states_.size_s(); ++i)
if (states_[i].value == value)
return states_[i];
return State();
}
bool checkConditions(const Rule & rule) {
//if (cond.size_s() < rule.conditions.size_s()) return false;
int oc = 0;
for (int i = 0; i < cond.size_s(); ++i) {
PIString & rn(cond[i].first);
for (int j = 0; j < rule.conditions.size_s(); ++j) {
if (rn != rule.conditions[j].first) continue;
if (cond[i].second < rule.conditions[j].second) return false;
oc++;
}
}
return (rule.conditions.size_s() == oc);
}
void resetConditions(const Rule & rule) {
if (rule.resetAllConditions) {
cond.clear();
return;
}
for (int i = 0; i < cond.size_s(); ++i) {
PIString & rn(cond[i].first);
for (int j = 0; j < rule.conditions.size_s(); ++j) {
if (rn != rule.conditions[j].first) continue;
cond[i].second -= rule.conditions[j].second;
if (cond[i].second <= 0) {
cond.remove(i);
i--;
}
}
}
}
PIVector<State> states_;
PIVector<Rule> rules_;
State init_, state_;
Type switch_to;
void * parent_;
int cond_count;
PIVector<Condition> cond;
};
#endif // PISTATEMACHINE_H

View File

@@ -1,23 +1,25 @@
/*
PIP - Platform Independent Primitives
String
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
String
Ivan Pelipenko peri4ko@yandex.ru, 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 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.
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/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piincludes_p.h"
#include "pistring.h"
#include "pistringlist.h"
#ifdef PIP_ICU
# define U_NOEXCEPT
# include "unicode/ucnv.h"
@@ -216,7 +218,6 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
else base = 10;
} else
if (base < 2 || base > 40) {if (ok != 0) *ok = false; return 0;}
//v.reverse();
if (ok) *ok = true;
PIVector<int> digits;
llong ret = 0, m = 1;
@@ -236,14 +237,6 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
m *= base;
}
if (neg) ret = -ret;
/*piForeachC (PIChar & i, v) {
if (i == PIChar('-')) {ret = -ret; continue;}
cs = fromBaseN[int(i.toAscii())];
cout << i << " = " << cs << endl;
if (cs < 0 || cs >= base) return ret;
ret += cs * m;
m *= base;
}*/
return ret;
}
@@ -494,29 +487,6 @@ PIString & PIString::operator +=(const char * str) {
PIString & PIString::operator +=(const wchar_t * str) {
if (!str) return *this;
//cout << "wc" << endl;
/*int l = 0, sz;
char * c = new char[MB_CUR_MAX];
while (str[l] != 0) ++l;
for (int i = 0; i < l; ++i) {
sz = wctomb(c, str[i]);
switch (sz) {
case 4:
push_back(PIChar(*(int*)c));
continue;
case 3:
push_back(PIChar(*(int*)c));
back().ch &= 0xFFFFFF;
continue;
case 2:
push_back(PIChar(*(short * )c));
continue;
default:
push_back(PIChar(c[0]));
break;
}
}
delete[] c;*/
int i = -1;
while (str[++i])
push_back(PIChar(ushort(str[i])));
@@ -589,9 +559,6 @@ PIString PIString::mid(const int start, const int len) const {
} else {
if (l > length() - s)
l = length() - s;
//for (int i = s; i < s + l; ++i)
// str += at(i);
// std::cout << "mid " << s << " " << l << " " << size_s() << " " << start << " " << len << "\n";
return PIString(&(at(s)), l);
}
return PIString();
@@ -668,8 +635,6 @@ PIString & PIString::replaceAll(const PIString & what, const PIString & with) {
PIString & PIString::insert(int index, const PIString & str) {
//uint c = str.length();
//for (uint i = 0; i < c; ++i) insert(index + i, str[i]);
PIDeque<PIChar>::insert(index, *((const PIDeque<PIChar>*)&str));
return *this;
}
@@ -1094,46 +1059,6 @@ ldouble PIString::toLDouble() const {
return atof(toNativeDecimalPoints().data());
}
/*
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);
return v;
}
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);
return v;
}
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);
return v;
}
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);
return v;
}
*/
PIString & PIString::setReadableSize(llong bytes) {
clear();
@@ -1164,20 +1089,19 @@ PIString & PIString::setReadableSize(llong bytes) {
inline char chrUpr(char c) {
if (c >= 'a' && c <= 'z') return c + 'A' - 'a';
//if (c >= 'а' && c <= 'я') return c + 'А' - 'а';
return c;
}
inline char chrLwr(char c) {
if (c >= 'A' && c <= 'Z') return c + 'a' - 'A';
//if (c >= 'А' && c <= 'Я') return c + 'а' - 'А';
return c;
}
const static PIString _versionDelims_ = PIStringAscii("._-+");
void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
s.trim();
if (s.isEmpty()) {
@@ -1220,6 +1144,7 @@ void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
//piCout << codes << strs;
}
int versionLabelValue(PIString s) {
int ret = -10000;
if (s.isEmpty()) return 0;
@@ -1240,6 +1165,7 @@ int versionLabelValue(PIString s) {
return ret;
}
int versionCompare(const PIString & v0, const PIString & v1, int components) {
PIStringList strs[2]; PIVector<int> codes[2];
parseVersion(v0.toLowerCase(), codes[0], strs[0]);
@@ -1291,35 +1217,9 @@ PICout operator <<(PICout s, const PIString & v) {
s.space();
s.quote();
s.setControl(0, true);
//if (PICout::isBufferActive())
s << v.data();
//else {
// s << v.dataConsole();
//}
s << v.data();
s.restoreControl();
s.quote();
return s;
}
PIStringList& PIStringList::removeDuplicates() {
PIStringList l;
PIString s;
bool ae;
for (int i = 0; i < size_s(); ++i) {
ae = false;
s = at(i);
for (int j = 0; j < l.size_s(); ++j) {
if (s != l[j]) continue;
ae = true; break;
}
if (!ae) {
l << s;
continue;
}
remove(i);
--i;
}
return *this;
}

View File

@@ -4,22 +4,22 @@
* This file declare string and string list classes
*/
/*
PIP - Platform Independent Primitives
String
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
String
Ivan Pelipenko peri4ko@yandex.ru, 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 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.
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/>.
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 PISTRING_H
@@ -43,14 +43,12 @@ public:
static const float ElideCenter;
static const float ElideRight ;
//inline PIString & operator +=(const char c) {push_back(c); return *this;}
PIString & operator +=(const PIChar & c) {push_back(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 char c) {*this += c;}
PIString(const PIString & o): PIDeque<PIChar>() {*this += o;}
@@ -85,19 +83,6 @@ 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 short & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const ushort & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const int & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const uint & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const long & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const ulong & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const llong & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const ullong & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const float & value): PIDeque<PIChar>() {*this = fromNumber(value);}
// PIString(const double & value): PIDeque<PIChar>() {*this = fromNumber(value);}
~PIString() {}
@@ -122,7 +107,6 @@ public:
//! Compare operator
bool operator ==(const PIChar c) const {return *this == PIString(c);}
//inline bool operator ==(const char c) const {return *this == PIString(c);}
//! Compare operator
bool operator ==(const char * str) const {return *this == PIString(str);}
@@ -132,7 +116,6 @@ public:
//! Compare operator
bool operator !=(const PIChar c) const {return *this != PIString(c);}
//inline bool operator !=(const char c) const {return *this != PIString(c);}
//! Compare operator
bool operator !=(const char * str) const {return *this != PIString(str);}
@@ -142,7 +125,6 @@ public:
//! Compare operator
bool operator <(const PIChar c) const {return *this < PIString(c);}
//inline bool operator <(const char c) const {return *this < PIString(c);}
//! Compare operator
bool operator <(const char * str) const {return *this < PIString(str);}
@@ -152,7 +134,6 @@ public:
//! Compare operator
bool operator >(const PIChar c) const {return *this > PIString(c);}
//inline bool operator >(const char c) const {return *this > PIString(c);}
//! Compare operator
bool operator >(const char * str) const {return *this > PIString(str);}
@@ -162,7 +143,6 @@ public:
//! Compare operator
bool operator <=(const PIChar c) const {return *this <= PIString(c);}
//inline bool operator <=(const char c) const {return *this <= PIString(c);}
//! Compare operator
bool operator <=(const char * str) const {return *this <= PIString(str);}
@@ -172,29 +152,13 @@ public:
//! Compare operator
bool operator >=(const PIChar c) const {return *this >= PIString(c);}
//inline bool operator >=(const char c) const {return *this >= PIString(c);}
//! Compare operator
bool operator >=(const char * str) const {return *this >= PIString(str);}
// operator bool() const {return toBool();}
// operator short() const {return toShort();}
// operator ushort() const {return toUShort();}
// operator int() const {return toInt();}
// operator uint() const {return toUInt();}
// operator long() const {return toLong();}
// operator ulong() const {return toULong();}
// operator llong() const {return toLLong();}
// operator ullong() const {return toULLong();}
// operator float() const {return toFloat();}
// operator double() const {return toDouble();}
/*! \brief Append string "str" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(PIString) */
PIString & operator <<(const PIString & str) {*this += str; return *this;}
// inline PIString & operator <<(const char c) {*this += c; return *this;}
/*! \brief Append symbol "c" at the end of string
* \details Example: \snippet pistring.cpp PIString::<<(PIChar) */
@@ -633,8 +597,6 @@ public:
//! \details Example: \snippet pistring.cpp PIString::toFloat
ldouble toLDouble() const;
//inline PIString & setNumber(const char value) {clear(); *this += itos(value); return *this;}
//! \brief Set string content to numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::setNumber
PIString & setNumber(const short value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;}
@@ -683,8 +645,6 @@ public:
//! \details Example: \snippet pistring.cpp PIString::setReadableSize
PIString & setReadableSize(llong bytes);
//inline static PIString fromNumber(const char value) {return PIString(itos(value));}
//! \brief Return string contains numeric representation of "value" in base "base"
//! \details Example: \snippet pistring.cpp PIString::fromNumber
static PIString fromNumber(const short value, int base = 10, bool * ok = 0) {return fromNumberBaseS(llong(value), base, ok);}
@@ -793,13 +753,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIString & v) {v.clear(); s >>
//! \relatesalso PIString \brief Return concatenated string
inline PIString operator +(const PIString & str, const PIString & f) {PIString s(str); s += f; return s;}
//inline PIString operator +(const PIString & f, const char c) {PIString s(f); s.push_back(c); return s;}
//! \relatesalso PIString \brief Return concatenated string
inline PIString operator +(const PIString & f, const char * str) {PIString s(f); s += str; return s;}
//inline PIString operator +(const char c, const PIString & f) {return PIString(c) + f;}
//! \relatesalso PIString \brief Return concatenated string
inline PIString operator +(const char * str, const PIString & f) {return PIString(str) + f;}
@@ -812,79 +768,6 @@ int versionCompare(const PIString & v0, const PIString & v1, int components = 6)
PIString versionNormalize(const PIString & v);
/*!\brief Strings array class
* \details This class is based on \a PIDeque<PIString> and
* expand it functionality. */
class PIP_EXPORT PIStringList: public PIDeque<PIString>
{
public:
//! Contructs empty strings list
PIStringList() {;}
~PIStringList() {;}
//! Contructs strings list with one string "str"
PIStringList(const PIString & str) {push_back(str);}
//! Contructs empty strings list with strings "s0" and "s1"
PIStringList(const PIString & s0, const PIString & s1) {push_back(s0); push_back(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);}
//! 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(const PIStringList & o): PIDeque<PIString>() {resize(o.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = o[i];}
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];}
//! \brief Join all strings in one with delimiter "delim" and return it
//! \details Example: \snippet pistring.cpp PIStringList::join
PIString join(const PIString & delim) const {PIString s; for (uint i = 0; i < size(); ++i) {s += at(i); if (i < size() - 1) s += delim;} return s;}
//! \brief Remove all strings equal "value" and return this
//! \details Example: \snippet pistring.cpp PIStringList::removeStrings
PIStringList & removeStrings(const PIString & value) {for (uint i = 0; i < size(); ++i) {if (at(i) == value) {remove(i); --i;}} return *this;}
PIStringList & remove(uint num) {PIDeque<PIString>::remove(num); return *this;}
PIStringList & remove(uint num, uint count) {PIDeque<PIString>::remove(num, count); return *this;}
//! \brief Remove duplicated strings and return this
//! \details Example: \snippet pistring.cpp PIStringList::removeDuplicates
PIStringList & removeDuplicates();
//! \brief Trim all strings
//! \details Example: \snippet pistring.cpp PIStringList::trim
PIStringList & trim() {for (uint i = 0; i < size(); ++i) at(i).trim(); return *this;}
//! Return sum of lengths of all strings
uint contentSize() {uint s = 0; for (uint i = 0; i < size(); ++i) s += at(i).size(); return s;}
//! Compare operator
bool operator ==(const PIStringList & o) const {if (size() != o.size()) return false; for (size_t i = 0; i < size(); ++i) if (o[i] != (*this)[i]) return false; return true;}
//! Compare operator
bool operator !=(const PIStringList & o) const {return !(o == (*this));}
PIStringList & operator =(const PIStringList & o) {PIDeque<PIString>::operator=(o); return *this;}
PIStringList & operator <<(const PIString & str) {append(str); return *this;}
PIStringList & operator <<(const PIStringList & sl) {append(sl); return *this;}
};
//! \relatesalso PIStringList \relatesalso PIByteArray \brief Output operator to PIByteArray
inline PIByteArray & operator <<(PIByteArray & s, const PIStringList & v) {s << int(v.size_s()); for (int i = 0; i < v.size_s(); ++i) s << v[i]; return s;}
//! \relatesalso PIStringList \relatesalso PIByteArray \brief Input operator from PIByteArray
inline PIByteArray & operator >>(PIByteArray & s, PIStringList & v) {int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;}
//! \relatesalso PIStringList \relatesalso PICout \brief Output operator to PICout
inline PICout operator <<(PICout s, const PIStringList & v) {s.space(); s.setControl(0, true); s << "{"; for (uint i = 0; i < v.size(); ++i) {s << "\"" << v[i] << "\""; if (i < v.size() - 1) s << ", ";} s << "}"; s.restoreControl(); return s;}
template<> inline uint piHash(const PIString & s) {return s.hash();}

View File

@@ -5,8 +5,8 @@
*/
/*
PIP - Platform Independent Primitives
STD for PIString
Ivan Pelipenko peri4ko@yandex.ru
STD for PIString
Ivan Pelipenko peri4ko@yandex.ru, 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
@@ -28,7 +28,7 @@
typedef std::basic_string<wchar_t> wstring;
#endif
#include "pistring.h"
#include "pistringlist.h"
inline std::string PIString2StdString(const PIString & v) {
@@ -42,12 +42,6 @@ inline std::string PIString2StdString(const PIString & v) {
s.push_back(char(tc));
wc >>= 8;
}
/*if (at(i).isAscii())
s.push_back(at(i).toAscii());
else {
s.push_back(at(i).toCharPtr()[0]);
s.push_back(at(i).toCharPtr()[1]);
}*/
}
}
return s;

View File

@@ -0,0 +1,42 @@
/*
PIP - Platform Independent Primitives
Strings array class
Ivan Pelipenko peri4ko@yandex.ru, 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/>.
*/
#include "pistringlist.h"
PIStringList& PIStringList::removeDuplicates() {
PIStringList l;
PIString s;
bool ae;
for (int i = 0; i < size_s(); ++i) {
ae = false;
s = at(i);
for (int j = 0; j < l.size_s(); ++j) {
if (s != l[j]) continue;
ae = true; break;
}
if (!ae) {
l << s;
continue;
}
remove(i);
--i;
}
return *this;
}

View File

@@ -0,0 +1,100 @@
/*! \brief Strings array class
* \details This class is based on \a PIDeque<PIString> and
* expand it functionality. */
/*
PIP - Platform Independent Primitives
Strings array class
Ivan Pelipenko peri4ko@yandex.ru, 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 PISTRINGLIST_H
#define PISTRINGLIST_H
#include "pistring.h"
class PIP_EXPORT PIStringList: public PIDeque<PIString>
{
public:
//! Contructs empty strings list
PIStringList() {;}
~PIStringList() {;}
//! Contructs strings list with one string "str"
PIStringList(const PIString & str) {push_back(str);}
//! Contructs empty strings list with strings "s0" and "s1"
PIStringList(const PIString & s0, const PIString & s1) {push_back(s0); push_back(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);}
//! 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(const PIStringList & o): PIDeque<PIString>() {resize(o.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = o[i];}
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];}
//! \brief Join all strings in one with delimiter "delim" and return it
//! \details Example: \snippet pistring.cpp PIStringList::join
PIString join(const PIString & delim) const {PIString s; for (uint i = 0; i < size(); ++i) {s += at(i); if (i < size() - 1) s += delim;} return s;}
//! \brief Remove all strings equal "value" and return this
//! \details Example: \snippet pistring.cpp PIStringList::removeStrings
PIStringList & removeStrings(const PIString & value) {for (uint i = 0; i < size(); ++i) {if (at(i) == value) {remove(i); --i;}} return *this;}
PIStringList & remove(uint num) {PIDeque<PIString>::remove(num); return *this;}
PIStringList & remove(uint num, uint count) {PIDeque<PIString>::remove(num, count); return *this;}
//! \brief Remove duplicated strings and return this
//! \details Example: \snippet pistring.cpp PIStringList::removeDuplicates
PIStringList & removeDuplicates();
//! \brief Trim all strings
//! \details Example: \snippet pistring.cpp PIStringList::trim
PIStringList & trim() {for (uint i = 0; i < size(); ++i) at(i).trim(); return *this;}
//! Return sum of lengths of all strings
uint contentSize() {uint s = 0; for (uint i = 0; i < size(); ++i) s += at(i).size(); return s;}
//! Compare operator
bool operator ==(const PIStringList & o) const {if (size() != o.size()) return false; for (size_t i = 0; i < size(); ++i) if (o[i] != (*this)[i]) return false; return true;}
//! Compare operator
bool operator !=(const PIStringList & o) const {return !(o == (*this));}
PIStringList & operator =(const PIStringList & o) {PIDeque<PIString>::operator=(o); return *this;}
PIStringList & operator <<(const PIString & str) {append(str); return *this;}
PIStringList & operator <<(const PIStringList & sl) {append(sl); return *this;}
};
//! \relatesalso PIStringList \relatesalso PIByteArray \brief Output operator to PIByteArray
inline PIByteArray & operator <<(PIByteArray & s, const PIStringList & v) {s << int(v.size_s()); for (int i = 0; i < v.size_s(); ++i) s << v[i]; return s;}
//! \relatesalso PIStringList \relatesalso PIByteArray \brief Input operator from PIByteArray
inline PIByteArray & operator >>(PIByteArray & s, PIStringList & v) {int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;}
//! \relatesalso PIStringList \relatesalso PICout \brief Output operator to PICout
inline PICout operator <<(PICout s, const PIStringList & v) {s.space(); s.setControl(0, true); s << "{"; for (uint i = 0; i < v.size(); ++i) {s << "\"" << v[i] << "\""; if (i < v.size() - 1) s << ", ";} s << "}"; s.restoreControl(); return s;}
#endif // PISTRINGLIST_H

View File

@@ -1,21 +1,22 @@
/*
PIP - Platform Independent Primitives
Timer
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Timer
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 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.
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/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piincludes_p.h"
#include "pitime.h"
#include "pisystemtests.h"
@@ -244,8 +245,6 @@ PISystemTime PISystemTime::current(bool precise_but_not_system) {
ullong lt = ullong(sft.dwHighDateTime) * 0x100000000U + ullong(sft.dwLowDateTime);
return PISystemTime(lt / 10000000U, (lt % 10000000U) * 100U);
}
//long t_cur = GetCurrentTime();
//return PISystemTime(t_cur / 1000, (t_cur % 1000) * 1000000);
#else
# ifdef MAC_OS
mach_timespec_t t_cur;

View File

@@ -2,22 +2,22 @@
* \brief Time structs
*/
/*
PIP - Platform Independent Primitives
Time structs
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Time structs
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 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.
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/>.
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 PITIME_H

View File

@@ -31,11 +31,6 @@
#include <windows.h>
//inline PISystemTime SYSTEMTIME2PISystemTime(SYSTEMTIME &t) {
// PISystemTime st;
//}
inline PISystemTime FILETIME2PISystemTime(const FILETIME &t) {
PISystemTime st;
ullong lt = ullong(t.dwHighDateTime) * 0x100000000U + ullong(t.dwLowDateTime);

View File

@@ -82,8 +82,6 @@ struct PIP_EXPORT __PIVariantTypeInfo__ {
__TYPEINFO_SINGLE(T, T &) \
__TYPEINFO_SINGLE(T, const T) \
__TYPEINFO_SINGLE(T, const T &)
//__TYPEINFO_SINGLE(T, T *)
//__TYPEINFO_SINGLE(T, const T *)
class PIP_EXPORT __PIVariantInfoStorage__ {
@@ -465,31 +463,6 @@ public:
* Otherwise returns content as type T. */
template<typename T>
T value() const {return getAsValue<T>(*this);}
/*
operator bool() const {return toBool();}
operator char() const {return toInt();}
operator uchar() const {return toInt();}
operator short() const {return toInt();}
operator ushort() const {return toInt();}
operator int() const {return toInt();}
operator uint() const {return toInt();}
operator long() const {return toInt();}
operator ulong() const {return toInt();}
operator llong() const {return toLLong();}
operator ullong() const {return (ullong)toLLong();}
operator float() const {return toFloat();}
operator double() const {return toDouble();}
operator ldouble() const {return toLDouble();}
operator PITime() const {return toTime();}
operator PIDate() const {return toDate();}
operator PIDateTime() const {return toDateTime();}
operator PIString() const {return toString();}
operator PIStringList() const {return toStringList();}
operator PIBitArray() const {return toBitArray();}
operator PIByteArray() const {return toByteArray();}
operator const char*() const {return toString().data();}
operator void*() const {return (void*)(toLLong());}
*/
//! Assign operator
PIVariant & operator =(const PIVariant & v);
@@ -683,7 +656,6 @@ template<> inline PIVariantTypes::IODevice PIVariant::value() const {return toIO
template<> inline PIPointd PIVariant::value() const {return toPoint();}
template<> inline PIRectd PIVariant::value() const {return toRect();}
//template<> inline PIVariant PIVariant::fromValue(const char * v) {return PIVariant(PIString(v));}
template<> inline PIVariant PIVariant::fromValue(const bool & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const char & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const uchar & v) {return PIVariant(v);}

View File

@@ -25,7 +25,7 @@
#ifndef PIVARIANTYPES_H
#define PIVARIANTYPES_H
#include "pistring.h"
#include "pistringlist.h"
class PIPropertyStorage;
@@ -33,125 +33,125 @@ class PIPropertyStorage;
namespace PIVariantTypes {
/**
* @brief name-value pair
*/
struct PIP_EXPORT Enumerator {
Enumerator(int v = 0, const PIString & n = PIString()): value(v), name(n) {}
int value;
PIString name;
};
/**
* @brief name-value pair
*/
struct PIP_EXPORT Enumerator {
Enumerator(int v = 0, const PIString & n = PIString()): value(v), name(n) {}
int value;
PIString name;
};
/**
* @brief Collection of PIVariantTypes::Enumerator. It's replace classic c-style enum.
* Contains elements with unique name and not uniqueue values.
*/
struct PIP_EXPORT Enum {
Enum(const PIString & n = PIString()): enum_name(n) {}
PIString toString() const {return selected;} // obsolete
/**
* @brief Collection of PIVariantTypes::Enumerator. It's replace classic c-style enum.
* Contains elements with unique name and not uniqueue values.
* @brief Find selected value.
* @return selected value, otherwrise 0
*/
struct PIP_EXPORT Enum {
Enum(const PIString & n = PIString()): enum_name(n) {}
PIString toString() const {return selected;} // obsolete
int selectedValue() const;
/**
* @brief Find selected value.
* @return selected value, otherwrise 0
*/
int selectedValue() const;
/**
* @brief Get selected name
* @return selected name, otherwrise empty PIString
*/
PIString selectedName() const {return selected;}
/**
* @brief Get selected name
* @return selected name, otherwrise empty PIString
*/
PIString selectedName() const {return selected;}
/**
* @brief Select value if exists in Enum. If Enum contains several PIVariantTypes::Enumerator with same values,
* first PIVariantTypes::Enumerator will selected
* @param v value for selection
* @return true if value exists in Enum, false otherwrise
*/
bool selectValue(int v);
/**
* @brief Select value if exists in Enum. If Enum contains several PIVariantTypes::Enumerator with same values,
* first PIVariantTypes::Enumerator will selected
* @param v value for selection
* @return true if value exists in Enum, false otherwrise
*/
bool selectValue(int v);
/**
* @brief Select name if exists in enum
* @param n name for selection
* @return true if name exists in Enum, false otherwrise
*/
bool selectName(const PIString & n);
/**
* @brief Select name if exists in enum
* @param n name for selection
* @return true if name exists in Enum, false otherwrise
*/
bool selectName(const PIString & n);
/**
* @brief Find PIVariantTypes::Enumerator with specific name and return it value
* @param n name for search
* @return value of founded PIVariantTypes::Enumerator, 0 otherwrise
*/
int value(const PIString & n) const;
/**
* @brief Find PIVariantTypes::Enumerator with specific name and return it value
* @param n name for search
* @return value of founded PIVariantTypes::Enumerator, 0 otherwrise
*/
int value(const PIString & n) const;
/**
* @brief Find first PIVariantTypes::Enumerator with specific value and return it name
* @param v value for search
* @return name of founded PIVariantTypes::Enumerator, empty string otherwrise
*/
PIString name(int v) const;
/**
* @brief Find first PIVariantTypes::Enumerator with specific value and return it name
* @param v value for search
* @return name of founded PIVariantTypes::Enumerator, empty string otherwrise
*/
PIString name(int v) const;
/**
* @brief Make vector of Enum values
*/
PIVector<int> values() const;
/**
* @brief Make vector of Enum values
*/
PIVector<int> values() const;
/**
* @brief Make vector of Enum names
*/
PIStringList names() const;
PIString enum_name;
PIString selected;
PIVector<Enumerator> enum_list;
/**
* @brief Make vector of Enum names
*/
PIStringList names() const;
PIString enum_name;
PIString selected;
PIVector<Enumerator> enum_list;
/**
* @brief Add PIVariantTypes::Enumerator to Enum
*/
Enum & operator <<(const Enumerator & v);
/**
* @brief Add PIVariantTypes::Enumerator to Enum
*/
Enum & operator <<(const Enumerator & v);
/**
* @brief Add PIVariantTypes::Enumerator element to Enum. Element contains specific name and value more per
* unit then last element. If the is no elements, contains zero value.
* @param v name for new PIVariantTypes::Enumerator element
*/
Enum & operator <<(const PIString & v);
/**
* @brief Add PIVariantTypes::Enumerator element to Enum. Element contains specific name and value more per
* unit then last element. If the is no elements, contains zero value.
* @param v name for new PIVariantTypes::Enumerator element
*/
Enum & operator <<(const PIString & v);
/**
* @brief Add PIVariantTypes::Enumerator element for each name in vector
*/
Enum & operator <<(const PIStringList & v);
};
/**
* @brief Add PIVariantTypes::Enumerator element for each name in vector
*/
Enum & operator <<(const PIStringList & v);
};
struct PIP_EXPORT File {
File(const PIString & p = PIString(), const PIString & f = PIString(), bool abs = false): file(p), filter(f), is_abs(abs) {}
PIString toString() const {return file;}
PIString file;
PIString filter;
bool is_abs;
};
struct PIP_EXPORT File {
File(const PIString & p = PIString(), const PIString & f = PIString(), bool abs = false): file(p), filter(f), is_abs(abs) {}
PIString toString() const {return file;}
PIString file;
PIString filter;
bool is_abs;
};
struct PIP_EXPORT Dir {
Dir(const PIString & d = PIString(), bool abs = false): dir(d), is_abs(abs) {}
PIString toString() const {return dir;}
PIString dir;
bool is_abs;
};
struct PIP_EXPORT Dir {
Dir(const PIString & d = PIString(), bool abs = false): dir(d), is_abs(abs) {}
PIString toString() const {return dir;}
PIString dir;
bool is_abs;
};
struct PIP_EXPORT Color {
Color(uint v = 0) {rgba = v;}
uint rgba;
};
struct PIP_EXPORT Color {
Color(uint v = 0) {rgba = v;}
uint rgba;
};
struct PIP_EXPORT IODevice {
IODevice();
void set(const PIPropertyStorage & ps);
PIPropertyStorage get() const;
PIString toPICout() const;
PIString prefix;
int mode; // PIIODevice::DeviceMode
int options; // PIIODevice::DeviceOptions
PIByteArray props;
};
struct PIP_EXPORT IODevice {
IODevice();
void set(const PIPropertyStorage & ps);
PIPropertyStorage get() const;
PIString toPICout() const;
PIString prefix;
int mode; // PIIODevice::DeviceMode
int options; // PIIODevice::DeviceOptions
PIByteArray props;
};
}