diff --git a/main.cpp b/main.cpp index 61c13687..51e6de7d 100644 --- a/main.cpp +++ b/main.cpp @@ -12,7 +12,7 @@ REGISTER_VARIANT_CAST(__S__, PIString) {return v.text + PIString::fromNumber(v.i REGISTER_VARIANT_CAST(__S__, int) {return v.i;} int main(int argc, char *argv[]) { - __S__ s, s1; + /*__S__ s, s1; s.text = "123"; s.i = -1; PIVariant v = PIVariant::fromValue(s); @@ -20,7 +20,16 @@ int main(int argc, char *argv[]) { ba << v; PIVariant v1; ba >> v1; - piCout << v1; + piCout << v1;*/ + PISet s0; + s0 << 1 << 3 << 5; + PIVector v; + v << -1 << 8 << 0 << 2 << 1 << 6 << 4 << 3; + piCout << s0; + PISet s1(v); + piCout << s1; + s1.subtract(s0); + piCout << s1; return 0; } diff --git a/src/containers/piset.h b/src/containers/piset.h index ddb19120..adde5f6d 100644 --- a/src/containers/piset.h +++ b/src/containers/piset.h @@ -53,7 +53,20 @@ public: //! Contructs set with elements "v0", "v1", "v2" and "v3" PISet(const T & v0, const T & v1, const T & v2, const T & v3) {_CSet::insert(v0, 0); _CSet::insert(v1, 0); _CSet::insert(v2, 0); _CSet::insert(v3, 0);} - + + //! Contructs set from vector of elements + PISet(const PIVector & values) { + if (values.isEmpty()) return; + //_CSet::pim_content.resize(values.size_s()); + //_CSet::pim_index.resize(values.size_s()); + for (int i = 0; i < values.size_s(); ++i) { + //_CSet::pim_index[i].index = i; + //_CSet::pim_index[i].key = values[i]; + _CSet::insert(values[i], 0); + } + //_CSet::_sort(); + } + typedef T key_type; PISet & operator <<(const T & t) {_CSet::insert(t, 0); return *this;} @@ -64,9 +77,41 @@ public: //! Returns if element "t" exists in this set PISet & remove(const T & t) {_CSet::remove(t); return *this;} - + + //! Unite set with "v" + PISet & unite(const PISet & v) { + for (typename PIMap::const_iterator i = v.begin(); i != v.end(); ++i) + _CSet::insert(i->first, 0); + return *this; + } + + //! Subtract set with "v" + PISet & subtract(const PISet & v) { + for (typename PIMap::const_iterator i = v.begin(); i != v.end(); ++i) + _CSet::remove(i->first); + return *this; + } + //! Returns content of set as PIVector PIVector toVector() const {PIVector ret; for (typename _CSet::const_iterator i = _CSet::begin(); i != _CSet::end(); ++i) ret << (*i).first; return ret;} }; + +template +inline PICout operator <<(PICout s, const PISet & v) { + s.space(); + s.setControl(0, true); + s << "{"; + bool first = true; + for (typename PIMap::const_iterator i = v.begin(); i != v.end(); ++i) { + if (!first) + s << ", "; + first = false; + s << i->first; + } + s << "}"; + s.restoreControl(); + return s; +} + #endif // PISET_H diff --git a/src/core/pichunkstream.h b/src/core/pichunkstream.h index 72ef16c9..f1aac273 100644 --- a/src/core/pichunkstream.h +++ b/src/core/pichunkstream.h @@ -67,6 +67,10 @@ public: //! Returns value of last readed chunk template T getData() const {T ret; PIByteArray s(last_data); s >> ret; return ret;} + + //! Place value of last readed chunk into "v" + template + void get(T & v) const {v = getData();} private: void _init(); diff --git a/src/io/piiodevice.cpp b/src/io/piiodevice.cpp index f6ecebc2..91ba9570 100755 --- a/src/io/piiodevice.cpp +++ b/src/io/piiodevice.cpp @@ -232,13 +232,13 @@ void PIIODevice::run() { return; } if (!thread_started_) { - msleep(5); + piMSleep(5); //cout << "not started\n"; return; } readed_ = read(buffer_tr.data(), buffer_tr.size_s()); if (readed_ <= 0) { - msleep(10); + piMSleep(10); //cout << readed_ << ", " << errno << ", " << errorString() << endl; return; } diff --git a/src/math/picrypt.cpp b/src/math/picrypt.cpp index a0df92da..f52baf55 100644 --- a/src/math/picrypt.cpp +++ b/src/math/picrypt.cpp @@ -85,7 +85,7 @@ PIByteArray PICrypt::crypt(const PIByteArray & data, PIByteArray key) { crypto_secretbox_easy(ret.data(), data.data(), data.size(), n.data(), key.data()); ret.append(n); #else - piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT="; + piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=1"; #endif return ret; }