git-svn-id: svn://db.shs.com.ru/pip@599 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
29
main.cpp
29
main.cpp
@@ -1,7 +1,34 @@
|
|||||||
#include "pip.h"
|
#include "pip.h"
|
||||||
|
|
||||||
|
struct S {
|
||||||
|
S() {
|
||||||
|
_int = -66;
|
||||||
|
int_v << 1 << 2;
|
||||||
|
d = 10.5;
|
||||||
|
str = "S String";
|
||||||
|
}
|
||||||
|
int _int;
|
||||||
|
PIVector<int> int_v;
|
||||||
|
double d;
|
||||||
|
PIString str;
|
||||||
|
};
|
||||||
|
|
||||||
|
PIByteArray getMember(const S * p, const char * name) {
|
||||||
|
PIByteArray ret;
|
||||||
|
if (!p || !name) return ret;
|
||||||
|
if (strcmp(name, "_int") == 0) ret << p->_int;
|
||||||
|
if (strcmp(name, "int_v") == 0) ret << p->int_v;
|
||||||
|
if (strcmp(name, "d") == 0) ret << p->d;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
piCout << "Hello VS!";
|
S s;
|
||||||
|
s.int_v <<777;
|
||||||
|
PIByteArray ba = getMember(&s, "int_v");
|
||||||
|
piCout << PICoutManipulators::Hex << ba;
|
||||||
|
PIVector<int> i; ba >> i;
|
||||||
|
piCout << i;
|
||||||
//S s;
|
//S s;
|
||||||
//s.i;
|
//s.i;
|
||||||
//PICodeParser cp;
|
//PICodeParser cp;
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ void usage() {
|
|||||||
piCout << "-M " << Green << "- write metainfo";
|
piCout << "-M " << Green << "- write metainfo";
|
||||||
piCout << "-E " << Green << "- write enums";
|
piCout << "-E " << Green << "- write enums";
|
||||||
piCout << "-S " << Green << "- write stream operators";
|
piCout << "-S " << Green << "- write stream operators";
|
||||||
piCout << "-T " << Green << "- write text serialize functions";
|
piCout << "-G " << Green << "- write getter functions";
|
||||||
|
//piCout << "-T " << Green << "- write text serialize functions";
|
||||||
piCout << "-o <output_file> " << Green << "- output file for code model without extension (e.g. \"ccm\" - files \"ccm.h\" and \"ccm.cpp\" will be created)";
|
piCout << "-o <output_file> " << Green << "- output file for code model without extension (e.g. \"ccm\" - files \"ccm.h\" and \"ccm.cpp\" will be created)";
|
||||||
piCout << "";
|
piCout << "";
|
||||||
piCout << Bold << "Input control";
|
piCout << Bold << "Input control";
|
||||||
@@ -159,7 +160,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) {
|
||||||
PIVector<PICodeParser::Member> ml;
|
PIVector<PICodeParser::Member> ml;
|
||||||
piForeachC (PICodeParser::Member & m, e->members) {
|
piForeachC (PICodeParser::Member & m, e->members) {
|
||||||
if (m.is_type_ptr) continue;
|
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||||
ml << m;
|
ml << m;
|
||||||
}
|
}
|
||||||
bool is_union = e->type == "union";
|
bool is_union = e->type == "union";
|
||||||
@@ -197,7 +198,7 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int
|
|||||||
void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & cnt) {
|
void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & cnt) {
|
||||||
PIVector<PICodeParser::Member> ml;
|
PIVector<PICodeParser::Member> ml;
|
||||||
piForeachC (PICodeParser::Member & m, e->members) {
|
piForeachC (PICodeParser::Member & m, e->members) {
|
||||||
if (m.is_type_ptr) continue;
|
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||||
ml << m;
|
ml << m;
|
||||||
}
|
}
|
||||||
bool is_union = e->type == "union";
|
bool is_union = e->type == "union";
|
||||||
@@ -268,7 +269,25 @@ void makeClassStreamHeader(PIFile & f, const PICodeParser::Entity * e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool meta, bool enums, bool streams, bool texts) {
|
void makeGetter(PIFile & f, const PICodeParser::Entity * e) {
|
||||||
|
f << "\nPIByteArray getMember(const " << e->name << " * p, const char * name) {\n";
|
||||||
|
f << "\tPIByteArray ret;\n";
|
||||||
|
f << "\tif (!p) return ret;\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) {ret << " << m.name << "; return ret;}\n";
|
||||||
|
}
|
||||||
|
f << "\treturn ret;\n}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void makeGetterHeader(PIFile & f, const PICodeParser::Entity * e) {
|
||||||
|
f << "\nPIByteArray getMember(const " << e->name << " * p, const char * name);\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool meta, bool enums, bool streams, bool texts, bool getters) {
|
||||||
PIVector<const PICodeParser::Entity * > ventities;
|
PIVector<const PICodeParser::Entity * > ventities;
|
||||||
PIString defname = out.replaceAll(".", "_").replaceAll("/", "_").replaceAll(":", "_").replaceAll("-", "_").toUpperCase() + "_H";
|
PIString defname = out.replaceAll(".", "_").replaceAll("/", "_").replaceAll(":", "_").replaceAll("-", "_").toUpperCase() + "_H";
|
||||||
|
|
||||||
@@ -365,6 +384,13 @@ void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
|||||||
makeClassStream(f, e);
|
makeClassStream(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;
|
||||||
|
makeGetter(f, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
@@ -408,6 +434,13 @@ const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), cons
|
|||||||
makeClassStreamHeader(f, e);
|
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\n#endif // " << defname << "\n";
|
f << "\n\n#endif // " << defname << "\n";
|
||||||
f.close();
|
f.close();
|
||||||
}
|
}
|
||||||
@@ -424,6 +457,7 @@ int main(int argc, char * argv[]) {
|
|||||||
cli.addArgument("Metainfo");
|
cli.addArgument("Metainfo");
|
||||||
cli.addArgument("Enum");
|
cli.addArgument("Enum");
|
||||||
cli.addArgument("Stream");
|
cli.addArgument("Stream");
|
||||||
|
cli.addArgument("Getter");
|
||||||
cli.addArgument("Text");
|
cli.addArgument("Text");
|
||||||
cli.addArgument("print");
|
cli.addArgument("print");
|
||||||
cli.addArgument("Print");
|
cli.addArgument("Print");
|
||||||
@@ -446,9 +480,10 @@ int main(int argc, char * argv[]) {
|
|||||||
piCout << Cyan << Bold << "Writing code model ...";
|
piCout << Cyan << Bold << "Writing code model ...";
|
||||||
bool all = cli.hasArgument("All");
|
bool all = cli.hasArgument("All");
|
||||||
writeModel(parser, cli, cli.argumentValue("output"), cli.hasArgument("Metainfo") || all,
|
writeModel(parser, cli, cli.argumentValue("output"), cli.hasArgument("Metainfo") || all,
|
||||||
cli.hasArgument("Enum") || all,
|
cli.hasArgument("Enum") || all,
|
||||||
cli.hasArgument("Stream") || all,
|
cli.hasArgument("Stream") || all,
|
||||||
cli.hasArgument("Text") || all);
|
cli.hasArgument("Text") || all,
|
||||||
|
cli.hasArgument("Getter") || all);
|
||||||
piCout << Cyan << Bold << "Writing done";
|
piCout << Cyan << Bold << "Writing done";
|
||||||
if (cli.hasArgument("print") || cli.hasArgument("Print")) {
|
if (cli.hasArgument("print") || cli.hasArgument("Print")) {
|
||||||
bool womain = cli.hasArgument("print");
|
bool womain = cli.hasArgument("print");
|
||||||
|
|||||||
Reference in New Issue
Block a user