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"
|
||||
|
||||
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[]) {
|
||||
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.i;
|
||||
//PICodeParser cp;
|
||||
|
||||
@@ -45,7 +45,8 @@ void usage() {
|
||||
piCout << "-M " << Green << "- write metainfo";
|
||||
piCout << "-E " << Green << "- write enums";
|
||||
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 << "";
|
||||
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) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr) continue;
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
ml << m;
|
||||
}
|
||||
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) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr) continue;
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
ml << m;
|
||||
}
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
||||
@@ -408,6 +434,13 @@ 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\n#endif // " << defname << "\n";
|
||||
f.close();
|
||||
}
|
||||
@@ -424,6 +457,7 @@ int main(int argc, char * argv[]) {
|
||||
cli.addArgument("Metainfo");
|
||||
cli.addArgument("Enum");
|
||||
cli.addArgument("Stream");
|
||||
cli.addArgument("Getter");
|
||||
cli.addArgument("Text");
|
||||
cli.addArgument("print");
|
||||
cli.addArgument("Print");
|
||||
@@ -446,9 +480,10 @@ int main(int argc, char * argv[]) {
|
||||
piCout << Cyan << Bold << "Writing code model ...";
|
||||
bool all = cli.hasArgument("All");
|
||||
writeModel(parser, cli, cli.argumentValue("output"), cli.hasArgument("Metainfo") || all,
|
||||
cli.hasArgument("Enum") || all,
|
||||
cli.hasArgument("Stream") || all,
|
||||
cli.hasArgument("Text") || all);
|
||||
cli.hasArgument("Enum") || all,
|
||||
cli.hasArgument("Stream") || all,
|
||||
cli.hasArgument("Text") || all,
|
||||
cli.hasArgument("Getter") || all);
|
||||
piCout << Cyan << Bold << "Writing done";
|
||||
if (cli.hasArgument("print") || cli.hasArgument("Print")) {
|
||||
bool womain = cli.hasArgument("print");
|
||||
|
||||
Reference in New Issue
Block a user