180 lines
4.2 KiB
C++
180 lines
4.2 KiB
C++
#include "pibytearray.h"
|
|
#include "piclientserver_client.h"
|
|
#include "piclientserver_server.h"
|
|
#include "picodeparser.h"
|
|
#include "piintrospection_server.h"
|
|
#include "piiostream.h"
|
|
#include "pijson.h"
|
|
#include "pilog.h"
|
|
#include "pimathbase.h"
|
|
#include "pip.h"
|
|
#include "piprotectedvariable.h"
|
|
#include "pitranslator_p.h"
|
|
#include "pivaluetree_conversions.h"
|
|
|
|
#include <windows.h>
|
|
|
|
using namespace PICoutManipulators;
|
|
/*
|
|
class MyStr: public PIString {
|
|
public:
|
|
MyStr(): PIString() {}
|
|
MyStr(const char * o): PIString(o) { piCout << "MyStr *"; }
|
|
MyStr(const MyStr & o): PIString(o) { piCout << "MyStr &"; }
|
|
// MyStr(const MyStr & o): PIString(o) { piCout << "MyStr &"; }
|
|
MyStr(MyStr && o): PIString(o) { piCout << "MyStr &&"; }
|
|
MyStr & operator=(const MyStr & o) {
|
|
*this += o;
|
|
piCout << "MyStr =&";
|
|
return *this;
|
|
}
|
|
MyStr & operator=(MyStr && o) {
|
|
*this += o;
|
|
piCout << "MyStr =&&";
|
|
return *this;
|
|
}
|
|
};
|
|
*/
|
|
|
|
|
|
class RWL {
|
|
public:
|
|
void lockWrite() { mutex.lock(); }
|
|
void unlockWrite() { mutex.unlock(); }
|
|
void lockRead() {}
|
|
void unlockRead() {}
|
|
PIMutex mutex;
|
|
};
|
|
|
|
PIMutex mutex;
|
|
PISemaphore sem(10);
|
|
|
|
int main(int argc, char * argv[]) {
|
|
/*sem.acquire(2);
|
|
piCout << sem.tryAcquire(2);
|
|
piCout << sem.available();
|
|
return 0;*/
|
|
PIThread t_w(
|
|
[] {
|
|
// PIMutexLocker _ml(mutex);
|
|
piCout << "write start ...";
|
|
piMSleep(500);
|
|
sem.release(11);
|
|
piCout << "write end" << sem.available() << "\n";
|
|
},
|
|
true,
|
|
1_Hz);
|
|
|
|
int cnt0 = 0, cnt1 = 0;
|
|
PIThread t_r0(
|
|
[&cnt0] {
|
|
// PIMutexLocker _ml(mutex);
|
|
piCout << "read0 start ...";
|
|
piMSleep(50);
|
|
sem.acquire(2);
|
|
bool ok = true; // sem.tryAcquire(2, 100_ms);
|
|
if (ok) ++cnt0;
|
|
piCout << "read0 end" << sem.available() << ok;
|
|
},
|
|
true,
|
|
10_Hz);
|
|
PIThread t_r1(
|
|
[&cnt1] {
|
|
// PIMutexLocker _ml(mutex);
|
|
piCout << "read1 start ...";
|
|
piMSleep(50);
|
|
sem.acquire(2);
|
|
bool ok = true; // sem.tryAcquire(2, 100_ms);
|
|
if (ok) ++cnt1;
|
|
piCout << "read1 end" << sem.available() << ok;
|
|
},
|
|
true,
|
|
11_Hz);
|
|
|
|
piSleep(5.);
|
|
|
|
t_r0.stopAndWait();
|
|
t_r1.stopAndWait();
|
|
t_w.stopAndWait();
|
|
|
|
piCout << cnt0 << cnt1;
|
|
|
|
/*PICodeParser parser;
|
|
parser.parseFile("client_server.h");
|
|
for (auto m: parser.enums) {
|
|
piCout << "";
|
|
piCout << m.name; // << m.args << m.value;
|
|
// piCout << m.expand({"hello"});
|
|
}*/
|
|
|
|
return 0;
|
|
PITranslator::loadLang("ru");
|
|
PISerial f("COM123");
|
|
f.open();
|
|
|
|
/*auto test = [](PIString s, PIString v) {
|
|
piCout << " in:" << s;
|
|
piCout << "arg:" << minArgPlaceholder(s);
|
|
piCout << "out:" << arg(s, v);
|
|
piCout << "";
|
|
};
|
|
|
|
test(" %", "asd");
|
|
test("%", "asd");
|
|
test("1", "asd");
|
|
test(" %11", "asd");
|
|
test("%1%2 %0f%0g", "asd");
|
|
test("%01 ", "asd");*/
|
|
|
|
/*piCout << PIString::readableSize(50_KiB);
|
|
piCout << PIString::readableSize(1_GB);
|
|
PITranslator::loadLang("ru");
|
|
piCout << PIString::readableSize(50_KiB);
|
|
piCout << PIString::readableSize(1_GB);
|
|
piCout << "test\nstring"_tr;
|
|
PITranslator::clear();
|
|
piCout << PIString::readableSize(50_KiB);
|
|
piCout << PIString::readableSize(1_GB);
|
|
piCout << "test\nstring"_tr;
|
|
piCout << "hello!"_tr;
|
|
PITranslator::loadConfig("[]\nhello!=привет!\n[Co]\nhello!=привет CO!\n"_u8);
|
|
piCout << "hello!"_tr("Co") << "hello!"_tr;*/
|
|
// piCout << "hello!"_trNoOp;
|
|
|
|
|
|
/*PISet<int> set;
|
|
piCout << set << piSerialize(set) << piDeserialize<PISet<int>>(piSerialize(set));
|
|
set << 1 << 2 << 3;
|
|
piCout << set << piSerialize(set) << piDeserialize<PISet<int>>(piSerialize(set));
|
|
set << 1 << -2 << 50 << -100;
|
|
piCout << set << piSerialize(set) << piDeserialize<PISet<int>>(piSerialize(set));*/
|
|
return 0;
|
|
|
|
std::numeric_limits<complexf>::epsilon();
|
|
using cmlp = complexf;
|
|
PIMathMatrixT<3, 3, double> v0;
|
|
PIMathMatrixT<3, 3, cmlp> v1;
|
|
v0[0][1] = 1;
|
|
v0[1][1] = 2;
|
|
v0[2][1] = 3;
|
|
v1[0][1] = cmlp(1., 0);
|
|
v1[1][1] = cmlp(2., -1);
|
|
v1[2][1] = cmlp(3., 2);
|
|
piCout << v0 << v1;
|
|
piCout << (v0 * 2.) << (v1 * cmlp(2., 2.));
|
|
piCout << (v0 + 2.) << (v1 + cmlp(2.));
|
|
piCout << (v0 - 2.) << (v1 - cmlp(2.));
|
|
piCout << (v0 / 2.) << (v1 / cmlp(2., 1.));
|
|
// piCout << (v0.length()) << (v1.length());
|
|
// piCout << (v0.lengthSqr()) << (v1.lengthSqr());
|
|
// piCout << (v0.manhattanLength()) << (v1.manhattanLength());
|
|
|
|
/*foo<int>();
|
|
foo<double>();
|
|
foo<complexf>();
|
|
foo<complexd>();
|
|
return 0;*/
|
|
|
|
return 0;
|
|
}
|