Skip to content

Instantly share code, notes, and snippets.

@qrealka
Created July 27, 2018 07:55
Show Gist options
  • Save qrealka/e61fd98a8eb34b7e207d445b7e99d75f to your computer and use it in GitHub Desktop.
Save qrealka/e61fd98a8eb34b7e207d445b7e99d75f to your computer and use it in GitHub Desktop.
tagged backend
#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