mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor(workspaces): listen ipc event
This commit is contained in:
34
include/util/json.hpp
Normal file
34
include/util/json.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
namespace waybar::util {
|
||||
|
||||
struct JsonParser {
|
||||
|
||||
JsonParser()
|
||||
: _reader(_builder.newCharReader())
|
||||
{}
|
||||
|
||||
Json::Value parse(const std::string data)
|
||||
{
|
||||
Json::Value root;
|
||||
std::string err;
|
||||
bool res =
|
||||
_reader->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
|
||||
if (!res)
|
||||
throw std::runtime_error(err);
|
||||
return root;
|
||||
}
|
||||
|
||||
~JsonParser()
|
||||
{
|
||||
delete _reader;
|
||||
}
|
||||
|
||||
private:
|
||||
Json::CharReaderBuilder _builder;
|
||||
Json::CharReader *_reader;
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user