Skip to content

Instantly share code, notes, and snippets.

@foodtooth
Created August 8, 2019 06:44
Show Gist options
  • Save foodtooth/d7dc5b48dce5647719d9bd4cbcc2ec40 to your computer and use it in GitHub Desktop.
Save foodtooth/d7dc5b48dce5647719d9bd4cbcc2ec40 to your computer and use it in GitHub Desktop.
Singleton example, and Interface basic concept
#ifndef RESPONSE_MANAGER_H
#define RESPONSE_MANAGER_H
#include <unordered_map>
#include <string>
#include <memory>
class ResponseInterface {
public:
ResponseInterface(const ResponseInterface&) = default;
ResponseInterface(ResponseInterface&&) = default;
ResponseInterface& operator=(const ResponseInterface&) = default;
ResponseInterface& operator=(ResponseInterface&&) = default;
ResponseInterface() = default;
virtual ~ResponseInterface() = default;
};
template <typename MRes>
class ResponseManager final {
public:
ResponseManager(const ResponseManager&) = delete;
ResponseManager(ResponseManager&&) = delete;
ResponseManager& operator=(const ResponseManager&) = delete;
ResponseManager& operator=(ResponseManager&&) = delete;
static ResponseManager& GetInstance() {
static ResponseManager instance;
return instance;
}
private:
ResponseManager() = default;
~ResponseManager() = default;
std::unordered_map<std::string, std::unique_ptr<ResponseInterface>> responses_map_;
};
#endif // RESPONSE_MANAGER_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment