2018-10-24 18:02:42 +00:00
|
|
|
#ifndef __ABYSS_JSON_JSON_HPP
|
|
|
|
#define __ABYSS_JSON_JSON_HPP
|
|
|
|
|
2018-10-25 17:03:25 +00:00
|
|
|
#include <memory>
|
|
|
|
//#if __cplusplus >= 201703L
|
|
|
|
#if 0
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <any>
|
2018-10-24 18:02:42 +00:00
|
|
|
namespace abyss
|
|
|
|
{
|
|
|
|
namespace json
|
|
|
|
{
|
2018-10-25 17:03:25 +00:00
|
|
|
typedef std::unordered_map< std::string, std::any > Object;
|
2018-10-24 18:02:42 +00:00
|
|
|
}
|
|
|
|
} // namespace abyss
|
2018-10-25 17:03:25 +00:00
|
|
|
#else
|
|
|
|
#include <rapidjson/document.h>
|
|
|
|
namespace abyss
|
|
|
|
{
|
|
|
|
namespace json
|
|
|
|
{
|
|
|
|
typedef rapidjson::Document Document;
|
|
|
|
typedef rapidjson::Value Value;
|
|
|
|
} // namespace json
|
|
|
|
} // namespace abyss
|
|
|
|
#endif
|
|
|
|
namespace abyss
|
|
|
|
{
|
2018-11-01 12:47:14 +00:00
|
|
|
#if __cplusplus >= 201703L
|
2018-10-26 13:02:15 +00:00
|
|
|
typedef std::string_view string_view;
|
|
|
|
#else
|
|
|
|
typedef std::string string_view;
|
|
|
|
#endif
|
2018-10-25 17:03:25 +00:00
|
|
|
namespace json
|
|
|
|
{
|
|
|
|
struct IParser
|
|
|
|
{
|
|
|
|
virtual ~IParser(){};
|
|
|
|
|
|
|
|
/// result from feeding data to parser
|
|
|
|
enum Result
|
|
|
|
{
|
|
|
|
/// we need more data to finish parsing
|
|
|
|
eNeedData,
|
|
|
|
/// we have parsed the object fully
|
|
|
|
eDone,
|
|
|
|
/// we have a parsing syntax error
|
|
|
|
eParseError
|
|
|
|
};
|
|
|
|
|
|
|
|
/// feed data to parser return true if successful
|
|
|
|
virtual bool
|
|
|
|
FeedData(const char *buf, size_t sz) = 0;
|
|
|
|
/// parse internal buffer
|
|
|
|
virtual Result
|
|
|
|
Parse(Document &obj) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// create new parser
|
|
|
|
IParser *
|
|
|
|
MakeParser(size_t contentSize);
|
|
|
|
|
|
|
|
void
|
|
|
|
ToString(const json::Document &obj, std::string &out);
|
|
|
|
|
|
|
|
} // namespace json
|
|
|
|
} // namespace abyss
|
2018-10-24 18:02:42 +00:00
|
|
|
|
|
|
|
#endif
|