version 3.15.0 - improved pip_cmg and PICodeInfo storage
Important! changed API to access PICodeInfo storage
This commit is contained in:
@@ -45,18 +45,39 @@ PIVariantTypes::Enum PICodeInfo::EnumInfo::toPIVariantEnum() {
|
||||
}
|
||||
|
||||
|
||||
PIMap<PIConstChars, PICodeInfo::ClassInfo *> * PICodeInfo::classesInfo;
|
||||
PIMap<PIConstChars, PICodeInfo::EnumInfo *> * PICodeInfo::enumsInfo;
|
||||
PIMap<PIConstChars, PICodeInfo::AccessValueFunction> * PICodeInfo::accessValueFunctions;
|
||||
PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> * PICodeInfo::accessTypeFunctions;
|
||||
|
||||
bool __PICodeInfoInitializer__::_inited_ = false;
|
||||
|
||||
|
||||
PIVariant PICodeInfo::getMemberAsVariant(const void * p, const char * class_name, const char * member_name) {
|
||||
if (!p || !class_name || !member_name || !accessTypeFunctions || !accessValueFunctions) return PIVariant();
|
||||
AccessTypeFunction atf = accessTypeFunctions->value(class_name, (AccessTypeFunction)0);
|
||||
AccessValueFunction avf = accessValueFunctions->value(class_name, (AccessValueFunction)0);
|
||||
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 (!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";
|
||||
}
|
||||
|
||||
|
||||
PICodeInfo::__Storage__ * PICodeInfo::__Storage__::instance() {
|
||||
static __Storage__ ret;
|
||||
return &ret;
|
||||
}
|
||||
|
||||
@@ -278,28 +278,40 @@ inline PICout operator<<(PICout s, const PICodeInfo::EnumInfo & v) {
|
||||
}
|
||||
|
||||
|
||||
//! \~english Pointer to single storage of PICodeInfo::ClassInfo, access by name
|
||||
//! \~russian Указатель на единое хренилище PICodeInfo::ClassInfo, доступ по имени
|
||||
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::ClassInfo *> * classesInfo;
|
||||
class PIP_EXPORT __Storage__ {
|
||||
__Storage__();
|
||||
~__Storage__();
|
||||
|
||||
//! \~english Pointer to single storage of PICodeInfo::EnumInfo, access by name
|
||||
//! \~russian Указатель на единое хренилище PICodeInfo::EnumInfo, доступ по имени
|
||||
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::EnumInfo *> * enumsInfo;
|
||||
public:
|
||||
static __Storage__ * instance();
|
||||
|
||||
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::AccessValueFunction> * accessValueFunctions;
|
||||
//! \~english Getter for single storage of PICodeInfo::ClassInfo, access by name
|
||||
//! \~russian Доступ к единому хранилищу PICodeInfo::ClassInfo, доступ по имени
|
||||
const PIMap<PIConstChars, PICodeInfo::ClassInfo *> & classes() { return *classesInfo; }
|
||||
|
||||
//! \~english Getter for single storage of PICodeInfo::EnumInfo, access by name
|
||||
//! \~russian Доступ к единому хранилищу хранилище PICodeInfo::EnumInfo, доступ по имени
|
||||
const PIMap<PIConstChars, PICodeInfo::EnumInfo *> & enums() { return *enumsInfo; }
|
||||
|
||||
PIMap<PIConstChars, PICodeInfo::ClassInfo *> * classesInfo;
|
||||
PIMap<PIConstChars, PICodeInfo::EnumInfo *> * enumsInfo;
|
||||
PIMap<PIConstChars, PICodeInfo::AccessValueFunction> * accessValueFunctions;
|
||||
PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> * accessTypeFunctions;
|
||||
};
|
||||
|
||||
#define PICODEINFO (PICodeInfo::__Storage__::instance())
|
||||
|
||||
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> * accessTypeFunctions;
|
||||
|
||||
inline PIByteArray getMemberValue(const void * p, const char * class_name, const char * member_name) {
|
||||
if (!p || !class_name || !member_name || !accessValueFunctions) return PIByteArray();
|
||||
AccessValueFunction af = accessValueFunctions->value(class_name, (AccessValueFunction)0);
|
||||
if (!p || !class_name || !member_name || !PICODEINFO->accessValueFunctions) return PIByteArray();
|
||||
AccessValueFunction af = PICODEINFO->accessValueFunctions->value(class_name, (AccessValueFunction)0);
|
||||
if (!af) return PIByteArray();
|
||||
return af(p, member_name);
|
||||
}
|
||||
|
||||
inline const char * getMemberType(const char * class_name, const char * member_name) {
|
||||
if (!class_name || !member_name || !accessTypeFunctions) return "";
|
||||
AccessTypeFunction af = accessTypeFunctions->value(class_name, (AccessTypeFunction)0);
|
||||
if (!class_name || !member_name || !PICODEINFO->accessTypeFunctions) return "";
|
||||
AccessTypeFunction af = PICODEINFO->accessTypeFunctions->value(class_name, (AccessTypeFunction)0);
|
||||
if (!af) return "";
|
||||
return af(member_name);
|
||||
}
|
||||
@@ -317,19 +329,5 @@ void serialize(PIByteArray & ret, const T & v) {}
|
||||
|
||||
} // namespace PICodeInfo
|
||||
|
||||
class PIP_EXPORT __PICodeInfoInitializer__ {
|
||||
public:
|
||||
__PICodeInfoInitializer__() {
|
||||
if (_inited_) return;
|
||||
_inited_ = true;
|
||||
PICodeInfo::classesInfo = new PIMap<PIConstChars, PICodeInfo::ClassInfo *>;
|
||||
PICodeInfo::enumsInfo = new PIMap<PIConstChars, PICodeInfo::EnumInfo *>;
|
||||
PICodeInfo::accessValueFunctions = new PIMap<PIConstChars, PICodeInfo::AccessValueFunction>;
|
||||
PICodeInfo::accessTypeFunctions = new PIMap<PIConstChars, PICodeInfo::AccessTypeFunction>;
|
||||
}
|
||||
static bool _inited_;
|
||||
};
|
||||
|
||||
static __PICodeInfoInitializer__ __picodeinfoinitializer__;
|
||||
|
||||
#endif // PICODEINFO_H
|
||||
|
||||
Reference in New Issue
Block a user