DEPRECATED[M], createMemoryBlock(), text stream ...

This commit is contained in:
2022-05-11 20:55:51 +03:00
parent 0897a8369f
commit ef8ffcd02f
12 changed files with 84 additions and 39 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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 Создает пустой байтовый массив

View File

@@ -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());

View File

@@ -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;}

View File

@@ -57,4 +57,7 @@ private:
};
template<typename T>
PIMemoryBlock createMemoryBlock(const T * ptr) {return PIMemoryBlock(ptr, sizeof(T));}
#endif // PIMEMORYBLOCK_H

View File

@@ -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;
};