Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 7edd1cd8 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add DataStream integration

parent 36232f19
......@@ -2,4 +2,5 @@ build
build2
.kdev4/
.tmp_project/
*.kdev4
......@@ -108,10 +108,47 @@ bool testClassConfigInheritance(){
return b;
}
///Test the PClassConfig
/** @return true on success, false otherwise
*/
bool testClassConfigDataStream(){
bool b(true);
PClassConfig conf;
PClassAttribute attrA(createClassAttribute("int", "attr1", "///some attribute doc")), attrB, attrC, attrD;
attrB = createClassAttribute("int", "attr2", false, true, "///some attribute doc");
attrC = createClassAttribute("double", "attr3", true, false, "///some attribute doc");
attrD = createClassAttribute("float", "attr4", true, true, "///some attribute doc");
printPClassAttribute(attrA);
printPClassAttributeConst(attrA);
conf.setClassDocumentation("///Some documentation of the class");
conf.setName("Shadok");
std::list<PClassAttribute> listAttribute1, listAttribute2;
listAttribute1.push_back(attrA);
listAttribute1.push_back(attrB);
listAttribute2.push_back(attrD);
conf.setListAttribute(listAttribute1);
conf.addAttribute(attrC);
conf.addListAttribute(listAttribute2);
std::list<PClassConfig> listClassConfig;
listClassConfig.push_back(conf);
std::list<std::string> listInclude;
b &= saveClassImplDecl(listClassConfig, "ShadokDS", listInclude, true);
return b;
}
int main(int argc, char ** argv){
bool b(testClassConfig());
b &= testClassConfigInheritance();
b &= testClassConfigDataStream();
return b - 1;
}
......
......@@ -165,9 +165,10 @@ bool parserClassConfig(std::list<PClassConfig> & listClassConfig, std::list<std:
///Parser list class config
/** @param baseFileNameOutput : base of the output files
* @param fileName : file name of the config
* @param enableDataStream : true to enable the serialization/deserialization with DataStream, false otherwise
* @return true on success, false otherwise
*/
bool saveParserClassConfig(const std::string & baseFileNameOutput, const std::string & fileName){
bool saveParserClassConfig(const std::string & baseFileNameOutput, const std::string & fileName, bool enableDataStream){
std::list<std::string> listInclude;
std::list<PClassConfig> listClassConfig;
if(!parserClassConfig(listClassConfig, listInclude, fileName)){
......
......@@ -12,7 +12,7 @@
#include "PClassConfig.h"
bool parserClassConfig(std::list<PClassConfig> & listClassConfig, std::list<std::string> & listInclude, const std::string & fileName);
bool saveParserClassConfig(const std::string & baseFileNameOutput, const std::string & fileName);
bool saveParserClassConfig(const std::string & baseFileNameOutput, const std::string & fileName, bool enableDataStream = false);
#endif
......@@ -67,7 +67,6 @@ std::string createGetterDecl(const std::string & varType, const std::string & va
///Creates setters header file
/** @param[out] fs : header file name
* @param classConfig : class config we want to save
* @return true on success, false otherwise
*/
void saveDeclSetters(std::ofstream & fs, const PClassConfig & classConfig){
const std::list<PClassAttribute> & listAttr(classConfig.getListAttribute());
......@@ -79,7 +78,6 @@ void saveDeclSetters(std::ofstream & fs, const PClassConfig & classConfig){
///Creates getters header file
/** @param[out] fs : header file name
* @param classConfig : class config we want to save
* @return true on success, false otherwise
*/
void saveDeclGetters(std::ofstream & fs, const PClassConfig & classConfig){
const std::list<PClassAttribute> & listAttr(classConfig.getListAttribute());
......@@ -89,12 +87,55 @@ void saveDeclGetters(std::ofstream & fs, const PClassConfig & classConfig){
}
}
///Creates the method which enable to save/load generated class with any kind of stream/message/file
/** @param[out] fs : header file name
* @param classConfig : class config we want to save
*/
void saveClassDataStreamMethod(std::ofstream & fs, const PClassConfig & classConfig){
std::string name(classConfig.getName());
fs << std::endl;
fs << "\t\t///Load the current "<<name<<" with a stream" << std::endl;
fs << "\t\t/** @param[out] ds : stream to be used" << std::endl;
fs << "\t\t * @return true on success, false otherwise" << std::endl;
fs << "\t\t*/" << std::endl;
fs << "\t\ttemplate<typename Stream, DataStreamMode::DataStreamMode Mode>" << std::endl;
fs << "\t\tbool readWriteStream(Stream & ds){" << std::endl;
fs << "\t\t\tbool b(true);" << std::endl;
const std::list<PClassAttribute> & listAttr(classConfig.getListAttribute());
for(std::list<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
fs << "\t\t\tb &= DataStream<Stream, Mode, "<<it->getType()<<" >::data_stream(ds, p_" << it->getName() << ");" << std::endl;
}
fs << "\t\t\treturn b;" << std::endl;
fs << "\t\t}" << std::endl << std::endl;
}
///Creates the method which enable to save/load generated class with any kind of stream/message/file
/** @param[out] fs : header file name
* @param classConfig : class config we want to save
*/
void saveClassDataStreamGenericFunction(std::ofstream & fs, const PClassConfig & classConfig){
std::string name(classConfig.getName());
fs << "///@brief Generic "<<name<<" serialisation/deserialisation, load/save and size function" << std::endl;
fs << "template<typename Stream, DataStreamMode::DataStreamMode Mode>" << std::endl;
fs << "struct DataStream<Stream, Mode, "<<name<<">{" << std::endl;
fs << "\t///Generic function to load/save/serialise/deserialise "<<name << std::endl;
fs << "\t/**\t@param data : "<<name<<" to be used" << std::endl;
fs << "\t * \t@return true on success, false otherwise" << std::endl;
fs << "\t*/" << std::endl;
fs << "\tstatic bool data_stream(Stream & ds, "<<name<<" & data){" << std::endl;
fs << "\t\treturn data.readWriteStream<Stream, Mode>(ds);" << std::endl;
fs << "\t}" << std::endl;
fs << "};" << std::endl << std::endl;
}
///Creates header file
/** @param[out] fs : header file name
* @param classConfig : class config we want to save
* @return true on success, false otherwise
* @param enableDataStream : true to enable the serialization/deserialization with DataStream, false otherwise
*/
void saveClassDecl(std::ofstream & fs, const PClassConfig & classConfig){
void saveClassDecl(std::ofstream & fs, const PClassConfig & classConfig, bool enableDataStream){
if(classConfig.getClassDocumentation() != "") fs << classConfig.getClassDocumentation() << endl;
string name(classConfig.getName());
fs << "class " << name;
......@@ -116,6 +157,11 @@ void saveClassDecl(std::ofstream & fs, const PClassConfig & classConfig){
fs << "\t\t" << name << " & operator = (const " << name << " & other);" << endl;
saveDeclSetters(fs, classConfig);
saveDeclGetters(fs, classConfig);
if(enableDataStream){
saveClassDataStreamMethod(fs, classConfig);
}
fs << "\tprotected:" << endl;
fs << "\t\tvoid copy" << name << "(const " << name << " & other);" << endl;
......@@ -126,6 +172,11 @@ void saveClassDecl(std::ofstream & fs, const PClassConfig & classConfig){
fs << "\t\t" << it->getType() << " p_" << it->getName() << ";" << endl;
}
fs << "};" << endl << endl;
if(enableDataStream){
saveClassDataStreamGenericFunction(fs, classConfig);
fs << endl << endl;
}
}
///Saves constructor of the class
......@@ -267,9 +318,10 @@ void saveClassImpl(std::ofstream & fs, const PClassConfig & classConfig){
/** @param classConfig : class config we want to save
* @param headerFile : header file name
* @param listInclude : list of the include files
* @param enableDataStream : true to enable the serialization/deserialization with DataStream, false otherwise
* @return true on success, false otherwise
*/
bool saveClassDecl(const std::list<PClassConfig> & classConfig, const std::string & headerFile, const std::list<std::string> & listInclude){
bool saveClassDecl(const std::list<PClassConfig> & classConfig, const std::string & headerFile, const std::list<std::string> & listInclude, bool enableDataStream){
if(headerFile == "") return false;
std::ofstream fs;
fs.open(headerFile.c_str());
......@@ -287,8 +339,12 @@ bool saveClassDecl(const std::list<PClassConfig> & classConfig, const std::strin
}
fs << endl;
}
if(enableDataStream){
fs << "#include \"data_all.h\"" << std::endl << std::endl;
}
for(std::list<PClassConfig>::const_iterator it(classConfig.begin()); it != classConfig.end(); ++it){
saveClassDecl(fs, *it);
saveClassDecl(fs, *it, enableDataStream);
}
fs << endl << endl << "#endif" << endl << endl;
fs.close();
......@@ -322,11 +378,12 @@ bool saveClassImpl(const std::list<PClassConfig> & classConfig, const std::strin
/** @param classConfig : class config we want to save
* @param baseFileName : base file name for header or source file
* @param listInclude : list of the include files
* @param enableDataStream : true to enable the serialization/deserialization with DataStream, false otherwise
* @return true on success, false otherwise
*/
bool saveClassImplDecl(const std::list<PClassConfig> & classConfig, const std::string & baseFileName, const std::list<std::string> & listInclude){
bool saveClassImplDecl(const std::list<PClassConfig> & classConfig, const std::string & baseFileName, const std::list<std::string> & listInclude, bool enableDataStream){
if(baseFileName == "") return false;
if(!saveClassDecl(classConfig, baseFileName + ".h", listInclude)) return false;
if(!saveClassDecl(classConfig, baseFileName + ".h", listInclude, enableDataStream)) return false;
if(!saveClassImpl(classConfig, baseFileName + ".cpp", baseFileName + ".h")) return false;
return true;
}
......
......@@ -18,7 +18,7 @@ std::string createGetterDecl(const std::string & varType, const std::string & va
void saveDeclSetters(std::ofstream & fs, const PClassConfig & classConfig);
void saveDeclGetters(std::ofstream & fs, const PClassConfig & classConfig);
void saveClassDecl(std::ofstream & fs, const PClassConfig & classConfig);
void saveClassDecl(std::ofstream & fs, const PClassConfig & classConfig, bool enableDataStream);
void saveClassConstructorImpl(std::ofstream & fs, const PClassConfig & classConfig);
......@@ -30,10 +30,10 @@ void saveClassGettersImpl(std::ofstream & fs, const PClassConfig & classConfig);
void saveClassCopyFunctionImpl(std::ofstream & fs, const PClassConfig & classConfig);
void saveClassImpl(std::ofstream & fs, const PClassConfig & classConfig);
bool saveClassDecl(const std::list<PClassConfig> & classConfig, const std::string & headerFile, const std::list<std::string> & listInclude);
bool saveClassDecl(const std::list<PClassConfig> & classConfig, const std::string & headerFile, const std::list<std::string> & listInclude, bool enableDataStream);
bool saveClassImpl(const std::list<PClassConfig> & classConfig, const std::string & sourceFile, const std::string & headerFile);
bool saveClassImplDecl(const std::list<PClassConfig> & classConfig, const std::string & baseFileName, const std::list<std::string> & listInclude = std::list<std::string>());
bool saveClassImplDecl(const std::list<PClassConfig> & classConfig, const std::string & baseFileName, const std::list<std::string> & listInclude = std::list<std::string>(), bool enableDataStream = false);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment