string ascii
This commit is contained in:
@@ -290,13 +290,7 @@ PIString PIString::fromUTF8(const PIByteArray & ba) {
|
||||
|
||||
|
||||
PIString PIString::fromAscii(const char * s) {
|
||||
PIString ret;
|
||||
int l = 0;
|
||||
while (s[l] != '\0') {
|
||||
ret.push_back(PIChar(s[l]));
|
||||
++l;
|
||||
}
|
||||
return ret;
|
||||
return fromAscii(s, strlen(s));
|
||||
}
|
||||
|
||||
|
||||
|
||||
132
main.cpp
132
main.cpp
@@ -1,71 +1,89 @@
|
||||
#include "pip.h"
|
||||
|
||||
class ConstChars {
|
||||
REGISTER_VARIANT_TYPEINFO(PIVector<double>)
|
||||
|
||||
PIEthernet eth;
|
||||
|
||||
class OH: public PIObject {
|
||||
PIOBJECT(OH)
|
||||
public:
|
||||
inline ConstChars() : len(0), str(nullptr) {}
|
||||
inline ConstChars(const char * string) {
|
||||
str = string;
|
||||
len = strlen(string);
|
||||
EVENT_HANDLER0(void, eh0) {
|
||||
piCout << "eh0";
|
||||
}
|
||||
inline ConstChars(const char * data, size_t size) {
|
||||
str = data;
|
||||
len = size;
|
||||
EVENT_HANDLER1(void, eh1, PIStringList, sl) {
|
||||
piCout << "eh1" << sl;
|
||||
}
|
||||
// inline ROString(const char string[]) {
|
||||
// str = string;
|
||||
// len = sizeof(string);
|
||||
// }
|
||||
|
||||
inline const char & operator[](size_t pos) const {return str[pos];}
|
||||
inline const char * data() const {return str;}
|
||||
|
||||
inline bool isEmpty() const {return len == 0;}
|
||||
inline bool isNotEmpty() const {return len > 0;}
|
||||
inline size_t length() const {return len;}
|
||||
inline size_t size() const {return len;}
|
||||
inline ssize_t size_s() const {return len;}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
inline ConstChars & operator =(const ConstChars & s) {
|
||||
if (this == &s) return *this;
|
||||
len = s.len;
|
||||
str = s.str;
|
||||
return *this;
|
||||
EVENT_HANDLER2(void, eh2, PIStringList, sl, const PIVector< double > &, vd) {
|
||||
piCout << "eh2" << sl << vd;
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Assign move operator.
|
||||
//! \~russian Оператор перемещающего присваивания.
|
||||
inline ConstChars & operator =(ConstChars && s) {
|
||||
swap(s);
|
||||
return *this;
|
||||
EVENT_HANDLER3(void, eh3, PIStringList, sl, const PIVector<double> &, vd, PISystemTime, st) {
|
||||
piCout << "eh3" << sl << vd << st;
|
||||
}
|
||||
|
||||
inline void swap(ConstChars& v) {
|
||||
piSwap<const char *>(str, v.str);
|
||||
piSwap<size_t>(len, v.len);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t len;
|
||||
const char * str;
|
||||
int cnt = 0;
|
||||
};
|
||||
|
||||
class OE: public PIThread {
|
||||
PIOBJECT_SUBCLASS(OE, PIThread)
|
||||
public:
|
||||
EVENT0(e0);
|
||||
EVENT1(e1, PIStringList, sl);
|
||||
EVENT2(e2, PIStringList, sl, PIVector< double>, vd);
|
||||
EVENT3(e3, PIStringList, sl, PIVector< double>, vd, PISystemTime, st);
|
||||
private:
|
||||
};
|
||||
|
||||
PIThreadNotifier notifier;
|
||||
PITimeMeasurer time;
|
||||
|
||||
class Worker: public PIThread {
|
||||
PIOBJECT_SUBCLASS(Worker, PIThread)
|
||||
public:
|
||||
Worker(const PIString & n) {
|
||||
setName(n);
|
||||
}
|
||||
void run() override {
|
||||
piCoutObj << (int)time.elapsed_m() << "wait ...";
|
||||
notifier.wait();
|
||||
piCoutObj << (int)time.elapsed_m() << "done";
|
||||
};
|
||||
};
|
||||
|
||||
PICout operator <<(PICout s, const ConstChars & v) {
|
||||
s.space();
|
||||
s.quote();
|
||||
s.write(v.data(), v.size());
|
||||
s.quote();
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
PIVector<int> v{1, 2, 3, 4, 5, 6};
|
||||
PIVector<PIVector<int>> xv = v.reshape(3,2);
|
||||
piCout << xv;
|
||||
piCout << xv.flatten<int>();
|
||||
piCout << xv.reshape<int>(2,3);
|
||||
typedef int(*MyFunc)(int,int);
|
||||
PILibrary * lib = new PILibrary();
|
||||
if (lib->load("libpip_plugin.dll")) {
|
||||
MyFunc fadd = (MyFunc)lib->resolve("exportedSum");
|
||||
MyFunc fmul = (MyFunc)lib->resolve("exportedMul");
|
||||
if (fadd) {
|
||||
int sum = fadd(1, 2);
|
||||
piCout << "sum =" << sum;
|
||||
} else {
|
||||
piCout << "Can`t resolve" << "exportedSum";
|
||||
}
|
||||
if (fmul) {
|
||||
int mul = fadd(10, 20);
|
||||
piCout << "mul =" << mul;
|
||||
} else {
|
||||
piCout << "Can`t resolve" << "exportedMul";
|
||||
}
|
||||
} else {
|
||||
piCout << lib->lastError();
|
||||
}
|
||||
delete lib;
|
||||
/*OH oh;
|
||||
OE oe;
|
||||
CONNECTU(&oe, e3, &oh, eh0);
|
||||
CONNECTU(&oe, e3, &oh, eh1);
|
||||
CONNECTU(&oe, e3, &oh, eh2);
|
||||
CONNECTU(&oe, e3, &oh, eh3);
|
||||
//oh.dump();
|
||||
oe.dump();
|
||||
oe.e0();
|
||||
oe.e1({"a", "b", "c"});
|
||||
oe.e2({"a", "b", "c"}, {1., 1.5, 2.});
|
||||
oe.e3({"a", "b", "c"}, {1., 1.5, 2.}, PISystemTime::current());
|
||||
//piCout << oe.methodsEH();*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user