git-svn-id: svn://db.shs.com.ru/pip@299 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
13
main.cpp
13
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;}
|
REGISTER_VARIANT_CAST(__S__, int) {return v.i;}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
__S__ s, s1;
|
/*__S__ s, s1;
|
||||||
s.text = "123";
|
s.text = "123";
|
||||||
s.i = -1;
|
s.i = -1;
|
||||||
PIVariant v = PIVariant::fromValue(s);
|
PIVariant v = PIVariant::fromValue(s);
|
||||||
@@ -20,7 +20,16 @@ int main(int argc, char *argv[]) {
|
|||||||
ba << v;
|
ba << v;
|
||||||
PIVariant v1;
|
PIVariant v1;
|
||||||
ba >> v1;
|
ba >> v1;
|
||||||
piCout << v1;
|
piCout << v1;*/
|
||||||
|
PISet<int> s0;
|
||||||
|
s0 << 1 << 3 << 5;
|
||||||
|
PIVector<int> v;
|
||||||
|
v << -1 << 8 << 0 << 2 << 1 << 6 << 4 << 3;
|
||||||
|
piCout << s0;
|
||||||
|
PISet<int> s1(v);
|
||||||
|
piCout << s1;
|
||||||
|
s1.subtract(s0);
|
||||||
|
piCout << s1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,19 @@ public:
|
|||||||
//! Contructs set with elements "v0", "v1", "v2" and "v3"
|
//! 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);}
|
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<T> & 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;
|
typedef T key_type;
|
||||||
|
|
||||||
PISet<T> & operator <<(const T & t) {_CSet::insert(t, 0); return *this;}
|
PISet<T> & operator <<(const T & t) {_CSet::insert(t, 0); return *this;}
|
||||||
@@ -65,8 +78,40 @@ public:
|
|||||||
//! Returns if element "t" exists in this set
|
//! Returns if element "t" exists in this set
|
||||||
PISet<T> & remove(const T & t) {_CSet::remove(t); return *this;}
|
PISet<T> & remove(const T & t) {_CSet::remove(t); return *this;}
|
||||||
|
|
||||||
|
//! Unite set with "v"
|
||||||
|
PISet<T> & unite(const PISet<T> & v) {
|
||||||
|
for (typename PIMap<T, uchar>::const_iterator i = v.begin(); i != v.end(); ++i)
|
||||||
|
_CSet::insert(i->first, 0);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Subtract set with "v"
|
||||||
|
PISet<T> & subtract(const PISet<T> & v) {
|
||||||
|
for (typename PIMap<T, uchar>::const_iterator i = v.begin(); i != v.end(); ++i)
|
||||||
|
_CSet::remove(i->first);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! Returns content of set as PIVector
|
//! Returns content of set as PIVector
|
||||||
PIVector<T> toVector() const {PIVector<T> ret; for (typename _CSet::const_iterator i = _CSet::begin(); i != _CSet::end(); ++i) ret << (*i).first; return ret;}
|
PIVector<T> toVector() const {PIVector<T> ret; for (typename _CSet::const_iterator i = _CSet::begin(); i != _CSet::end(); ++i) ret << (*i).first; return ret;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
inline PICout operator <<(PICout s, const PISet<Type> & v) {
|
||||||
|
s.space();
|
||||||
|
s.setControl(0, true);
|
||||||
|
s << "{";
|
||||||
|
bool first = true;
|
||||||
|
for (typename PIMap<Type, uchar>::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
|
#endif // PISET_H
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ public:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T getData() const {T ret; PIByteArray s(last_data); s >> ret; return ret;}
|
T getData() const {T ret; PIByteArray s(last_data); s >> ret; return ret;}
|
||||||
|
|
||||||
|
//! Place value of last readed chunk into "v"
|
||||||
|
template <typename T>
|
||||||
|
void get(T & v) const {v = getData<T>();}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _init();
|
void _init();
|
||||||
|
|
||||||
|
|||||||
@@ -232,13 +232,13 @@ void PIIODevice::run() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!thread_started_) {
|
if (!thread_started_) {
|
||||||
msleep(5);
|
piMSleep(5);
|
||||||
//cout << "not started\n";
|
//cout << "not started\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
readed_ = read(buffer_tr.data(), buffer_tr.size_s());
|
readed_ = read(buffer_tr.data(), buffer_tr.size_s());
|
||||||
if (readed_ <= 0) {
|
if (readed_ <= 0) {
|
||||||
msleep(10);
|
piMSleep(10);
|
||||||
//cout << readed_ << ", " << errno << ", " << errorString() << endl;
|
//cout << readed_ << ", " << errno << ", " << errorString() << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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());
|
crypto_secretbox_easy(ret.data(), data.data(), data.size(), n.data(), key.data());
|
||||||
ret.append(n);
|
ret.append(n);
|
||||||
#else
|
#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
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user