2019-02-08 19:43:25 +00:00
|
|
|
#include <util/status.hpp>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
|
|
|
StatusObject::StatusObject()
|
|
|
|
{
|
|
|
|
#ifdef USE_ABYSS
|
|
|
|
Impl.SetObject();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusObject::~StatusObject()
|
|
|
|
{
|
2019-02-08 21:29:56 +00:00
|
|
|
Impl.RemoveAllMembers();
|
2019-02-08 19:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StatusObject::PutBool(const char* name, bool val)
|
|
|
|
{
|
|
|
|
#ifdef USE_ABYSS
|
2019-02-08 21:29:56 +00:00
|
|
|
auto& a = Impl.GetAllocator();
|
2019-02-08 19:43:25 +00:00
|
|
|
Value_t v;
|
|
|
|
v.SetBool(val);
|
2019-02-08 21:29:56 +00:00
|
|
|
Value_t k(name, a);
|
|
|
|
Impl.AddMember(k, v, a);
|
2019-02-08 19:43:25 +00:00
|
|
|
#else
|
|
|
|
(void)name;
|
|
|
|
(void)val;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StatusObject::PutInt(const char* name, uint64_t val)
|
|
|
|
{
|
|
|
|
#ifdef USE_ABYSS
|
2019-02-08 21:29:56 +00:00
|
|
|
auto& a = Impl.GetAllocator();
|
2019-02-08 19:43:25 +00:00
|
|
|
Value_t v;
|
2019-02-08 21:29:56 +00:00
|
|
|
v.SetUint64(val);
|
|
|
|
Value_t k(name, a);
|
|
|
|
Impl.AddMember(k, v, a);
|
2019-02-08 19:43:25 +00:00
|
|
|
#else
|
|
|
|
(void)name;
|
|
|
|
(void)val;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-08 21:29:56 +00:00
|
|
|
StatusObject::PutObject(const char* name, StatusObject& val)
|
2019-02-08 19:43:25 +00:00
|
|
|
{
|
|
|
|
#ifdef USE_ABYSS
|
2019-02-08 21:29:56 +00:00
|
|
|
auto& a = Impl.GetAllocator();
|
2019-02-08 19:43:25 +00:00
|
|
|
Value_t v;
|
|
|
|
v.SetObject();
|
2019-02-08 21:29:56 +00:00
|
|
|
v.CopyFrom(val.Impl, a);
|
|
|
|
Value_t k(name, a);
|
|
|
|
Impl.AddMember(k, v, a);
|
2019-02-08 19:43:25 +00:00
|
|
|
#else
|
|
|
|
(void)name;
|
|
|
|
(void)val;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StatusObject::PutObjectArray(const char* name,
|
2019-02-08 21:29:56 +00:00
|
|
|
std::vector< StatusObject >& arr)
|
2019-02-08 19:43:25 +00:00
|
|
|
{
|
|
|
|
#ifdef USE_ABYSS
|
2019-02-08 21:29:56 +00:00
|
|
|
auto& a = Impl.GetAllocator();
|
2019-02-08 19:43:25 +00:00
|
|
|
Value_t v;
|
|
|
|
v.SetArray();
|
2019-02-08 21:29:56 +00:00
|
|
|
Value_t i;
|
2019-02-08 19:43:25 +00:00
|
|
|
for(const auto& obj : arr)
|
|
|
|
{
|
2019-02-08 21:29:56 +00:00
|
|
|
v.PushBack(i.SetObject().CopyFrom(obj.Impl, a), a);
|
2019-02-08 19:43:25 +00:00
|
|
|
}
|
2019-02-08 21:29:56 +00:00
|
|
|
Value_t k(name, a);
|
|
|
|
|
|
|
|
Impl.AddMember(k, v, a);
|
2019-02-08 19:43:25 +00:00
|
|
|
#else
|
|
|
|
(void)name;
|
2019-02-08 21:29:56 +00:00
|
|
|
(void)arr;
|
2019-02-08 19:43:25 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StatusObject::PutStringArray(const char* name,
|
2019-02-08 21:29:56 +00:00
|
|
|
std::vector< std::string >& arr)
|
2019-02-08 19:43:25 +00:00
|
|
|
{
|
|
|
|
#ifdef USE_ABYSS
|
2019-02-08 21:29:56 +00:00
|
|
|
auto& a = Impl.GetAllocator();
|
2019-02-08 19:43:25 +00:00
|
|
|
Value_t v;
|
|
|
|
v.SetArray();
|
2019-02-08 21:29:56 +00:00
|
|
|
Value_t i;
|
|
|
|
for(auto& str : arr)
|
2019-02-08 19:43:25 +00:00
|
|
|
{
|
2019-02-08 21:29:56 +00:00
|
|
|
v.PushBack(i.SetString(str.c_str(), a), a);
|
2019-02-08 19:43:25 +00:00
|
|
|
}
|
2019-02-08 21:29:56 +00:00
|
|
|
Value_t k(name, a);
|
|
|
|
Impl.AddMember(k, v, a);
|
2019-02-08 19:43:25 +00:00
|
|
|
#else
|
|
|
|
(void)name;
|
2019-02-08 21:29:56 +00:00
|
|
|
(void)arr;
|
2019-02-08 19:43:25 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StatusObject::PutString(const char* name, const std::string& val)
|
|
|
|
{
|
|
|
|
#ifdef USE_ABYSS
|
2019-02-08 21:29:56 +00:00
|
|
|
auto& a = Impl.GetAllocator();
|
2019-02-08 19:43:25 +00:00
|
|
|
Value_t v;
|
2019-02-08 21:29:56 +00:00
|
|
|
v.SetString(val.c_str(), a);
|
|
|
|
Value_t k(name, a);
|
|
|
|
Impl.AddMember(k, v, a);
|
2019-02-08 19:43:25 +00:00
|
|
|
#else
|
|
|
|
(void)name;
|
|
|
|
(void)val;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} // namespace util
|
|
|
|
} // namespace llarp
|