diff --git a/libs/main/types/pivariant.cpp b/libs/main/types/pivariant.cpp index 8aaa81ee..59802111 100644 --- a/libs/main/types/pivariant.cpp +++ b/libs/main/types/pivariant.cpp @@ -112,7 +112,18 @@ void PIVariant::setValueFromString(const PIString & v) { case PIVariant::pivDir: {PIVariantTypes::Dir r = toDir(); r.dir = v; setValue(r);} break; case PIVariant::pivColor: {setValue(PIVariantTypes::Color(v.mid(1).toUInt(16)));} break; case PIVariant::pivIODevice: {setValue(PIVariantTypes::IODevice());} break; // TODO - case PIVariant::pivCustom: {} break; // TODO; + case PIVariant::pivCustom: { +#ifdef CUSTOM_PIVARIANT + __PIVariantInfo__ * vi = __PIVariantInfoStorage__::get()->map->value(__PIVariantFunctions__::typeIDHelper()); + if (vi) { + __PIVariantInfo__::castHelperFunc cf = vi->cast.value(_typeID); + if (cf) { + PIByteArray sba; sba << v; + _content = cf(sba); + } + } +#endif + } break; default: break; } } @@ -216,8 +227,10 @@ PIVariant::Type PIVariant::typeFromID(uint type_id) { if (type_id == typeID()) return PIVariant::pivMathMatrix; if (type_id == typeID()) return PIVariant::pivLine; if (type_id == typeID()) return PIVariant::pivIODevice; +#ifdef CUSTOM_PIVARIANT if (__PIVariantInfoStorage__::get()->map->contains(type_id)) return PIVariant::pivCustom; +#endif return PIVariant::pivInvalid; } diff --git a/libs/main/types/pivariant.h b/libs/main/types/pivariant.h index 3a0af353..294aef12 100644 --- a/libs/main/types/pivariant.h +++ b/libs/main/types/pivariant.h @@ -136,12 +136,12 @@ public: return ret; \ } \ STATIC_INITIALIZER_BEGIN \ - __PIVariantInfo__ * vi(__PIVariantInfoStorage__::get()->map->value(name.hash(), nullptr)); \ + __PIVariantInfo__ * vi(__PIVariantInfoStorage__::get()->map->value(__PIVariantFunctions__< classname_from >::typeIDHelper(), nullptr)); \ if (!vi) { \ piCout << "Warning! Using REGISTER_VARIANT_CAST("#classname_from", "#classname_to") before REGISTER_VARIANT("#classname_from"), ignore."; \ return; \ } \ - vi->cast[cname.hash()] = __PIVariantFunctions__::castHelper; \ + vi->cast[__PIVariantFunctions__< classname_to >::typeIDHelper()] = __PIVariantFunctions__::castHelper; \ STATIC_INITIALIZER_END \ template<> template<> \ classname_to __PIVariantFunctions__::castVariant(const classname_from & v) @@ -737,7 +737,11 @@ public: template static uint typeID() { +#ifdef CUSTOM_PIVARIANT return __PIVariantFunctions__::typeIDHelper(); +#else + return 0; +#endif } private: @@ -762,13 +766,13 @@ private: template inline static T getAsValue(const PIVariant & v) { #ifdef CUSTOM_PIVARIANT if (v._content.isEmpty() || !v._info) return T(); - PIString cn = __PIVariantFunctions__::typeNameHelper(); + uint cnid = __PIVariantFunctions__::typeIDHelper(); //piCout << "gav" << cn; PIByteArray ba; - if (cn == v._info->typeName) { + if (cnid == v._info->typeID) { ba = v._content; } else { - __PIVariantInfo__::castHelperFunc cf = v._info->cast.value(cn.hash()); + __PIVariantInfo__::castHelperFunc cf = v._info->cast.value(cnid); //piCout << "gav cast" << cf; if (!cf) return T(); ba = cf(v._content); diff --git a/main.cpp b/main.cpp index e70a223e..dc5e48b6 100644 --- a/main.cpp +++ b/main.cpp @@ -13,217 +13,174 @@ typedef PIVector PIVariantVector; REGISTER_VARIANT(PIVariantMap); REGISTER_VARIANT(PIVariantVector); -#ifdef WINDOWS -# include -# include -# include -# include -typedef HANDLE pipe_type; -#else -# include -typedef int pipe_type; -#endif -struct Pipe { - pipe_type fd_read = 0; - pipe_type fd_write = 0; - void create() { -#ifdef WINDOWS - CreatePipe(&fd_read, &fd_write, NULL, 0); -#else - pipe((int*)this); -#endif - } - void destoy() { -#ifdef WINDOWS - CloseHandle(fd_read); - CloseHandle(fd_write); -#else - close(fd_read); - close(fd_write); -#endif - } - int read(void * d, int s) { -#ifdef WINDOWS - DWORD ret(0); - ReadFile(fd_read, d, s, &ret, NULL); - return ret; -#else - return ::read(fd_read, d, s); -#endif - } - int write(void * d, int s) { -#ifdef WINDOWS - DWORD ret(0); - WriteFile(fd_write, d, s, &ret, NULL); - return ret; -#else - return ::write(fd_write, d, s); -#endif - } -}; - -constexpr int count = 4; -Pipe pipes[count]; - -class T: public PIThread { +class PIValueTree { public: - T(int index): PIThread() {ind = index; pipe = pipes[index];} - void run() { - PIByteArray data(1024); - piCout << "[T"<