2022-03-09 17:27:48 +02:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2022-03-09 17:27:48 +02:00
|
|
|
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-03-27 04:12:25 +03: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 17:27:48 +02: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|