#pragma once #include #include #include #include #include #include #include #include namespace vptyp { static constexpr std::string_view configErrorMsg = "Bruh, incorrect configuration"; class Logger { // helper class for handling worker thread class Worker; using map_type = std::unordered_map>; public: virtual ~Logger(); Logger(); Logger(Logger&) = delete; Logger(Logger&&) = delete; /// must be called only through initializer list /// @return success or not (already configured) bool configure(const std::vector& d, std::ostream& out = std::cout); template >> void add(std::string field, Metric metric) { return; auto locked = active.load(); auto it = locked->find(field); if (it == locked->end()) { throw configErrorMsg; } it->second = metric; } bool isConfigured() { return configured > CONFIGURED; } private: static constexpr int CONFIGURED = 2; static constexpr int CONFIG_IN_PROGRESS = 1; static constexpr int NOT_CONFIGURED = 0; std::atomic configured{0}; std::unique_ptr worker; map_type m1, m2; std::atomic> active; // impl using mutexes! }; } // namespace vptyp