From f5f41e7721d15c33517498d5178da150b9630a9f Mon Sep 17 00:00:00 2001 From: Matthew McGill <mhollismcgill@gmail.com> Date: Mon, 24 Sep 2018 18:45:52 +0000 Subject: [PATCH] Interface changes Former-commit-id: af8d489f959a5fd65773df254be54d6e5d5c74ab --- libIRDB/include/util/IR_Files.hpp | 42 +++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/libIRDB/include/util/IR_Files.hpp b/libIRDB/include/util/IR_Files.hpp index 79668eb00..346826f09 100644 --- a/libIRDB/include/util/IR_Files.hpp +++ b/libIRDB/include/util/IR_Files.hpp @@ -1,35 +1,45 @@ #ifndef IR_Files_h #define IR_Files_h +// TODO: This should really use unordered maps and sets, +// but I was having trouble building with those. #include <map> #include <utility> #include <memory> -#include <iterator> +#include <set> +// If our toolchain use paradigm changes, this class can be extended +// to support adding, removing, writing back, and getting individual file IRs +// in a variant (may require adding more maps). + +// *** A toolchain step should NOT delete pointers to any variant, file IR, or file object stored +// in a IRFiles_t object. I have made pointers shared where possible to communicate this. *** class IRFiles_t { public: IRFiles_t() {}; ~IRFiles_t(); - // add/remove file IRs (have option to write back to DB upon removal) - // If choosing to write back to DB, may throw a database error exception. - // If the write back fails, the FileIR will not be destroyed. - void AddFileIR(FileIR_t&); - void RemoveFileIR(FileIR_t&, bool); - void RemoveFileIR(File_t&, bool); - - // has file IR? - bool HasFileIR(File_t&); - bool HasFileIR(FileIR_t&); + // Add/remove file IRs. + // Adding file IRs also adds the variant the files belong to. + // Removing file IRs also removes the variant the files belong to. + // When removing file IRs, have the option to write back to the DB. + int AddFileIRs(db_id_t variant_id); + int RemoveFileIRs(db_id_t variant_id, bool write_to_DB); + + // get a variant + std::shared_ptr<VariantID_t> GetVariant(db_id_t variant_id); + // get file IRs (returns a shared ptr to a set of shared ptrs to file IRs) + std::shared_ptr<std::set<std::shared_ptr<FileIR_t>>> GetFileIRs(db_id_t variant_id); - // get file IR - FileIR_t* GetFileIR(File_t&); + // Write back all variants and file IRs stored in this IRFiles_t object. + int WriteBackAll(void); private: - // map for speed of finding if a needed file - // has already been read from the DB - std::map<File_t*, std::shared_ptr<FileIR_t>> file_IR_map; + // maps for speed of finding needed file IRs and/or variants + // that have already been read from the DB + std::map<db_id_t, std::shared_ptr<VariantID_t>> variant_map; + std::map<db_id_t, std::shared_ptr<std::set<std::shared_ptr<FileIR_t>>>> file_IRs_map; }; -- GitLab