2022-03-09 15:27:48 +00:00
|
|
|
#pragma once
|
2023-04-01 03:18:41 +00:00
|
|
|
///@file
|
2022-03-09 15:27:48 +00:00
|
|
|
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-03-27 01:12:25 +00:00
|
|
|
/**
|
|
|
|
* Helper to try downcasting a Store with a nice method if it fails.
|
|
|
|
*
|
|
|
|
* This is basically an alternative to the user-facing part of
|
|
|
|
* Store::unsupported that allows us to still have a nice message but
|
|
|
|
* better interface design.
|
|
|
|
*/
|
2022-03-09 15:27:48 +00:00
|
|
|
template<typename T>
|
|
|
|
T & require(Store & store)
|
|
|
|
{
|
|
|
|
auto * castedStore = dynamic_cast<T *>(&store);
|
|
|
|
if (!castedStore)
|
|
|
|
throw UsageError("%s not supported by store '%s'", T::operationName, store.getUri());
|
|
|
|
return *castedStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|