version 2.91.0, PITextStream works
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#ifndef MICRO_PIP
|
||||
# include "pisysteminfo.h"
|
||||
# include "pifile.h"
|
||||
# include "piiostream.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -753,7 +754,8 @@ bool dumpApplicationToFile(const PIString & path, bool with_objects) {
|
||||
bool ba = PICout::isBufferActive();
|
||||
PICout::setBufferActive(true, true);
|
||||
dumpApplication(with_objects);
|
||||
f << PICout::buffer();
|
||||
PIIOTextStream ts(&f);
|
||||
ts << PICout::buffer();
|
||||
f.close();
|
||||
PICout::setBufferActive(ba, true);
|
||||
PIFile::rename(path + "_tmp", path);
|
||||
|
||||
@@ -215,6 +215,13 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::fromConsole(const PIByteArray & ba) {
|
||||
PIString ret;
|
||||
if (ba.isNotEmpty()) ret.appendFromChars((const char*)ba.data(), ba.size(), __sysoemname__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::fromConsole(const char * s) {
|
||||
PIString ret;
|
||||
if (!s) return ret;
|
||||
@@ -224,6 +231,13 @@ PIString PIString::fromConsole(const char * s) {
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::fromSystem(const PIByteArray & ba) {
|
||||
PIString ret;
|
||||
if (ba.isNotEmpty()) ret.appendFromChars((const char*)ba.data(), ba.size(), __syslocname__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::fromSystem(const char * s) {
|
||||
PIString ret;
|
||||
if (!s) return ret;
|
||||
@@ -361,6 +375,13 @@ uint PIString::hash() const {
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIString::toSystem() const {
|
||||
if (isEmpty()) return PIByteArray();
|
||||
buildData(__syslocname__);
|
||||
return PIByteArray(data_, strlen(data_));
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIString::toUTF8() const {
|
||||
if (isEmpty()) return PIByteArray();
|
||||
buildData(__utf8name__);
|
||||
|
||||
@@ -908,6 +908,10 @@ public:
|
||||
//! \~russian Тоже самое, что \a toUTF8().
|
||||
PIByteArray toByteArray() const {return toUTF8();}
|
||||
|
||||
//! \~english Returns \a PIByteArray contains \a data() of this string without terminating null-char.
|
||||
//! \~russian Возвращает \a PIByteArray содержащий \a data() строки без завершающего нулевого байта.
|
||||
PIByteArray toSystem() const;
|
||||
|
||||
//! \~english Returns \a PIByteArray contains \a dataUTF8() of this string without terminating null-char.
|
||||
//! \~russian Возвращает \a PIByteArray содержащий \a dataUTF8() строки без завершающего нулевого байта.
|
||||
PIByteArray toUTF8() const;
|
||||
@@ -1506,10 +1510,18 @@ public:
|
||||
//! \~english Returns "true" or "false"
|
||||
//! \~russian Возвращает "true" или "false"
|
||||
static PIString fromBool(const bool value) {return PIString(value ? PIStringAscii("true") : PIStringAscii("false"));}
|
||||
|
||||
//! \~english Returns string constructed from terminal codepage.
|
||||
//! \~russian Возвращает строку созданную из кодировки консоли.
|
||||
static PIString fromConsole(const PIByteArray & s);
|
||||
|
||||
//! \~english Returns string constructed from terminal codepage.
|
||||
//! \~russian Возвращает строку созданную из кодировки консоли.
|
||||
static PIString fromConsole(const char * s);
|
||||
|
||||
//! \~english Returns string constructed from system codepage.
|
||||
//! \~russian Возвращает строку созданную из кодировки системы.
|
||||
static PIString fromSystem(const PIByteArray & s);
|
||||
|
||||
//! \~english Returns string constructed from system codepage.
|
||||
//! \~russian Возвращает строку созданную из кодировки системы.
|
||||
|
||||
@@ -36,26 +36,126 @@
|
||||
template<typename P>
|
||||
class PITextStream {
|
||||
public:
|
||||
PITextStream(PIBinaryStream<P> * stream): s(stream) {}
|
||||
|
||||
//! \~english Floating-point numbers write format
|
||||
//! \~russian Формат записи чисел с плавающей точкой
|
||||
enum FloatFormat {
|
||||
DecimalFormat /** \~english Decimal format, "*.*" \~russian Десятичный формат, "*.*" */ = 'f',
|
||||
ExponentFormat /** \~english Exponential format, "*e+-<E>" \~russian Экспонентный формат, "*e+-<E>" */ = 'e'
|
||||
};
|
||||
|
||||
//! \~english String encoding
|
||||
//! \~russian Кодировка строк
|
||||
enum Encoding {
|
||||
System /** \~english System encoding \~russian Системная кодировка */,
|
||||
UTF8 /** \~english UTF-8 encoding \~russian Кодировка UTF-8 */,
|
||||
};
|
||||
|
||||
//! \~english Construct text stream binded to "stream_"
|
||||
//! \~russian Возвращает привязанный к "stream_" текстовый поток
|
||||
PITextStream(PIBinaryStream<P> * stream_) {setStream(stream_);}
|
||||
|
||||
//! \~english Returns binded PIBinaryStream
|
||||
//! \~russian Возвращает привязанный PIBinaryStream
|
||||
PIBinaryStream<P> * stream() const {return s;}
|
||||
void setStream(PIBinaryStream<P> * stream_) {
|
||||
s = stream_;
|
||||
is_end = false;
|
||||
}
|
||||
|
||||
//! \~english Returns if end of stream reached
|
||||
//! \~russian Возвращает достигнут ли конец потока
|
||||
bool isEnd() const {return is_end;}
|
||||
|
||||
//! \~english Returns read/write encoding
|
||||
//! \~russian Возвращает кодировку чтения/записи
|
||||
Encoding encoding() const {return enc;}
|
||||
|
||||
//! \~english Set read/write encoding, default UTF8
|
||||
//! \~russian Устанавливает кодировку чтения/записи, по умолчанию UTF8
|
||||
void setEncoding(Encoding e) {enc = e;}
|
||||
|
||||
//! \~english Returns float numbers write format
|
||||
//! \~russian Возвращает формат записи чисел с плавающей точкой
|
||||
FloatFormat floatFormat() const {return format_;}
|
||||
|
||||
//! \~english Set float numbers write format, default DecimalFormat
|
||||
//! \~russian Устанавливает формат записи чисел с плавающей точкой, по умолчанию DecimalFormat
|
||||
void setFloatFormat(FloatFormat format) {format_ = format;}
|
||||
|
||||
//! \~english Returns float numbers write precision
|
||||
//! \~russian Возвращает точность записи чисел с плавающей точкой
|
||||
int floatPrecision() const {return prec_;}
|
||||
|
||||
//! \~english Set float numbers write precision to "prec_" digits, default 5
|
||||
//! \~russian Устанавливает точность записи чисел с плавающей точкой, по умолчанию 5
|
||||
void setFloatPrecision(int prec) {prec_ = prec;}
|
||||
|
||||
//! \~english Append space
|
||||
//! \~russian Добавляет пробел
|
||||
PITextStream<P> & space() {s->binaryStreamAppend(' '); return *this;}
|
||||
|
||||
//! \~english Append new line
|
||||
//! \~russian Добавляет новую строку
|
||||
PITextStream<P> & newLine() {s->binaryStreamAppend('\n'); return *this;}
|
||||
|
||||
//! \~english Append "v" string
|
||||
//! \~russian Добавляет строку "v"
|
||||
void append(const PIString & v) {
|
||||
if (v.isEmpty()) return;
|
||||
auto utf8 = v.toUTF8();
|
||||
s->binaryStreamAppend(utf8.data(), utf8.size());
|
||||
PIByteArray d;
|
||||
switch (enc) {
|
||||
case System: d = v.toSystem(); break;
|
||||
case UTF8 : d = v.toUTF8(); break;
|
||||
}
|
||||
s->binaryStreamAppend(d.data(), d.size());
|
||||
}
|
||||
|
||||
//! \~english Append "v" as ASCII
|
||||
//! \~russian Добавляет "v" как ASCII
|
||||
void append(const PIConstChars & v) {if (!v.isEmpty()) s->binaryStreamAppend(v.data(), v.size());}
|
||||
|
||||
//! \~english Append "v" char as character
|
||||
//! \~russian Добавляет "v" как символ
|
||||
void append(char v) {s->binaryStreamAppend(v);}
|
||||
|
||||
//! \~english Append "v" as ASCII
|
||||
//! \~russian Добавляет "v" как ASCII
|
||||
void append(const char * v) {append(PIConstChars(v));}
|
||||
|
||||
//! \~english Append boolean, "true" of "false"
|
||||
//! \~russian Добавляет логическое, "true" of "false"
|
||||
void append(bool v) {append(v ? "true" : "false");}
|
||||
|
||||
//! \~english Append integer
|
||||
//! \~russian Добавляет целое
|
||||
void append(int v) {append(PIString::fromNumber(v));}
|
||||
|
||||
//! \~english Append integer
|
||||
//! \~russian Добавляет целое
|
||||
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);}
|
||||
//! \~english Append floating-point number, using \a floatFormat() and \a floatPrecision()
|
||||
//! \~russian Добавляет число с плавающей точкой, используя \a floatFormat() и \a floatPrecision()
|
||||
void append(float v) {append(PIString::fromNumber(v, (char)format_, prec_));}
|
||||
|
||||
//! \~english Append floating-point number, using \a floatFormat() and \a floatPrecision()
|
||||
//! \~russian Добавляет число с плавающей точкой, используя \a floatFormat() и \a floatPrecision()
|
||||
void append(double v) {append(PIString::fromNumber(v, (char)format_, prec_));}
|
||||
|
||||
|
||||
//! \~english Read character
|
||||
//! \~russian Читает символ
|
||||
char takeChar(bool * rok) {
|
||||
bool ok = true;
|
||||
char ret = (char)s->binaryStreamTakeByte(&ok);
|
||||
if (!ok) is_end = true;
|
||||
if (rok) *rok = ok;
|
||||
return ret;
|
||||
}
|
||||
|
||||
//! \~english Read line
|
||||
//! \~russian Читает строку
|
||||
PIString takeLine() {
|
||||
PIByteArray ret;
|
||||
bool ok = true;
|
||||
@@ -65,23 +165,36 @@ public:
|
||||
if (b != '\r')
|
||||
ret.append((uchar)b);
|
||||
}
|
||||
return PIString::fromUTF8(ret);
|
||||
return fromBytes(ret);
|
||||
}
|
||||
|
||||
//! \~english Read word, skip leading whitespaces, until next whitespace
|
||||
//! \~russian Читает слово, пропуская начальные пробельные символы, до следующего пробельного символа
|
||||
PIString takeWord() {
|
||||
static PIConstChars spaces(" \t\n\r");
|
||||
return takeUntil(spaces);
|
||||
}
|
||||
|
||||
//! \~english
|
||||
//! \~russian
|
||||
PIString takeCWord() {
|
||||
static PIConstChars chars(" \t\n\r:;%$&#@!?~/*-+=.,\\\"'`[](){}<>");
|
||||
return takeUntil(chars);
|
||||
}
|
||||
|
||||
private:
|
||||
PIString fromBytes(const PIByteArray & ba) {
|
||||
switch (enc) {
|
||||
case System: return PIString::fromSystem(ba);
|
||||
case UTF8 : return PIString::fromUTF8(ba);
|
||||
}
|
||||
return PIString();
|
||||
}
|
||||
PIString takeUntil(const PIConstChars & chars) {
|
||||
static PIConstChars spaces(" \t\n\r");
|
||||
//static PIConstChars spaces(" \t\n\r");
|
||||
bool ok = true;
|
||||
char c = skipWhile(spaces, &ok);
|
||||
if (!ok || chars.contains(c)) return PIString();
|
||||
char c = skipWhile(chars, &ok);
|
||||
if (!ok) return PIString();
|
||||
PIByteArray ret;
|
||||
ret.append((uchar)c);
|
||||
for (;;) {
|
||||
@@ -89,7 +202,7 @@ private:
|
||||
if (!ok || chars.contains(c)) break;
|
||||
ret.append((uchar)c);
|
||||
}
|
||||
return PIString::fromUTF8(ret);
|
||||
return fromBytes(ret);
|
||||
}
|
||||
// returns first non-"chars" char
|
||||
char skipWhile(const PIConstChars & chars, bool * rok) {
|
||||
@@ -104,26 +217,125 @@ private:
|
||||
}
|
||||
|
||||
PIBinaryStream<P> * s;
|
||||
Encoding enc = UTF8;
|
||||
FloatFormat format_ = DecimalFormat;
|
||||
bool is_end = false;
|
||||
int prec_ = 5;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//! \~english Returns PITextStream for binary stream "stream"
|
||||
//! \~russian Возвращает PITextStream для бинарного потока "stream"
|
||||
template<typename P>
|
||||
inline PITextStream<P> createPITextStream(PIBinaryStream<P> * stream) {return PITextStream<P>(stream);}
|
||||
|
||||
|
||||
//! \~english Append boolean
|
||||
//! \~russian Добавляет логическое
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, bool v) {s.append(v); return s;}
|
||||
|
||||
//! \~english Append character
|
||||
//! \~russian Добавляет символ
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, char v) {s.append(v); return s;}
|
||||
|
||||
//! \~english Append integer
|
||||
//! \~russian Добавляет целое
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, uchar v) {s.append((int)v); return s;}
|
||||
|
||||
//! \~english Append integer
|
||||
//! \~russian Добавляет целое
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, short v) {s.append((int)v); return s;}
|
||||
|
||||
//! \~english Append integer
|
||||
//! \~russian Добавляет целое
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, ushort v) {s.append((int)v); return s;}
|
||||
|
||||
//! \~english Append integer
|
||||
//! \~russian Добавляет целое
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, int v) {s.append((int)v); return s;}
|
||||
|
||||
//! \~english Append integer
|
||||
//! \~russian Добавляет целое
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, uint v) {s.append((int)v); return s;}
|
||||
|
||||
//! \~english Append integer
|
||||
//! \~russian Добавляет целое
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, llong v) {s.append((llong)v); return s;}
|
||||
|
||||
//! \~english Append integer
|
||||
//! \~russian Добавляет целое
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, ullong v) {s.append((llong)v); return s;}
|
||||
|
||||
//! \~english Append floating-point number
|
||||
//! \~russian Добавляет число с плавающей точкой
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, float v) {s.append(v); return s;}
|
||||
|
||||
//! \~english Append floating-point number
|
||||
//! \~russian Добавляет число с плавающей точкой
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, double v) {s.append(v); return s;}
|
||||
|
||||
|
||||
//! \~english Append string
|
||||
//! \~russian Добавляет строку
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, const char * v) {s.append(v); return s;}
|
||||
|
||||
//! \~english Append string
|
||||
//! \~russian Добавляет строку
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, const PIConstChars & v) {s.append(v); return s;}
|
||||
|
||||
//! \~english Append string
|
||||
//! \~russian Добавляет строку
|
||||
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, const PIString & v) {s.append(v); return s;}
|
||||
|
||||
|
||||
//! \~english Read word as bool
|
||||
//! \~russian Читает слово как логическое
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, bool & v) {v = s.takeWord().toBool(); return s;}
|
||||
|
||||
//! \~english Read character
|
||||
//! \~russian Читает символ
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, char & v) {v = s.takeChar(); return s;}
|
||||
|
||||
//! \~english Read word as integer
|
||||
//! \~russian Читает слово как целое
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, uchar & v) {v = s.takeWord().toUInt(); return s;}
|
||||
|
||||
//! \~english Read word as integer
|
||||
//! \~russian Читает слово как целое
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, short & v) {v = s.takeWord().toInt(); return s;}
|
||||
|
||||
//! \~english Read word as integer
|
||||
//! \~russian Читает слово как целое
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, ushort & v) {v = s.takeWord().toUInt(); return s;}
|
||||
|
||||
//! \~english Read word as integer
|
||||
//! \~russian Читает слово как целое
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, int & v) {v = s.takeWord().toInt(); return s;}
|
||||
|
||||
//! \~english Read word as integer
|
||||
//! \~russian Читает слово как целое
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, uint & v) {v = s.takeWord().toUInt(); return s;}
|
||||
|
||||
//! \~english Read word as integer
|
||||
//! \~russian Читает слово как целое
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, llong & v) {v = s.takeWord().toLLong(); return s;}
|
||||
|
||||
//! \~english Read word as integer
|
||||
//! \~russian Читает слово как целое
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, ullong & v) {v = s.takeWord().toULLong(); return s;}
|
||||
|
||||
//! \~english Read word as floating-point number
|
||||
//! \~russian Читает слово как число с плавающей точкой
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, float & v) {v = s.takeWord().toFloat(); return s;}
|
||||
|
||||
//! \~english Read word as floating-point number
|
||||
//! \~russian Читает слово как число с плавающей точкой
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, double & v) {v = s.takeWord().toDouble(); return s;}
|
||||
|
||||
|
||||
//! \~english Read word
|
||||
//! \~russian Читает слово
|
||||
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, PIString & v) {v = s.takeWord(); return s;}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -400,7 +400,7 @@ PIString PIConfig::_readLineDev() {
|
||||
void PIConfig::_writeDev(const PIString & l) {
|
||||
//piCout << "write \"" << l << "\"";
|
||||
if (!dev) return;
|
||||
if (PIString(dev->className()) == "PIFile") {*((PIFile*)dev) << (l); return;}
|
||||
if (PIString(dev->className()) == "PIFile") {((PIFile*)dev)->write(l.toUTF8()); return;}
|
||||
if (PIString(dev->className()) == "PIIOString") {((PIIOString*)dev)->writeString(l); return;}
|
||||
dev->write(l.toByteArray());
|
||||
}
|
||||
|
||||
@@ -452,7 +452,8 @@ void PIFile::setPrecision(int prec) {
|
||||
|
||||
|
||||
PIFile & PIFile::put(const PIByteArray & v) {
|
||||
writeBinary((int)v.size_s());
|
||||
int sz = (int)v.size_s();
|
||||
write(createMemoryBlock(&sz));
|
||||
write(v);
|
||||
return *this;
|
||||
}
|
||||
@@ -461,7 +462,7 @@ PIFile & PIFile::put(const PIByteArray & v) {
|
||||
PIByteArray PIFile::get() {
|
||||
PIByteArray ret;
|
||||
int sz(0);
|
||||
read(&sz, sizeof(sz));
|
||||
read(createMemoryBlock(&sz));
|
||||
if (sz > 0) {
|
||||
ret.resize(sz);
|
||||
read(ret.data(), sz);
|
||||
@@ -470,156 +471,6 @@ PIByteArray PIFile::get() {
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(double v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "lf").data(), v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(double & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lf", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(float & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%f", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(ullong & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lln", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(ulong & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%ln", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(uint & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%n", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(ushort & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hn", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(uchar & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hhn", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(llong & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lln", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(long & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%ln", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(int & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%n", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(short & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hn", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator >>(char & v) {
|
||||
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hhn", &v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(float v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "f").data(), v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(ullong v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%llu", v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(ulong v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%lu", v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(uint v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%u", v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(ushort v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%hu", v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(uchar v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%u", int(v));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(llong v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%lld", v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(long v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%ld", v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(int v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%d", v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(short v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%hd", v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(const PIByteArray & v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) write(v.data(), v.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(const char v) {
|
||||
if (canWrite() && PRIVATE->fd != 0) write(&v, 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
int PIFile::readDevice(void * read_to, int max_size) {
|
||||
if (!canRead() || PRIVATE->fd == 0) return -1;
|
||||
return fread(read_to, 1, max_size, PRIVATE->fd);
|
||||
@@ -632,13 +483,6 @@ int PIFile::writeDevice(const void * data, int max_size) {
|
||||
}
|
||||
|
||||
|
||||
PIFile &PIFile::operator <<(const PIString & v) {
|
||||
if (canWrite() && v.isNotEmpty() && PRIVATE->fd != 0)
|
||||
*this << v.toCharset(defaultCharset());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void PIFile::clear() {
|
||||
close();
|
||||
PRIVATE->fd = fopen(path().data(), "w");
|
||||
|
||||
@@ -260,161 +260,6 @@ public:
|
||||
//! \~russian Читает из файла размер байтового массива и его содержимое (десериализация)
|
||||
PIByteArray get();
|
||||
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const char v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const short v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const int v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const long v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const llong v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const uchar v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const ushort v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const uint v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const ulong v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const ullong v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const float v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
//! \~english Write to file binary content of "v"
|
||||
//! \~russian Пишет в файл байтовое содержимое "v"
|
||||
PIFile & writeBinary(const double v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(const char v);
|
||||
|
||||
//! \~english Write to file string "v"
|
||||
//! \~russian Пишет в файл строку "v"
|
||||
PIFile & operator <<(const PIString & v);
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(const PIByteArray & v);
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(short v);
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(int v);
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(long v);
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(llong v);
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(uchar v);
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(ushort v);
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(uint v);
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(ulong v);
|
||||
|
||||
//! \~english Write to file text representation of "v"
|
||||
//! \~russian Пишет в файл текстовое представление "v"
|
||||
PIFile & operator <<(ullong v);
|
||||
|
||||
//! \~english Write to file text representation of "v" with precision \a precision()
|
||||
//! \~russian Пишет в файл текстовое представление "v" с точностью \a precision()
|
||||
PIFile & operator <<(float v);
|
||||
|
||||
//! \~english Write to file text representation of "v" with precision \a precision()
|
||||
//! \~russian Пишет в файл текстовое представление "v" с точностью \a precision()
|
||||
PIFile & operator <<(double v);
|
||||
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(char & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(short & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(int & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(long & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(llong & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(uchar & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(ushort & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(uint & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(ulong & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(ullong & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(float & v);
|
||||
|
||||
//! \~english Read from file text representation of "v"
|
||||
//! \~russian Читает из файла текстовое представление "v"
|
||||
PIFile & operator >>(double & v);
|
||||
|
||||
EVENT_HANDLER(void, clear);
|
||||
EVENT_HANDLER(void, remove);
|
||||
EVENT_HANDLER1(void, resize, llong, new_size) {resize(new_size, 0);}
|
||||
|
||||
@@ -276,6 +276,10 @@ public:
|
||||
//! \~russian Читает из устройства не более "max_size" байт в "read_to"
|
||||
int read(void * read_to, int max_size) {return readDevice(read_to, max_size);}
|
||||
|
||||
//! \~english Read from device to memory block "mb"
|
||||
//! \~russian Читает из устройства в блок памяти "mb"
|
||||
int read(PIMemoryBlock mb) {return readDevice(mb.data(), mb.size());}
|
||||
|
||||
//! \~english Read from device maximum "max_size" bytes and returns them as PIByteArray
|
||||
//! \~russian Читает из устройства не более "max_size" байт и возвращает данные как PIByteArray
|
||||
PIByteArray read(int max_size);
|
||||
@@ -357,6 +361,10 @@ public:
|
||||
EVENT_HANDLER(bool, close);
|
||||
EVENT_HANDLER1(int, write, PIByteArray, data);
|
||||
|
||||
//! \~english Write memory block "mb" to device
|
||||
//! \~russian Пишет в устройство блок памяти "mb"
|
||||
int write(const PIMemoryBlock & mb) {return write(mb.data(), mb.size());}
|
||||
|
||||
EVENT_VHANDLER(void, flush) {;}
|
||||
|
||||
EVENT(opened)
|
||||
|
||||
Reference in New Issue
Block a user