Files
pip/main.cpp

221 lines
4.8 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() {
PIMutexLocker _ml(mutex);
while (reading > 0 || writing) {
var.wait(mutex);
}
writing = true;
}
void unlockWrite() {
PIMutexLocker _ml(mutex);
writing = false;
var.notifyAll();
}
void lockRead() {
PIMutexLocker _ml(mutex);
while (writing) {
var.wait(mutex);
}
++reading;
}
void unlockRead() {
PIMutexLocker _ml(mutex);
--reading;
var.notifyAll();
}
private:
PIConditionVariable var;
int reading = 0;
bool writing = false;
PIMutex mutex;
};
PIMutex mutex;
PISemaphore sem(10);
PIReadWriteLock rwl;
int main(int argc, char * argv[]) {
/*sem.acquire(2);
piCout << sem.tryAcquire(2);
piCout << sem.available();
return 0;*/
PIThread t_w0(
[] {
// PIMutexLocker _ml(mutex);
PIWriteLocker rl(rwl);
piCout << "write0 start ...";
piMSleep(500);
piCout << "write0 end"
<< "\n";
},
true,
1_Hz);
PIThread t_w1(
[] {
// PIMutexLocker _ml(mutex);
PIWriteLocker rl(rwl);
piCout << "write1 start ...";
piMSleep(500);
piCout << "write1 end"
<< "\n";
},
true,
1_Hz);
int cnt0 = 0, cnt1 = 0;
PIThread t_r0(
[&cnt0] {
// PIMutexLocker _ml(mutex);
PIReadLocker rl(rwl);
piCout << "read0 start ...";
piMSleep(50);
// bool ok = rwl.tryLockRead(100_ms);
// if (ok) ++cnt0;
piCout << "read0 end";
// if (ok) rwl.unlockRead();
},
true,
10_Hz);
PIThread t_r1(
[&cnt1] {
// PIMutexLocker _ml(mutex);
// PIReadLocker rl(rwl);
piCout << "read1 start ...";
piMSleep(50);
bool ok = rwl.tryLockRead(100_ms);
if (ok) ++cnt1;
piCout << "read1 end" << ok;
if (ok) rwl.unlockRead();
},
true,
11_Hz);
piSleep(8.);
t_r0.stopAndWait();
t_r1.stopAndWait();
t_w0.stopAndWait();
t_w1.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;
}