Skip to content

Commit

Permalink
refractor: pass cfg struct from executable to library instead of usin…
Browse files Browse the repository at this point in the history
…g setter functions
  • Loading branch information
jannikbusse committed Nov 29, 2023
1 parent 1fad058 commit 385c1d4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/executable/helperExec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void printHelpMessage()
* @return int error code
*/
int parseArgs(int argc, char **argv, config &settings) {

bool foundFile = false, setOutputName = false;
char defaultPath[]="";
settings.outputName = defaultPath;
Expand Down
13 changes: 10 additions & 3 deletions src/executable/libImports.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
#ifndef EXPORT_H
#define EXPORT_H

#include<string>
#include <string>
#include "settingsExec.h"



//use struct from lib instead.
struct r_config{
bool silentMode = false;
char* filename;
char* outputName;
char *xmlSchemeLocation;
};


extern "C" void setFileName(char* file);
Expand All @@ -24,6 +29,8 @@ extern "C" int executePipeline(char* file);
extern "C" void setOutputName(char* file);
extern "C" void setSilentMode(bool sMode);
extern "C" void setXMLSchemaLocation(char* file);
extern "C" int executePipelineCfg(r_config cfg);



#endif
18 changes: 12 additions & 6 deletions src/executable/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using namespace std;
std::string _logfile = "log.txt";

r_config cfg;


/**
* @brief main function that calls the roadgeneration library functions
Expand All @@ -39,12 +41,16 @@ int main(int argc, char** argv){
if (parseArgs(argc, argv, settings)){
return -1;
}

setFileName(settings.filename);
setXMLSchemaLocation(&schemaLocation[0]);
setOutputName(settings.outputName);
setSilentMode(settings.silentMode);
execPipeline();
cfg.silentMode = settings.silentMode;
cfg.filename = settings.filename;
cfg.xmlSchemeLocation = &schemaLocation[0];
cfg.outputName = settings.outputName;
cout << cfg.outputName << endl;
//setFileName(settings.filename);
//setXMLSchemaLocation(&schemaLocation[0]);
//setOutputName(settings.outputName);
//setSilentMode(settings.silentMode);
executePipelineCfg(cfg);

return 0;
}
Expand Down
32 changes: 15 additions & 17 deletions src/libfiles/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,24 @@ EXPORTED void setXMLSchemaLocation(char* file){
EXPORTED int executePipeline(char* file)
{

char dt[100];//stores timestamp as string

if (file == NULL){
cout << "ERR: no file has been provided!" << endl;
return -1;
}


// --- initialization ------------------------------------------------------

xmlTree inputxml;
roadNetwork data;
string outputFile = setting.outname;
char dt[100];//stores timestamp as string

data.outputFile = outputFile.substr(0, outputFile.find(".xml"));
data.outputFile = data.outputFile.substr(0, outputFile.find(".xodr"));

setting.warnings = 0;

if(!setting.outputNameSet){
setting.outname = file;
}
Expand All @@ -104,16 +115,6 @@ EXPORTED int executePipeline(char* file)
printLogo();
}

// --- initialization ------------------------------------------------------

xmlTree inputxml;

roadNetwork data;
string outputFile = setting.outname;
data.outputFile = outputFile.substr(0, outputFile.find(".xml"));
data.outputFile = data.outputFile.substr(0, outputFile.find(".xodr"));

setting.warnings = 0;

// --- pipeline ------------------------------------------------------------

Expand All @@ -140,8 +141,6 @@ EXPORTED int executePipeline(char* file)
return -1;
}

//resolveLaneLinkConflicts(data);

if (createXMLXercesC(data))
{
cerr << "ERR: error during createXML" << endl;
Expand All @@ -154,7 +153,7 @@ EXPORTED int executePipeline(char* file)
return -1;
}

//warning handling
//handle warnings
if(!setting.silentMode)
{
if(setting.warnings > 0)
Expand All @@ -174,11 +173,10 @@ EXPORTED int executePipeline(char* file)

EXPORTED int executePipelineCfg(r_config cfg)
{
setOutputName(cfg.outputName);
setting.silentMode = cfg.silentMode;
setting.xmlSchemaLocation = cfg.xmlSchemeLocation;
setFileName(cfg.filename);
//if(cfg.outputName != "")
// setOutputName(cfg.outputName);
execPipeline();
return 0;
}
6 changes: 2 additions & 4 deletions src/libfiles/export.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@

#include<string>



struct r_config{
bool silentMode = false;
char* filename;
char* outputName;
char *xmlSchemeLocation;
};





/**
* @brief Sets the filename of the input file
* @param file file name *
Expand Down

0 comments on commit 385c1d4

Please sign in to comment.