From 367109341e17360979581efa7905ebff9d6e3372 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Wed, 22 Oct 2014 17:22:49 +0200 Subject: [PATCH] Generate enums with the good values in lp_gen_wrappers. --- tools/generator.cc | 7 +++---- tools/genwrappers.cc | 8 ++++++-- tools/software-desc.hh | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tools/generator.cc b/tools/generator.cc index 82f50c660..2b8ab0a39 100644 --- a/tools/generator.cc +++ b/tools/generator.cc @@ -52,7 +52,7 @@ void CplusplusGenerator::generate(Project *proj){ void CplusplusGenerator::writeEnumMember(ConstField *cf, bool isLast){ writeTabs(1); - mOutfile<getName(); + mOutfile<getName()<<"="<getValue(); if (!isLast) mOutfile<<","; if (!cf->getHelp().empty()) mOutfile<<"\t/**< "<getHelp()<<" */"; mOutfile< members=klass->getConstFields(); list::iterator it; string enum_name=getEnumName(klass); - int value=0; filename<getName())<<"/"<getHelp().empty()){ writeTabs(1); @@ -254,7 +253,7 @@ void JavascriptGenerator::writeEnum(Class *klass){ mOutfile<<"*/"<getName().substr(prefix_size,string::npos)<<" : "<getName().substr(prefix_size,string::npos)<<" : "<getValue(); if (++it!=members.end()) mOutfile<<","; mOutfile< #include #include +#include #include #include #include @@ -335,11 +336,14 @@ static void parseEnum(Project *proj, XmlNode node){ klass->setHelp(node.getChild("detaileddescription").getChild("para").getText()); list enumValues=node.getChildren("enumvalue"); list::iterator it; + int value = 0; for (it=enumValues.begin();it!=enumValues.end();++it){ - ConstField *cf=new ConstField(Type::getType("int"),(*it).getChild("name").getText()); + XmlNode initializer = (*it).getChild("initializer"); + if (initializer) value=atoi(initializer.getText().c_str()); + ConstField *cf=new ConstField(Type::getType("int"),(*it).getChild("name").getText(),value); cf->setHelp((*it).getChild("detaileddescription").getChild("para").getText()); klass->addConstField(cf); - + value++; } } diff --git a/tools/software-desc.hh b/tools/software-desc.hh index 2d454e502..575f52fb0 100644 --- a/tools/software-desc.hh +++ b/tools/software-desc.hh @@ -294,7 +294,7 @@ private: class ConstField{ public: - ConstField(Type *type, const string &name, const string &value="") : mType(type), mName(name), mValue(value){ + ConstField(Type *type, const string &name, int value) : mType(type), mName(name), mValue(value){ } void setHelp(const string & help){ mHelp=help; @@ -308,7 +308,7 @@ public: Type *getType()const{ return mType; } - const string &getValue()const{ + int getValue()const{ return mValue; } static string getCommonPrefix(list fields){ @@ -338,7 +338,7 @@ public: private: Type *mType; string mName; - string mValue; + int mValue; string mHelp; };