style: run clang-format over all files

This commit is contained in:
2026-08-22 15:52:58 +03:00
parent 8828aa3f81
commit f6075307b6
124 changed files with 1607 additions and 1737 deletions
+57 -51
View File
@@ -1,63 +1,69 @@
#include "pip.h" #include "pip.h"
void _() { void _() {
//! [0] //! [0]
PIByteArray ba; PIByteArray ba;
int i = -1, j = 2; int i = -1, j = 2;
float f = 1.; float f = 1.;
PIString text("123"); PIString text("123");
ba << i << j << f << text; // form binary data ba << i << j << f << text; // form binary data
piCout << "data =" << ba; piCout << "data =" << ba;
i = j = 0; // clear variables i = j = 0; // clear variables
f = 0; // clear variables f = 0; // clear variables
text.clear(); // clear variables text.clear(); // clear variables
piCout << i << j << f << text; // show variables piCout << i << j << f << text; // show variables
ba >> i >> j >> f >> text; // restore data ba >> i >> j >> f >> text; // restore data
piCout << i << j << f << text; // show variables piCout << i << j << f << text; // show variables
piCout << "data =" << ba; piCout << "data =" << ba;
//! [0] //! [0]
//! [1] //! [1]
struct MyType { struct MyType {
MyType(int i_ = 0, const PIString & t_ = PIString()) { MyType(int i_ = 0, const PIString & t_ = PIString()) {
m_i = i_; m_i = i_;
m_text = t_; m_text = t_;
} }
int m_i; int m_i;
PIString m_text; PIString m_text;
}; };
inline PIByteArray & operator <<(PIByteArray & s, const MyType & v) {s << v.m_i << v.m_text; return s;} inline PIByteArray & operator<<(PIByteArray & s, const MyType & v) {
inline PIByteArray & operator >>(PIByteArray & s, MyType & v) {s >> v.m_i >> v.m_text; return s;} s << v.m_i << v.m_text;
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, MyType & v) {
s >> v.m_i >> v.m_text;
return s;
}
PIByteArray ba; PIByteArray ba;
PIVector<MyType> my_vec; PIVector<MyType> my_vec;
my_vec << MyType(1, "s1") << MyType(10, "s10"); // add to vector my_vec << MyType(1, "s1") << MyType(10, "s10"); // add to vector
ba << my_vec; // store to byte array ba << my_vec; // store to byte array
piCout << "data =" << ba; piCout << "data =" << ba;
my_vec.clear(); // clear vector my_vec.clear(); // clear vector
ba >> my_vec; // restore from byte array ba >> my_vec; // restore from byte array
//! [1] //! [1]
//! [2] //! [2]
PIByteArray ba; PIByteArray ba;
const char * chars = "8 bytes"; const char * chars = "8 bytes";
ba << PIByteArray::RawData(chars, 8); // form binary data ba << PIByteArray::RawData(chars, 8); // form binary data
piCout << "data =" << ba; piCout << "data =" << ba;
char rchars[16]; char rchars[16];
memset(rchars, 0, 16); // clear data memset(rchars, 0, 16); // clear data
ba >> PIByteArray::RawData(rchars, 8); // restore data ba >> PIByteArray::RawData(rchars, 8); // restore data
piCout << rchars; piCout << rchars;
piCout << "data =" << ba; piCout << "data =" << ba;
//! [2] //! [2]
//! [3] //! [3]
PIByteArray ba, sba; PIByteArray ba, sba;
uchar uc(127); uchar uc(127);
sba << uc; // byte array with one byte sba << uc; // byte array with one byte
ba << sba; // stream operator ba << sba; // stream operator
piCout << ba; // result piCout << ba; // result
// {1, 0, 0, 0, 127} // {1, 0, 0, 0, 127}
ba.clear(); ba.clear();
ba.append(sba); ba.append(sba);
piCout << ba; // result piCout << ba; // result
// {127} // {127}
//! [3] //! [3]
}; };
+1 -2
View File
@@ -3,5 +3,4 @@
//! [main] //! [main]
//! [main] //! [main]
void _() { void _() {};
};
+3 -3
View File
@@ -29,10 +29,10 @@ int main() {
PIStringList gl = PICollection::groups(); PIStringList gl = PICollection::groups();
piCout << gl; // {"ab_group", "c_group"} piCout << gl; // {"ab_group", "c_group"}
piForeachC (PIString g, gl) { piForeachC(PIString g, gl) {
PIVector<const PIObject * > go = PICollection::groupElements(g); PIVector<const PIObject *> go = PICollection::groupElements(g);
piCout << "group" << g << ":"; piCout << "group" << g << ":";
piForeachC (PIObject * o, go) piForeachC(PIObject * o, go)
piCout << Tab << o->className(); piCout << Tab << o->className();
} }
+20 -22
View File
@@ -2,26 +2,24 @@
void _() { void _() {
//! [PIConfig::Entry]
//! [PIConfig::Entry] /* "example.conf"
/* "example.conf" a = 1
a = 1 s0.a = A
s0.a = A s0.b = B
s0.b = B */
*/ PIConfig conf("example.conf", PIIODevice::ReadOnly);
PIConfig conf("example.conf", PIIODevice::ReadOnly); PIConfig::Entry ce = conf.getValue("a");
PIConfig::Entry ce = conf.getValue("a"); int a = ce; // a = 1
int a = ce; // a = 1 PIString A = ce; // A = "1"
PIString A = ce; // A = "1" ce = conf.getValue("s0");
ce = conf.getValue("s0"); piCout << ce.childCount(); // 2
piCout << ce.childCount(); // 2 A = ce.getValue("b"); // A = "B"
A = ce.getValue("b"); // A = "B" A = conf.getValue("s0.a"); // A = "A"
A = conf.getValue("s0.a"); // A = "A" //! [PIConfig::Entry]
//! [PIConfig::Entry] //! [fullName]
//! [fullName] PIConfig conf("example.conf", PIIODevice::ReadOnly);
PIConfig conf("example.conf", PIIODevice::ReadOnly); piCout << conf.getValue("a.b.c").name(); // "c"
piCout << conf.getValue("a.b.c").name(); // "c" piCout << conf.getValue("a.b.c").fullName(); // "a.b.c"
piCout << conf.getValue("a.b.c").fullName(); // "a.b.c" //! [fullName]
//! [fullName]
}; };
+183 -182
View File
@@ -1,213 +1,214 @@
#include "pip.h" #include "pip.h"
void _() { void _() {
//! [foreach]
PIVector<int> vec;
vec << 1 << 2 << 3;
//! [foreach] piForeach(int & i, vec)
PIVector<int> vec; piCout << i;
vec << 1 << 2 << 3; // 1
// 2
// 3
piForeach (int & i, vec) piCout << i; piForeach(int & i, vec)
// 1
// 2
// 3
piForeach (int & i, vec) i++;
piForeach (int & i, vec) piCout << i;
// 2
// 3
// 4
//! [foreach]
//! [foreachC]
PIVector<int> vec;
vec << 1 << 2 << 3;
piForeachC (int & i, vec)
cout << i << ", ";
// 1, 2, 3,
piForeachC (int & i, vec)
i++; // ERROR! const iterator
//! [foreachC]
//! [foreachR]
PIVector<int> vec;
vec << 1 << 2 << 3;
piForeachR (int & i, vec)
cout << i << ", ";
// 3, 2, 1,
piForeachR (int & i, vec)
i++; i++;
piForeachR (int & i, vec) piForeach(int & i, vec)
piCout << i;
// 2
// 3
// 4
//! [foreach]
//! [foreachC]
PIVector<int> vec;
vec << 1 << 2 << 3;
piForeachC(int & i, vec)
cout << i << ", "; cout << i << ", ";
// 4, 3, 2, // 1, 2, 3,
//! [foreachR] piForeachC(int & i, vec)
//! [foreachCR]
PIVector<int> vec;
vec << 1 << 2 << 3;
piForeachCR (int & i, vec)
cout << i << ", ";
// 3, 2, 1,
piForeachCR (int & i, vec)
i++; // ERROR! const iterator i++; // ERROR! const iterator
//! [foreachCR] //! [foreachC]
//! [foreachR]
//! [PIVector::PIVector] PIVector<int> vec;
PIVector<char> vec(4u, 'p'); vec << 1 << 2 << 3;
piForeachC (char i, vec) piForeachR(int & i, vec)
cout << i << ", "; cout << i << ", ";
// p, p, p, p, // 3, 2, 1,
piForeachR(int & i, vec)
i++;
piForeachR(int & i, vec)
cout << i << ", ";
// 4, 3, 2,
//! [foreachR]
//! [foreachCR]
PIVector<int> vec;
vec << 1 << 2 << 3;
piForeachCR(int & i, vec)
cout << i << ", ";
// 3, 2, 1,
piForeachCR(int & i, vec)
i++; // ERROR! const iterator
//! [foreachCR]
piCout << PIVector<int>({1, 2, 3}); //! [PIVector::PIVector]
// 1, 2, 3 PIVector<char> vec(4u, 'p');
//! [PIVector::PIVector] piForeachC(char i, vec)
//! [PIVector::at_c] cout << i << ", ";
PIVector<int> vec; // p, p, p, p,
vec << 1 << 3 << 5;
for (int i = 0; i < vec.size_s(); ++i) piCout << PIVector<int>({1, 2, 3});
// 1, 2, 3
//! [PIVector::PIVector]
//! [PIVector::at_c]
PIVector<int> vec;
vec << 1 << 3 << 5;
for (int i = 0; i < vec.size_s(); ++i)
cout << vec.at(i) << ", "; cout << vec.at(i) << ", ";
// 1, 3, 5, // 1, 3, 5,
//! [PIVector::at_c] //! [PIVector::at_c]
//! [PIVector::at] //! [PIVector::at]
PIVector<int> vec; PIVector<int> vec;
vec << 1 << 3 << 5; vec << 1 << 3 << 5;
for (int i = 0; i < vec.size_s(); ++i) for (int i = 0; i < vec.size_s(); ++i)
vec.at(i) += 1; vec.at(i) += 1;
for (int i = 0; i < vec.size_s(); ++i) for (int i = 0; i < vec.size_s(); ++i)
cout << vec.at(i) << ", "; cout << vec.at(i) << ", ";
// 2, 4, 6, // 2, 4, 6,
//! [PIVector::at] //! [PIVector::at]
//! [PIVector::()_c] //! [PIVector::()_c]
PIVector<int> vec; PIVector<int> vec;
vec << 1 << 3 << 5; vec << 1 << 3 << 5;
for (int i = 0; i < vec.size_s(); ++i) for (int i = 0; i < vec.size_s(); ++i)
cout << vec[i] << ", "; cout << vec[i] << ", ";
// 1, 3, 5, // 1, 3, 5,
//! [PIVector::()_c] //! [PIVector::()_c]
//! [PIVector::()] //! [PIVector::()]
PIVector<int> vec; PIVector<int> vec;
vec << 1 << 3 << 5; vec << 1 << 3 << 5;
for (int i = 0; i < vec.size_s(); ++i) for (int i = 0; i < vec.size_s(); ++i)
vec[i] += 1; vec[i] += 1;
for (int i = 0; i < vec.size_s(); ++i) for (int i = 0; i < vec.size_s(); ++i)
cout << vec[i] << ", "; cout << vec[i] << ", ";
// 2, 4, 6, // 2, 4, 6,
//! [PIVector::()] //! [PIVector::()]
//! [PIVector::data_c] //! [PIVector::data_c]
PIVector<int> vec; PIVector<int> vec;
vec << 1 << 3 << 5; vec << 1 << 3 << 5;
int carr[3]; int carr[3];
// copy data from "vec" to "carr" // copy data from "vec" to "carr"
memcpy(carr, vec.data(), vec.size() * sizeof(int)); memcpy(carr, vec.data(), vec.size() * sizeof(int));
for (int i = 0; i < vec.size_s(); ++i) for (int i = 0; i < vec.size_s(); ++i)
cout << carr[i] << ", "; cout << carr[i] << ", ";
// 1, 3, 5, // 1, 3, 5,
//! [PIVector::data_c] //! [PIVector::data_c]
//! [PIVector::data] //! [PIVector::data]
PIVector<int> vec; PIVector<int> vec;
vec << 1 << 3 << 5; vec << 1 << 3 << 5;
int carr[2] = {12, 13}; int carr[2] = {12, 13};
// copy data from "carr" to "vec" with offset // copy data from "carr" to "vec" with offset
memcpy(vec.data(1), carr, 2 * sizeof(int)); memcpy(vec.data(1), carr, 2 * sizeof(int));
for (int i = 0; i < vec.size_s(); ++i) for (int i = 0; i < vec.size_s(); ++i)
cout << vec[i] << ", "; cout << vec[i] << ", ";
// 1, 12, 13, // 1, 12, 13,
//! [PIVector::data] //! [PIVector::data]
//! [PIVector::resize] //! [PIVector::resize]
PIVector<int> vec; PIVector<int> vec;
vec << 1 << 2; vec << 1 << 2;
vec.resize(4); vec.resize(4);
piForeachC (int & i, vec) piForeachC(int & i, vec)
cout << i << ", "; cout << i << ", ";
// 1, 2, 0, 0, // 1, 2, 0, 0,
vec.resize(3); vec.resize(3);
piForeachC (int & i, vec) piForeachC(int & i, vec)
cout << i << ", "; cout << i << ", ";
// 1, 2, 0, // 1, 2, 0,
//! [PIVector::resize] //! [PIVector::resize]
//! [PIVector::sort_0] //! [PIVector::sort_0]
PIVector<int> vec; PIVector<int> vec;
vec << 3 << 2 << 5 << 1 << 4; vec << 3 << 2 << 5 << 1 << 4;
vec.sort(); vec.sort();
piForeachC (int & i, vec) piForeachC(int & i, vec)
cout << i << ", "; cout << i << ", ";
// 1, 2, 3, 4, 5, // 1, 2, 3, 4, 5,
//! [PIVector::sort_0] //! [PIVector::sort_0]
//! [PIVector::sort_1] //! [PIVector::sort_1]
static int mycomp(const int * v0, const int * v1) { static int mycomp(const int * v0, const int * v1) {
if (*v0 == *v1) return 0; if (*v0 == *v1) return 0;
return *v0 < *v1 ? 1 : -1; return *v0 < *v1 ? 1 : -1;
} }
PIVector<int> vec; PIVector<int> vec;
vec << 3 << 2 << 5 << 1 << 4; vec << 3 << 2 << 5 << 1 << 4;
vec.sort(mycomp); vec.sort(mycomp);
piForeachC (int & i, vec) piForeachC(int & i, vec)
cout << i << ", "; cout << i << ", ";
// 5, 4, 3, 2, 1, // 5, 4, 3, 2, 1,
//! [PIVector::sort_1] //! [PIVector::sort_1]
//! [PIVector::fill] //! [PIVector::fill]
PIVector<char> vec; PIVector<char> vec;
vec << '1' << '2' << '3' << '4' << '5'; vec << '1' << '2' << '3' << '4' << '5';
vec.fill('0'); vec.fill('0');
piForeachC (char i, vec) piForeachC(char i, vec)
cout << i << ", "; cout << i << ", ";
// 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0,
//! [PIVector::fill] //! [PIVector::fill]
//! [PIVector::remove_0] //! [PIVector::remove_0]
PIVector<char> vec; PIVector<char> vec;
vec << '1' << '2' << '3' << '4' << '5'; vec << '1' << '2' << '3' << '4' << '5';
vec.remove(1); vec.remove(1);
piForeachC (char i, vec) piForeachC(char i, vec)
cout << i << ", "; cout << i << ", ";
// 1, 3, 4, 5, // 1, 3, 4, 5,
//! [PIVector::remove_0] //! [PIVector::remove_0]
//! [PIVector::remove_1] //! [PIVector::remove_1]
PIVector<char> vec; PIVector<char> vec;
vec << '1' << '2' << '3' << '4' << '5'; vec << '1' << '2' << '3' << '4' << '5';
vec.remove(2, 2); vec.remove(2, 2);
piForeachC (char i, vec) piForeachC(char i, vec)
cout << i << ", "; cout << i << ", ";
// 1, 2, 5, // 1, 2, 5,
//! [PIVector::remove_1] //! [PIVector::remove_1]
//! [PIVector::removeOne] //! [PIVector::removeOne]
PIVector<char> vec; PIVector<char> vec;
vec << '1' << '2' << '3' << '2' << '1'; vec << '1' << '2' << '3' << '2' << '1';
vec.removeOne('2'); vec.removeOne('2');
piForeachC (char i, vec) piForeachC(char i, vec)
cout << i << ", "; cout << i << ", ";
// 1, 3, 2, 1, // 1, 3, 2, 1,
//! [PIVector::removeOne] //! [PIVector::removeOne]
//! [PIVector::removeAll] //! [PIVector::removeAll]
PIVector<char> vec; PIVector<char> vec;
vec << '1' << '2' << '3' << '2' << '1'; vec << '1' << '2' << '3' << '2' << '1';
vec.removeAll('2'); vec.removeAll('2');
piForeachC (char i, vec) piForeachC(char i, vec)
cout << i << ", "; cout << i << ", ";
// 1, 3, 1, // 1, 3, 1,
//! [PIVector::removeAll] //! [PIVector::removeAll]
//! [PIVector::insert_0] //! [PIVector::insert_0]
PIVector<char> vec; PIVector<char> vec;
vec << '1' << '3' << '4'; vec << '1' << '3' << '4';
vec.insert(1, '2'); vec.insert(1, '2');
piForeachC (char i, vec) piForeachC(char i, vec)
cout << i << ", "; cout << i << ", ";
// 1, 2, 3, 4, // 1, 2, 3, 4,
//! [PIVector::insert_0] //! [PIVector::insert_0]
//! [PIVector::insert_1] //! [PIVector::insert_1]
PIVector<char> vec, vec2; PIVector<char> vec, vec2;
vec << '1' << '4' << '5'; vec << '1' << '4' << '5';
vec2 << '2' << '3'; vec2 << '2' << '3';
vec.insert(1, vec2); vec.insert(1, vec2);
piForeachC (char i, vec) piForeachC(char i, vec)
cout << i << ", "; cout << i << ", ";
// 1, 2, 3, 4, 5, // 1, 2, 3, 4, 5,
//! [PIVector::insert_1] //! [PIVector::insert_1]
//! [PIVector::ostream<<] //! [PIVector::ostream<<]
PIVector<char> vec; PIVector<char> vec;
vec << '1' << '2' << '3' << '4' << '5'; vec << '1' << '2' << '3' << '4' << '5';
cout << vec << endl; cout << vec << endl;
// {1, 2, 3, 4, 5} // {1, 2, 3, 4, 5}
//! [PIVector::ostream<<] //! [PIVector::ostream<<]
//! [PIVector::PICout<<] //! [PIVector::PICout<<]
PIVector<char> vec; PIVector<char> vec;
vec << '1' << '2' << '3' << '4' << '5'; vec << '1' << '2' << '3' << '4' << '5';
piCout << vec; piCout << vec;
// {1, 2, 3, 4, 5} // {1, 2, 3, 4, 5}
//! [PIVector::PICout<<] //! [PIVector::PICout<<]
}; };
+18 -18
View File
@@ -1,31 +1,31 @@
#include "pip.h" #include "pip.h"
void _() { void _() {
//! [main] //! [main]
PIEvaluator eval; PIEvaluator eval;
eval.check("2*sin(pi/2)"); eval.check("2*sin(pi/2)");
piCout << eval.expression() << "=" << eval.evaluate().real(); piCout << eval.expression() << "=" << eval.evaluate().real();
// 2*sin(pi/2) = 2 // 2*sin(pi/2) = 2
eval.check("10x"); eval.check("10x");
piCout << eval.error() << eval.unknownVariables(); piCout << eval.error() << eval.unknownVariables();
// Unknown variables: "x" {"x"} // Unknown variables: "x" {"x"}
eval.setVariable("x", complexd(1, 2)); eval.setVariable("x", complexd(1, 2));
eval.check("10x"); eval.check("10x");
piCout << eval.error() << eval.unknownVariables(); piCout << eval.error() << eval.unknownVariables();
// Correct {} // Correct {}
piCout << eval.expression() << "=" << eval.evaluate(); piCout << eval.expression() << "=" << eval.evaluate();
// 10*x = (10; 20) // 10*x = (10; 20)
eval.setVariable("x", complexd(-2, 0)); eval.setVariable("x", complexd(-2, 0));
piCout << eval.expression() << "=" << eval.evaluate(); piCout << eval.expression() << "=" << eval.evaluate();
// 10*x = (-20; 0) // 10*x = (-20; 0)
//! [main] //! [main]
}; };
+54 -52
View File
@@ -1,55 +1,57 @@
#include "pip.h" #include "pip.h"
void _() { void _() {
//! [swap]
//! [swap] int v1 = 1, v2 = 2;
int v1 = 1, v2 = 2; piCout << v1 << v2; // 1 2
piCout << v1 << v2; // 1 2 piSwap<int>(v1, v2);
piSwap<int>(v1, v2); piCout << v1 << v2; // 2 1
piCout << v1 << v2; // 2 1 //! [swap]
//! [swap] //! [round]
//! [round] piCout << piRoundf(0.6f) << piRoundd(0.2); // 1 0
piCout << piRoundf(0.6f) << piRoundd(0.2); // 1 0 piCout << piRoundf(-0.6f) << piRoundd(-0.2); // -1 0
piCout << piRoundf(-0.6f) << piRoundd(-0.2); // -1 0 //! [round]
//! [round] //! [floor]
//! [floor] piCout << piFloorf(0.6f) << piFloorf(0.2); // 0 0
piCout << piFloorf(0.6f) << piFloorf(0.2); // 0 0 piCout << piFloorf(-0.6f) << piFloorf(-0.2f); // -1 -1
piCout << piFloorf(-0.6f) << piFloorf(-0.2f); // -1 -1 //! [floor]
//! [floor] //! [ceil]
//! [ceil] piCout << piCeilf(0.6f) << piCeilf(0.2); // 1 1
piCout << piCeilf(0.6f) << piCeilf(0.2); // 1 1 piCout << piCeilf(-0.6f) << piCeilf(-0.2f); // 0 0
piCout << piCeilf(-0.6f) << piCeilf(-0.2f); // 0 0 //! [ceil]
//! [ceil] //! [abs]
//! [abs] piCout << piAbsi(5) << piAbsi(-11); // 5 11
piCout << piAbsi(5) << piAbsi(-11); // 5 11 piCout << piAbsf(-0.6f) << piAbsf(-0.2f); // 0.6 0.2
piCout << piAbsf(-0.6f) << piAbsf(-0.2f); // 0.6 0.2 //! [abs]
//! [abs] //! [min2]
//! [min2] piCout << piMini(5, 1); // 1
piCout << piMini(5, 1); // 1 piCout << piMinf(-0.6f, -0.2f); // -0.6
piCout << piMinf(-0.6f, -0.2f); // -0.6 //! [min2]
//! [min2] //! [min3]
//! [min3] piCout << piMini(5, 1, -1); // -1
piCout << piMini(5, 1, -1); // -1 piCout << piMinf(-0.6f, -0.2f, 1.f); // -0.6
piCout << piMinf(-0.6f, -0.2f, 1.f); // -0.6 //! [min3]
//! [min3] //! [max2]
//! [max2] piCout << piMaxi(5, 1); // 5
piCout << piMaxi(5, 1); // 5 piCout << piMaxf(-0.6f, -0.2f); // -0.2
piCout << piMaxf(-0.6f, -0.2f); // -0.2 //! [max2]
//! [max2] //! [max3]
//! [max3] piCout << piMaxi(5, 1, -1); // 5
piCout << piMaxi(5, 1, -1); // 5 piCout << piMaxf(-0.6f, -0.2f, 1.f); // 1
piCout << piMaxf(-0.6f, -0.2f, 1.f); // 1 //! [max3]
//! [max3] //! [clamp]
//! [clamp] piCout << piClampf(-5, -3, 2); // -3
piCout << piClampf(-5, -3, 2); // -3 piCout << piClampf(1, -3, 2); // 1
piCout << piClampf(1, -3, 2); // 1 piCout << piClampf(5, -3, 2); // 2
piCout << piClampf(5, -3, 2); // 2 //! [clamp]
//! [clamp] //! [flags]
//! [flags] enum TestEnum {
enum TestEnum {First = 0x1, Second = 0x2, Third = 0x4}; First = 0x1,
PIFlags<TestEnum> testFlags(First); Second = 0x2,
testFlags |= Third; Third = 0x4
piCout << testFlags[First] << testFlags[Second] << testFlags[Third]; // 1 0 1 };
piCout << (int)testFlags; // 5 PIFlags<TestEnum> testFlags(First);
//! [flags] testFlags |= Third;
piCout << testFlags[First] << testFlags[Second] << testFlags[Third]; // 1 0 1
piCout << (int)testFlags; // 5
//! [flags]
}; };
+24 -27
View File
@@ -1,12 +1,13 @@
#include "pip.h" #include "pip.h"
void _() { void _() {
//! [0]
//! [0] class SomeIO: public PIIODevice {
class SomeIO: public PIIODevice {
PIIODEVICE(SomeIO, "myio") PIIODEVICE(SomeIO, "myio")
public:
public:
SomeIO(): PIIODevice() {} SomeIO(): PIIODevice() {}
protected:
protected:
bool openDevice() override { bool openDevice() override {
// open your device here // open your device here
return if_success; return if_success;
@@ -22,31 +23,27 @@ protected:
void configureFromFullPathDevice(const PIString & full_path) override { void configureFromFullPathDevice(const PIString & full_path) override {
// parse full_path and configure device here // parse full_path and configure device here
} }
}; };
REGISTER_DEVICE(SomeIO) REGISTER_DEVICE(SomeIO)
//! [0] //! [0]
//! [configure] //! [configure]
// file example.conf // file example.conf
dev.reopenEnabled = false dev.reopenEnabled = false dev.device = / dev / ttyS0 dev.speed = 9600
dev.device = /dev/ttyS0 // end example.conf
dev.speed = 9600 // code
// end example.conf PISerial ser;
// code ser.configure("example.conf", "dev");
PISerial ser; //! [configure]
ser.configure("example.conf", "dev"); //! [configureDevice]
//! [configure] class SomeIO: public PIIODevice {
//! [configureDevice] ... bool configureDevice(const void * e_main, const void * e_parent) override {
class SomeIO: public PIIODevice { PIConfig::Entry * em = (PIConfig::Entry *)e_main;
... PIConfig::Entry * ep = (PIConfig::Entry *)e_parent;
bool configureDevice(const void * e_main, const void * e_parent) override {
PIConfig::Entry * em = (PIConfig::Entry * )e_main;
PIConfig::Entry * ep = (PIConfig::Entry * )e_parent;
setStringParam(readDeviceSetting<PIString>("stringParam", stringParam(), em, ep)); setStringParam(readDeviceSetting<PIString>("stringParam", stringParam(), em, ep));
setIntParam(readDeviceSetting<int>("intParam", intParam(), em, ep)); setIntParam(readDeviceSetting<int>("intParam", intParam(), em, ep));
return true; return true;
} }
... ...
}; };
//! [configureDevice] //! [configureDevice]
}; };
+2 -3
View File
@@ -1,7 +1,7 @@
#include "pip.h" #include "pip.h"
//! [main] //! [main]
void key_event(char key, void * ) { void key_event(char key, void *) {
piCout << "key" << key << "pressed"; piCout << "key" << key << "pressed";
} }
int main(int argc, char ** argv) { int main(int argc, char ** argv) {
@@ -13,5 +13,4 @@ int main(int argc, char ** argv) {
} }
//! [main] //! [main]
void _() { void _() {};
};
+2 -2
View File
@@ -1,6 +1,6 @@
#include "pip.h" #include "pip.h"
void _() { void _() {
//! [main] //! [main]
//! [main] //! [main]
} }
+6 -4
View File
@@ -3,16 +3,18 @@
//! [main] //! [main]
class ObjectA: public PIObject { class ObjectA: public PIObject {
PIOBJECT(ObjectA) PIOBJECT(ObjectA)
public: public:
EVENT_HANDLER1(void, handlerA, const PIString & , str) {piCoutObj << "handler A:" << str;} EVENT_HANDLER1(void, handlerA, const PIString &, str) { piCoutObj << "handler A:" << str; }
EVENT1(eventA1, const PIString & , str); EVENT1(eventA1, const PIString &, str);
EVENT2(eventA2, int, i, float, f); EVENT2(eventA2, int, i, float, f);
}; };
class ObjectB: public PIObject { class ObjectB: public PIObject {
PIOBJECT(ObjectB) PIOBJECT(ObjectB)
public: public:
EVENT_HANDLER2(void, handlerB, int, i, float, f) {piCoutObj << "handler B:" << i << "," << f;} EVENT_HANDLER2(void, handlerB, int, i, float, f) { piCoutObj << "handler B:" << i << "," << f; }
EVENT1(eventB, PIString, str); EVENT1(eventB, PIString, str);
}; };
@@ -30,7 +32,7 @@ int main(int argc, char * argv[]) {
obj_a.eventA1("event to event"); obj_a.eventA1("event to event");
obj_a.piDisconnect("eventA1"); obj_a.piDisconnect("eventA1");
CONNECTL(&obj_a, eventA1, ([](const PIString & str){piCout << str;})); CONNECTL(&obj_a, eventA1, ([](const PIString & str) { piCout << str; }));
obj_a.eventA1("event to lambda"); obj_a.eventA1("event to lambda");
}; };
//! [main] //! [main]
+13 -9
View File
@@ -7,22 +7,25 @@ enum Header {
hVoid hVoid
}; };
class MyObj: public PIObject, public PIParseHelper<uchar> { class MyObj
: public PIObject
, public PIParseHelper<uchar> {
PIOBJECT(MyObj); PIOBJECT(MyObj);
public: public:
MyObj(): PIParseHelper<uchar>(this) { MyObj(): PIParseHelper<uchar>(this) {
// Keys with 1 argument // Keys with 1 argument
assign(hInt, std::function<void(int)>([this](int i){piCout << "lambda type Int" << i;})); assign(hInt, std::function<void(int)>([this](int i) { piCout << "lambda type Int" << i; }));
assign(hInt, HANDLER(methodI)); assign(hInt, HANDLER(methodI));
assign(hString, HANDLER(methodS)); assign(hString, HANDLER(methodS));
// hVoid key, without arguments // hVoid key, without arguments
assign(hVoid, [](){piCout << "type void";}); assign(hVoid, []() { piCout << "type void"; });
assign(hVoid, HANDLER(method)); assign(hVoid, HANDLER(method));
} }
EVENT_HANDLER1(void, methodI, int, i) {piCout << "methodI" << i;} EVENT_HANDLER1(void, methodI, int, i) { piCout << "methodI" << i; }
EVENT_HANDLER1(void, methodS, PIString, s) {piCout << "methodS" << s;} EVENT_HANDLER1(void, methodS, PIString, s) { piCout << "methodS" << s; }
EVENT_HANDLER0(void, method) {piCout << "method";} EVENT_HANDLER0(void, method) { piCout << "method"; }
}; };
int main() { int main() {
@@ -58,10 +61,11 @@ enum Header {
class MyObj: public PIObject { class MyObj: public PIObject {
PIOBJECT(MyObj); PIOBJECT(MyObj);
public: public:
EVENT_HANDLER1(void, methodI, int, i) {piCout << "methodI" << i;} EVENT_HANDLER1(void, methodI, int, i) { piCout << "methodI" << i; }
EVENT_HANDLER1(void, methodS, PIString, s) {piCout << "methodS" << s;} EVENT_HANDLER1(void, methodS, PIString, s) { piCout << "methodS" << s; }
EVENT_HANDLER0(void, method) {piCout << "method";} EVENT_HANDLER0(void, method) { piCout << "method"; }
}; };
int main() { int main() {
+21 -18
View File
@@ -1,10 +1,17 @@
//! [main] //! [main]
#include "pip.h" #include "pip.h"
enum Mode {Start, Manual, Auto, Finish, End}; enum Mode {
Start,
Manual,
Auto,
Finish,
End
};
class Machine: public PIStateMachine<Mode> { class Machine: public PIStateMachine<Mode> {
PIOBJECT_SUBCLASS(Machine, PIObject) PIOBJECT_SUBCLASS(Machine, PIObject)
public: public:
Machine() { Machine() {
addState(Start, "start", HANDLER(startFunc)); addState(Start, "start", HANDLER(startFunc));
@@ -26,32 +33,28 @@ public:
setInitialState(Start); setInitialState(Start);
CONNECT2(void, void*, int, &timer, timeout, this, tick); CONNECT2(void, void *, int, &timer, timeout, this, tick);
timer.start(500); timer.start(500);
} }
virtual void execution(const State & state) { virtual void execution(const State & state) { piCout << "performed conditions:" << currentConditions(); }
piCout << "performed conditions:" << currentConditions(); virtual void transition(const State & from, const State & to) { piCout << "switch from" << from.name << "to" << to.name << "state"; }
}
virtual void transition(const State & from, const State & to) {
piCout << "switch from" << from.name << "to" << to.name << "state";
}
EVENT_HANDLER(void, startFunc) {piCout << "start function";} EVENT_HANDLER(void, startFunc) { piCout << "start function"; }
EVENT_HANDLER(void, manualFunc) {piCout << "manual function";} EVENT_HANDLER(void, manualFunc) { piCout << "manual function"; }
EVENT_HANDLER(void, autoFunc) {piCout << "auto function";} EVENT_HANDLER(void, autoFunc) { piCout << "auto function"; }
EVENT_HANDLER(void, finishFunc) {piCout << "finish function";} EVENT_HANDLER(void, finishFunc) { piCout << "finish function"; }
EVENT_HANDLER(void, endFunc) {piCout << "end function";} EVENT_HANDLER(void, endFunc) { piCout << "end function"; }
EVENT_HANDLER(void, beginManualFunc) {piCout << "begin manual function";} EVENT_HANDLER(void, beginManualFunc) { piCout << "begin manual function"; }
EVENT_HANDLER(void, beginAutoFunc) {piCout << "begin auto function";} EVENT_HANDLER(void, beginAutoFunc) { piCout << "begin auto function"; }
EVENT_HANDLER(void, autoToManualFunc) {piCout << "switch from auto to manual function";} EVENT_HANDLER(void, autoToManualFunc) { piCout << "switch from auto to manual function"; }
EVENT_HANDLER(void, manualToAutoFunc) {piCout << "switch from manual to auto function";} EVENT_HANDLER(void, manualToAutoFunc) { piCout << "switch from manual to auto function"; }
PITimer timer; PITimer timer;
}; };
Machine machine; Machine machine;
void key_event(char key, void*) { void key_event(char key, void *) {
switch (key) { switch (key) {
case 's': machine.switchToState(Start); break; case 's': machine.switchToState(Start); break;
case 'm': machine.switchToState(Manual); break; case 'm': machine.switchToState(Manual); break;
+1 -1
View File
@@ -60,7 +60,7 @@ int main() {
}; };
//! [system_time] //! [system_time]
void _(){ void _() {
}; };
+1 -2
View File
@@ -135,8 +135,7 @@ PIPair<PICloud::TCP::Type, PICloud::TCP::Role> PICloud::TCP::parseHeader(PIByteA
PICloud::TCP::Header hdr; PICloud::TCP::Header hdr;
ba >> hdr; ba >> hdr;
if (hdr.version != header.version) { if (hdr.version != header.version) {
piCout << "[PICloud]" piCout << "[PICloud]" << "Invalid PICloud::TCP version!"_tr("PICloud");
<< "Invalid PICloud::TCP version!"_tr("PICloud");
return ret; return ret;
} }
ret.first = (Type)hdr.type; ret.first = (Type)hdr.type;
+3 -6
View File
@@ -40,8 +40,7 @@ PIByteArray piCompress(const PIByteArray & ba, int level) {
ulong sz = zba.size(); ulong sz = zba.size();
ret = compress2(zba.data(), &sz, ba.data(), ba.size(), level); ret = compress2(zba.data(), &sz, ba.data(), ba.size(), level);
if (ret != Z_OK) { if (ret != Z_OK) {
piCout << "[PICompress]" piCout << "[PICompress]" << "Error: invalid input or not enought memory"_tr("PICompress");
<< "Error: invalid input or not enought memory"_tr("PICompress");
return ba; return ba;
} }
zba.resize(sz); zba.resize(sz);
@@ -59,8 +58,7 @@ PIByteArray piDecompress(const PIByteArray & zba) {
#ifdef PIP_COMPRESS #ifdef PIP_COMPRESS
ullong sz = 0; ullong sz = 0;
if (zba.size() < sizeof(ullong)) { if (zba.size() < sizeof(ullong)) {
piCout << "[PICompress]" piCout << "[PICompress]" << "Error: invalid input"_tr("PICompress");
<< "Error: invalid input"_tr("PICompress");
return zba; return zba;
} }
PIByteArray ba(zba.data(zba.size() - sizeof(ullong)), sizeof(ullong)); PIByteArray ba(zba.data(zba.size() - sizeof(ullong)), sizeof(ullong));
@@ -70,8 +68,7 @@ PIByteArray piDecompress(const PIByteArray & zba) {
ulong s = sz; ulong s = sz;
ret = uncompress(ba.data(), &s, zba.data(), zba.size() - sizeof(ullong)); ret = uncompress(ba.data(), &s, zba.data(), zba.size() - sizeof(ullong));
if (ret != Z_OK) { if (ret != Z_OK) {
piCout << "[PICompress]" piCout << "[PICompress]" << "Error: invalid input or not enought memory"_tr("PICompress");
<< "Error: invalid input or not enought memory"_tr("PICompress");
return zba; return zba;
} }
return ba; return ba;
+28 -28
View File
@@ -20,74 +20,74 @@
#include "piscreendrawer.h" #include "piscreendrawer.h"
// comment for use ascii instead of unicode symbols // comment for use ascii instead of unicode symbols
# define USE_UNICODE #define USE_UNICODE
using namespace PIScreenTypes; using namespace PIScreenTypes;
PIScreenDrawer::PIScreenDrawer(PIVector<PIVector<Cell>> & c): cells(c) { PIScreenDrawer::PIScreenDrawer(PIVector<PIVector<Cell>> & c): cells(c) {
arts_[LineVertical] = arts_[LineVertical] =
# ifdef USE_UNICODE #ifdef USE_UNICODE
PIChar::fromUTF8("│"); PIChar::fromUTF8("│");
# else #else
PIChar('|'); PIChar('|');
# endif #endif
arts_[LineHorizontal] = arts_[LineHorizontal] =
# ifdef USE_UNICODE #ifdef USE_UNICODE
PIChar::fromUTF8("─"); PIChar::fromUTF8("─");
# else #else
PIChar('-'); PIChar('-');
# endif #endif
arts_[Cross] = arts_[Cross] =
# ifdef USE_UNICODE #ifdef USE_UNICODE
PIChar::fromUTF8("┼"); PIChar::fromUTF8("┼");
# else #else
PIChar('+'); PIChar('+');
# endif #endif
arts_[CornerTopLeft] = arts_[CornerTopLeft] =
# ifdef USE_UNICODE #ifdef USE_UNICODE
PIChar::fromUTF8("┌"); PIChar::fromUTF8("┌");
# else #else
PIChar('+'); PIChar('+');
# endif #endif
arts_[CornerTopRight] = arts_[CornerTopRight] =
# ifdef USE_UNICODE #ifdef USE_UNICODE
PIChar::fromUTF8("┐"); PIChar::fromUTF8("┐");
# else #else
PIChar('+'); PIChar('+');
# endif #endif
arts_[CornerBottomLeft] = arts_[CornerBottomLeft] =
# ifdef USE_UNICODE #ifdef USE_UNICODE
PIChar::fromUTF8("└"); PIChar::fromUTF8("└");
# else #else
PIChar('+'); PIChar('+');
# endif #endif
arts_[CornerBottomRight] = arts_[CornerBottomRight] =
# ifdef USE_UNICODE #ifdef USE_UNICODE
PIChar::fromUTF8("┘"); PIChar::fromUTF8("┘");
# else #else
PIChar('+'); PIChar('+');
# endif #endif
arts_[Unchecked] = arts_[Unchecked] =
# ifdef USE_UNICODE #ifdef USE_UNICODE
PIChar::fromUTF8("☐"); PIChar::fromUTF8("☐");
# else #else
PIChar('O'); PIChar('O');
# endif #endif
arts_[Checked] = arts_[Checked] =
# ifdef USE_UNICODE #ifdef USE_UNICODE
PIChar::fromUTF8("☑"); PIChar::fromUTF8("☑");
# else #else
PIChar('0'); PIChar('0');
# endif #endif
} }
-2
View File
@@ -980,5 +980,3 @@ bool PITerminal::resize(int cols, int rows) {
} }
#endif // PIP_HAS_PROCESS #endif // PIP_HAS_PROCESS
+2 -5
View File
@@ -32,8 +32,7 @@ constexpr int hash_def_key_size = 9;
PICrypt::PICrypt() { PICrypt::PICrypt() {
if (!init()) { if (!init()) {
piCout << "[PICrypt]" piCout << "[PICrypt]" << "Error while initialize sodium!"_tr("PICrypt");
<< "Error while initialize sodium!"_tr("PICrypt");
} }
nonce_.resize(crypto_secretbox_NONCEBYTES); nonce_.resize(crypto_secretbox_NONCEBYTES);
key_.resize(crypto_secretbox_KEYBYTES); key_.resize(crypto_secretbox_KEYBYTES);
@@ -183,9 +182,7 @@ ullong PICrypt::shorthash(const PIString & s, PIByteArray key) {
key.fill(0); key.fill(0);
return hash; return hash;
} }
if (crypto_shorthash_BYTES != sizeof(hash)) if (crypto_shorthash_BYTES != sizeof(hash)) piCout << "[PICrypt]" << "internal error: bad hash size"_tr("PICrypt");
piCout << "[PICrypt]"
<< "internal error: bad hash size"_tr("PICrypt");
if (key.size() != crypto_shorthash_KEYBYTES) { if (key.size() != crypto_shorthash_KEYBYTES) {
piCout << "[PICrypt]" piCout << "[PICrypt]"
<< "invalid key size %1, should be %2, filled with zeros"_tr("PICrypt").arg(key.size()).arg(crypto_shorthash_KEYBYTES); << "invalid key size %1, should be %2, filled with zeros"_tr("PICrypt").arg(key.size()).arg(crypto_shorthash_KEYBYTES);
+1 -3
View File
@@ -226,9 +226,7 @@ int answer_callback(void * cls,
m = Method::Patch; m = Method::Patch;
if (m == Method::Unknown) { if (m == Method::Unknown) {
piCout << "[MicrohttpdServer]" piCout << "[MicrohttpdServer]" << "Warning:" << "Unknown method!";
<< "Warning:"
<< "Unknown method!";
return MHD_NO; return MHD_NO;
} }
+16 -17
View File
@@ -21,10 +21,10 @@
#ifdef PIP_HAS_SOCKET #ifdef PIP_HAS_SOCKET
#include "pitranslator.h" # include "pitranslator.h"
#ifdef PIP_CRYPT # ifdef PIP_CRYPT
# include "picrypt.h" # include "picrypt.h"
#endif # endif
/** \class PIEthUtilBase /** \class PIEthUtilBase
* \brief Base class for ethernet utils * \brief Base class for ethernet utils
@@ -85,13 +85,12 @@ void PIEthUtilBase::setCryptKey(const PIByteArray & k) {
void PIEthUtilBase::createCryptKey(const PIString & k) { void PIEthUtilBase::createCryptKey(const PIString & k) {
#ifdef PIP_CRYPT # ifdef PIP_CRYPT
_key = PICrypt::hash("sodium_bug"); _key = PICrypt::hash("sodium_bug");
_key = PICrypt::hash(k); _key = PICrypt::hash(k);
#else # else
piCout << "[PIEthUtilBase]" piCout << "[PIEthUtilBase]" << "PICrypt wasn`t built!"_tr("PIEthUtilBase");
<< "PICrypt wasn`t built!"_tr("PIEthUtilBase"); # endif
#endif
_crypt = true; _crypt = true;
} }
@@ -104,32 +103,32 @@ PIByteArray PIEthUtilBase::cryptKey() const {
PIByteArray PIEthUtilBase::cryptData(const PIByteArray & data) { PIByteArray PIEthUtilBase::cryptData(const PIByteArray & data) {
if (!_crypt) return data; if (!_crypt) return data;
return return
#ifdef PIP_CRYPT # ifdef PIP_CRYPT
PICrypt::crypt(data, _key); PICrypt::crypt(data, _key);
#else # else
PIByteArray(); PIByteArray();
#endif # endif
} }
PIByteArray PIEthUtilBase::decryptData(const PIByteArray & data) { PIByteArray PIEthUtilBase::decryptData(const PIByteArray & data) {
if (!_crypt) return data; if (!_crypt) return data;
#ifdef PIP_CRYPT # ifdef PIP_CRYPT
bool ok = false; bool ok = false;
PIByteArray ret = PICrypt::decrypt(data, _key, &ok); PIByteArray ret = PICrypt::decrypt(data, _key, &ok);
if (!ok) return PIByteArray(); if (!ok) return PIByteArray();
return ret; return ret;
#else # else
return PIByteArray(); return PIByteArray();
#endif # endif
} }
size_t PIEthUtilBase::cryptSizeAddition() { size_t PIEthUtilBase::cryptSizeAddition() {
#ifdef PIP_CRYPT # ifdef PIP_CRYPT
return PICrypt::sizeCrypt(); return PICrypt::sizeCrypt();
#else # else
return 0; return 0;
#endif # endif
} }
#endif // PIP_HAS_SOCKET #endif // PIP_HAS_SOCKET
+2 -2
View File
@@ -27,9 +27,9 @@
#include "pitranslator.h" #include "pitranslator.h"
#ifdef PIP_HAS_SOCKET #ifdef PIP_HAS_SOCKET
#ifdef __GNUC__ # ifdef __GNUC__
# pragma GCC diagnostic pop # pragma GCC diagnostic pop
#endif # endif
/** \class PIStreamPacker /** \class PIStreamPacker
* \brief Simple packet wrap aroud any PIIODevice * \brief Simple packet wrap aroud any PIIODevice
+2 -4
View File
@@ -296,10 +296,8 @@ private:
//! \~russian Оператор вывода в \a PICout //! \~russian Оператор вывода в \a PICout
inline PICout operator<<(PICout s, const PISystemMonitor::ThreadStats & v) { inline PICout operator<<(PICout s, const PISystemMonitor::ThreadStats & v) {
s.saveAndSetControls(0); s.saveAndSetControls(0);
s << "ThreadInfo(\"" << v.name << "\", created " << v.created << ", work " << v.work_time.toMilliseconds() << " ms" s << "ThreadInfo(\"" << v.name << "\", created " << v.created << ", work " << v.work_time.toMilliseconds() << " ms" << ", kernel "
<< ", kernel " << v.kernel_time.toMilliseconds() << " ms" << v.kernel_time.toMilliseconds() << " ms" << ", user " << v.user_time.toMilliseconds() << " ms" << ")\n";
<< ", user " << v.user_time.toMilliseconds() << " ms"
<< ")\n";
s.restoreControls(); s.restoreControls();
return s; return s;
} }
@@ -89,8 +89,10 @@ public:
PIDiagnostics::State diagnostics() const; PIDiagnostics::State diagnostics() const;
//! \~english Returns how many payload bytes of the current packet are already received (all bytes count passed in \a receivePacketStart()). //! \~english Returns how many payload bytes of the current packet are already received (all bytes count passed in \a
//! \~russian Возвращает, сколько байтов полезной нагрузки текущего пакета уже получено (общее количество передается в \a receivePacketStart()). //! receivePacketStart()).
//! \~russian Возвращает, сколько байтов полезной нагрузки текущего пакета уже получено (общее количество передается в \a
//! receivePacketStart()).
int receivePacketProgress() const; int receivePacketProgress() const;
//! \~english Returns the current packet framing configuration. //! \~english Returns the current packet framing configuration.
+17 -108
View File
@@ -202,137 +202,46 @@ void PICodeParser::clear() {
defines << Define(PIStringAscii("PICODE"), "") << custom_defines; defines << Define(PIStringAscii("PICODE"), "") << custom_defines;
macros << Macro(PIStringAscii("PIOBJECT"), "", PIStringList() << "name") macros << Macro(PIStringAscii("PIOBJECT"), "", PIStringList() << "name")
<< Macro(PIStringAscii("PIOBJECT_PARENT"), "", PIStringList() << "parent") << Macro(PIStringAscii("PIOBJECT_PARENT"), "", PIStringList() << "parent")
<< Macro(PIStringAscii("PIOBJECT_SUBCLASS"), << Macro(PIStringAscii("PIOBJECT_SUBCLASS"), "", PIStringList() << "name" << "parent")
"",
PIStringList() << "name"
<< "parent")
<< Macro(PIStringAscii("PIIODEVICE"), "", PIStringList() << "name") << Macro(PIStringAscii("PIIODEVICE"), "", PIStringList() << "name")
<< Macro(PIStringAscii("NO_COPY_CLASS"), "", PIStringList() << "name") << Macro(PIStringAscii("PRIVATE_DECLARATION")) << Macro(PIStringAscii("NO_COPY_CLASS"), "", PIStringList() << "name") << Macro(PIStringAscii("PRIVATE_DECLARATION"))
<< Macro(PIStringAscii("EVENT"), "void name();", PIStringList() << "name") << Macro(PIStringAscii("EVENT"), "void name();", PIStringList() << "name")
<< Macro(PIStringAscii("EVENT0"), "void name();", PIStringList() << "name") << Macro(PIStringAscii("EVENT0"), "void name();", PIStringList() << "name")
<< Macro(PIStringAscii("EVENT1"), << Macro(PIStringAscii("EVENT1"), "void name(a0 n0);", PIStringList() << "name" << "a0" << "n0")
"void name(a0 n0);", << Macro(PIStringAscii("EVENT2"), "void name(a0 n0, a1 n1);", PIStringList() << "name" << "a0" << "n0" << "a1" << "n1")
PIStringList() << "name"
<< "a0"
<< "n0")
<< Macro(PIStringAscii("EVENT2"),
"void name(a0 n0, a1 n1);",
PIStringList() << "name"
<< "a0"
<< "n0"
<< "a1"
<< "n1")
<< Macro(PIStringAscii("EVENT3"), << Macro(PIStringAscii("EVENT3"),
"void name(a0 n0, a1 n1, a2 n2);", "void name(a0 n0, a1 n1, a2 n2);",
PIStringList() << "name" PIStringList() << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2")
<< "a0"
<< "n0"
<< "a1"
<< "n1"
<< "a2"
<< "n2")
<< Macro(PIStringAscii("EVENT4"), << Macro(PIStringAscii("EVENT4"),
"void name(a0 n0, a1 n1, a2 n2, a3 n3);", "void name(a0 n0, a1 n1, a2 n2, a3 n3);",
PIStringList() << "name" PIStringList() << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2" << "a3" << "n3")
<< "a0"
<< "n0"
<< "a1"
<< "n1"
<< "a2"
<< "n2"
<< "a3"
<< "n3")
<< Macro(PIStringAscii("EVENT_HANDLER"), << Macro(PIStringAscii("EVENT_HANDLER"), "ret name()", PIStringList() << "ret" << "name")
"ret name()", << Macro(PIStringAscii("EVENT_HANDLER0"), "ret name()", PIStringList() << "ret" << "name")
PIStringList() << "ret" << Macro(PIStringAscii("EVENT_HANDLER1"), "ret name(a0 n0)", PIStringList() << "ret" << "name" << "a0" << "n0")
<< "name")
<< Macro(PIStringAscii("EVENT_HANDLER0"),
"ret name()",
PIStringList() << "ret"
<< "name")
<< Macro(PIStringAscii("EVENT_HANDLER1"),
"ret name(a0 n0)",
PIStringList() << "ret"
<< "name"
<< "a0"
<< "n0")
<< Macro(PIStringAscii("EVENT_HANDLER2"), << Macro(PIStringAscii("EVENT_HANDLER2"),
"ret name(a0 n0, a1 n1)", "ret name(a0 n0, a1 n1)",
PIStringList() << "ret" PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1")
<< "name"
<< "a0"
<< "n0"
<< "a1"
<< "n1")
<< Macro(PIStringAscii("EVENT_HANDLER3"), << Macro(PIStringAscii("EVENT_HANDLER3"),
"ret name(a0 n0, a1 n1, a2 n2)", "ret name(a0 n0, a1 n1, a2 n2)",
PIStringList() << "ret" PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2")
<< "name"
<< "a0"
<< "n0"
<< "a1"
<< "n1"
<< "a2"
<< "n2")
<< Macro(PIStringAscii("EVENT_HANDLER4"), << Macro(PIStringAscii("EVENT_HANDLER4"),
"ret name(a0 n0, a1 n1, a2 n2, a3 n3)", "ret name(a0 n0, a1 n1, a2 n2, a3 n3)",
PIStringList() << "ret" PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2" << "a3" << "n3")
<< "name"
<< "a0"
<< "n0"
<< "a1"
<< "n1"
<< "a2"
<< "n2"
<< "a3"
<< "n3")
<< Macro(PIStringAscii("EVENT_VHANDLER"), << Macro(PIStringAscii("EVENT_VHANDLER"), "virtual ret name()", PIStringList() << "ret" << "name")
"virtual ret name()", << Macro(PIStringAscii("EVENT_VHANDLER0"), "virtual ret name()", PIStringList() << "ret" << "name")
PIStringList() << "ret" << Macro(PIStringAscii("EVENT_VHANDLER1"), "virtual ret name(a0 n0)", PIStringList() << "ret" << "name" << "a0" << "n0")
<< "name")
<< Macro(PIStringAscii("EVENT_VHANDLER0"),
"virtual ret name()",
PIStringList() << "ret"
<< "name")
<< Macro(PIStringAscii("EVENT_VHANDLER1"),
"virtual ret name(a0 n0)",
PIStringList() << "ret"
<< "name"
<< "a0"
<< "n0")
<< Macro(PIStringAscii("EVENT_VHANDLER2"), << Macro(PIStringAscii("EVENT_VHANDLER2"),
"virtual ret name(a0 n0, a1 n1)", "virtual ret name(a0 n0, a1 n1)",
PIStringList() << "ret" PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1")
<< "name"
<< "a0"
<< "n0"
<< "a1"
<< "n1")
<< Macro(PIStringAscii("EVENT_VHANDLER3"), << Macro(PIStringAscii("EVENT_VHANDLER3"),
"virtual ret name(a0 n0, a1 n1, a2 n2)", "virtual ret name(a0 n0, a1 n1, a2 n2)",
PIStringList() << "ret" PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2")
<< "name"
<< "a0"
<< "n0"
<< "a1"
<< "n1"
<< "a2"
<< "n2")
<< Macro(PIStringAscii("EVENT_VHANDLER4"), << Macro(PIStringAscii("EVENT_VHANDLER4"),
"virtual ret name(a0 n0, a1 n1, a2 n2, a3 n3)", "virtual ret name(a0 n0, a1 n1, a2 n2, a3 n3)",
PIStringList() << "ret" PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2" << "a3" << "n3");
<< "name"
<< "a0"
<< "n0"
<< "a1"
<< "n1"
<< "a2"
<< "n2"
<< "a3"
<< "n3");
} }
+4 -1
View File
@@ -1234,7 +1234,10 @@ public:
//! \~english The function can modify the elements. //! \~english The function can modify the elements.
//! \~russian Функция может изменять элементы. //! \~russian Функция может изменять элементы.
//! \~\sa forEach (read-only), PIVector::forEach() //! \~\sa forEach (read-only), PIVector::forEach()
inline PIVector2D<T> & forEach(std::function<void(T &)> func) { mat.forEach(func); return *this; } inline PIVector2D<T> & forEach(std::function<void(T &)> func) {
mat.forEach(func);
return *this;
}
//! \~english Applies a function to each element and returns a new 2D array of a different type. //! \~english Applies a function to each element and returns a new 2D array of a different type.
//! \~russian Применяет функцию к каждому элементу и возвращает новый двумерный массив другого типа. //! \~russian Применяет функцию к каждому элементу и возвращает новый двумерный массив другого типа.
+2 -1
View File
@@ -727,6 +727,7 @@ inline bool piDeleteSafety(T *& pointer) {
//! \~russian В данном примере будет выведен "Error!" при каждом \b false возврате из функции. //! \~russian В данном примере будет выведен "Error!" при каждом \b false возврате из функции.
class PIP_EXPORT PIScopeExitCall { class PIP_EXPORT PIScopeExitCall {
NO_COPY_CLASS(PIScopeExitCall) NO_COPY_CLASS(PIScopeExitCall)
public: public:
//! \~\brief //! \~\brief
//! \~english Constructor that takes a function to execute //! \~english Constructor that takes a function to execute
@@ -769,7 +770,7 @@ private:
struct PIP_EXPORT PINonTriviallyCopyable { struct PIP_EXPORT PINonTriviallyCopyable {
PINonTriviallyCopyable() = default; PINonTriviallyCopyable() = default;
PINonTriviallyCopyable(const PINonTriviallyCopyable &) = default; PINonTriviallyCopyable(const PINonTriviallyCopyable &) = default;
PINonTriviallyCopyable(PINonTriviallyCopyable &&) ; PINonTriviallyCopyable(PINonTriviallyCopyable &&);
PINonTriviallyCopyable & operator=(const PINonTriviallyCopyable &) = default; PINonTriviallyCopyable & operator=(const PINonTriviallyCopyable &) = default;
PINonTriviallyCopyable & operator=(PINonTriviallyCopyable &&) = default; PINonTriviallyCopyable & operator=(PINonTriviallyCopyable &&) = default;
~PINonTriviallyCopyable() = default; ~PINonTriviallyCopyable() = default;
-1
View File
@@ -33,7 +33,6 @@
#define PIMEMORYBLOCK_H #define PIMEMORYBLOCK_H
//! \~\brief //! \~\brief
//! \~english Helper struct to store and restore custom blocks of data to/from PIBinaryStream //! \~english Helper struct to store and restore custom blocks of data to/from PIBinaryStream
//! \~russian Вспомогательная структура для сохранения и извлечения произвольных блоков данных в/из PIBinaryStream //! \~russian Вспомогательная структура для сохранения и извлечения произвольных блоков данных в/из PIBinaryStream
@@ -82,7 +82,7 @@ class PIIntrospectionServer;
#else #else
#ifdef PIP_INTROSPECTION # ifdef PIP_INTROSPECTION
# define __PIINTROSPECTION_SINGLETON_H__(T) static PIIntrospection##T##Interface * instance(); # define __PIINTROSPECTION_SINGLETON_H__(T) static PIIntrospection##T##Interface * instance();
# define __PIINTROSPECTION_SINGLETON_CPP__(T) \ # define __PIINTROSPECTION_SINGLETON_CPP__(T) \
@@ -90,7 +90,7 @@ class PIIntrospectionServer;
static PIIntrospection##T##Interface ret; \ static PIIntrospection##T##Interface ret; \
return &ret; \ return &ret; \
} }
#endif // PIP_INTROSPECTION # endif // PIP_INTROSPECTION
#endif // DOXYGEN #endif // DOXYGEN
#endif // PIINTROSPECTION_BASE_H #endif // PIINTROSPECTION_BASE_H
@@ -24,8 +24,8 @@
#ifdef PIP_INTROSPECTION #ifdef PIP_INTROSPECTION
#include "pimap.h" # include "pimap.h"
#include "pithread.h" # include "pithread.h"
class PIP_EXPORT PIIntrospectionThreads { class PIP_EXPORT PIIntrospectionThreads {
+49 -49
View File
@@ -17,22 +17,22 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef PIP_HAS_FILESYSTEM #ifdef PIP_HAS_FILESYSTEM
#include "pidir.h" # include "pidir.h"
#include "piincludes_p.h" # include "piincludes_p.h"
const PIChar PIDir::separator = '/'; const PIChar PIDir::separator = '/';
#ifdef QNX # ifdef QNX
# define _stat_struct_ struct stat # define _stat_struct_ struct stat
# define _stat_call_ stat # define _stat_call_ stat
# define _stat_link_ lstat # define _stat_link_ lstat
#else # else
# define _stat_struct_ struct stat64 # define _stat_struct_ struct stat64
# define _stat_call_ stat64 # define _stat_call_ stat64
# define _stat_link_ lstat64 # define _stat_link_ lstat64
#endif # endif
#ifndef WINDOWS # ifndef WINDOWS
# ifdef ANDROID # ifdef ANDROID
# include <dirent.h> # include <dirent.h>
# else # else
@@ -45,7 +45,7 @@ extern "C" {
# endif # endif
# endif # endif
# include <sys/stat.h> # include <sys/stat.h>
#endif # endif
//! \class PIDir pidir.h //! \class PIDir pidir.h
@@ -80,9 +80,9 @@ bool PIDir::operator==(const PIDir & d) const {
bool PIDir::isAbsolute() const { bool PIDir::isAbsolute() const {
if (path_.isEmpty()) return false; if (path_.isEmpty()) return false;
if (path_[0] == separator) return true; if (path_[0] == separator) return true;
#ifdef WINDOWS # ifdef WINDOWS
return (path_.mid(1, 1) == ":"); return (path_.mid(1, 1) == ":");
#endif # endif
return false; return false;
} }
@@ -96,28 +96,28 @@ PIString PIDir::name() const {
PIString PIDir::path() const { PIString PIDir::path() const {
#ifdef WINDOWS # ifdef WINDOWS
if (path_.startsWith(separator)) { if (path_.startsWith(separator)) {
if (path_.length() == 1) if (path_.length() == 1)
return separator; return separator;
else else
return path_.mid(1); return path_.mid(1);
} else } else
#endif # endif
return path_; return path_;
} }
PIString PIDir::absolutePath() const { PIString PIDir::absolutePath() const {
if (isAbsolute()) { if (isAbsolute()) {
#ifdef WINDOWS # ifdef WINDOWS
if (path_.startsWith(separator)) { if (path_.startsWith(separator)) {
if (path_.length() == 1) if (path_.length() == 1)
return separator; return separator;
else else
return path_.mid(1); return path_.mid(1);
} else } else
#endif # endif
return path_; return path_;
} }
return PIDir(PIDir::current().path() + separator + path_).path(); return PIDir(PIDir::current().path() + separator + path_).path();
@@ -205,11 +205,11 @@ PIString PIDir::absolute(const PIString & path) const {
PIDir & PIDir::setDir(const PIString & path) { PIDir & PIDir::setDir(const PIString & path) {
path_ = path; path_ = path;
#ifdef WINDOWS # ifdef WINDOWS
path_.replaceAll("\\", separator); path_.replaceAll("\\", separator);
if (path_.length() > 2) if (path_.length() > 2)
if (path_.mid(1, 2).contains(":")) path_.prepend(separator); if (path_.mid(1, 2).contains(":")) path_.prepend(separator);
#endif # endif
cleanPath(); cleanPath();
return *this; return *this;
} }
@@ -226,9 +226,9 @@ PIDir & PIDir::cd(const PIString & path) {
bool PIDir::make(bool withParents) { bool PIDir::make(bool withParents) {
PIDir d = cleanedPath(); PIDir d = cleanedPath();
// PIString tp; // PIString tp;
#ifndef WINDOWS # ifndef WINDOWS
bool is_abs = isAbsolute(); bool is_abs = isAbsolute();
#endif # endif
if (withParents) { if (withParents) {
PIStringList l = d.path().split(separator); PIStringList l = d.path().split(separator);
// piCout << l; // piCout << l;
@@ -237,9 +237,9 @@ bool PIDir::make(bool withParents) {
PIString cdp; PIString cdp;
for (const auto & i: l) { for (const auto & i: l) {
if (!cdp.isEmpty() if (!cdp.isEmpty()
#ifndef WINDOWS # ifndef WINDOWS
|| is_abs || is_abs
#endif # endif
) )
cdp += separator; cdp += separator;
cdp += i; cdp += i;
@@ -278,11 +278,11 @@ bool PIDir::rename(const PIString & new_name) {
} }
#ifdef WINDOWS # ifdef WINDOWS
bool sort_compare(const PIFile::FileInfo & v0, const PIFile::FileInfo & v1) { bool sort_compare(const PIFile::FileInfo & v0, const PIFile::FileInfo & v1) {
return strcoll(v0.path.data(), v1.path.data()) < 0; return strcoll(v0.path.data(), v1.path.data()) < 0;
} }
#endif # endif
//! \~\details //! \~\details
@@ -309,7 +309,7 @@ PIVector<PIFile::FileInfo> PIDir::entries(const PIRegularExpression & regexp) {
else if (!dp.endsWith(separator)) else if (!dp.endsWith(separator))
dp += separator; dp += separator;
// piCout << "start entries from" << p; // piCout << "start entries from" << p;
#ifdef WINDOWS # ifdef WINDOWS
PIFile::FileInfo fi; PIFile::FileInfo fi;
if (dp == separator) { if (dp == separator) {
char letters[1024]; char letters[1024];
@@ -359,7 +359,7 @@ PIVector<PIFile::FileInfo> PIDir::entries(const PIRegularExpression & regexp) {
} }
} }
#else # else
# if defined(QNX) || defined(FREERTOS) # if defined(QNX) || defined(FREERTOS)
struct dirent * de = 0; struct dirent * de = 0;
DIR * dir = 0; DIR * dir = 0;
@@ -389,7 +389,7 @@ PIVector<PIFile::FileInfo> PIDir::entries(const PIRegularExpression & regexp) {
} }
free(list); free(list);
# endif # endif
#endif # endif
// piCout << "end entries from" << p; // piCout << "end entries from" << p;
return ret; return ret;
} }
@@ -442,45 +442,45 @@ PIVector<PIFile::FileInfo> PIDir::allEntries(const PIRegularExpression & regexp)
bool PIDir::isExists(const PIString & path) { bool PIDir::isExists(const PIString & path) {
#ifdef WINDOWS # ifdef WINDOWS
DWORD ret = GetFileAttributes((LPCTSTR)(path.data())); DWORD ret = GetFileAttributes((LPCTSTR)(path.data()));
return (ret != 0xFFFFFFFF) && (ret & FILE_ATTRIBUTE_DIRECTORY); return (ret != 0xFFFFFFFF) && (ret & FILE_ATTRIBUTE_DIRECTORY);
#else # else
DIR * dir_ = opendir(path.data()); DIR * dir_ = opendir(path.data());
if (dir_ == 0) return false; if (dir_ == 0) return false;
closedir(dir_); closedir(dir_);
#endif # endif
return true; return true;
} }
PIDir PIDir::current() { PIDir PIDir::current() {
#ifndef ESP_PLATFORM # ifndef ESP_PLATFORM
char rc[1024]; char rc[1024];
#endif # endif
#ifdef WINDOWS # ifdef WINDOWS
piZeroMemory(rc, 1024); piZeroMemory(rc, 1024);
if (GetCurrentDirectory(1024, (LPTSTR)rc) == 0) return PIString(); if (GetCurrentDirectory(1024, (LPTSTR)rc) == 0) return PIString();
PIString ret(rc); PIString ret(rc);
ret.replaceAll("\\", PIDir::separator); ret.replaceAll("\\", PIDir::separator);
ret.prepend(separator); ret.prepend(separator);
return PIDir(ret); return PIDir(ret);
#else # else
# ifndef ESP_PLATFORM # ifndef ESP_PLATFORM
if (getcwd(rc, 1024) == 0) return PIString(); if (getcwd(rc, 1024) == 0) return PIString();
return PIDir(rc); return PIDir(rc);
# else # else
return PIDir("/spiffs"); return PIDir("/spiffs");
# endif # endif
#endif # endif
} }
PIDir PIDir::home() { PIDir PIDir::home() {
#ifndef ESP_PLATFORM # ifndef ESP_PLATFORM
char * rc = nullptr; char * rc = nullptr;
#endif # endif
#ifdef WINDOWS # ifdef WINDOWS
rc = new char[1024]; rc = new char[1024];
piZeroMemory(rc, 1024); piZeroMemory(rc, 1024);
if (ExpandEnvironmentStrings((LPCTSTR) "%HOMEPATH%", (LPTSTR)rc, 1024) == 0) { if (ExpandEnvironmentStrings((LPCTSTR) "%HOMEPATH%", (LPTSTR)rc, 1024) == 0) {
@@ -498,7 +498,7 @@ PIDir PIDir::home() {
delete[] rc; delete[] rc;
// s.prepend(separator); // s.prepend(separator);
return PIDir(hd + hp); return PIDir(hd + hp);
#else # else
# ifndef ESP_PLATFORM # ifndef ESP_PLATFORM
rc = getenv("HOME"); rc = getenv("HOME");
if (!rc) return PIDir(); if (!rc) return PIDir();
@@ -506,13 +506,13 @@ PIDir PIDir::home() {
# else # else
return PIDir(); return PIDir();
# endif # endif
#endif # endif
} }
PIDir PIDir::temporary() { PIDir PIDir::temporary() {
char * rc = nullptr; char * rc = nullptr;
#ifdef WINDOWS # ifdef WINDOWS
rc = new char[1024]; rc = new char[1024];
piZeroMemory(rc, 1024); piZeroMemory(rc, 1024);
int ret = GetTempPath(1024, (LPTSTR)rc); int ret = GetTempPath(1024, (LPTSTR)rc);
@@ -525,13 +525,13 @@ PIDir PIDir::temporary() {
delete[] rc; delete[] rc;
s.prepend(separator); s.prepend(separator);
return PIDir(s); return PIDir(s);
#else # else
char template_rc[] = "/tmp/pidir_tmp_XXXXXX"; char template_rc[] = "/tmp/pidir_tmp_XXXXXX";
rc = mkdtemp(template_rc); rc = mkdtemp(template_rc);
if (!rc) return PIDir(); if (!rc) return PIDir();
PIString s(rc); PIString s(rc);
return PIDir(s.left(s.findLast(PIDir::separator))); return PIDir(s.left(s.findLast(PIDir::separator)));
#endif # endif
} }
@@ -548,33 +548,33 @@ bool PIDir::make(const PIString & path, bool withParents) {
bool PIDir::setCurrent(const PIString & path) { bool PIDir::setCurrent(const PIString & path) {
#ifdef WINDOWS # ifdef WINDOWS
if (SetCurrentDirectory((LPCTSTR)(path.data())) != 0) return true; if (SetCurrentDirectory((LPCTSTR)(path.data())) != 0) return true;
#else # else
if (chdir(path.data()) == 0) return true; if (chdir(path.data()) == 0) return true;
#endif # endif
printf("[PIDir] setCurrent(\"%s\") error: %s\n", path.data(), errorString().data()); printf("[PIDir] setCurrent(\"%s\") error: %s\n", path.data(), errorString().data());
return false; return false;
} }
bool PIDir::makeDir(const PIString & path) { bool PIDir::makeDir(const PIString & path) {
#ifdef WINDOWS # ifdef WINDOWS
if (CreateDirectory((LPCTSTR)(path.data()), NULL) != 0) return true; if (CreateDirectory((LPCTSTR)(path.data()), NULL) != 0) return true;
#else # else
if (mkdir(path.data(), 16877) == 0) return true; if (mkdir(path.data(), 16877) == 0) return true;
#endif # endif
printf("[PIDir] makeDir(\"%s\") error: %s\n", path.data(), errorString().data()); printf("[PIDir] makeDir(\"%s\") error: %s\n", path.data(), errorString().data());
return false; return false;
} }
bool PIDir::removeDir(const PIString & path) { bool PIDir::removeDir(const PIString & path) {
#ifdef WINDOWS # ifdef WINDOWS
if (RemoveDirectory((LPCTSTR)(path.data())) != 0) return true; if (RemoveDirectory((LPCTSTR)(path.data())) != 0) return true;
#else # else
if (rmdir(path.data()) == 0) return true; if (rmdir(path.data()) == 0) return true;
#endif # endif
printf("[PIDir] removeDir(\"%s\") error: %s\n", path.data(), errorString().data()); printf("[PIDir] removeDir(\"%s\") error: %s\n", path.data(), errorString().data());
return false; return false;
} }
+2 -2
View File
@@ -339,8 +339,8 @@ public:
//! \ioparams //! \ioparams
//! \{ //! \{
#ifdef DOXYGEN # ifdef DOXYGEN
#endif # endif
//! \} //! \}
protected: protected:
+1 -2
View File
@@ -126,8 +126,7 @@ bool PISPI::openDevice() {
PRIVATE->fd = -1; PRIVATE->fd = -1;
return false; return false;
} }
piCoutObj << "SPI open" << path() << "speed:" << spi_speed / 1000 << "KHz" piCoutObj << "SPI open" << path() << "speed:" << spi_speed / 1000 << "KHz" << "mode" << spi_mode << "bits" << spi_bits;
<< "mode" << spi_mode << "bits" << spi_bits;
PRIVATE->spi_ioc_tr.delay_usecs = 0; PRIVATE->spi_ioc_tr.delay_usecs = 0;
PRIVATE->spi_ioc_tr.speed_hz = 0; PRIVATE->spi_ioc_tr.speed_hz = 0;
PRIVATE->spi_ioc_tr.bits_per_word = spi_bits; PRIVATE->spi_ioc_tr.bits_per_word = spi_bits;
+2 -2
View File
@@ -26,8 +26,8 @@
#define PIETHUTILBASE_H #define PIETHUTILBASE_H
#ifdef PIP_HAS_SOCKET #ifdef PIP_HAS_SOCKET
#include "pibytearray.h" # include "pibytearray.h"
#include "pip_io_utils_export.h" # include "pip_io_utils_export.h"
//! \~\ingroup IO-Utils //! \~\ingroup IO-Utils
//! \~\brief //! \~\brief
+4 -4
View File
@@ -26,10 +26,10 @@
#define pipackedtcp_H #define pipackedtcp_H
#ifdef PIP_HAS_SOCKET #ifdef PIP_HAS_SOCKET
#include "piiodevice.h" # include "piiodevice.h"
#include "pinetworkaddress.h" # include "pinetworkaddress.h"
#include "pip_io_utils_export.h" # include "pip_io_utils_export.h"
#include "pistreampacker.h" # include "pistreampacker.h"
class PIEthernet; class PIEthernet;
+3 -3
View File
@@ -26,9 +26,9 @@
#define PISTREAMPACKER_H #define PISTREAMPACKER_H
#ifdef PIP_HAS_SOCKET #ifdef PIP_HAS_SOCKET
#include "piethutilbase.h" # include "piethutilbase.h"
#include "piobject.h" # include "piobject.h"
#include "pip_io_utils_export.h" # include "pip_io_utils_export.h"
class PIIODevice; class PIIODevice;
+3 -1
View File
@@ -110,7 +110,9 @@
# define PIP_PLUGIN \ # define PIP_PLUGIN \
extern "C" { \ extern "C" { \
PIP_PLUGIN_EXPORT int __PIP_PLUGIN_LOADER_VERSION_FUNC__() { return __PIP_PLUGIN_LOADER_VERSION__; } \ PIP_PLUGIN_EXPORT int __PIP_PLUGIN_LOADER_VERSION_FUNC__() { \
return __PIP_PLUGIN_LOADER_VERSION__; \
} \
} }
# define PIP_PLUGIN_STATIC_SECTION_MERGE \ # define PIP_PLUGIN_STATIC_SECTION_MERGE \
+47 -47
View File
@@ -24,36 +24,36 @@
#endif #endif
#ifdef PIP_HAS_THREADS #ifdef PIP_HAS_THREADS
#include "piconditionvar.h" # include "piconditionvar.h"
#include "piincludes_p.h" # include "piincludes_p.h"
#ifdef WINDOWS # ifdef WINDOWS
# include <synchapi.h> # include <synchapi.h>
# include <winbase.h> # include <winbase.h>
# include <windef.h> # include <windef.h>
#endif # endif
#ifdef FREERTOS # ifdef FREERTOS
# include <event_groups.h> # include <event_groups.h>
#endif # endif
PRIVATE_DEFINITION_START(PIConditionVariable) PRIVATE_DEFINITION_START(PIConditionVariable)
#if defined(WINDOWS) # if defined(WINDOWS)
CONDITION_VARIABLE CONDITION_VARIABLE
#elif defined(FREERTOS) # elif defined(FREERTOS)
EventGroupHandle_t EventGroupHandle_t
#else # else
pthread_cond_t pthread_cond_t
#endif # endif
nativeHandle; nativeHandle;
PRIVATE_DEFINITION_END(PIConditionVariable) PRIVATE_DEFINITION_END(PIConditionVariable)
PIConditionVariable::PIConditionVariable() { PIConditionVariable::PIConditionVariable() {
#if defined(WINDOWS) # if defined(WINDOWS)
InitializeConditionVariable(&PRIVATE->nativeHandle); InitializeConditionVariable(&PRIVATE->nativeHandle);
#elif defined(FREERTOS) # elif defined(FREERTOS)
PRIVATE->nativeHandle = xEventGroupCreate(); PRIVATE->nativeHandle = xEventGroupCreate();
#else # else
pthread_condattr_t condattr; pthread_condattr_t condattr;
pthread_condattr_init(&condattr); pthread_condattr_init(&condattr);
# if !defined(MAC_OS) # if !defined(MAC_OS)
@@ -61,87 +61,87 @@ PIConditionVariable::PIConditionVariable() {
# endif # endif
piZeroMemory(PRIVATE->nativeHandle); piZeroMemory(PRIVATE->nativeHandle);
pthread_cond_init(&PRIVATE->nativeHandle, &condattr); pthread_cond_init(&PRIVATE->nativeHandle, &condattr);
#endif # endif
} }
PIConditionVariable::~PIConditionVariable() { PIConditionVariable::~PIConditionVariable() {
#if defined(WINDOWS) # if defined(WINDOWS)
#elif defined(FREERTOS) # elif defined(FREERTOS)
vEventGroupDelete(PRIVATE->nativeHandle); vEventGroupDelete(PRIVATE->nativeHandle);
#else # else
pthread_cond_destroy(&PRIVATE->nativeHandle); pthread_cond_destroy(&PRIVATE->nativeHandle);
#endif # endif
} }
void PIConditionVariable::wait(PIMutex & lk) { void PIConditionVariable::wait(PIMutex & lk) {
#if defined(WINDOWS) # if defined(WINDOWS)
SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), INFINITE); SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), INFINITE);
#elif defined(FREERTOS) # elif defined(FREERTOS)
xEventGroupClearBits(PRIVATE->nativeHandle, 1); xEventGroupClearBits(PRIVATE->nativeHandle, 1);
xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, portMAX_DELAY); xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, portMAX_DELAY);
#else # else
pthread_cond_wait(&PRIVATE->nativeHandle, (pthread_mutex_t *)lk.handle()); pthread_cond_wait(&PRIVATE->nativeHandle, (pthread_mutex_t *)lk.handle());
#endif # endif
} }
void PIConditionVariable::wait(PIMutex & lk, std::function<bool()> condition) { void PIConditionVariable::wait(PIMutex & lk, std::function<bool()> condition) {
while (true) { while (true) {
if (condition()) break; if (condition()) break;
#if defined(WINDOWS) # if defined(WINDOWS)
SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), INFINITE); SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), INFINITE);
#elif defined(FREERTOS) # elif defined(FREERTOS)
xEventGroupClearBits(PRIVATE->nativeHandle, 1); xEventGroupClearBits(PRIVATE->nativeHandle, 1);
xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, portMAX_DELAY); xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, portMAX_DELAY);
#else # else
pthread_cond_wait(&PRIVATE->nativeHandle, (pthread_mutex_t *)lk.handle()); pthread_cond_wait(&PRIVATE->nativeHandle, (pthread_mutex_t *)lk.handle());
#endif # endif
} }
} }
bool PIConditionVariable::waitFor(PIMutex & lk, PISystemTime timeout) { bool PIConditionVariable::waitFor(PIMutex & lk, PISystemTime timeout) {
bool isNotTimeout; bool isNotTimeout;
#if defined(WINDOWS) # if defined(WINDOWS)
isNotTimeout = SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), timeout.toMilliseconds()) != 0; isNotTimeout = SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), timeout.toMilliseconds()) != 0;
#elif defined(FREERTOS) # elif defined(FREERTOS)
xEventGroupClearBits(PRIVATE->nativeHandle, 1); xEventGroupClearBits(PRIVATE->nativeHandle, 1);
EventBits_t uxBits; EventBits_t uxBits;
uxBits = xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, timeout.toMilliseconds() / portTICK_PERIOD_MS); uxBits = xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, timeout.toMilliseconds() / portTICK_PERIOD_MS);
isNotTimeout = (uxBits & 1) != 0; isNotTimeout = (uxBits & 1) != 0;
#else # else
PISystemTime st = PISystemTime::current(true) + timeout; PISystemTime st = PISystemTime::current(true) + timeout;
timespec expire_ts; timespec expire_ts;
st.toTimespec(&expire_ts); st.toTimespec(&expire_ts);
isNotTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t *)lk.handle(), &expire_ts) == 0; isNotTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t *)lk.handle(), &expire_ts) == 0;
#endif # endif
return isNotTimeout; return isNotTimeout;
} }
bool PIConditionVariable::waitFor(PIMutex & lk, PISystemTime timeout, std::function<bool()> condition) { bool PIConditionVariable::waitFor(PIMutex & lk, PISystemTime timeout, std::function<bool()> condition) {
#if defined(WINDOWS) || defined(FREERTOS) # if defined(WINDOWS) || defined(FREERTOS)
PITimeMeasurer measurer; PITimeMeasurer measurer;
#else # else
PISystemTime st = PISystemTime::current(true) + timeout; PISystemTime st = PISystemTime::current(true) + timeout;
timespec expire_ts; timespec expire_ts;
st.toTimespec(&expire_ts); st.toTimespec(&expire_ts);
#endif # endif
#ifdef FREERTOS # ifdef FREERTOS
xEventGroupClearBits(PRIVATE->nativeHandle, 1); xEventGroupClearBits(PRIVATE->nativeHandle, 1);
#endif # endif
while (true) { while (true) {
if (condition()) break; if (condition()) break;
bool isTimeout; bool isTimeout;
#if defined(WINDOWS) # if defined(WINDOWS)
{ {
int remain = (int)(timeout.toMilliseconds() - (int)measurer.elapsed_m()); int remain = (int)(timeout.toMilliseconds() - (int)measurer.elapsed_m());
if (remain <= 0) return false; if (remain <= 0) return false;
isTimeout = SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), remain) == 0; isTimeout = SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), remain) == 0;
} }
#elif defined(FREERTOS) # elif defined(FREERTOS)
{ {
int remain = (int)(timeout.toMilliseconds() - (int)measurer.elapsed_m()); int remain = (int)(timeout.toMilliseconds() - (int)measurer.elapsed_m());
if (remain <= 0) return false; if (remain <= 0) return false;
@@ -149,9 +149,9 @@ bool PIConditionVariable::waitFor(PIMutex & lk, PISystemTime timeout, std::funct
uxBits = xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, remain / portTICK_PERIOD_MS); uxBits = xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, remain / portTICK_PERIOD_MS);
isTimeout = (uxBits & 1) == 0; isTimeout = (uxBits & 1) == 0;
} }
#else # else
isTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t *)lk.handle(), &expire_ts) != 0; isTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t *)lk.handle(), &expire_ts) != 0;
#endif # endif
if (isTimeout) return false; if (isTimeout) return false;
} }
return true; return true;
@@ -159,23 +159,23 @@ bool PIConditionVariable::waitFor(PIMutex & lk, PISystemTime timeout, std::funct
void PIConditionVariable::notifyOne() { void PIConditionVariable::notifyOne() {
#if defined(WINDOWS) # if defined(WINDOWS)
WakeConditionVariable(&PRIVATE->nativeHandle); WakeConditionVariable(&PRIVATE->nativeHandle);
#elif defined(FREERTOS) # elif defined(FREERTOS)
xEventGroupSetBits(PRIVATE->nativeHandle, 1); xEventGroupSetBits(PRIVATE->nativeHandle, 1);
#else # else
pthread_cond_signal(&PRIVATE->nativeHandle); pthread_cond_signal(&PRIVATE->nativeHandle);
#endif # endif
} }
void PIConditionVariable::notifyAll() { void PIConditionVariable::notifyAll() {
#if defined(WINDOWS) # if defined(WINDOWS)
WakeAllConditionVariable(&PRIVATE->nativeHandle); WakeAllConditionVariable(&PRIVATE->nativeHandle);
#elif defined(FREERTOS) # elif defined(FREERTOS)
xEventGroupSetBits(PRIVATE->nativeHandle, 1); xEventGroupSetBits(PRIVATE->nativeHandle, 1);
#else # else
pthread_cond_broadcast(&PRIVATE->nativeHandle); pthread_cond_broadcast(&PRIVATE->nativeHandle);
#endif # endif
} }
#endif // PIP_HAS_THREADS #endif // PIP_HAS_THREADS
+33 -33
View File
@@ -108,26 +108,26 @@
#ifdef PIP_HAS_THREADS #ifdef PIP_HAS_THREADS
#include "pimutex.h" # include "pimutex.h"
#include "piincludes_p.h" # include "piincludes_p.h"
#if defined(WINDOWS) # if defined(WINDOWS)
# include <synchapi.h> # include <synchapi.h>
#elif defined(FREERTOS) # elif defined(FREERTOS)
# include <semphr.h> # include <semphr.h>
#else # else
# include <pthread.h> # include <pthread.h>
#endif # endif
PRIVATE_DEFINITION_START(PIMutex) PRIVATE_DEFINITION_START(PIMutex)
#if defined(WINDOWS) # if defined(WINDOWS)
CRITICAL_SECTION CRITICAL_SECTION
#elif defined(FREERTOS) # elif defined(FREERTOS)
SemaphoreHandle_t SemaphoreHandle_t
#else # else
pthread_mutex_t pthread_mutex_t
#endif # endif
mutex; mutex;
PRIVATE_DEFINITION_END(PIMutex) PRIVATE_DEFINITION_END(PIMutex)
@@ -150,13 +150,13 @@ PIMutex::~PIMutex() {
//! Если мьютекс свободен, то блокирует его и возвращает управление немедленно. //! Если мьютекс свободен, то блокирует его и возвращает управление немедленно.
//! Если мьютекс заблокирован, то ожидает разблокировки, затем блокирует и возвращает управление //! Если мьютекс заблокирован, то ожидает разблокировки, затем блокирует и возвращает управление
void PIMutex::lock() { void PIMutex::lock() {
#if defined(WINDOWS) # if defined(WINDOWS)
EnterCriticalSection(&(PRIVATE->mutex)); EnterCriticalSection(&(PRIVATE->mutex));
#elif defined(FREERTOS) # elif defined(FREERTOS)
xSemaphoreTake(PRIVATE->mutex, portMAX_DELAY); xSemaphoreTake(PRIVATE->mutex, portMAX_DELAY);
#else # else
pthread_mutex_lock(&(PRIVATE->mutex)); pthread_mutex_lock(&(PRIVATE->mutex));
#endif # endif
} }
@@ -166,13 +166,13 @@ void PIMutex::lock() {
//! \~russian //! \~russian
//! В любом случае возвращает управление немедленно //! В любом случае возвращает управление немедленно
void PIMutex::unlock() { void PIMutex::unlock() {
#if defined(WINDOWS) # if defined(WINDOWS)
LeaveCriticalSection(&(PRIVATE->mutex)); LeaveCriticalSection(&(PRIVATE->mutex));
#elif defined(FREERTOS) # elif defined(FREERTOS)
xSemaphoreGive(PRIVATE->mutex); xSemaphoreGive(PRIVATE->mutex);
#else # else
pthread_mutex_unlock(&(PRIVATE->mutex)); pthread_mutex_unlock(&(PRIVATE->mutex));
#endif # endif
} }
@@ -183,32 +183,32 @@ void PIMutex::unlock() {
//! \~russian //! \~russian
bool PIMutex::tryLock() { bool PIMutex::tryLock() {
bool ret = bool ret =
#if defined(WINDOWS) # if defined(WINDOWS)
(TryEnterCriticalSection(&(PRIVATE->mutex)) != 0); (TryEnterCriticalSection(&(PRIVATE->mutex)) != 0);
#elif defined(FREERTOS) # elif defined(FREERTOS)
xSemaphoreTake(PRIVATE->mutex, 0); xSemaphoreTake(PRIVATE->mutex, 0);
#else # else
(pthread_mutex_trylock(&(PRIVATE->mutex)) == 0); (pthread_mutex_trylock(&(PRIVATE->mutex)) == 0);
#endif # endif
return ret; return ret;
} }
void * PIMutex::handle() { void * PIMutex::handle() {
#ifdef FREERTOS # ifdef FREERTOS
return PRIVATE->mutex; return PRIVATE->mutex;
#else # else
return (void *)&(PRIVATE->mutex); return (void *)&(PRIVATE->mutex);
#endif # endif
} }
void PIMutex::init() { void PIMutex::init() {
#if defined(WINDOWS) # if defined(WINDOWS)
InitializeCriticalSection(&(PRIVATE->mutex)); InitializeCriticalSection(&(PRIVATE->mutex));
#elif defined(FREERTOS) # elif defined(FREERTOS)
PRIVATE->mutex = xSemaphoreCreateMutex(); PRIVATE->mutex = xSemaphoreCreateMutex();
#else # else
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
piZeroMemory(attr); piZeroMemory(attr);
pthread_mutexattr_init(&attr); pthread_mutexattr_init(&attr);
@@ -216,17 +216,17 @@ void PIMutex::init() {
piZeroMemory(PRIVATE->mutex); piZeroMemory(PRIVATE->mutex);
pthread_mutex_init(&(PRIVATE->mutex), &attr); pthread_mutex_init(&(PRIVATE->mutex), &attr);
pthread_mutexattr_destroy(&attr); pthread_mutexattr_destroy(&attr);
#endif # endif
} }
void PIMutex::destroy() { void PIMutex::destroy() {
#if defined(WINDOWS) # if defined(WINDOWS)
DeleteCriticalSection(&(PRIVATE->mutex)); DeleteCriticalSection(&(PRIVATE->mutex));
#elif defined(FREERTOS) # elif defined(FREERTOS)
vSemaphoreDelete(PRIVATE->mutex); vSemaphoreDelete(PRIVATE->mutex);
#else # else
pthread_mutex_destroy(&(PRIVATE->mutex)); pthread_mutex_destroy(&(PRIVATE->mutex));
#endif # endif
} }
#endif // PIP_HAS_THREADS #endif // PIP_HAS_THREADS
+4 -4
View File
@@ -18,11 +18,11 @@
*/ */
#ifdef PIP_HAS_THREADS #ifdef PIP_HAS_THREADS
#include "pitimer.h" # include "pitimer.h"
#include "piconditionvar.h" # include "piconditionvar.h"
#include "piliterals_time.h" # include "piliterals_time.h"
#include "pithread.h" # include "pithread.h"
//! \addtogroup Thread //! \addtogroup Thread
+2 -4
View File
@@ -329,8 +329,7 @@ PISystemTime PITimeMeasurer::elapsedAndReset() {
PISystemTime PISystemTime::Frequency::toSystemTime() const { PISystemTime PISystemTime::Frequency::toSystemTime() const {
if (value_hz <= 0.) { if (value_hz <= 0.) {
piCout << "[PISystemTime::Frequency]" piCout << "[PISystemTime::Frequency]" << "toSystemTime() Warning: invalid hertz: %1"_tr("PISystemTime").arg(value_hz);
<< "toSystemTime() Warning: invalid hertz: %1"_tr("PISystemTime").arg(value_hz);
return PISystemTime(); return PISystemTime();
} }
return PISystemTime::fromSeconds(1. / value_hz); return PISystemTime::fromSeconds(1. / value_hz);
@@ -339,8 +338,7 @@ PISystemTime PISystemTime::Frequency::toSystemTime() const {
PISystemTime::Frequency PISystemTime::Frequency::fromSystemTime(const PISystemTime & st) { PISystemTime::Frequency PISystemTime::Frequency::fromSystemTime(const PISystemTime & st) {
if (st == PISystemTime()) { if (st == PISystemTime()) {
piCout << "[PISystemTime::Frequency]" piCout << "[PISystemTime::Frequency]" << "fromSystemTime() Warning: null frequency"_tr("PISystemTime");
<< "fromSystemTime() Warning: null frequency"_tr("PISystemTime");
return Frequency(); return Frequency();
} }
return Frequency(1. / st.toSeconds()); return Frequency(1. / st.toSeconds());
+10 -5
View File
@@ -165,11 +165,12 @@ public:
STATIC_INITIALIZER_BEGIN \ STATIC_INITIALIZER_BEGIN \
__PIVariantInfo__ * vi(__PIVariantInfoStorage__::get().value(__PIVariantFunctions__<classname_from>::typeIDHelper(), nullptr)); \ __PIVariantInfo__ * vi(__PIVariantInfoStorage__::get().value(__PIVariantFunctions__<classname_from>::typeIDHelper(), nullptr)); \
if (!vi) { \ if (!vi) { \
piCout << "Warning! Using REGISTER_VARIANT_CAST(" #classname_from ", " #classname_to ") before REGISTER_VARIANT(" #classname_from \ piCout << "Warning! Using REGISTER_VARIANT_CAST(" #classname_from ", " #classname_to \
"), ignore."; \ ") before REGISTER_VARIANT(" #classname_from "), ignore."; \
return; \ return; \
} \ } \
vi->cast[__PIVariantFunctions__<classname_to>::typeIDHelper()] = __PIVariantFunctions__<classname_from>::castHelper<classname_to>; \ vi->cast[__PIVariantFunctions__<classname_to>::typeIDHelper()] = \
__PIVariantFunctions__<classname_from>::castHelper<classname_to>; \
STATIC_INITIALIZER_END \ STATIC_INITIALIZER_END \
template<> \ template<> \
template<> \ template<> \
@@ -181,10 +182,14 @@ public:
# define REGISTER_VARIANT_CAST_SIMPLE(classname_from, classname_to) \ # define REGISTER_VARIANT_CAST_SIMPLE(classname_from, classname_to) \
REGISTER_VARIANT_CAST(classname_from, classname_to) { return classname_to(v); } REGISTER_VARIANT_CAST(classname_from, classname_to) { \
return classname_to(v); \
}
# define REGISTER_VARIANT_CAST_SIMPLE_H(classname_from, classname_to) REGISTER_VARIANT_CAST_H(classname_from, classname_to) # define REGISTER_VARIANT_CAST_SIMPLE_H(classname_from, classname_to) REGISTER_VARIANT_CAST_H(classname_from, classname_to)
# define REGISTER_VARIANT_CAST_SIMPLE_CPP(classname_from, classname_to) \ # define REGISTER_VARIANT_CAST_SIMPLE_CPP(classname_from, classname_to) \
REGISTER_VARIANT_CAST_CPP(classname_from, classname_to) { return classname_to(v); } REGISTER_VARIANT_CAST_CPP(classname_from, classname_to) { \
return classname_to(v); \
}
#else #else
+3 -1
View File
@@ -83,7 +83,9 @@
bool supportPrefixesSmaller(int type) const override; \ bool supportPrefixesSmaller(int type) const override; \
\ \
public: \ public: \
PIString className() const override { return piTr(#Name, "PIUnits"); } \ PIString className() const override { \
return piTr(#Name, "PIUnits"); \
} \
uint classID() const override { \ uint classID() const override { \
static uint ret = PIStringAscii(#Name).hash(); \ static uint ret = PIStringAscii(#Name).hash(); \
return ret; \ return ret; \
+28 -56
View File
@@ -89,8 +89,7 @@ void PIOpenCL::Initializer::init() {
cl_uint plat_num = 0; cl_uint plat_num = 0;
ret = clGetPlatformIDs(max_size, cl_platforms, &plat_num); ret = clGetPlatformIDs(max_size, cl_platforms, &plat_num);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL]" piCout << "[PIOpenCL]" << "Error: OpenCL platforms not found!"_tr("PIOpenCL");
<< "Error: OpenCL platforms not found!"_tr("PIOpenCL");
return; return;
} }
for (uint i = 0; i < plat_num; i++) { for (uint i = 0; i < plat_num; i++) {
@@ -205,14 +204,12 @@ PIOpenCL::Context * PIOpenCL::Context::create(const PIOpenCL::DeviceList & dl) {
cl_int ret = 0; cl_int ret = 0;
cl_context con = clCreateContext(0, cldl.size_s(), cldl.data(), 0, 0, &ret); cl_context con = clCreateContext(0, cldl.size_s(), cldl.data(), 0, 0, &ret);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Context]" piCout << "[PIOpenCL::Context]" << "clCreateContext error" << ret;
<< "clCreateContext error" << ret;
return 0; return 0;
} }
cl_command_queue comq = clCreateCommandQueue(con, cldl[0], 0, &ret); cl_command_queue comq = clCreateCommandQueue(con, cldl[0], 0, &ret);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Context]" piCout << "[PIOpenCL::Context]" << "clCreateCommandQueue error" << ret;
<< "clCreateCommandQueue error" << ret;
clReleaseContext(con); clReleaseContext(con);
return 0; return 0;
} }
@@ -253,8 +250,7 @@ PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, co
cl_int ret = 0; cl_int ret = 0;
cl_program prog = clCreateProgramWithSource(PRIVATE->context, 1, &csrc, &src_size, &ret); cl_program prog = clCreateProgramWithSource(PRIVATE->context, 1, &csrc, &src_size, &ret);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Context]" piCout << "[PIOpenCL::Context]" << "clCreateProgramWithSource error" << ret;
<< "clCreateProgramWithSource error" << ret;
if (error) (*error) += "clCreateProgramWithSource error " + PIString::fromNumber(ret); if (error) (*error) += "clCreateProgramWithSource error " + PIString::fromNumber(ret);
return 0; return 0;
} }
@@ -264,8 +260,7 @@ PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, co
clGetProgramBuildInfo(prog, PRIVATE->devices[0], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, 0); clGetProgramBuildInfo(prog, PRIVATE->devices[0], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, 0);
if (ret != 0) { if (ret != 0) {
clReleaseProgram(prog); clReleaseProgram(prog);
piCout << "[PIOpenCL::Context]" piCout << "[PIOpenCL::Context]" << "clBuildProgram error" << ret; // << ":" << buffer;
<< "clBuildProgram error" << ret; // << ":" << buffer;
if (error) (*error) = buffer; if (error) (*error) = buffer;
return 0; return 0;
} }
@@ -273,8 +268,7 @@ PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, co
ret = clGetProgramInfo(prog, CL_PROGRAM_NUM_KERNELS, sizeof(uret), &uret, 0); ret = clGetProgramInfo(prog, CL_PROGRAM_NUM_KERNELS, sizeof(uret), &uret, 0);
if (ret != 0) { if (ret != 0) {
clReleaseProgram(prog); clReleaseProgram(prog);
piCout << "[PIOpenCL::Context]" piCout << "[PIOpenCL::Context]" << "clGetProgramInfo error" << ret;
<< "clGetProgramInfo error" << ret;
if (error) (*error) = "Can`t retrieve CL_PROGRAM_NUM_KERNELS"; if (error) (*error) = "Can`t retrieve CL_PROGRAM_NUM_KERNELS";
return 0; return 0;
} }
@@ -283,8 +277,7 @@ PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, co
ret = clGetProgramInfo(prog, CL_PROGRAM_KERNEL_NAMES, ccnt, knames, 0); ret = clGetProgramInfo(prog, CL_PROGRAM_KERNEL_NAMES, ccnt, knames, 0);
if (ret != 0) { if (ret != 0) {
clReleaseProgram(prog); clReleaseProgram(prog);
piCout << "[PIOpenCL::Context]" piCout << "[PIOpenCL::Context]" << "clGetProgramInfo error" << ret;
<< "clGetProgramInfo error" << ret;
if (error) (*error) = "Can`t retrieve CL_PROGRAM_KERNEL_NAMES"; if (error) (*error) = "Can`t retrieve CL_PROGRAM_KERNEL_NAMES";
return 0; return 0;
} }
@@ -293,8 +286,7 @@ PIOpenCL::Program * PIOpenCL::Context::createProgram(const PIString & source, co
for (const auto & k: knl) { for (const auto & k: knl) {
cl_kernel kern = clCreateKernel(prog, k.dataAscii(), &ret); cl_kernel kern = clCreateKernel(prog, k.dataAscii(), &ret);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Context]" piCout << "[PIOpenCL::Context]" << "clCreateKernel" << k << "error" << ret;
<< "clCreateKernel" << k << "error" << ret;
if (error) (*error) += "clCreateKernel(\"" + k + "\") error " + ret; if (error) (*error) += "clCreateKernel(\"" + k + "\") error " + ret;
for (auto * _k: kerns) for (auto * _k: kerns)
clReleaseKernel((cl_kernel)_k); clReleaseKernel((cl_kernel)_k);
@@ -370,8 +362,7 @@ bool PIOpenCL::Buffer::init() {
} }
PRIVATE->buffer = clCreateBuffer(context_->PRIVATEWB->context, f, elements * def.size(), container ? containerData() : 0, &ret); PRIVATE->buffer = clCreateBuffer(context_->PRIVATEWB->context, f, elements * def.size(), container ? containerData() : 0, &ret);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Buffer]" piCout << "[PIOpenCL::Buffer]" << "clCreateBuffer error" << ret;
<< "clCreateBuffer error" << ret;
return false; return false;
} }
return true; return true;
@@ -396,8 +387,7 @@ void PIOpenCL::Buffer::clear() {
cl_int ret = cl_int ret =
clEnqueueFillBuffer(context_->PRIVATEWB->queue, PRIVATE->buffer, def.data(), def.size_s(), 0, elements * def.size(), 0, 0, 0); clEnqueueFillBuffer(context_->PRIVATEWB->queue, PRIVATE->buffer, def.data(), def.size_s(), 0, elements * def.size(), 0, 0, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Buffer]" piCout << "[PIOpenCL::Buffer]" << "clEnqueueFillBuffer error" << ret;
<< "clEnqueueFillBuffer error" << ret;
} }
} }
@@ -412,8 +402,7 @@ void PIOpenCL::Buffer::copyTo(void * data) {
if (!PRIVATE->buffer) return; if (!PRIVATE->buffer) return;
cl_int ret = clEnqueueReadBuffer(context_->PRIVATEWB->queue, PRIVATE->buffer, CL_TRUE, 0, elements * def.size(), data, 0, 0, 0); cl_int ret = clEnqueueReadBuffer(context_->PRIVATEWB->queue, PRIVATE->buffer, CL_TRUE, 0, elements * def.size(), data, 0, 0, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Buffer]" piCout << "[PIOpenCL::Buffer]" << "clEnqueueReadBuffer error" << ret;
<< "clEnqueueReadBuffer error" << ret;
} }
} }
@@ -430,8 +419,7 @@ void PIOpenCL::Buffer::copyTo(void * data, int elements_count, int elements_offs
0, 0,
0); 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Buffer]" piCout << "[PIOpenCL::Buffer]" << "clEnqueueReadBuffer error" << ret;
<< "clEnqueueReadBuffer error" << ret;
} }
} }
@@ -451,8 +439,7 @@ void PIOpenCL::Buffer::copyFrom(void * data) {
if (!PRIVATE->buffer) return; if (!PRIVATE->buffer) return;
cl_int ret = clEnqueueWriteBuffer(context_->PRIVATEWB->queue, PRIVATE->buffer, CL_TRUE, 0, elements * def.size(), data, 0, 0, 0); cl_int ret = clEnqueueWriteBuffer(context_->PRIVATEWB->queue, PRIVATE->buffer, CL_TRUE, 0, elements * def.size(), data, 0, 0, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Buffer]" piCout << "[PIOpenCL::Buffer]" << "clEnqueueWriteBuffer error" << ret;
<< "clEnqueueWriteBuffer error" << ret;
} }
} }
@@ -469,8 +456,7 @@ void PIOpenCL::Buffer::copyFrom(void * data, int elements_count, int elements_fr
0, 0,
0); 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Buffer]" piCout << "[PIOpenCL::Buffer]" << "clEnqueueWriteBuffer error" << ret;
<< "clEnqueueWriteBuffer error" << ret;
} }
} }
@@ -498,8 +484,7 @@ void PIOpenCL::Buffer::copy(Buffer * buffer_from,
nullptr, nullptr,
nullptr); nullptr);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Buffer]" piCout << "[PIOpenCL::Buffer]" << "clEnqueueCopyBuffer error" << ret;
<< "clEnqueueCopyBuffer error" << ret;
} }
} }
@@ -546,14 +531,12 @@ bool PIOpenCL::Program::initKernels(PIVector<void *> kerns) {
bool PIOpenCL::Kernel::execute() { bool PIOpenCL::Kernel::execute() {
if (dims.isEmpty()) { if (dims.isEmpty()) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "Error: empty range"_tr("PIOpenCL");
<< "Error: empty range"_tr("PIOpenCL");
return false; return false;
} }
cl_int ret = clEnqueueNDRangeKernel(context_->PRIVATEWB->queue, PRIVATE->kernel, dims.size(), 0, dims.data(), 0, 0, 0, 0); cl_int ret = clEnqueueNDRangeKernel(context_->PRIVATEWB->queue, PRIVATE->kernel, dims.size(), 0, dims.data(), 0, 0, 0, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "clEnqueueNDRangeKernel error" << ret;
<< "clEnqueueNDRangeKernel error" << ret;
return false; return false;
} }
return true; return true;
@@ -593,16 +576,14 @@ bool PIOpenCL::Kernel::init() {
cl_int ret = 0; cl_int ret = 0;
ret = clGetKernelInfo(PRIVATE->kernel, CL_KERNEL_FUNCTION_NAME, 1024, kname, 0); ret = clGetKernelInfo(PRIVATE->kernel, CL_KERNEL_FUNCTION_NAME, 1024, kname, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "clGetKernelInfo(CL_KERNEL_FUNCTION_NAME) error" << ret;
<< "clGetKernelInfo(CL_KERNEL_FUNCTION_NAME) error" << ret;
return false; return false;
} }
name_ = kname; name_ = kname;
cl_uint na = 0; cl_uint na = 0;
ret = clGetKernelInfo(PRIVATE->kernel, CL_KERNEL_NUM_ARGS, sizeof(na), &na, 0); ret = clGetKernelInfo(PRIVATE->kernel, CL_KERNEL_NUM_ARGS, sizeof(na), &na, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "clGetKernelInfo(CL_KERNEL_NUM_ARGS) error" << ret;
<< "clGetKernelInfo(CL_KERNEL_NUM_ARGS) error" << ret;
return false; return false;
} }
for (cl_uint i = 0; i < na; ++i) { for (cl_uint i = 0; i < na; ++i) {
@@ -623,14 +604,12 @@ void setArgV(cl_kernel k, int index, T v) {
bool PIOpenCL::Kernel::setArgValueS(int index, const PIVariant & value) { bool PIOpenCL::Kernel::setArgValueS(int index, const PIVariant & value) {
if (index < 0 || index >= args_.size_s()) { if (index < 0 || index >= args_.size_s()) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "setArgValue invalid index %1"_tr("PIOpenCL").arg(index);
<< "setArgValue invalid index %1"_tr("PIOpenCL").arg(index);
return false; return false;
} }
KernelArg & ka(args_[index]); KernelArg & ka(args_[index]);
if (ka.dims > 0) { if (ka.dims > 0) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "setArgValue set scalar to \"%1 %2\""_tr("PIOpenCL").arg(ka.type_name).arg(ka.arg_name);
<< "setArgValue set scalar to \"%1 %2\""_tr("PIOpenCL").arg(ka.type_name).arg(ka.arg_name);
return false; return false;
} }
switch (ka.arg_type) { switch (ka.arg_type) {
@@ -653,14 +632,12 @@ bool PIOpenCL::Kernel::setArgValueS(int index, const PIVariant & value) {
bool PIOpenCL::Kernel::bindArgValue(int index, Buffer * buffer) { bool PIOpenCL::Kernel::bindArgValue(int index, Buffer * buffer) {
if (!buffer) return false; if (!buffer) return false;
if (index < 0 || index >= args_.size_s()) { if (index < 0 || index >= args_.size_s()) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "bindArgValue invalid index %1"_tr("PIOpenCL").arg(index);
<< "bindArgValue invalid index %1"_tr("PIOpenCL").arg(index);
return false; return false;
} }
KernelArg & ka(args_[index]); KernelArg & ka(args_[index]);
if (ka.dims <= 0) { if (ka.dims <= 0) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "bindArgValue set buffer to \"%1 %2\""_tr("PIOpenCL").arg(ka.type_name).arg(ka.arg_name);
<< "bindArgValue set buffer to \"%1 %2\""_tr("PIOpenCL").arg(ka.type_name).arg(ka.arg_name);
return false; return false;
} }
clSetKernelArg(PRIVATE->kernel, index, sizeof(buffer->PRIVATEWB->buffer), &(buffer->PRIVATEWB->buffer)); clSetKernelArg(PRIVATE->kernel, index, sizeof(buffer->PRIVATEWB->buffer), &(buffer->PRIVATEWB->buffer));
@@ -699,22 +676,19 @@ void PIOpenCL::KernelArg::init(void * _k, uint index) {
piZeroMemory(nm, 1024); piZeroMemory(nm, 1024);
ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_TYPE_NAME, 1024, nm, 0); ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_TYPE_NAME, 1024, nm, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "clGetKernelArgInfo(CL_KERNEL_ARG_TYPE_NAME) error" << ret;
<< "clGetKernelArgInfo(CL_KERNEL_ARG_TYPE_NAME) error" << ret;
} }
type_name = nm; type_name = nm;
piZeroMemory(nm, 1024); piZeroMemory(nm, 1024);
ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_NAME, 1024, nm, 0); ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_NAME, 1024, nm, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "clGetKernelArgInfo(CL_KERNEL_ARG_NAME) error" << ret;
<< "clGetKernelArgInfo(CL_KERNEL_ARG_NAME) error" << ret;
} }
arg_name = nm; arg_name = nm;
cl_kernel_arg_address_qualifier addq = 0; cl_kernel_arg_address_qualifier addq = 0;
ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_ADDRESS_QUALIFIER, sizeof(addq), &addq, 0); ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_ADDRESS_QUALIFIER, sizeof(addq), &addq, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "clGetKernelArgInfo(CL_KERNEL_ARG_ADDRESS_QUALIFIER) error" << ret;
<< "clGetKernelArgInfo(CL_KERNEL_ARG_ADDRESS_QUALIFIER) error" << ret;
} }
switch (addq) { switch (addq) {
case CL_KERNEL_ARG_ADDRESS_GLOBAL: address_qualifier = AddressGlobal; break; case CL_KERNEL_ARG_ADDRESS_GLOBAL: address_qualifier = AddressGlobal; break;
@@ -725,8 +699,7 @@ void PIOpenCL::KernelArg::init(void * _k, uint index) {
cl_kernel_arg_access_qualifier accq = 0; cl_kernel_arg_access_qualifier accq = 0;
ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_ACCESS_QUALIFIER, sizeof(accq), &accq, 0); ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_ACCESS_QUALIFIER, sizeof(accq), &accq, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "clGetKernelArgInfo(CL_KERNEL_ARG_ACCESS_QUALIFIER) error" << ret;
<< "clGetKernelArgInfo(CL_KERNEL_ARG_ACCESS_QUALIFIER) error" << ret;
} }
switch (accq) { switch (accq) {
case CL_KERNEL_ARG_ACCESS_READ_ONLY: access_qualifier = AccessReadOnly; break; case CL_KERNEL_ARG_ACCESS_READ_ONLY: access_qualifier = AccessReadOnly; break;
@@ -737,8 +710,7 @@ void PIOpenCL::KernelArg::init(void * _k, uint index) {
cl_kernel_arg_type_qualifier tq = 0; cl_kernel_arg_type_qualifier tq = 0;
ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_TYPE_QUALIFIER, sizeof(tq), &tq, 0); ret = clGetKernelArgInfo(k, index, CL_KERNEL_ARG_TYPE_QUALIFIER, sizeof(tq), &tq, 0);
if (ret != 0) { if (ret != 0) {
piCout << "[PIOpenCL::Kernel]" piCout << "[PIOpenCL::Kernel]" << "clGetKernelArgInfo(CL_KERNEL_ARG_TYPE_QUALIFIER) error" << ret;
<< "clGetKernelArgInfo(CL_KERNEL_ARG_TYPE_QUALIFIER) error" << ret;
} }
switch (tq) { switch (tq) {
case CL_KERNEL_ARG_TYPE_CONST: type_qualifier = TypeConst; break; case CL_KERNEL_ARG_TYPE_CONST: type_qualifier = TypeConst; break;
+8 -16
View File
@@ -392,17 +392,12 @@ PICout operator<<(PICout s, const PIUSB::Endpoint & v) {
s.saveAndSetControls(0); s.saveAndSetControls(0);
s << PICoutManipulators::NewLine << "{" << PICoutManipulators::NewLine; s << PICoutManipulators::NewLine << "{" << PICoutManipulators::NewLine;
if (v.isNull()) if (v.isNull())
s << " " s << " " << "Null Endpoint";
<< "Null Endpoint";
else { else {
s << " " s << " " << "Address: " << v.address << PICoutManipulators::NewLine;
<< "Address: " << v.address << PICoutManipulators::NewLine; s << " " << "Attributes: " << v.attributes << PICoutManipulators::NewLine;
s << " " s << " " << "Direction: " << (v.direction == PIUSB::Endpoint::Write ? "Write" : "Read") << PICoutManipulators::NewLine;
<< "Attributes: " << v.attributes << PICoutManipulators::NewLine; s << " " << "Transfer Type: ";
s << " "
<< "Direction: " << (v.direction == PIUSB::Endpoint::Write ? "Write" : "Read") << PICoutManipulators::NewLine;
s << " "
<< "Transfer Type: ";
switch (v.transfer_type) { switch (v.transfer_type) {
case PIUSB::Endpoint::Control: s << "Control" << PICoutManipulators::NewLine; break; case PIUSB::Endpoint::Control: s << "Control" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::Bulk: s << "Bulk" << PICoutManipulators::NewLine; break; case PIUSB::Endpoint::Bulk: s << "Bulk" << PICoutManipulators::NewLine; break;
@@ -411,8 +406,7 @@ PICout operator<<(PICout s, const PIUSB::Endpoint & v) {
default: break; default: break;
} }
if (v.transfer_type == PIUSB::Endpoint::Isochronous) { if (v.transfer_type == PIUSB::Endpoint::Isochronous) {
s << " " s << " " << "Synchronisation Type: ";
<< "Synchronisation Type: ";
switch (v.synchronisation_type) { switch (v.synchronisation_type) {
case PIUSB::Endpoint::NoSynchonisation: s << "No Synchonisation" << PICoutManipulators::NewLine; break; case PIUSB::Endpoint::NoSynchonisation: s << "No Synchonisation" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::Asynchronous: s << "Asynchronous" << PICoutManipulators::NewLine; break; case PIUSB::Endpoint::Asynchronous: s << "Asynchronous" << PICoutManipulators::NewLine; break;
@@ -420,8 +414,7 @@ PICout operator<<(PICout s, const PIUSB::Endpoint & v) {
case PIUSB::Endpoint::Synchronous: s << "Synchronous" << PICoutManipulators::NewLine; break; case PIUSB::Endpoint::Synchronous: s << "Synchronous" << PICoutManipulators::NewLine; break;
default: break; default: break;
} }
s << " " s << " " << "Usage Type: ";
<< "Usage Type: ";
switch (v.usage_type) { switch (v.usage_type) {
case PIUSB::Endpoint::DataEndpoint: s << "Data Endpoint" << PICoutManipulators::NewLine; break; case PIUSB::Endpoint::DataEndpoint: s << "Data Endpoint" << PICoutManipulators::NewLine; break;
case PIUSB::Endpoint::FeedbackEndpoint: s << "Feedback Endpoint" << PICoutManipulators::NewLine; break; case PIUSB::Endpoint::FeedbackEndpoint: s << "Feedback Endpoint" << PICoutManipulators::NewLine; break;
@@ -431,8 +424,7 @@ PICout operator<<(PICout s, const PIUSB::Endpoint & v) {
default: break; default: break;
} }
} }
s << " " s << " " << "Max Packet Size: " << v.max_packet_size << PICoutManipulators::NewLine;
<< "Max Packet Size: " << v.max_packet_size << PICoutManipulators::NewLine;
} }
s << "}" << PICoutManipulators::NewLine; s << "}" << PICoutManipulators::NewLine;
s.restoreControls(); s.restoreControls();
+1 -1
View File
@@ -80,7 +80,7 @@ void keyEvent(char key, void *) {
}; };
}; };
void timerEvent(void *, int){ void timerEvent(void *, int) {
// sl.send(); // sl.send();
}; };
-1
View File
@@ -11,4 +11,3 @@ TEST(PIFile_Test, openTemporary) {
ASSERT_EQ(ba, f.readAll()); ASSERT_EQ(ba, f.readAll());
ASSERT_TRUE(f.close()); ASSERT_TRUE(f.close());
} }
+2 -2
View File
@@ -557,7 +557,7 @@ TEST_F(Vector2DTest, deleteRows_beyond_bounds_is_limited) {
// All new rows should have original content // All new rows should have original content
for (size_t r = oldRows; r < vec.rows(); ++r) { for (size_t r = oldRows; r < vec.rows(); ++r) {
for (size_t c = 0; c < vec.cols(); ++c) { for (size_t c = 0; c < vec.cols(); ++c) {
EXPECT_EQ(vec.element(r, c), static_cast<int>((r+count) * COLS_COUNT_INIT + c)); EXPECT_EQ(vec.element(r, c), static_cast<int>((r + count) * COLS_COUNT_INIT + c));
} }
} }
} }
@@ -674,7 +674,7 @@ TEST_F(Vector2DTest, addColumn_appends_column_to_existing) {
size_t oldRows = vec.rows(); size_t oldRows = vec.rows();
size_t oldCols = vec.cols(); size_t oldCols = vec.cols();
PIVector<int> newCol(oldRows, [](size_t i){return -900 - (int)i;}); PIVector<int> newCol(oldRows, [](size_t i) { return -900 - (int)i; });
vec.addColumn(newCol); vec.addColumn(newCol);
EXPECT_EQ(vec.rows(), oldRows); EXPECT_EQ(vec.rows(), oldRows);
+3 -3
View File
@@ -1,7 +1,7 @@
#include "piliterals_time.h"
#include "piprotectedvariable.h" #include "piprotectedvariable.h"
#include "pistring.h" #include "pistring.h"
#include "pithread.h" #include "pithread.h"
#include "piliterals_time.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include <atomic> #include <atomic>
@@ -103,8 +103,8 @@ TEST(PIProtectedVariable_ThreadSafety, ConcurrentReadWrite) {
})); }));
} }
threads.forEach([](PIThread * & t) {t->startOnce();}); threads.forEach([](PIThread *& t) { t->startOnce(); });
threads.forEach([](PIThread * & t) {t->waitForFinish(2_s);}); threads.forEach([](PIThread *& t) { t->waitForFinish(2_s); });
piDeleteAll(threads); piDeleteAll(threads);
// Verify results // Verify results
+1 -2
View File
@@ -75,8 +75,7 @@ void CloudServer::stop() {
void CloudServer::printStatus() { void CloudServer::printStatus() {
PIMutexLocker locker(mutex_clients); PIMutexLocker locker(mutex_clients);
piCout << " " piCout << " " << "Clients for" << server->address() << server_uuid.toHex() << ":";
<< "Clients for" << server->address() << server_uuid.toHex() << ":";
for (auto c: clients) { for (auto c: clients) {
piCout << " " << c->address() << c->clientId(); piCout << " " << c->address() << c->clientId();
} }
View File
+1 -2
View File
@@ -106,8 +106,7 @@ void makeClassInfo(Runtime & rt, const PICodeParser::Entity * e) {
} }
rt.ts << "\tci_ci[ci->name] = ci;\n"; rt.ts << "\tci_ci[ci->name] = ci;\n";
if (e->parent_scope) { if (e->parent_scope) {
rt.ts << "\tpci = " rt.ts << "\tpci = " << "ci_ci.value(\"" << e->parent_scope->name << "\", 0);\n";
<< "ci_ci.value(\"" << e->parent_scope->name << "\", 0);\n";
rt.ts << "\tif (pci) pci->children_info << ci;\n"; rt.ts << "\tif (pci) pci->children_info << ci;\n";
} }
for (const PICodeParser::Entity * p: e->parents) for (const PICodeParser::Entity * p: e->parents)
+2 -7
View File
@@ -128,15 +128,10 @@ QtDep qt_deps[] = {QtDep("core", PIStringList() << "platforms"),
QtDep("sql", PIStringList() << "sqldrivers"), QtDep("sql", PIStringList() << "sqldrivers"),
QtDep("positioning", PIStringList() << "position"), QtDep("positioning", PIStringList() << "position"),
QtDep("location", PIStringList() << "geoservices"), QtDep("location", PIStringList() << "geoservices"),
QtDep("multimedia", QtDep("multimedia", PIStringList() << "audio" << "mediaservice" << "playlistformats"),
PIStringList() << "audio"
<< "mediaservice"
<< "playlistformats"),
QtDep("printsupport", PIStringList() << "printsupport"), QtDep("printsupport", PIStringList() << "printsupport"),
QtDep("virtualkeyboard", PIStringList() << "platforminputcontexts"), QtDep("virtualkeyboard", PIStringList() << "platforminputcontexts"),
QtDep("sensors", QtDep("sensors", PIStringList() << "sensors" << "sensorgestures"),
PIStringList() << "sensors"
<< "sensorgestures"),
QtDep("texttospeech", PIStringList() << "texttospeech"), QtDep("texttospeech", PIStringList() << "texttospeech"),
QtDep("serialbus", PIStringList() << "canbus"), QtDep("serialbus", PIStringList() << "canbus"),
QtDep()}; QtDep()};
Executable → Regular
+5 -7
View File
@@ -184,11 +184,10 @@ public:
addrs_tl->content.clear(); addrs_tl->content.clear();
peerinfo_tl->content.clear(); peerinfo_tl->content.clear();
peermap_tl->content.clear(); peermap_tl->content.clear();
peers_tl->content << TileList::Row( peers_tl->content << TileList::Row("this | 0 | 0 | " + PIString::fromNumber(daemon_.allPeers().size_s())
"this | 0 | 0 | " + PIString::fromNumber(daemon_.allPeers().size_s()) // + " [em = " +
// + " [em = " + PIString::fromBool(daemon_.lockedEth()) + ", //PIString::fromBool(daemon_.lockedEth()) + ", " "mm
//" "mm = " + PIString::fromBool(daemon_.lockedMBcasts()) + ", " //= " + PIString::fromBool(daemon_.lockedMBcasts()) + ", " "sm
//"sm
//= //=
//" //"
//+ PIString::fromBool(daemon_.lockedSends()) + ", " "ms = " + //+ PIString::fromBool(daemon_.lockedSends()) + ", " "ms = " +
@@ -396,8 +395,7 @@ int main(int argc, char * argv[]) {
PIINTROSPECTION_START(pisd) PIINTROSPECTION_START(pisd)
if (cli.hasArgument("daemon")) { if (cli.hasArgument("daemon")) {
PIStringList args; PIStringList args;
args << "-1" args << "-1" << "-s";
<< "-s";
if (cli.hasArgument("force")) args << "-f"; if (cli.hasArgument("force")) args << "-f";
if (cli.hasArgument("address")) args << "-a" << sip; if (cli.hasArgument("address")) args << "-a" << sip;
if (!name.isEmpty()) args << "-n" << name; if (!name.isEmpty()) args << "-n" << name;
+1 -2
View File
@@ -116,8 +116,7 @@ private:
#endif #endif
<< ft.stateString() << ft.curFile() << ft.diagnostic().receiveSpeed() << ft.diagnostic().sendSpeed() << "(" << ft.stateString() << ft.curFile() << ft.diagnostic().receiveSpeed() << ft.diagnostic().sendSpeed() << "("
<< PIString::readableSize(ft.bytesFileCur()) << "/" << PIString::readableSize(ft.bytesFileAll()) << ", " << PIString::readableSize(ft.bytesFileCur()) << "/" << PIString::readableSize(ft.bytesFileAll()) << ", "
<< PIString::readableSize(ft.bytesCur()) << "/" << PIString::readableSize(ft.bytesAll()) << ")" << PIString::readableSize(ft.bytesCur()) << "/" << PIString::readableSize(ft.bytesAll()) << ")" << "ETA"
<< "ETA"
<< (ft.diagnostic().state().received_bytes_per_sec > 0 << (ft.diagnostic().state().received_bytes_per_sec > 0
? PIString::fromNumber( ? PIString::fromNumber(
PISystemTime::fromSeconds((ft.bytesAll() - ft.bytesCur()) / ft.diagnostic().state().received_bytes_per_sec) PISystemTime::fromSeconds((ft.bytesAll() - ft.bytesCur()) / ft.diagnostic().state().received_bytes_per_sec)