git-svn-id: svn://db.shs.com.ru/pip@775 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "picodeinfo.h"
|
||||
#include "pivariant.h"
|
||||
|
||||
|
||||
PIString PICodeInfo::EnumInfo::memberName(int value_) const {
|
||||
@@ -38,6 +39,16 @@ int PICodeInfo::EnumInfo::memberValue(const PIString & name_) const {
|
||||
|
||||
PIMap<PIString, PICodeInfo::ClassInfo * > * PICodeInfo::classesInfo;
|
||||
PIMap<PIString, PICodeInfo::EnumInfo * > * PICodeInfo::enumsInfo;
|
||||
PIMap<PIString, PICodeInfo::AccessFunction> * PICodeInfo::accessFunctions;
|
||||
PIMap<PIString, PICodeInfo::AccessValueFunction> * PICodeInfo::accessValueFunctions;
|
||||
PIMap<PIString, 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(PIStringAscii(class_name), (AccessTypeFunction)0);
|
||||
AccessValueFunction avf = accessValueFunctions->value(PIStringAscii(class_name), (AccessValueFunction)0);
|
||||
if (!atf || !avf) return PIVariant();
|
||||
return PIVariant::fromValue(avf(p, member_name), PIStringAscii(atf(member_name)));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
#include "pistring.h"
|
||||
|
||||
class PIVariant;
|
||||
|
||||
namespace PICodeInfo {
|
||||
|
||||
enum PIP_EXPORT TypeFlag {
|
||||
@@ -41,7 +43,8 @@ enum PIP_EXPORT TypeFlag {
|
||||
|
||||
typedef PIFlags<PICodeInfo::TypeFlag> TypeFlags;
|
||||
typedef PIMap<PIString, PIString> MetaMap;
|
||||
typedef PIByteArray(*AccessFunction)(const void *, const char *);
|
||||
typedef PIByteArray(*AccessValueFunction)(const void *, const char *);
|
||||
typedef const char*(*AccessTypeFunction)(const char *);
|
||||
|
||||
struct PIP_EXPORT TypeInfo {
|
||||
TypeInfo(const PIString & n = PIString(), const PIString & t = PIString(), PICodeInfo::TypeFlags f = 0, int b = -1) {name = n; type = t; flags = f; bits = b;}
|
||||
@@ -152,15 +155,25 @@ inline PICout operator <<(PICout s, const PICodeInfo::EnumInfo & v) {
|
||||
|
||||
extern PIMap<PIString, PICodeInfo::ClassInfo * > * classesInfo;
|
||||
extern PIMap<PIString, PICodeInfo::EnumInfo * > * enumsInfo;
|
||||
extern PIMap<PIString, PICodeInfo::AccessFunction> * accessFunctions;
|
||||
extern PIMap<PIString, PICodeInfo::AccessValueFunction> * accessValueFunctions;
|
||||
extern PIMap<PIString, PICodeInfo::AccessTypeFunction> * accessTypeFunctions;
|
||||
|
||||
inline PIByteArray getMember(const void * p, const char * class_name, const char * member_name) {
|
||||
if (!p || !class_name || !member_name || !accessFunctions) return PIByteArray();
|
||||
AccessFunction af = accessFunctions->value(PIStringAscii(class_name), (AccessFunction)0);
|
||||
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(PIStringAscii(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(PIStringAscii(class_name), (AccessTypeFunction)0);
|
||||
if (!af) return "";
|
||||
return af(member_name);
|
||||
}
|
||||
|
||||
PIVariant getMemberAsVariant(const void * p, const char * class_name, const char * member_name);
|
||||
|
||||
}
|
||||
|
||||
class __PICodeInfoInitializer__ {
|
||||
@@ -170,7 +183,8 @@ public:
|
||||
_inited_ = true;
|
||||
PICodeInfo::classesInfo = new PIMap<PIString, PICodeInfo::ClassInfo * >;
|
||||
PICodeInfo::enumsInfo = new PIMap<PIString, PICodeInfo::EnumInfo * >;
|
||||
PICodeInfo::accessFunctions = new PIMap<PIString, PICodeInfo::AccessFunction>;
|
||||
PICodeInfo::accessValueFunctions = new PIMap<PIString, PICodeInfo::AccessValueFunction>;
|
||||
PICodeInfo::accessTypeFunctions = new PIMap<PIString, PICodeInfo::AccessTypeFunction>;
|
||||
}
|
||||
static bool _inited_;
|
||||
};
|
||||
|
||||
@@ -285,8 +285,20 @@ void makeClassStreamHeader(PIFile & f, const PICodeParser::Entity * e) {
|
||||
}
|
||||
|
||||
|
||||
void makeGetter(PIFile & f, const PICodeParser::Entity * e) {
|
||||
f << "\nPIByteArray getter" << toCName(e->name) << "(const void * p, const char * name) {\n";
|
||||
void makeGetterType(PIFile & f, const PICodeParser::Entity * e) {
|
||||
f << "\nconst char * getterType" << toCName(e->name) << "(const char * name) {\n";
|
||||
f << "\tif (!name) return \"\";\n";
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr || m.isBitfield() || !m.dims.isEmpty() || (m.visibility != PICodeParser::Public))
|
||||
continue;
|
||||
f << "\tif (strcmp(name, \"" << m.name << "\") == 0) return \"" << m.type << "\";\n";
|
||||
}
|
||||
f << "\treturn \"\";\n}\n";
|
||||
}
|
||||
|
||||
|
||||
void makeGetterValue(PIFile & f, const PICodeParser::Entity * e) {
|
||||
f << "\nPIByteArray getterValue" << toCName(e->name) << "(const void * p, const char * name) {\n";
|
||||
f << "\tPIByteArray ret;\n";
|
||||
f << "\tif (!p || !name) return ret;\n";
|
||||
f << "\t" << e->name << " * o = (" << e->name << "*)p;\n";
|
||||
@@ -298,11 +310,6 @@ void makeGetter(PIFile & f, const PICodeParser::Entity * e) {
|
||||
f << "\treturn ret;\n}\n";
|
||||
}
|
||||
|
||||
/*
|
||||
void makeGetterHeader(PIFile & f, const PICodeParser::Entity * e) {
|
||||
f << "\nPIByteArray getter" << toCName(e->name) << "(const void * p, const char * name);";
|
||||
}
|
||||
*/
|
||||
|
||||
void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool meta, bool enums, bool streams, bool texts, bool getters) {
|
||||
PIVector<const PICodeParser::Entity * > ventities;
|
||||
@@ -384,7 +391,8 @@ void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
f << "\n\n// Getter funtions\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeGetter(f, e);
|
||||
makeGetterType(f, e);
|
||||
makeGetterValue(f, e);
|
||||
}
|
||||
}
|
||||
f << "\n\n// Metainformation\n\n__ClassInfo_" << defname << "_Initializer__::__ClassInfo_" << defname << "_Initializer__() {\n";
|
||||
@@ -413,7 +421,8 @@ void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
f << "\n// Getters\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
f << "\t(*accessFunctions)[\"" << e->name << "\"] = getter" << toCName(e->name) << ";\n";
|
||||
f << "\t(*accessValueFunctions)[\"" << e->name << "\"] = getterValue" << toCName(e->name) << ";\n";
|
||||
f << "\t(*accessTypeFunctions)[\"" << e->name << "\"] = getterType" << toCName(e->name) << ";\n";
|
||||
}
|
||||
}
|
||||
f << "}\n";
|
||||
@@ -458,14 +467,6 @@ const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), cons
|
||||
makeClassStreamHeader(f, e);
|
||||
}
|
||||
}
|
||||
/*if (getters) {
|
||||
f << "\n\n// Getter funtions\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeGetterHeader(f, e);
|
||||
}
|
||||
f << "\n";
|
||||
}*/
|
||||
if (meta || enums || getters) {
|
||||
f << "\n\n// Metainformation\n\nclass __ClassInfo_" << defname << "_Initializer__ {\n";
|
||||
f << "public:\n\t__ClassInfo_" << defname << "_Initializer__();\n\tstatic bool _inited_;\n};\n";
|
||||
|
||||
Reference in New Issue
Block a user