diff --git a/libs/main/core/pibytearray.h b/libs/main/core/pibytearray.h index 7db8b7b5..a5e9488d 100644 --- a/libs/main/core/pibytearray.h +++ b/libs/main/core/pibytearray.h @@ -166,8 +166,6 @@ PIP_EXPORT PICout operator <<(PICout s, const PIByteArray & ba); // store operators for basic types -#define PBA_OPERATOR_TO int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); - //! \relatesalso PIByteArray \brief Store operator inline PIByteArray & operator <<(PIByteArray & s, const bool v) {s.push_back(v); return s;} @@ -178,14 +176,14 @@ inline PIByteArray & operator <<(PIByteArray & s, const char v) {s.push_back(v); inline PIByteArray & operator <<(PIByteArray & s, const uchar v) {s.push_back(v); return s;} //! \relatesalso PIByteArray \brief Store operator -inline PIByteArray & operator <<(PIByteArray & s, const PIChar & v) {PBA_OPERATOR_TO return s;} +inline PIByteArray & operator <<(PIByteArray & s, const PIChar & v) {int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); return s;} //! \relatesalso PIByteArray \brief Store operator -template inline PIByteArray & operator <<(PIByteArray & s, const PIFlags & v) {PBA_OPERATOR_TO return s;} +template inline PIByteArray & operator <<(PIByteArray & s, const PIFlags & v) {int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); return s;} //! \relatesalso PIByteArray \brief Store operator for any trivial copyable type template::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const T & v) {PBA_OPERATOR_TO return s;} +inline PIByteArray & operator <<(PIByteArray & s, const T & v) {int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); return s;} //! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v) { @@ -251,16 +249,12 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIBitArray & v) {s << v. template inline PIByteArray & operator <<(PIByteArray & s, const PIPair & v) {s << v.first << v.second; return s;} -#undef PBA_OPERATOR_TO - // restore operators for basic types -#define PBA_OPERATOR_FROM memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v)); - //! \relatesalso PIByteArray \brief Restore operator inline PIByteArray & operator >>(PIByteArray & s, bool & v) {assert(s.size() >= 1u); v = s.take_front(); return s;} @@ -271,14 +265,14 @@ inline PIByteArray & operator >>(PIByteArray & s, char & v) {assert(s.size() >= inline PIByteArray & operator >>(PIByteArray & s, uchar & v) {assert(s.size() >= 1u); v = s.take_front(); return s;} //! \relatesalso PIByteArray \brief Restore operator -inline PIByteArray & operator >>(PIByteArray & s, PIChar & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIChar & v) {assert(s.size() >= sizeof(v)); memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v)); return s;} //! \relatesalso PIByteArray \brief Restore operator for any trivial copyable type template::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, T & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;} +inline PIByteArray & operator >>(PIByteArray & s, T & v) {assert(s.size() >= sizeof(v)); memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v)); return s;} //! \relatesalso PIByteArray \brief Restore operator -template inline PIByteArray & operator >>(PIByteArray & s, PIFlags & v) {PBA_OPERATOR_FROM return s;} +template inline PIByteArray & operator >>(PIByteArray & s, PIFlags & v) {memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v)); return s;} //! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIByteArray & v); @@ -340,8 +334,6 @@ inline PIByteArray & operator >>(PIByteArray & s, PIBitArray & v) {assert(s.size template inline PIByteArray & operator >>(PIByteArray & s, PIPair & v) {s >> v.first >> v.second; return s;} -#undef PBA_OPERATOR_FROM - diff --git a/libs/main/core/pivariantsimple.h b/libs/main/core/pivariantsimple.h index ba2d2e9e..64114a4e 100644 --- a/libs/main/core/pivariantsimple.h +++ b/libs/main/core/pivariantsimple.h @@ -36,7 +36,7 @@ public: virtual uint hash() const {return 0;} virtual void newT(void *& ptr, const void * value) {;} virtual void newNullT(void *& ptr) {;} - virtual void equalT(void *& ptr, const void * value) {;} + virtual void assignT(void *& ptr, const void * value) {;} virtual void deleteT(void *& ptr) {;} //virtual PIByteArray toData(const void * ptr) const {return PIByteArray();} //virtual void fromData(void *& ptr, PIByteArray ba) {;} @@ -47,15 +47,15 @@ public: template class __VariantFunctions__: public __VariantFunctionsBase__ { public: - __VariantFunctionsBase__ * instance() override {static __VariantFunctions__ ret; return &ret;} - PIString typeName() const override {static PIString ret(typeid(T).name()); return ret;} - uint hash() const override {static uint ret = typeName().hash(); return ret;} - void newT(void *& ptr, const void * value) override {ptr = (void*)(new T(*(const T*)value)); /*printf(" * new\n")*/;} - void newNullT(void *& ptr) override {ptr = (void*)(new T());/* printf(" * new null\n")*/;} - void equalT(void *& ptr, const void * value) override {*(T*)ptr = *(const T*)value; /*printf(" * =\n")*/;} - void deleteT(void *& ptr) override {delete (T*)(ptr); /*printf(" * del\n")*/;} - //PIByteArray toData(const void * ptr) const override {PIByteArray ret; ret << (*(const T* &)ptr); return ret;} - //void fromData(void *& ptr, PIByteArray ba) override {ba >> *(T*)ptr;} + __VariantFunctionsBase__ * instance() final {static __VariantFunctions__ ret; return &ret;} + PIString typeName() const final {static PIString ret(typeid(T).name()); return ret;} + uint hash() const final {static uint ret = typeName().hash(); return ret;} + void newT(void *& ptr, const void * value) final {ptr = (void*)(new T(*(const T*)value)); /*printf(" * new\n")*/;} + void newNullT(void *& ptr) final {ptr = (void*)(new T());/* printf(" * new null\n")*/;} + void assignT(void *& ptr, const void * value) final {*(T*)ptr = *(const T*)value; /*printf(" * =\n")*/;} + void deleteT(void *& ptr) final {delete (T*)(ptr); /*printf(" * del\n")*/;} + //PIByteArray toData(const void * ptr) const final {PIByteArray ret; ret << (*(const T* &)ptr); return ret;} + //void fromData(void *& ptr, PIByteArray ba) final {ba >> *(T*)ptr;} }; class PIVariantSimple { @@ -81,7 +81,7 @@ public: void setValue(const T & v) { if (f) { if (isMyType()) { - f->equalT(ptr, (const void *)&v); + f->assignT(ptr, (const void *)&v); return; } } diff --git a/libs/main/io_devices/pifile.cpp b/libs/main/io_devices/pifile.cpp index 8f598b05..c8754a08 100644 --- a/libs/main/io_devices/pifile.cpp +++ b/libs/main/io_devices/pifile.cpp @@ -124,10 +124,12 @@ PIString PIFile::FileInfo::extension() const { PIString PIFile::FileInfo::dir() const { if (path.isEmpty()) return PIString(); - PIString ret = path.mid(0, path.findLast(PIDir::separator)); - if (ret.isEmpty()) ret = PIDir::separator; - if (!PIDir(ret).isExists()) return (PIStringAscii(".") + PIDir::separator); - return ret; + int ind = path.findLast(PIDir::separator); + PIString ret; + if (ind >= 0) + ret = path.mid(0, ind); + if (ret.isEmpty()) ret = "."; + return ret + PIDir::separator; } diff --git a/libs/main/io_devices/pifile.h b/libs/main/io_devices/pifile.h index 56b1df6f..a84cd63d 100644 --- a/libs/main/io_devices/pifile.h +++ b/libs/main/io_devices/pifile.h @@ -36,7 +36,7 @@ public: explicit PIFile(); struct PIP_EXPORT FileInfo { - FileInfo() {size = 0; id_group = id_user = 0;} + FileInfo(const PIString & path_ = PIString()) {path = path_; size = 0; id_group = id_user = 0;} enum Flag { File = 0x01,