string ascii

This commit is contained in:
2022-04-24 19:15:51 +03:00
parent c1c324a5a8
commit cf48c9ebf7
2 changed files with 76 additions and 64 deletions

View File

@@ -290,13 +290,7 @@ PIString PIString::fromUTF8(const PIByteArray & ba) {
PIString PIString::fromAscii(const char * s) { PIString PIString::fromAscii(const char * s) {
PIString ret; return fromAscii(s, strlen(s));
int l = 0;
while (s[l] != '\0') {
ret.push_back(PIChar(s[l]));
++l;
}
return ret;
} }

130
main.cpp
View File

@@ -1,71 +1,89 @@
#include "pip.h" #include "pip.h"
class ConstChars { REGISTER_VARIANT_TYPEINFO(PIVector<double>)
PIEthernet eth;
class OH: public PIObject {
PIOBJECT(OH)
public: public:
inline ConstChars() : len(0), str(nullptr) {} EVENT_HANDLER0(void, eh0) {
inline ConstChars(const char * string) { piCout << "eh0";
str = string;
len = strlen(string);
} }
inline ConstChars(const char * data, size_t size) { EVENT_HANDLER1(void, eh1, PIStringList, sl) {
str = data; piCout << "eh1" << sl;
len = size;
} }
// inline ROString(const char string[]) { EVENT_HANDLER2(void, eh2, PIStringList, sl, const PIVector< double > &, vd) {
// str = string; piCout << "eh2" << sl << vd;
// 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_HANDLER3(void, eh3, PIStringList, sl, const PIVector<double> &, vd, PISystemTime, st) {
//! \~\brief piCout << "eh3" << sl << vd << st;
//! \~english Assign move operator.
//! \~russian Оператор перемещающего присваивания.
inline ConstChars & operator =(ConstChars && s) {
swap(s);
return *this;
} }
inline void swap(ConstChars& v) {
piSwap<const char *>(str, v.str);
piSwap<size_t>(len, v.len);
}
private: private:
size_t len; int cnt = 0;
const char * str;
}; };
PICout operator <<(PICout s, const ConstChars & v) { class OE: public PIThread {
s.space(); PIOBJECT_SUBCLASS(OE, PIThread)
s.quote(); public:
s.write(v.data(), v.size()); EVENT0(e0);
s.quote(); EVENT1(e1, PIStringList, sl);
return s; 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";
};
};
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
PIVector<int> v{1, 2, 3, 4, 5, 6}; typedef int(*MyFunc)(int,int);
PIVector<PIVector<int>> xv = v.reshape(3,2); PILibrary * lib = new PILibrary();
piCout << xv; if (lib->load("libpip_plugin.dll")) {
piCout << xv.flatten<int>(); MyFunc fadd = (MyFunc)lib->resolve("exportedSum");
piCout << xv.reshape<int>(2,3); 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; return 0;
} }