diff options
Diffstat (limited to 'oop2eindopdr/CacheManager.h')
-rw-r--r-- | oop2eindopdr/CacheManager.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/oop2eindopdr/CacheManager.h b/oop2eindopdr/CacheManager.h index 1e0a565..9bd47e3 100644 --- a/oop2eindopdr/CacheManager.h +++ b/oop2eindopdr/CacheManager.h @@ -15,7 +15,19 @@ private: const unsigned int max_tries = 100; - virtual void retry(std::string label, std::function<void()> action, std::function<bool()> retry_if); + /** + * @brief retry `action` as long as `retry_if` returns false, until `max_tries` + * + * @param label this label gets printed if retry_count exceeds max_tries + * @param check_pre `true` = check `retry_if` before `action`, `false` = check `retry_if` after `action` + * @param action this gets executed as long as `retry_if` returns false + * @param retry_if this returns whether `action` is successful (boolean) + */ + virtual void retry(std::string label, bool check_pre, std::function<void()> action, std::function<bool()> retry_if); + /** @brief alias for `retry` with `check_pre` = false (check after action) */ + virtual void retry_while(std::string label, std::function<void()> action, std::function<bool()> retry_if) { retry(label, false, action, retry_if); }; + /** @brief alias for `retry` with `check_pre` = true (check before action) */ + virtual void retry_if(std::string label, std::function<void()> action, std::function<bool()> retry_if) { retry(label, true, action, retry_if); }; public: /** @brief initialize CacheManager class at `cache_path` */ CacheManager(const char* cache_path); @@ -35,10 +47,10 @@ public: /** @brief get fstream for file in cache or create file */ virtual std::fstream* cache_get(const char* filename); - virtual std::fstream* cache_get(std::string filename); + virtual std::fstream* cache_get(std::string filename) { return cache_get(filename.c_str()); }; /** @brief check if file exists in cache */ virtual bool cache_exists(const char* filename); - virtual bool cache_exists(std::string filename); + virtual bool cache_exists(std::string filename) { return cache_exists(filename.c_str()); }; /** @brief add cache path before filename */ virtual std::string prefix_cache_path(const char* filename); |