version 2.92
pip_cmg
This commit is contained in:
@@ -42,8 +42,8 @@ const char help_string[] =
|
||||
"\n"
|
||||
"-S (Stream operators)\n"
|
||||
"Generate store/restore operators with format\n"
|
||||
"PIByteArray & operator <<(PIByteArray & s, const <type> & v);\n"
|
||||
"PIByteArray & operator >>(PIByteArray & s, <type> & v);\n"
|
||||
"BINARY_STREAM_WRITE(<type>);\n"
|
||||
"BINARY_STREAM_READ (<type>);\n"
|
||||
"Only public variables used. All variables stored/restored\n"
|
||||
"using PIChunkStream. IDs are variable number, starting from 1.\n"
|
||||
"You can override ID with PIMETA(id=<ID>). If in class or struct\n"
|
||||
@@ -354,7 +354,7 @@ bool needClassStream(const PICodeParser::Entity * e) {
|
||||
void makeClassStream(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
bool simple = e->meta.contains("simple-stream");
|
||||
ts << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v) {\n";
|
||||
ts << "\nBINARY_STREAM_WRITE(" << e->name << ") {\n";
|
||||
if (!simple)
|
||||
ts << "\tPIChunkStream cs;\n";
|
||||
int cnt = 0;
|
||||
@@ -362,9 +362,9 @@ void makeClassStream(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!simple)
|
||||
ts << "\ts << cs.data();\n";
|
||||
ts << "\treturn s;\n}\n";
|
||||
ts << "PIByteArray & operator >>(PIByteArray & s, " << e->name << " & v) {\n";
|
||||
ts << "BINARY_STREAM_READ (" << e->name << ") {\n";
|
||||
if (!simple) {
|
||||
ts << "\tif (s.size_s() < 4) return s;\n";
|
||||
//ts << "\tif (s.size_s() < 4) return s;\n";
|
||||
ts << "\tPIByteArray csba; s >> csba;\n";
|
||||
ts << "\tPIChunkStream cs(csba);\n";
|
||||
ts << "\twhile (!cs.atEnd()) {\n";
|
||||
@@ -378,20 +378,6 @@ void makeClassStream(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
}
|
||||
|
||||
|
||||
void makeClassStreamHeader(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
ts << "\n";
|
||||
PIStringList sl = e->name.split("::");
|
||||
for (int i = 0; i < sl.size_s() - 1; ++i)
|
||||
ts << "namespace " << sl[i] << " {";
|
||||
ts << e->type << " " << sl.back() << ";";
|
||||
if (sl.size_s() > 1) ts << PIString('}').repeat(sl.size_s() - 1);
|
||||
|
||||
ts << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v);";
|
||||
ts << "\nPIByteArray & operator >>(PIByteArray & s, " << e->name << " & v);\n";
|
||||
}
|
||||
|
||||
|
||||
void makeGetterType(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
ts << "\nconst char * getterType" << toCName(e->name) << "(const char * name) {\n";
|
||||
@@ -424,7 +410,7 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
PIString defname = "CCM_" + PIString::fromNumber(out.hash()) + "_H";
|
||||
PISet<PIString> inc_files;
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities)
|
||||
if (e->name.find("::") < 0 && !e->name.startsWith("_PI"))
|
||||
if (!e->name.startsWith("_PI"))
|
||||
inc_files << e->file;
|
||||
PIString inc_string;
|
||||
PIVector<PIString> incf = inc_files.toVector();
|
||||
@@ -442,11 +428,8 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
PIIOTextStream ts(&f);
|
||||
ts << "// Generated by \"PIP Code model generator\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n\n");
|
||||
ts << "#include <string.h>\n";
|
||||
if (streams || texts)
|
||||
ts << "#include <pichunkstream.h>\n";
|
||||
ts << "#include \"" << out << ".h\"";
|
||||
ts << inc_string << "\n";
|
||||
ts << "\nusing namespace PICodeInfo;\n\n";
|
||||
ts << "#include \"" << out << ".h\"\n";
|
||||
ts << "\nusing namespace PICodeInfo;\n";
|
||||
|
||||
if (meta || enums || getters) {
|
||||
if (getters) {
|
||||
@@ -491,13 +474,6 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
ts << "}\n";
|
||||
ts << "\n\nbool __ClassInfo_" << defname << "_Initializer__::_inited_ = false;\n";
|
||||
}
|
||||
if (streams) {
|
||||
ts << "\n\n// Stream operators\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeClassStream(ts, e);
|
||||
}
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
||||
@@ -515,11 +491,14 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
ts << "\n";
|
||||
ts << "#ifndef " << defname << "\n#define " << defname << "\n\n";
|
||||
ts << "#include <pivariant.h>\n#include <picodeinfo.h>";
|
||||
if (streams || texts)
|
||||
ts << "\n#include <pichunkstream.h>";
|
||||
ts << inc_string << "\n";
|
||||
if (streams) {
|
||||
ts << "\n\n// Stream operators\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeClassStreamHeader(ts, e);
|
||||
makeClassStream(ts, e);
|
||||
}
|
||||
}
|
||||
if (meta || enums || getters) {
|
||||
|
||||
Reference in New Issue
Block a user