mirror of
https://github.com/NixOS/nix
synced 2025-06-26 20:01:15 +02:00
Simplify Implementations registration
This commit is contained in:
parent
93844a5998
commit
f59ccb468e
3 changed files with 8 additions and 7 deletions
|
@ -902,12 +902,15 @@ struct StoreFactory
|
||||||
|
|
||||||
struct Implementations
|
struct Implementations
|
||||||
{
|
{
|
||||||
static std::vector<StoreFactory> * registered;
|
static std::vector<StoreFactory> & registered()
|
||||||
|
{
|
||||||
|
static std::vector<StoreFactory> registered;
|
||||||
|
return registered;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, typename TConfig>
|
template<typename T, typename TConfig>
|
||||||
static void add()
|
static void add()
|
||||||
{
|
{
|
||||||
if (!registered) registered = new std::vector<StoreFactory>();
|
|
||||||
StoreFactory factory{
|
StoreFactory factory{
|
||||||
.uriSchemes = TConfig::uriSchemes(),
|
.uriSchemes = TConfig::uriSchemes(),
|
||||||
.create =
|
.create =
|
||||||
|
@ -919,7 +922,7 @@ struct Implementations
|
||||||
-> std::shared_ptr<StoreConfig>
|
-> std::shared_ptr<StoreConfig>
|
||||||
{ return std::make_shared<TConfig>(StringMap({})); })
|
{ return std::make_shared<TConfig>(StringMap({})); })
|
||||||
};
|
};
|
||||||
registered->push_back(factory);
|
registered().push_back(factory);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1355,7 +1355,7 @@ ref<Store> openStore(StoreReference && storeURI)
|
||||||
return std::make_shared<LocalStore>(params);
|
return std::make_shared<LocalStore>(params);
|
||||||
},
|
},
|
||||||
[&](const StoreReference::Specified & g) {
|
[&](const StoreReference::Specified & g) {
|
||||||
for (const auto & implem : *Implementations::registered)
|
for (const auto & implem : Implementations::registered())
|
||||||
if (implem.uriSchemes.count(g.scheme))
|
if (implem.uriSchemes.count(g.scheme))
|
||||||
return implem.create(g.scheme, g.authority, params);
|
return implem.create(g.scheme, g.authority, params);
|
||||||
|
|
||||||
|
@ -1399,6 +1399,4 @@ std::list<ref<Store>> getDefaultSubstituters()
|
||||||
return stores;
|
return stores;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<StoreFactory> * Implementations::registered = 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
|
||||||
res["args"] = toJSON();
|
res["args"] = toJSON();
|
||||||
|
|
||||||
auto stores = nlohmann::json::object();
|
auto stores = nlohmann::json::object();
|
||||||
for (auto & implem : *Implementations::registered) {
|
for (auto & implem : Implementations::registered()) {
|
||||||
auto storeConfig = implem.getConfig();
|
auto storeConfig = implem.getConfig();
|
||||||
auto storeName = storeConfig->name();
|
auto storeName = storeConfig->name();
|
||||||
auto & j = stores[storeName];
|
auto & j = stores[storeName];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue