code brush
This commit is contained in:
@@ -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<typename T> inline PIByteArray & operator <<(PIByteArray & s, const PIFlags<T> & v) {PBA_OPERATOR_TO return s;}
|
||||
template<typename T> inline PIByteArray & operator <<(PIByteArray & s, const PIFlags<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 for any trivial copyable type
|
||||
template<typename T, typename std::enable_if< std::is_trivially_copyable<T>::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<typename Type0, typename Type1>
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIPair<Type0, Type1> & 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<typename T, typename std::enable_if< std::is_trivially_copyable<T>::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<typename T> inline PIByteArray & operator >>(PIByteArray & s, PIFlags<T> & v) {PBA_OPERATOR_FROM return s;}
|
||||
template<typename T> inline PIByteArray & operator >>(PIByteArray & s, PIFlags<T> & 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<typename Type0, typename Type1>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIPair<Type0, Type1> & v) {s >> v.first >> v.second; return s;}
|
||||
|
||||
#undef PBA_OPERATOR_FROM
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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<typename T>
|
||||
class __VariantFunctions__: public __VariantFunctionsBase__ {
|
||||
public:
|
||||
__VariantFunctionsBase__ * instance() override {static __VariantFunctions__<T> 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__<T> 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<T>()) {
|
||||
f->equalT(ptr, (const void *)&v);
|
||||
f->assignT(ptr, (const void *)&v);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user