DEPRECATED[M], createMemoryBlock(), text stream ...
This commit is contained in:
@@ -265,13 +265,15 @@
|
||||
|
||||
#ifdef CC_GCC
|
||||
# undef DEPRECATED
|
||||
# undef DEPRECATEDM
|
||||
# define DEPRECATED __attribute__((deprecated))
|
||||
# define DEPRECATEDM(msg) __attribute__((deprecated(msg)))
|
||||
# if CC_GCC_VERSION > 0x025F // > 2.95
|
||||
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
||||
# ifdef LINUX
|
||||
# define HAS_LOCALE
|
||||
# endif
|
||||
# ifdef MAC_OS
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
# pragma GCC diagnostic ignored "-Wundefined-bool-conversion"
|
||||
# pragma GCC diagnostic ignored "-Wc++11-extensions"
|
||||
# endif
|
||||
@@ -287,7 +289,9 @@
|
||||
|
||||
#ifdef CC_VC
|
||||
# undef DEPRECATED
|
||||
# define DEPRECATED
|
||||
# undef DEPRECATEDM
|
||||
# define DEPRECATED __declspec(deprecated)
|
||||
# define DEPRECATEDM(msg) __declspec(deprecated(msg))
|
||||
# pragma warning(disable: 4018)
|
||||
# pragma warning(disable: 4061)
|
||||
# pragma warning(disable: 4100)
|
||||
@@ -312,7 +316,9 @@
|
||||
|
||||
#ifdef CC_OTHER
|
||||
# undef DEPRECATED
|
||||
# undef DEPRECATEDM
|
||||
# define DEPRECATED
|
||||
# define DEPRECATEDM(msg)
|
||||
#endif
|
||||
|
||||
#endif //DOXYGEN
|
||||
|
||||
@@ -104,12 +104,8 @@ template<typename P, typename T> inline PIBinaryStream<P> & operator >>(PIBinary
|
||||
|
||||
|
||||
// specify types
|
||||
template<typename P> inline PIBinaryStreamTrivialRef<P> operator <<(PIBinaryStream<P> & s, const bool v) {s.binaryStreamAppend((uchar)v); return s;}
|
||||
template<typename P> inline PIBinaryStreamTrivialRef<P> operator <<(PIBinaryStream<P> & s, const char v) {s.binaryStreamAppend((uchar)v); return s;}
|
||||
template<typename P> inline PIBinaryStreamTrivialRef<P> operator <<(PIBinaryStream<P> & s, const uchar v) {s.binaryStreamAppend((uchar)v); return s;}
|
||||
template<typename P> inline PIBinaryStreamTrivialRef<P> operator >>(PIBinaryStream<P> & s, bool & v) {v = s.binaryStreamTakeByte(); return s;}
|
||||
template<typename P> inline PIBinaryStreamTrivialRef<P> operator >>(PIBinaryStream<P> & s, char & v) {v = s.binaryStreamTakeByte(); return s;}
|
||||
template<typename P> inline PIBinaryStreamTrivialRef<P> operator >>(PIBinaryStream<P> & s, uchar & v) {v = s.binaryStreamTakeByte(); return s;}
|
||||
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const bool v) {s.binaryStreamAppend((uchar)v); return s;}
|
||||
template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, bool & v) {v = s.binaryStreamTakeByte(); return s;}
|
||||
|
||||
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIMemoryBlock v) {
|
||||
s.binaryStreamAppend(v.data(), v.size());
|
||||
@@ -128,7 +124,7 @@ template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> &
|
||||
|
||||
template<typename P, typename T,
|
||||
typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
|
||||
inline PIBinaryStreamTrivialRef<P> operator <<(PIBinaryStream<P> & s, const T & v) {
|
||||
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const T & v) {
|
||||
//piCout << "<< enum";
|
||||
s.binaryStreamAppend((int)v);
|
||||
return s;
|
||||
@@ -231,7 +227,7 @@ inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIPair<Type0
|
||||
|
||||
template<typename P, typename T,
|
||||
typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
|
||||
inline PIBinaryStreamTrivialRef<P> operator >>(PIBinaryStream<P> & s, T & v) {
|
||||
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, T & v) {
|
||||
//piCout << ">> enum";
|
||||
v = (T)s.binaryStreamTakeInt();
|
||||
return s;
|
||||
|
||||
@@ -41,7 +41,7 @@ class PIByteArray;
|
||||
class PIP_EXPORT PIByteArray: public PIDeque<uchar>, public PIBinaryStream<PIByteArray>
|
||||
{
|
||||
public:
|
||||
typedef ::PIMemoryBlock RawData;
|
||||
typedef ::PIMemoryBlock RawData DEPRECATEDM("use PIMemoryBlock instead");
|
||||
|
||||
//! \~english Constructs an empty byte array
|
||||
//! \~russian Создает пустой байтовый массив
|
||||
|
||||
@@ -42,6 +42,13 @@
|
||||
//!
|
||||
|
||||
|
||||
bool PIConstChars::contains(char c) const {
|
||||
for (int i = 0; i < (int)len; ++i)
|
||||
if (str[i] == c) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PIConstChars::startsWith(const PIConstChars & str) const {
|
||||
if (size() < str.size()) return false;
|
||||
return str == left(str.size());
|
||||
|
||||
@@ -86,6 +86,10 @@ public:
|
||||
//! \~russian Возвращает \c true если строка непустая, т.е. длина > 0.
|
||||
inline bool isNotEmpty() const {return len > 0;}
|
||||
|
||||
//! \~english Returns \c true if string contains character "c".
|
||||
//! \~russian Возвращает \c true если строка содержит символ "c".
|
||||
bool contains(char c) const;
|
||||
|
||||
//! \~english Returns characters length of string.
|
||||
//! \~russian Возвращает длину строки в символах.
|
||||
inline size_t length() const {return len;}
|
||||
|
||||
@@ -57,4 +57,7 @@ private:
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
PIMemoryBlock createMemoryBlock(const T * ptr) {return PIMemoryBlock(ptr, sizeof(T));}
|
||||
|
||||
#endif // PIMEMORYBLOCK_H
|
||||
|
||||
@@ -38,8 +38,8 @@ class PITextStream {
|
||||
public:
|
||||
PITextStream(PIBinaryStream<P> * stream): s(stream) {}
|
||||
|
||||
PITextStream<P> & newLine() {s->binaryStreamAppend('\n'); return *this;}
|
||||
PITextStream<P> & space() {s->binaryStreamAppend(' '); return *this;}
|
||||
PITextStream<P> & newLine() {s->binaryStreamAppend('\n'); return *this;}
|
||||
void append(const PIString & v) {
|
||||
if (v.isEmpty()) return;
|
||||
auto utf8 = v.toUTF8();
|
||||
@@ -56,24 +56,53 @@ public:
|
||||
|
||||
char takeChar(bool * ok) {return (char)s->binaryStreamTakeByte(ok);}
|
||||
|
||||
bool skipSpaces() {
|
||||
|
||||
//if ()
|
||||
}
|
||||
PIString takeLine() {
|
||||
PIByteArray line;
|
||||
PIByteArray ret;
|
||||
bool ok = true;
|
||||
for (;;) {
|
||||
char b = takeChar(&ok);
|
||||
if (!ok || b == '\n') break;
|
||||
if (b != '\r')
|
||||
line.append((uchar)b);
|
||||
ret.append((uchar)b);
|
||||
}
|
||||
return PIString::fromUTF8(line);
|
||||
return PIString::fromUTF8(ret);
|
||||
}
|
||||
PIString takeWord() {
|
||||
static PIConstChars spaces(" \t\n\r");
|
||||
return takeUntil(spaces);
|
||||
}
|
||||
PIString takeCWord() {
|
||||
static PIConstChars chars(" \t\n\r:;%$&#@!?~/*-+=.,\\\"'`[](){}<>");
|
||||
return takeUntil(chars);
|
||||
}
|
||||
PIString takeWord();
|
||||
|
||||
private:
|
||||
PIString takeUntil(const PIConstChars & chars) {
|
||||
static PIConstChars spaces(" \t\n\r");
|
||||
bool ok = true;
|
||||
char c = skipWhile(spaces, &ok);
|
||||
if (!ok || chars.contains(c)) return PIString();
|
||||
PIByteArray ret;
|
||||
ret.append((uchar)c);
|
||||
for (;;) {
|
||||
c = takeChar(&ok);
|
||||
if (!ok || chars.contains(c)) break;
|
||||
ret.append((uchar)c);
|
||||
}
|
||||
return PIString::fromUTF8(ret);
|
||||
}
|
||||
// returns first non-"chars" char
|
||||
char skipWhile(const PIConstChars & chars, bool * rok) {
|
||||
bool ok = true;
|
||||
char c = 0;
|
||||
for (;;) {
|
||||
c = takeChar(&ok);
|
||||
if (!ok || !chars.contains(c)) break;
|
||||
}
|
||||
if (rok) *rok = ok;
|
||||
return c;
|
||||
}
|
||||
|
||||
PIBinaryStream<P> * s;
|
||||
|
||||
};
|
||||
|
||||
@@ -67,11 +67,11 @@ public:
|
||||
|
||||
|
||||
BINARY_STREAM_WRITE(PIIntrospectionContainers::TypeInfo) {
|
||||
s << PIByteArray::RawData(&v, sizeof(PIIntrospectionContainers::_Type)) << v.name;
|
||||
s << PIMemoryBlock(&v, sizeof(PIIntrospectionContainers::_Type)) << v.name;
|
||||
return s;
|
||||
}
|
||||
BINARY_STREAM_READ(PIIntrospectionContainers::TypeInfo) {
|
||||
s >> PIByteArray::RawData(&v, sizeof(PIIntrospectionContainers::_Type)) >> v.name;
|
||||
s >> PIMemoryBlock(&v, sizeof(PIIntrospectionContainers::_Type)) >> v.name;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -316,7 +316,7 @@ int PIBinaryLog::writeBinLog(int id, const void *data, int size) {
|
||||
return 0;
|
||||
}
|
||||
PIByteArray logdata;
|
||||
logdata << id << size << (PISystemTime::current() - startlogtime) << PIByteArray::RawData(data, size);
|
||||
logdata << id << size << (PISystemTime::current() - startlogtime) << PIMemoryBlock(data, size);
|
||||
int res = file.write(logdata.data(), logdata.size());
|
||||
file.flush();
|
||||
write_count++;
|
||||
@@ -330,7 +330,7 @@ int PIBinaryLog::writeBinLog(int id, const void *data, int size) {
|
||||
int PIBinaryLog::writeBinLog_raw(int id, const PISystemTime &time, const void *data, int size) {
|
||||
if (size <= 0 || !canWrite()) return -1;
|
||||
PIByteArray logdata;
|
||||
logdata << id << size << time << PIByteArray::RawData(data, size);
|
||||
logdata << id << size << time << PIMemoryBlock(data, size);
|
||||
logmutex.lock();
|
||||
int res = file.write(logdata.data(), logdata.size());
|
||||
file.flush();
|
||||
|
||||
@@ -228,11 +228,11 @@ private:
|
||||
inline bool operator ==(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element e2) {return (e1.type == e2.type && e1.num == e2.num);}
|
||||
inline bool operator !=(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element e2) {return (e1.type != e2.type || e1.num != e2.num);}
|
||||
|
||||
BINARY_STREAM_WRITE(PIEvaluatorTypes::Instruction) {s << PIByteArray::RawData(&v, sizeof(v) - sizeof(v.operators)) << v.operators; return s;}
|
||||
BINARY_STREAM_READ (PIEvaluatorTypes::Instruction) {s >> PIByteArray::RawData(&v, sizeof(v) - sizeof(v.operators)) >> v.operators; return s;}
|
||||
BINARY_STREAM_WRITE(PIEvaluatorTypes::Instruction) {s << PIMemoryBlock(&v, sizeof(v) - sizeof(v.operators)) << v.operators; return s;}
|
||||
BINARY_STREAM_READ (PIEvaluatorTypes::Instruction) {s >> PIMemoryBlock(&v, sizeof(v) - sizeof(v.operators)) >> v.operators; return s;}
|
||||
|
||||
BINARY_STREAM_WRITE(PIEvaluatorTypes::Element) {s << PIByteArray::RawData(&v, sizeof(v)); return s;}
|
||||
BINARY_STREAM_READ (PIEvaluatorTypes::Element) {s >> PIByteArray::RawData(&v, sizeof(v)); return s;}
|
||||
BINARY_STREAM_WRITE(PIEvaluatorTypes::Element) {s << createMemoryBlock(&v); return s;}
|
||||
BINARY_STREAM_READ (PIEvaluatorTypes::Element) {s >> createMemoryBlock(&v); return s;}
|
||||
|
||||
BINARY_STREAM_WRITE(PIEvaluatorTypes::Variable) {s << v.name << v.value; return s;}
|
||||
BINARY_STREAM_READ (PIEvaluatorTypes::Variable) {s >> v.name >> v.value; return s;}
|
||||
|
||||
@@ -294,7 +294,7 @@ inline PICout operator <<(PICout s, const PISystemMonitor::ThreadStats & v) {
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
BINARY_STREAM_WRITE(PISystemMonitor::ProcessStats) {
|
||||
s << PIByteArray::RawData(&v, sizeof(PISystemMonitor::ProcessStatsFixed))
|
||||
s << PIMemoryBlock(&v, sizeof(PISystemMonitor::ProcessStatsFixed))
|
||||
<< v.exec_name << v.state;
|
||||
return s;
|
||||
}
|
||||
@@ -302,7 +302,7 @@ BINARY_STREAM_WRITE(PISystemMonitor::ProcessStats) {
|
||||
//! \~english Restore operator
|
||||
//! \~russian Оператор извлечения
|
||||
BINARY_STREAM_READ (PISystemMonitor::ProcessStats) {
|
||||
s >> PIByteArray::RawData(&v, sizeof(PISystemMonitor::ProcessStatsFixed))
|
||||
s >> PIMemoryBlock(&v, sizeof(PISystemMonitor::ProcessStatsFixed))
|
||||
>> v.exec_name >> v.state;
|
||||
v.makeStrings();
|
||||
return s;
|
||||
@@ -311,7 +311,7 @@ BINARY_STREAM_READ (PISystemMonitor::ProcessStats) {
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
BINARY_STREAM_WRITE(PISystemMonitor::ThreadStats) {
|
||||
s << PIByteArray::RawData(&v, sizeof(PISystemMonitor::ThreadStatsFixed))
|
||||
s << PIMemoryBlock(&v, sizeof(PISystemMonitor::ThreadStatsFixed))
|
||||
<< v.name;
|
||||
return s;
|
||||
}
|
||||
@@ -319,7 +319,7 @@ BINARY_STREAM_WRITE(PISystemMonitor::ThreadStats) {
|
||||
//! \~english Restore operator
|
||||
//! \~russian Оператор извлечения
|
||||
BINARY_STREAM_READ (PISystemMonitor::ThreadStats) {
|
||||
s >> PIByteArray::RawData(&v, sizeof(PISystemMonitor::ThreadStatsFixed))
|
||||
s >> PIMemoryBlock(&v, sizeof(PISystemMonitor::ThreadStatsFixed))
|
||||
>> v.name;
|
||||
return s;
|
||||
}
|
||||
|
||||
14
main.cpp
14
main.cpp
@@ -35,19 +35,19 @@ 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[]) {
|
||||
PIFile f;
|
||||
/*PIFile f;
|
||||
f.open("_test.h", PIIODevice::ReadOnly);
|
||||
PIIOTextStream ts(&f);
|
||||
while (!f.isEnd())
|
||||
piCout << ts.takeLine();
|
||||
piCout << ts.takeCWord();*/
|
||||
|
||||
//PIIOByteArray ioba(&ba);
|
||||
PIByteArray ba;
|
||||
PIIOByteArray ioba(&ba);
|
||||
//PIIOBinaryStream stream(&ioba);
|
||||
/*ProcessStatsFixed_ ps;
|
||||
ba << ps;
|
||||
piCout << "s" << ba.data;*/
|
||||
PISystemMonitor::ProcessStatsFixed ps;
|
||||
ba << PIByteArray::RawData("123", 3);
|
||||
piCout << "s" << ba;
|
||||
//File f;
|
||||
//f.file.open("_", PIIODevice::ReadWrite);
|
||||
//f.file.clear();
|
||||
|
||||
Reference in New Issue
Block a user