2019-02-08 19:43:25 +00:00
|
|
|
#ifndef LLARP_UTIL_STATUS_HPP
|
|
|
|
#define LLARP_UTIL_STATUS_HPP
|
2019-02-19 09:43:17 +00:00
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
#include <util/string_view.hpp>
|
2019-02-19 09:43:17 +00:00
|
|
|
|
2019-03-02 02:27:38 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2019-02-08 19:43:25 +00:00
|
|
|
#include <vector>
|
2019-02-08 22:44:21 +00:00
|
|
|
#include <string>
|
2019-02-11 17:14:43 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <absl/types/variant.h>
|
2019-02-08 19:43:25 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
2019-03-02 02:27:38 +00:00
|
|
|
struct StatusVisitor;
|
2019-02-08 19:43:25 +00:00
|
|
|
struct StatusObject
|
|
|
|
{
|
2019-02-15 23:04:04 +00:00
|
|
|
using String_t = string_view;
|
2019-02-11 17:14:43 +00:00
|
|
|
using Variant = absl::variant< uint64_t, std::string, bool, StatusObject,
|
|
|
|
std::vector< std::string >,
|
|
|
|
std::vector< StatusObject > >;
|
2019-03-02 02:27:38 +00:00
|
|
|
using value_type = std::pair< String_t, Variant >;
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
StatusObject(std::initializer_list< value_type > vals)
|
|
|
|
{
|
|
|
|
std::for_each(vals.begin(), vals.end(),
|
|
|
|
[&](const value_type& item) { Put(item); });
|
|
|
|
}
|
2019-02-08 19:43:25 +00:00
|
|
|
|
|
|
|
void
|
2019-02-11 17:14:43 +00:00
|
|
|
Put(String_t name, const Variant& value);
|
2019-02-08 19:43:25 +00:00
|
|
|
|
|
|
|
void
|
2019-02-11 17:14:43 +00:00
|
|
|
Put(const value_type& value);
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2019-03-02 02:27:38 +00:00
|
|
|
nlohmann::json
|
|
|
|
get() const
|
|
|
|
{
|
|
|
|
return Impl;
|
|
|
|
}
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
private:
|
2019-03-02 02:27:38 +00:00
|
|
|
friend struct StatusVisitor;
|
|
|
|
nlohmann::json Impl;
|
2019-02-08 19:43:25 +00:00
|
|
|
};
|
|
|
|
} // namespace util
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|