pip_cmg supports for "simple-stream" PIMETA tag for structs and classes for simple de/serialization without PIChunkStream
This commit is contained in:
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||
project(pip)
|
||||
set(pip_MAJOR 2)
|
||||
set(pip_MINOR 33)
|
||||
set(pip_REVISION 0)
|
||||
set(pip_REVISION 1)
|
||||
set(pip_SUFFIX )
|
||||
set(pip_COMPANY SHS)
|
||||
set(pip_DOMAIN org.SHS)
|
||||
|
||||
@@ -193,7 +193,7 @@ void makeEnumInfo(PIFile & f, const PICodeParser::Enum * e) {
|
||||
}
|
||||
|
||||
|
||||
void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int & cnt) {
|
||||
void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
@@ -208,18 +208,31 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int
|
||||
if (m.meta.contains("id"))
|
||||
cnt = m.meta.value("id").toInt();
|
||||
if (m.dims.isEmpty()) {
|
||||
if (simple) {
|
||||
f << "\ts << ";
|
||||
if (parser.isEnum(m.type))
|
||||
f << "(int)";
|
||||
f << "v." << m.name << ";\n";
|
||||
} else {
|
||||
f << "\tcs << cs.chunk(" << cnt << ", ";
|
||||
if (parser.isEnum(m.type))
|
||||
f << "(int)";
|
||||
f << "v." << m.name << ");\n";
|
||||
} else {
|
||||
PIString ptype = m.type.left(m.type.find('['));
|
||||
f << "\tcs << cs.chunk(" << cnt << ", PIVector<" << ptype << " >((const " << ptype << " *)(v." << m.name << "), ";
|
||||
for (int i = 0; i < m.dims.size_s(); ++i) {
|
||||
if (i > 0) f << " * ";
|
||||
f << m.dims[i];
|
||||
}
|
||||
f << "));\n";
|
||||
} else {
|
||||
PIString ptype = m.type.left(m.type.find('[')).trim();
|
||||
PIString size = m.dims[0];
|
||||
for (int i = 1; i < m.dims.size_s(); ++i) {
|
||||
size += " * ";
|
||||
size += m.dims[i];
|
||||
}
|
||||
if (simple) {
|
||||
f << "\tfor (int i = 0; i < " << size << "; ++i)\n";
|
||||
f << "\t\ts << ((const " << ptype << " *)(v." << m.name << "))[i];\n";
|
||||
} else {
|
||||
f << "\tcs << cs.chunk(" << cnt << ", PIVector<" << ptype << " >((const " << ptype << " *)(v." << m.name << "), ";
|
||||
f << size << "));\n";
|
||||
}
|
||||
}
|
||||
if (is_union)
|
||||
break;
|
||||
@@ -227,12 +240,12 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int
|
||||
if (is_union) return;
|
||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
||||
if (ce->has_name) continue;
|
||||
writeClassStreamMembersOut(f, ce, cnt);
|
||||
writeClassStreamMembersOut(f, ce, cnt, simple);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & cnt) {
|
||||
void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
@@ -247,31 +260,43 @@ void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int &
|
||||
if (m.meta.contains("id"))
|
||||
cnt = m.meta.value("id").toInt();
|
||||
if (m.dims.isEmpty()) {
|
||||
if (simple) {
|
||||
f << "\ts >> ";
|
||||
if (parser.isEnum(m.type))
|
||||
f << "(int&)";
|
||||
f << "v." << m.name << ";\n";
|
||||
} else {
|
||||
f << "\t\tcase " << cnt << ": cs.get(";
|
||||
if (parser.isEnum(m.type))
|
||||
f << "(int&)";
|
||||
f << "v." << m.name << "); break;\n";
|
||||
} else {
|
||||
PIString ptype = m.type.left(m.type.find('['));
|
||||
f << "\t\tcase " << cnt << ": {\n\t\t\tPIVector<" << ptype << " > d; cs.get(d);\n";
|
||||
f << "\t\t\tint cnt = piMini(d.size_s(), ";
|
||||
for (int i = 0; i < m.dims.size_s(); ++i) {
|
||||
if (i > 0) f << " * ";
|
||||
f << m.dims[i];
|
||||
}
|
||||
f << ");\n";
|
||||
} else {
|
||||
PIString ptype = m.type.left(m.type.find('[')).trim();
|
||||
PIString size = m.dims[0];
|
||||
for (int i = 1; i < m.dims.size_s(); ++i) {
|
||||
size += " * ";
|
||||
size += m.dims[i];
|
||||
}
|
||||
if (simple) {
|
||||
f << "\tfor (int i = 0; i < " << size << "; ++i)\n";
|
||||
f << "\t\ts >> ((" << ptype << " *)(v." << m.name << "))[i];\n";
|
||||
} else {
|
||||
f << "\t\tcase " << cnt << ": {\n\t\t\tPIVector<" << ptype << " > d; cs.get(d);\n";
|
||||
f << "\t\t\tint cnt = piMini(d.size_s(), " << size << ");\n";
|
||||
f << "\t\t\tfor (int i = 0; i < cnt; ++i)\n";
|
||||
f << "\t\t\t\t((" << ptype << " *)(v." << m.name << "))[i] = d[i];\n";
|
||||
f << "\t\t\t}\n";
|
||||
f << "\t\t\tbreak;\n";
|
||||
}
|
||||
}
|
||||
if (is_union)
|
||||
break;
|
||||
}
|
||||
if (is_union) return;
|
||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
||||
if (ce->has_name) continue;
|
||||
writeClassStreamMembersIn(f, ce, cnt);
|
||||
writeClassStreamMembersIn(f, ce, cnt, simple);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,19 +315,26 @@ bool needClassStream(const PICodeParser::Entity * e) {
|
||||
|
||||
void makeClassStream(PIFile & f, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
bool simple = e->meta.contains("simple-stream");
|
||||
f << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v) {\n";
|
||||
if (!simple)
|
||||
f << "\tPIChunkStream cs;\n";
|
||||
int cnt = 0;
|
||||
writeClassStreamMembersOut(f, e, cnt);
|
||||
f << "\ts << cs.data();\n\treturn s;\n}\n";
|
||||
writeClassStreamMembersOut(f, e, cnt, simple);
|
||||
if (!simple)
|
||||
f << "\ts << cs.data();\n";
|
||||
f << "\treturn s;\n}\n";
|
||||
f << "PIByteArray & operator >>(PIByteArray & s, " << e->name << " & v) {\n";
|
||||
if (!simple) {
|
||||
f << "\tif (s.size_s() < 4) return s;\n";
|
||||
f << "\tPIByteArray csba; s >> csba;\n";
|
||||
f << "\tPIChunkStream cs(csba);\n";
|
||||
f << "\twhile (!cs.atEnd()) {\n";
|
||||
f << "\t\tswitch (cs.read()) {\n";
|
||||
}
|
||||
cnt = 0;
|
||||
writeClassStreamMembersIn(f, e, cnt);
|
||||
writeClassStreamMembersIn(f, e, cnt, simple);
|
||||
if (!simple)
|
||||
f << "\t\t}\n\t}\n";
|
||||
f << "\treturn s;\n}\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user