diff --git a/libIRDB/include/core/IRDB_Objects.hpp b/libIRDB/include/core/IRDB_Objects.hpp index f95a2947bc1470c9acc1fa48d28319fd65b9380a..5232f51a4a532fe4021da03c9d64dd383a65bdb2 100644 --- a/libIRDB/include/core/IRDB_Objects.hpp +++ b/libIRDB/include/core/IRDB_Objects.hpp @@ -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 diff --git a/libIRDB/include/core/transform_step.h b/libIRDB/include/core/transform_step.h index 40f09fbd7d034a26824842db32f71b0ff6c2723e..5b864c69e0c7e92def7a27e7d6288b68e8ada48c 100644 --- a/libIRDB/include/core/transform_step.h +++ b/libIRDB/include/core/transform_step.h @@ -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 diff --git a/libIRDB/test/fill_in_cfg.cpp b/libIRDB/test/fill_in_cfg.cpp index e78c40b29c706feea9dce42af536d92ea67dd089..9ffd312fa8fc7dfed911c626ac5dce7debb32211 100644 --- a/libIRDB/test/fill_in_cfg.cpp +++ b/libIRDB/test/fill_in_cfg.cpp @@ -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; } diff --git a/libIRDB/test/fill_in_cfg.hpp b/libIRDB/test/fill_in_cfg.hpp index 53007c207fbaa83a18fc5723c50d94ecbfda5085..255ca46dc6ad22a55b3e9914386f08afd6affe2d 100644 --- a/libIRDB/test/fill_in_cfg.hpp +++ b/libIRDB/test/fill_in_cfg.hpp @@ -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 diff --git a/tools/thanos/thanos.cpp b/tools/thanos/thanos.cpp index e6a0da08b42fe2d41029c60df8725acc8db24dc3..48d7adef9562b35268bcd27a099cbf40bfa70f46 100644 --- a/tools/thanos/thanos.cpp +++ b/tools/thanos/thanos.cpp @@ -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) {