Skip to content
Snippets Groups Projects
Commit 4476ff37 authored by Matthew McGill's avatar Matthew McGill
Browse files

Minor refactoring

Former-commit-id: 23c210c67f573f625702a92dd0e743cf519f037e
parent 42769837
No related branches found
No related tags found
No related merge requests found
......@@ -46,17 +46,19 @@ class IRDBObjects_t
private:
pqxxDB_t *pqxx_interface = new pqxxDB_t();
// maps for speed of finding needed files, file IRs and/or variants
// that have already been read from the DB
// type aliases of maps. maps allow speed of finding needed files, file IRs
// and/or variants that have already been read from the DB
using IdToVariantMap_t = std::map<db_id_t, const std::shared_ptr<VariantID_t>>;
using FileIRInfo_t = std::pair<File_t *const, std::shared_ptr<FileIR_t>>;
using IdToFileIRInfoMap_t = std::map<db_id_t, FileIRInfo_t>;
// maps variant id to variant
std::map<db_id_t, std::shared_ptr<VariantID_t>> variant_map;
// maps file id to (file, file ir)
std::map<db_id_t, std::pair<File_t*, std::shared_ptr<FileIR_t>>> file_IR_map;
IdToVariantMap_t variant_map;
IdToFileIRInfoMap_t file_IR_map;
// minor helpers (used to check assertions)
bool FilesAlreadyPresent(std::set<File_t*> the_files);
bool FilesBeingShared(std::shared_ptr<VariantID_t> the_variant);
bool FilesAlreadyPresent(const std::set<File_t*>& the_files) const;
bool FilesBeingShared(const std::shared_ptr<VariantID_t>& the_variant) const;
};
#endif
......
......@@ -9,15 +9,15 @@ namespace Transform_SDK
public:
// Step names must be unique, allows arguments to
// be directed to their matching transform steps.
virtual std::string GetStepName(void) = 0;
virtual std::string getStepName(void) const = 0;
// Allows all steps to parse args before any step takes time to execute
virtual int ParseArgs(int argc, char* argv[])
virtual int parseArgs(int argc, const char* const argv[])
{
return 0; // success
}
virtual int ExecuteStep(libIRDB::IRDBObjects_t *irdb_objects)
virtual int executeStep(libIRDB::IRDBObjects_t *const irdb_objects)
{
return 0; // success
}
......@@ -30,6 +30,6 @@ namespace Transform_SDK
}
extern "C"
Transform_SDK::TransformStep_t* GetTransformStep(void);
std::unique_ptr<Transform_SDK::TransformStep_t> GetTransformStep(void);
#endif
......@@ -580,10 +580,10 @@ void PopulateCFG::fill_in_landing_pads(FileIR_t *firp)
}
int PopulateCFG::ParseArgs
int PopulateCFG::parseArgs
(
int argc,
char* argv[]
const char* const argv[]
)
{
if(argc<2)
......@@ -611,7 +611,7 @@ int PopulateCFG::ParseArgs
return 0;
}
int PopulateCFG::ExecuteStep(IRDBObjects_t *irdb_objects)
int PopulateCFG::executeStep(IRDBObjects_t *const irdb_objects)
{
try
{
......@@ -664,7 +664,8 @@ int PopulateCFG::ExecuteStep(IRDBObjects_t *irdb_objects)
extern "C"
Transform_SDK::TransformStep_t* GetTransformStep(void)
unique_ptr<Transform_SDK::TransformStep_t> GetTransformStep(void)
{
return new PopulateCFG();
unique_ptr<Transform_SDK::TransformStep_t> the_step(new PopulateCFG());
return the_step;
}
......@@ -32,12 +32,12 @@ class PopulateCFG : public libIRDB::Transform_SDK::TransformStep_t
// are not managed by this class).
}
std::string GetStepName(void) override
std::string getStepName(void) const override
{
return std::string("fill_in_cfg");
}
int ParseArgs(int argc, char* argv[]) override;
int ExecuteStep(libIRDB::IRDBObjects_t*) override;
int parseArgs(int argc, const char* const argv[]) override;
int executeStep(libIRDB::IRDBObjects_t *const) override;
private: // methods
......
......@@ -21,7 +21,7 @@ using namespace Transform_SDK;
enum class Mode { DEBUG, VERBOSE, DEFAULT };
int execute_step(int argc, char* argv[], bool step_optional, Mode exec_mode,
IRDBObjects_t* shared_objects, TransformStep_t* the_step);
IRDBObjects_t* shared_objects, unique_ptr<TransformStep_t>& the_step);
// The toolchain driver script ps_analyze.sh communicates
......@@ -158,9 +158,9 @@ int main(int argc, char *argv[])
}
else
{
TransformStep_t* (*func)(void);
func = (TransformStep_t* (*)(void)) sym;
TransformStep_t* the_step = (*func)();
unique_ptr<TransformStep_t> (*func)(void);
func = (unique_ptr<TransformStep_t> (*)(void)) sym;
unique_ptr<TransformStep_t> the_step = (*func)();
assert(the_step != NULL);
bool step_optional = true;
......@@ -180,9 +180,9 @@ int main(int argc, char *argv[])
dup2(log_output_fd, STDOUT_FILENO);
dup2(log_output_fd, STDERR_FILENO);
}
int step_retval = execute_step(argc, argv, step_optional, exec_mode, shared_objects, the_step);
// cleanup from logging
if(exec_mode == Mode::DEFAULT || exec_mode == Mode::VERBOSE)
{
......@@ -194,7 +194,6 @@ int main(int argc, char *argv[])
close(saved_stderr);
// cleanup plugin
delete the_step;
free(argv);
dlclose(dlhdl);
......@@ -281,9 +280,9 @@ int main(int argc, char *argv[])
int execute_step(int argc, char* argv[], bool step_optional, Mode exec_mode,
IRDBObjects_t* shared_objects, TransformStep_t* the_step)
IRDBObjects_t* shared_objects, unique_ptr<TransformStep_t>& the_step)
{
int parse_retval = the_step->ParseArgs(argc, argv);
int parse_retval = the_step->parseArgs(argc, argv);
if(parse_retval != 0)
{
return parse_retval;
......@@ -305,7 +304,7 @@ int execute_step(int argc, char* argv[], bool step_optional, Mode exec_mode,
}
}
int step_error = the_step->ExecuteStep(shared_objects);
int step_error = the_step->executeStep(shared_objects);
if(step_error)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment