From 31a347250f74198391997d06d7a0492a0eb291f6 Mon Sep 17 00:00:00 2001 From: Ivan Pelipenko Date: Thu, 13 Aug 2020 12:59:29 +0300 Subject: [PATCH] version 2.2.0 remove deprecated members PIVariantTypes::File add "is_save" flag PIBinaryLog clear --- CMakeLists.txt | 2 +- lib/main/core/pibase.h | 13 ------------- lib/main/core/pivarianttypes.h | 22 ++++++++++++---------- lib/main/io_devices/pibinarylog.cpp | 16 +++++++++++++--- lib/main/io_devices/pibinarylog.h | 9 +-------- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53269b61..6fddfc2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(pip) set(_PIP_MAJOR 2) -set(_PIP_MINOR 1) +set(_PIP_MINOR 2) set(_PIP_REVISION 0) set(_PIP_SUFFIX _alpha) set(_PIP_COMPANY SHS) diff --git a/lib/main/core/pibase.h b/lib/main/core/pibase.h index 7d31d3c8..559ded47 100644 --- a/lib/main/core/pibase.h +++ b/lib/main/core/pibase.h @@ -454,19 +454,6 @@ template<> inline float piLetobe(const float & v) { return a.f; } -DEPRECATED inline ushort letobe_s(const ushort & v) {return (v << 8) | (v >> 8);} -DEPRECATED inline uint letobe_i(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);} - -#ifdef DOXYGEN - -/// \deprecated \brief Use \a piLetobe() instead of this function -ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);} - -/// \deprecated \brief Use \a piLetobe() instead of this function -uint letobe_i(uint v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);} - -#endif - /// \brief Generic hash function, implements murmur3/32 algorithm inline uint piHashData(const uchar * data, uint len, uint seed = 0) { if (!data || len <= 0) return 0u; diff --git a/lib/main/core/pivarianttypes.h b/lib/main/core/pivarianttypes.h index 395ecf38..95065d57 100644 --- a/lib/main/core/pivarianttypes.h +++ b/lib/main/core/pivarianttypes.h @@ -48,7 +48,6 @@ struct PIP_EXPORT Enumerator { */ struct PIP_EXPORT Enum { Enum(const PIString & n = PIString()): enum_name(n) {} - PIString toString() const {return selected;} // obsolete /** * @brief Find selected value. @@ -123,15 +122,18 @@ struct PIP_EXPORT Enum { }; struct PIP_EXPORT File { - File(const PIString & p = PIString(), const PIString & f = PIString(), bool abs = false): file(p), filter(f), is_abs(abs) {} + File(const PIString & p = PIString(), const PIString & f = PIString(), bool abs = false, bool save_mode = false): + file(p), filter(f), is_abs(abs), is_save(save_mode) {} PIString toString() const {return file;} PIString file; PIString filter; bool is_abs; + bool is_save; }; struct PIP_EXPORT Dir { - Dir(const PIString & d = PIString(), bool abs = false): dir(d), is_abs(abs) {} + Dir(const PIString & d = PIString(), bool abs = false): + dir(d), is_abs(abs) {} PIString toString() const {return dir;} PIString dir; bool is_abs; @@ -156,27 +158,27 @@ struct PIP_EXPORT IODevice { } inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::Enumerator & v) {s << v.value << v.name; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Enumerator & v) {s >> v.value >> v.name; return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Enumerator & v) {s >> v.value >> v.name; return s;} inline PICout operator <<(PICout s, const PIVariantTypes::Enumerator & v) {s << v.name << "(" << v.value << ")"; return s;} inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::Enum & v) {s << v.enum_name << v.selected << v.enum_list; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Enum & v) {s >> v.enum_name >> v.selected >> v.enum_list; return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Enum & v) {s >> v.enum_name >> v.selected >> v.enum_list; return s;} inline PICout operator <<(PICout s, const PIVariantTypes::Enum & v) {s << "Enum(" << v.selectedValue() << "=" << v.selectedName() << ")"; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::File & v) {s << v.file << v.filter << v.is_abs; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::File & v) {s >> v.file >> v.filter >> v.is_abs; return s;} +inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::File & v) {s << v.file << v.filter << uchar((v.is_abs ? 1 : 0) + (v.is_save ? 2 : 0)); return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::File & v) {uchar f(0); s >> v.file >> v.filter >> f; v.is_abs = ((f & 1) == 1); v.is_save = ((f & 2) == 2); return s;} inline PICout operator <<(PICout s, const PIVariantTypes::File & v) {s << "File(\"" << v.file << "\")"; return s;} inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::Dir & v) {s << v.dir << v.is_abs; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Dir & v) {s >> v.dir >> v.is_abs; return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Dir & v) {s >> v.dir >> v.is_abs; return s;} inline PICout operator <<(PICout s, const PIVariantTypes::Dir & v) {s << "Dir(\"" << v.dir << "\")"; return s;} inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::Color & v) {s << v.rgba; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Color & v) {s >> v.rgba; return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Color & v) {s >> v.rgba; return s;} inline PICout operator <<(PICout s, const PIVariantTypes::Color & v) {s.saveControl(); s << PICoutManipulators::Hex << "Color(#" << v.rgba << ")"; s.restoreControl(); return s;} inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::IODevice & v) {s << v.prefix << v.mode << v.options << v.props; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::IODevice & v) {s >> v.prefix >> v.mode >> v.options >> v.props; return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::IODevice & v) {s >> v.prefix >> v.mode >> v.options >> v.props; return s;} inline PICout operator <<(PICout s, const PIVariantTypes::IODevice & v) {s << v.toPICout(); return s;} #endif // PIVARIANTYPES_H diff --git a/lib/main/io_devices/pibinarylog.cpp b/lib/main/io_devices/pibinarylog.cpp index ebd44728..2fd71564 100644 --- a/lib/main/io_devices/pibinarylog.cpp +++ b/lib/main/io_devices/pibinarylog.cpp @@ -45,6 +45,11 @@ * */ +static const uchar binlog_sig[] = {'B','I','N','L','O','G'}; + +#define PIBINARYLOG_VERSION 0x32 +#define PIBINARYLOG_SIGNATURE_SIZE sizeof(binlog_sig) + REGISTER_DEVICE(PIBinaryLog) PIBinaryLog::PIBinaryLog() { @@ -358,6 +363,11 @@ int PIBinaryLog::readBinLog(int id, void *read_to, int max_size, PISystemTime * } +bool PIBinaryLog::isEmpty() const { + return (log_size <= llong(PIBINARYLOG_SIGNATURE_SIZE + 1)); +} + + void PIBinaryLog::setHeader(const PIByteArray & header) { user_header = header; } @@ -414,7 +424,7 @@ void PIBinaryLog::restart() { bool PIBinaryLog::writeFileHeader() { - if (file.write(&__S__PIBinaryLog::binlog_sig, PIBINARYLOG_SIGNATURE_SIZE) <= 0) return false; + if (file.write(binlog_sig, PIBINARYLOG_SIGNATURE_SIZE) <= 0) return false; uchar version = PIBINARYLOG_VERSION; if (file.write(&version, 1) <= 0) return false; uint32_t sz = user_header.size(); @@ -432,7 +442,7 @@ bool PIBinaryLog::checkFileHeader() { if (file.read(read_sig, PIBINARYLOG_SIGNATURE_SIZE) < 0) return false; bool correct = true; for (uint i=0; iread(read_sig, PIBINARYLOG_SIGNATURE_SIZE) < 0) {if (ginfo) bi->records_count = -1; ok = false;} for (uint i=0; irecords_count = -2; ok = false;} + if (read_sig[i] != binlog_sig[i]) {if (ginfo) bi->records_count = -2; ok = false;} uchar read_version = 0; if (f->read(&read_version, 1) < 0) {if (ginfo) bi->records_count = -3; ok = false;} if (read_version == 0) {if (ginfo) bi->records_count = -4; ok = false;} diff --git a/lib/main/io_devices/pibinarylog.h b/lib/main/io_devices/pibinarylog.h index f9b4bab7..13ee83d5 100644 --- a/lib/main/io_devices/pibinarylog.h +++ b/lib/main/io_devices/pibinarylog.h @@ -25,14 +25,7 @@ #include "pifile.h" -#define PIBINARYLOG_VERSION 0x32 -namespace __S__PIBinaryLog { -static const uchar binlog_sig[] = {'B','I','N','L','O','G'}; -} -#define PIBINARYLOG_SIGNATURE_SIZE sizeof(__S__PIBinaryLog::binlog_sig) -/// TODO: Create static functions to join binlog files -/// TODO: Create functions to insert and delete records class PIP_EXPORT PIBinaryLog: public PIIODevice { PIIODEVICE(PIBinaryLog) @@ -196,7 +189,7 @@ public: bool isEnd() const {if (isClosed()) return true; return file.isEnd();} //! Returns if BinLog file is empty - bool isEmpty() const {return (log_size <= llong(PIBINARYLOG_SIGNATURE_SIZE + 1));} + bool isEmpty() const; //! Returns BinLog pause status bool isPause() const {return is_pause;}