mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 23:36:16 +02:00
Merge pull request #6482 from edolstra/json-utils
Move json stuff out of util.cc
This commit is contained in:
commit
470e27ce80
5 changed files with 23 additions and 21 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include "worker-protocol.hh"
|
#include "worker-protocol.hh"
|
||||||
#include "topo-sort.hh"
|
#include "topo-sort.hh"
|
||||||
#include "callback.hh"
|
#include "callback.hh"
|
||||||
|
#include "json-utils.hh"
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
@ -56,8 +57,6 @@
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
void handleDiffHook(
|
void handleDiffHook(
|
||||||
|
|
|
@ -350,7 +350,7 @@ void Worker::waitForInput()
|
||||||
become `available'. Note that `available' (i.e., non-blocking)
|
become `available'. Note that `available' (i.e., non-blocking)
|
||||||
includes EOF. */
|
includes EOF. */
|
||||||
std::vector<struct pollfd> pollStatus;
|
std::vector<struct pollfd> pollStatus;
|
||||||
std::map <int, int> fdToPollStatus;
|
std::map<int, size_t> fdToPollStatus;
|
||||||
for (auto & i : children) {
|
for (auto & i : children) {
|
||||||
for (auto & j : i.fds) {
|
for (auto & j : i.fds) {
|
||||||
pollStatus.push_back((struct pollfd) { .fd = j, .events = POLLIN });
|
pollStatus.push_back((struct pollfd) { .fd = j, .events = POLLIN });
|
||||||
|
|
21
src/libutil/json-utils.hh
Normal file
21
src/libutil/json-utils.hh
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
|
||||||
|
const nlohmann::json * get(const nlohmann::json & map, const std::string & key)
|
||||||
|
{
|
||||||
|
auto i = map.find(key);
|
||||||
|
if (i == map.end()) return nullptr;
|
||||||
|
return &*i;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json * get(nlohmann::json & map, const std::string & key)
|
||||||
|
{
|
||||||
|
auto i = map.find(key);
|
||||||
|
if (i == map.end()) return nullptr;
|
||||||
|
return &*i;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1586,23 +1586,8 @@ std::string stripIndentation(std::string_view s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const nlohmann::json * get(const nlohmann::json & map, const std::string & key)
|
|
||||||
{
|
|
||||||
auto i = map.find(key);
|
|
||||||
if (i == map.end()) return nullptr;
|
|
||||||
return &*i;
|
|
||||||
}
|
|
||||||
|
|
||||||
nlohmann::json * get(nlohmann::json & map, const std::string & key)
|
|
||||||
{
|
|
||||||
auto i = map.find(key);
|
|
||||||
if (i == map.end()) return nullptr;
|
|
||||||
return &*i;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
static Sync<std::pair<unsigned short, unsigned short>> windowSize{{0, 0}};
|
static Sync<std::pair<unsigned short, unsigned short>> windowSize{{0, 0}};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -558,9 +558,6 @@ typename T::mapped_type * get(T & map, const typename T::key_type & key)
|
||||||
return &i->second;
|
return &i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nlohmann::json * get(const nlohmann::json & map, const std::string & key);
|
|
||||||
nlohmann::json * get(nlohmann::json & map, const std::string & key);
|
|
||||||
|
|
||||||
/* Get a value for the specified key from an associate container, or a default value if the key isn't present. */
|
/* Get a value for the specified key from an associate container, or a default value if the key isn't present. */
|
||||||
template <class T>
|
template <class T>
|
||||||
const typename T::mapped_type & getOr(T & map,
|
const typename T::mapped_type & getOr(T & map,
|
||||||
|
|
Loading…
Reference in a new issue