Created
July 27, 2018 07:55
-
-
Save qrealka/e61fd98a8eb34b7e207d445b7e99d75f to your computer and use it in GitHub Desktop.
tagged backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <string> | |
#include <atomic> | |
class base_object { | |
std::atomic<size_t> ref_count; | |
public: | |
size_t aquire() { return ++ref_count; } | |
size_t release() { return --ref_count; } | |
}; | |
template<class Tag> class service; | |
class interface { | |
service<interface>& get_service(); | |
const service<interface>& get_service() const; | |
std::shared_ptr<service<interface>> _service; | |
public: | |
interface( std::shared_ptr<service<interface>> service ); | |
bool open_file( const std::wstring& name); | |
}; | |
template<> | |
class service<interface> | |
{ | |
public: | |
virtual ~service<interface>() = default; | |
virtual bool checkout(const std::wstring& name) = 0; | |
virtual bool download(const std::wstring& name) = 0; | |
}; | |
interface::interface( std::shared_ptr<service<interface>> service ) | |
: _service{std::move(service)} | |
{} | |
service<interface>& interface::get_service() | |
{ return *_service; } | |
const service<interface>& interface::get_service() const | |
{ return *_service; } | |
bool interface::open_file( const std::wstring& name) { | |
return get_service().checkout(name) && get_service().download(name); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment