lokinet/llarp/util/status.hpp

52 lines
1.1 KiB
C++
Raw Normal View History

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
#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
{
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 > >;
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
nlohmann::json
get() const
{
return Impl;
}
2019-02-08 19:43:25 +00:00
2019-02-11 17:14:43 +00:00
private:
friend struct StatusVisitor;
nlohmann::json Impl;
2019-02-08 19:43:25 +00:00
};
} // namespace util
} // namespace llarp
#endif