PICodeInfo compatible with old interface, safety access to PICODEINFO

This commit is contained in:
2023-12-08 19:01:22 +03:00
parent b8fc44714c
commit c77afcc374
3 changed files with 98 additions and 35 deletions

View File

@@ -46,34 +46,30 @@ PIVariantTypes::Enum PICodeInfo::EnumInfo::toPIVariantEnum() {
PIVariant PICodeInfo::getMemberAsVariant(const void * p, const char * class_name, const char * member_name) {
if (!p || !class_name || !member_name || !PICODEINFO->accessTypeFunctions || !PICODEINFO->accessValueFunctions) return PIVariant();
AccessTypeFunction atf = PICODEINFO->accessTypeFunctions->value(class_name, (AccessTypeFunction)0);
AccessValueFunction avf = PICODEINFO->accessValueFunctions->value(class_name, (AccessValueFunction)0);
if (!p || !class_name || !member_name) return PIVariant();
AccessTypeFunction atf = PICODEINFO::accessTypeFunctions().value(class_name, (AccessTypeFunction) nullptr);
AccessValueFunction avf = PICODEINFO::accessValueFunctions().value(class_name, (AccessValueFunction) nullptr);
if (!atf || !avf) return PIVariant();
return PIVariant::fromValue(avf(p, member_name), PIStringAscii(atf(member_name)));
}
PICodeInfo::__Storage__::__Storage__() {
piCout << "PICodeInfo::__Storage__" << this << "new ...";
classesInfo = new PIMap<PIConstChars, ClassInfo *>;
enumsInfo = new PIMap<PIConstChars, EnumInfo *>;
accessValueFunctions = new PIMap<PIConstChars, AccessValueFunction>;
accessTypeFunctions = new PIMap<PIConstChars, AccessTypeFunction>;
(*enumsInfo)[""] = new EnumInfo();
piCout << "PICodeInfo::__Storage__" << this << "new done";
}
PICodeInfo::__Storage__::~__Storage__() {
piCout << "PICodeInfo::__Storage__" << this << "delete ...";
piDeleteAll(classesInfo->values());
piDeleteAll(enumsInfo->values());
piDeleteSafety(classesInfo);
piDeleteSafety(enumsInfo);
piDeleteSafety(accessValueFunctions);
piDeleteSafety(accessTypeFunctions);
piCout << "PICodeInfo::__Storage__" << this << "delete done";
}
@@ -81,3 +77,9 @@ PICodeInfo::__Storage__ * PICodeInfo::__Storage__::instance() {
static __Storage__ ret;
return &ret;
}
PICodeInfo::ClassInfoInterface classesInfo;
PICodeInfo::EnumsInfoInterface enumsInfo;
PICodeInfo::AccessValueFunctionInterface accessValueFunctions;
PICodeInfo::AccessTypeFunctionInterface accessTypeFunctions;