Commit c308f2dc authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add creation of YML file with the found offset

parent 27da430c
Pipeline #136569 passed with stages
in 53 seconds
......@@ -45,7 +45,6 @@ bool testOffsetFinder(){
std::cout << "testOffsetFinder : offsetTabA = " << offsetTabA << std::endl;
std::cout << "testOffsetFinder : offsetTabB = " << offsetTabB << std::endl;
for(size_t i(0lu); i < nbMessage; ++i){
char * message = tabMessage.data() + i*messageSize;
short * rowA = tabA.data() + i*nbValueA;
......@@ -54,7 +53,6 @@ bool testOffsetFinder(){
rowB, nbValueB, offsetTabB);
}
POffsetFinder finder;
finder.addAttribute("tabA", tabA.data(), nbValueA);
finder.addAttribute("tabB", tabB.data(), nbValueB);
......@@ -67,6 +65,9 @@ bool testOffsetFinder(){
size_t foundOffsetB(finder.getOffset("tabB"));
bool b(true);
b &= finder.saveYml("offset.yml");
b &= !finder.saveYml("some/UnexistingDir/offset.yml");
b &= offsetTabA == foundOffsetA;
b &= offsetTabB == foundOffsetB;
return b;
......@@ -75,13 +76,8 @@ bool testOffsetFinder(){
int main(int argc, char** argv){
bool b(testOffsetFinder());
if(b){
std::cout << "Test OK" << std::endl;
return 0;
}else{
std::cout << "Test Wrong" << std::endl;
return -1;
}
std::cout << "final : b = " << b << std::endl;
return b - 1;
}
......@@ -5,6 +5,7 @@
****************************************/
#include <iostream>
#include <fstream>
#include "POffsetFinder.h"
///Init the offset vector
......@@ -72,6 +73,22 @@ void printRemaningOffset(const PVecPossibleOffset & vecOffset, const std::string
}
}
///Print the remaning offset
/** @param[out] fs : ofstream to be updated
* @param vecOffset : vector of available offset
* @param indentation : indentation to be used
*/
void printRemaningOffset(std::ofstream & fs, const PVecPossibleOffset & vecOffset, const std::string & indentation){
size_t offset(0lu), i(0lu);
for(PVecPossibleOffset::const_iterator it(vecOffset.begin()); it != vecOffset.end(); ++it){
if(*it){ //If this is a potential offset
fs << indentation << i << " : " << offset << std::endl;
++i;
}
++offset;
}
}
///Default constructor of POffsetFinder
POffsetFinder::POffsetFinder(){
initialisationPOffsetFinder();
......@@ -155,6 +172,39 @@ void POffsetFinder::print() const{
}
}
///Save the found offset into a YML file
/** @param fileName : name of the file to be saved
*/
bool POffsetFinder::saveYml(const std::string & fileName) const{
std::ofstream fs;
fs.open(fileName);
if(!fs.is_open()){
std::cerr << "POffsetFinder::saveYml : cannot create file '" << fileName << "'" << std::endl;
return false;
}
for(PVecOffsetAttribute::const_iterator it(p_vecAttr.begin()); it != p_vecAttr.end(); ++it){
if(it->getIsFound()){
fs << it->getName() << ": " << it->getOffset() << std::endl;
}else{
if(it->getVecOffset().size() != 0lu){
size_t nbPossibleOffset(getNbPossibleOffset(it->getVecOffset()));
fs << "# Attribute '"<<it->getName()<<"' : Not enough data to conclude (potential conflict with other searched Attributes) => " << nbPossibleOffset << " possibilities." << std::endl;
if(nbPossibleOffset <= 10lu){
fs << "#\tcandidates are :" << std::endl;
printRemaningOffset(fs, it->getVecOffset(), "#\t\t");
}
fs << "# Let's take the fist one" << std::endl;
fs << it->getName() << ": " << it->getVecOffset().front() << std::endl;
}else{
fs << "# Attribute '"<<it->getName()<<"' : offset not found" << std::endl;
fs << it->getName() << ": UNDEFINED" << std::endl;
}
}
}
fs.close();
return true;
}
///Get the offset of the corresponding attribute
/** @param name : name of the attribute we want the offset
* @return corresponding attribute, or -1lu if the attribute offset was not found
......
......@@ -34,6 +34,7 @@ class POffsetFinder{
void computeOffset(const char* tabMessage, size_t messageSize, size_t nbMessage);
void print() const;
bool saveYml(const std::string & fileName) const;
size_t getOffset(const std::string & name) const;
......
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