pitextstream starts
This commit is contained in:
@@ -51,6 +51,18 @@ PRIVATE_DEFINITION_END(PIScreen::SystemConsole)
|
||||
PIScreen::SystemConsole::SystemConsole() {
|
||||
width = height = pwidth = pheight = 0;
|
||||
mouse_x = mouse_y = -1;
|
||||
}
|
||||
|
||||
|
||||
PIScreen::SystemConsole::~SystemConsole() {
|
||||
#ifdef WINDOWS
|
||||
SetConsoleMode(PRIVATE->hOut, PRIVATE->smode);
|
||||
SetConsoleTextAttribute(PRIVATE->hOut, PRIVATE->dattr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIScreen::SystemConsole::begin() {
|
||||
int w, h;
|
||||
#ifdef WINDOWS
|
||||
PRIVATE->ulcoord.X = 0;
|
||||
@@ -74,18 +86,6 @@ PIScreen::SystemConsole::SystemConsole() {
|
||||
# endif
|
||||
#endif
|
||||
resize(w, h);
|
||||
}
|
||||
|
||||
|
||||
PIScreen::SystemConsole::~SystemConsole() {
|
||||
#ifdef WINDOWS
|
||||
SetConsoleMode(PRIVATE->hOut, PRIVATE->smode);
|
||||
SetConsoleTextAttribute(PRIVATE->hOut, PRIVATE->dattr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIScreen::SystemConsole::begin() {
|
||||
#ifdef WINDOWS
|
||||
SetConsoleMode(PRIVATE->hOut, ENABLE_WRAP_AT_EOL_OUTPUT);
|
||||
GetConsoleScreenBufferInfo(PRIVATE->hOut, &PRIVATE->sbi);
|
||||
@@ -93,6 +93,7 @@ void PIScreen::SystemConsole::begin() {
|
||||
PRIVATE->bc.Y = 0;
|
||||
#endif
|
||||
clear();
|
||||
clearScreen();
|
||||
hideCursor();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,8 +69,24 @@ public:
|
||||
}
|
||||
template<typename T>
|
||||
void binaryStreamAppend(T v) {binaryStreamAppend(&v, sizeof(v));}
|
||||
uchar binaryStreamTakeByte() {uchar r = 0; binaryStreamTake(&r, sizeof(r)); return r;}
|
||||
int binaryStreamTakeInt() {int r = 0; binaryStreamTake(&r, sizeof(r)); return r;}
|
||||
uchar binaryStreamTakeByte(bool * ok = nullptr) {
|
||||
uchar r = 0;
|
||||
if (binaryStreamTake(&r, sizeof(r))) {
|
||||
if (ok) *ok = true;
|
||||
} else {
|
||||
if (ok) *ok = false;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
int binaryStreamTakeInt(bool * ok = nullptr) {
|
||||
int r = 0;
|
||||
if (binaryStreamTake(&r, sizeof(r))) {
|
||||
if (ok) *ok = true;
|
||||
} else {
|
||||
if (ok) *ok = false;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
92
libs/main/core/pitextstream.h
Normal file
92
libs/main/core/pitextstream.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*! \file pitextstream.h
|
||||
* \ingroup Core
|
||||
* \~\brief
|
||||
* \~english Text serialization interface
|
||||
* \~russian Интерфейс текстовой сериализации
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Text serialization interface
|
||||
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 PITEXTSTREAM_H
|
||||
#define PITEXTSTREAM_H
|
||||
|
||||
#include "pistring.h"
|
||||
|
||||
|
||||
//! \ingroup Core
|
||||
//! \~\brief
|
||||
//! \~english Text serialization interface.
|
||||
//! \~russian Интерфейс текстовой сериализации.
|
||||
template<typename P>
|
||||
class PITextStream {
|
||||
public:
|
||||
PITextStream(PIBinaryStream<P> * stream): s(stream) {}
|
||||
|
||||
PITextStream<P> & newLine() {s->binaryStreamAppend('\n'); return *this;}
|
||||
PITextStream<P> & space() {s->binaryStreamAppend(' '); return *this;}
|
||||
void append(const PIString & v) {
|
||||
if (v.isEmpty()) return;
|
||||
auto utf8 = v.toUTF8();
|
||||
s->binaryStreamAppend(utf8.data(), utf8.size());
|
||||
}
|
||||
void append(const PIConstChars & v) {if (!v.isEmpty()) s->binaryStreamAppend(v.data(), v.size());}
|
||||
void append(char v) {s->binaryStreamAppend(v);}
|
||||
void append(const char * v) {append(PIConstChars(v));}
|
||||
void append(bool v) {append(v ? "true" : "false");}
|
||||
void append(int v) {append(PIString::fromNumber(v));}
|
||||
void append(llong v) {append(PIString::fromNumber(v));}
|
||||
void append(float v) {append(PIString::fromNumber(v));}
|
||||
void append(double v) {append(PIString::fromNumber(v));}
|
||||
|
||||
char takeChar(bool * ok) {return (char)s->binaryStreamTakeByte(ok);}
|
||||
|
||||
bool textStreamSkipSpaces() {
|
||||
|
||||
//if ()
|
||||
}
|
||||
PIString textStreamTakeLine() {
|
||||
|
||||
}
|
||||
PIString textStreamTakeWord();
|
||||
|
||||
private:
|
||||
PIBinaryStream<P> * s;
|
||||
|
||||
};
|
||||
|
||||
template<typename P>
|
||||
inline PITextStream<P> createPITextStream(PIBinaryStream<P> * stream) {return PITextStream<P>(stream);}
|
||||
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, bool v) {s.append(v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, char v) {s.append(v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, uchar v) {s.append((int)v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, short v) {s.append((int)v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, ushort v) {s.append((int)v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, int v) {s.append((int)v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, uint v) {s.append((int)v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, llong v) {s.append((llong)v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, ullong v) {s.append((llong)v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, float v) {s.append(v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, double v) {s.append(v); return s;}
|
||||
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, const char * v) {s.append(v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, const PIConstChars & v) {s.append(v); return s;}
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, const PIString & v) {s.append(v); return s;}
|
||||
|
||||
#endif
|
||||
59
libs/main/io_devices/piiostream.h
Normal file
59
libs/main/io_devices/piiostream.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*! \file piiostream.h
|
||||
* \ingroup IO
|
||||
* \~\brief
|
||||
* \~english PIBinaryStream functionality for PIIODevice
|
||||
* \~russian Функциональность PIBinaryStream для PIIODevice
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIBinaryStream functionality for PIIODevice
|
||||
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 PIIOSTREAM_H
|
||||
#define PIIOSTREAM_H
|
||||
|
||||
#include "piiodevice.h"
|
||||
|
||||
|
||||
//! \ingroup IO
|
||||
//! \~\brief
|
||||
//! \~english PIBinaryStream functionality for PIIODevice.
|
||||
//! \~russian Функциональность PIBinaryStream для PIIODevice.
|
||||
class PIP_EXPORT PIIOBinaryStream: public PIBinaryStream<PIIOBinaryStream> {
|
||||
public:
|
||||
|
||||
//! \~english Contructs %PIIOBinaryStream for "device" device
|
||||
//! \~russian Создает %PIIOBinaryStream для устройства "device"
|
||||
PIIOBinaryStream(PIIODevice * device): dev(device) {}
|
||||
|
||||
bool binaryStreamAppendImp(const void * d, size_t s) {
|
||||
if (!dev) return false;
|
||||
return dev->write(d, s);
|
||||
}
|
||||
|
||||
bool binaryStreamTakeImp(void * d, size_t s) {
|
||||
if (!dev) return false;
|
||||
return dev->read(d, s);
|
||||
}
|
||||
|
||||
private:
|
||||
PIIODevice * dev;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // PIIOSTREAM_H
|
||||
@@ -573,7 +573,7 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
|
||||
if (type <= 0 || type >= 4) return true;
|
||||
PeerInfo pi;
|
||||
ba >> pi.name;
|
||||
// piCoutObj << "received mb from" << pi.name << "packet" << type;
|
||||
//piCout << "received mb from" << pi.name << "packet" << type;
|
||||
if (pi.name == self_info.name) return true;
|
||||
PIMutexLocker locker(mc_mutex);
|
||||
diag_s.received(size);
|
||||
@@ -789,6 +789,7 @@ void PIPeer::sendPeerInfo(const PeerInfo & info) {
|
||||
|
||||
|
||||
void PIPeer::sendPeerRemove(const PIString & peer) {
|
||||
//piCout << name() << "sendPeerRemove" << peer;
|
||||
PIByteArray ba;
|
||||
ba << int(2) << peer;
|
||||
sendMBcast(ba);
|
||||
@@ -858,7 +859,7 @@ void PIPeer::syncPeers() {
|
||||
PeerInfo & cp(peers[i]);
|
||||
if (cp.sync > 3) {
|
||||
pn = cp.name;
|
||||
//piCoutObj << "sync: remove " << pn;
|
||||
//piCout << "sync: remove " << pn;
|
||||
cp.destroy();
|
||||
addToRemoved(cp);
|
||||
peers.remove(i);
|
||||
|
||||
27
main.cpp
27
main.cpp
@@ -1,5 +1,7 @@
|
||||
#include "pip.h"
|
||||
#include "pibinarystream.h"
|
||||
#include "pitextstream.h"
|
||||
#include "piiostream.h"
|
||||
//#include "stream.h"
|
||||
//#include "ccm.h"
|
||||
//#include "pisystemmonitor_.h"
|
||||
@@ -33,8 +35,23 @@ PICout operator << (PICout c, const TS & v) {c << '{' << v.i << ", " << v.f << '
|
||||
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const TS & v) {s << v.i; return s;}
|
||||
template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, TS & v) {s >> v.i; return s;}
|
||||
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
PIByteArray ba;
|
||||
PIFile f;
|
||||
f.open("_", PIIODevice::ReadWrite);
|
||||
f.clear();
|
||||
PIIOBinaryStream ios(&f);
|
||||
auto ts = createPITextStream(&ios);
|
||||
|
||||
ts << "hello" << uchar('1');
|
||||
ts.space();
|
||||
(ts << PIString::fromUTF8("№") << 123).space() << -0.1f;
|
||||
ts.newLine();
|
||||
|
||||
piCout << PIString(ba);
|
||||
//PIIOByteArray ioba(&ba);
|
||||
//PIIOBinaryStream stream(&ioba);
|
||||
/*ProcessStatsFixed_ ps;
|
||||
ba << ps;
|
||||
piCout << "s" << ba.data;*/
|
||||
@@ -53,7 +70,8 @@ int main(int argc, char * argv[]) {
|
||||
ba >> vi;
|
||||
piCout << "res" << vi;
|
||||
piCout << "r" << ba.data;*/
|
||||
PIMap<PIIODevice::DeviceMode, PIStringList> map;
|
||||
|
||||
/*PIMap<PIIODevice::DeviceMode, PIStringList> map;
|
||||
map[PIIODevice::ReadOnly] = {"str0", PIString::fromUTF8("русский!")};
|
||||
piMSleep(100);
|
||||
map[PIIODevice::ReadWrite] = {""};
|
||||
@@ -61,13 +79,14 @@ int main(int argc, char * argv[]) {
|
||||
map[PIIODevice::WriteOnly] = {PIString::fromUTF8("русский!"), "", "1234567890", "qwertyuiop[]"};
|
||||
piCout << map;
|
||||
|
||||
ba << map;
|
||||
stream << map;
|
||||
piCout << ba;
|
||||
map.clear();
|
||||
|
||||
ba >> map;
|
||||
ioba.seekToBegin();
|
||||
stream >> map;
|
||||
piCout << map;
|
||||
piCout << ba;
|
||||
piCout << ba;*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -394,7 +394,7 @@ int main(int argc, char * argv[]) {
|
||||
MainMenu * menu = new MainMenu(*daemon);
|
||||
if (sapp) CONNECTU(sapp, messageReceived, menu, messageFromApp);
|
||||
if (cli.hasArgument("silent")) {
|
||||
PICout::setBufferActive(false);
|
||||
PICout::setOutputDevices(PICout::StdOut);
|
||||
PIKbdListener ls;
|
||||
ls.enableExitCapture(PIKbdListener::F10);
|
||||
ls.start();
|
||||
|
||||
Reference in New Issue
Block a user