95 lines
1.6 KiB
C++
95 lines
1.6 KiB
C++
#include "Public.h"
|
|
#include "JsonUnicodeWriter.h"
|
|
|
|
namespace uns
|
|
{
|
|
HashResult::HashResult()
|
|
{
|
|
success = false;
|
|
}
|
|
|
|
HashResult::HashResult(std::string res)
|
|
{
|
|
result = res;
|
|
success = true;
|
|
last_error = "";
|
|
}
|
|
|
|
HashResult::HashResult(const HashResult& obj)
|
|
{
|
|
result = obj.result;
|
|
success = obj.success;
|
|
last_error = obj.last_error;
|
|
}
|
|
|
|
HashResult::HashResult(bool succ, std::string res, std::string err)
|
|
{
|
|
result = res;
|
|
success = succ;
|
|
if (!success)
|
|
last_error = err;
|
|
}
|
|
|
|
HashResult HashResult::Faliure(std::string str)
|
|
{
|
|
return HashResult(false, "", str);
|
|
}
|
|
|
|
HashResult HashResult::Success(std::string str)
|
|
{
|
|
return HashResult(true, str, "");
|
|
}
|
|
|
|
std::string HashResult::GetResult()
|
|
{
|
|
return result;
|
|
}
|
|
|
|
std::string HashResult::GetLastError()
|
|
{
|
|
return last_error;
|
|
}
|
|
|
|
std::string HashResult::EncodeJsonString(bool unicode, bool styled)
|
|
{
|
|
if (unicode)
|
|
{
|
|
JsonUnicodeWriter writer;
|
|
return writer.write(*this);
|
|
}
|
|
try
|
|
{
|
|
Json::Writer* writer = nullptr;
|
|
if (styled)
|
|
writer = new Json::StyledWriter();
|
|
else
|
|
writer = new Json::FastWriter();
|
|
std::string result = writer->write(*this);
|
|
delete writer;
|
|
return result;
|
|
}
|
|
catch (...)
|
|
{
|
|
return "{\"Success\":false,\"Result\":\"\",\"LastError\":\"STD C++ Error Catched\"}";
|
|
}
|
|
}
|
|
|
|
HashResult::operator bool()
|
|
{
|
|
return success;
|
|
}
|
|
|
|
HashResult::operator std::string()
|
|
{
|
|
return (success ? result : last_error);
|
|
}
|
|
|
|
HashResult::operator Json::Value()
|
|
{
|
|
Json::Value root;
|
|
root["Result"] = result;
|
|
root["Success"] = success;
|
|
root["LastError"] = last_error;
|
|
return root;
|
|
}
|
|
}; |