79 lines
2.3 KiB
C++
79 lines
2.3 KiB
C++
#pragma once
|
|
|
|
namespace Json
|
|
{
|
|
class Value;
|
|
}
|
|
|
|
namespace tinyxml2
|
|
{
|
|
class XMLElement;
|
|
}
|
|
|
|
namespace a8
|
|
{
|
|
|
|
const int XOT_SIMPLE = 0;
|
|
const int XOT_ARRAY = 1;
|
|
const int XOT_OBJECT = 2;
|
|
|
|
class XObject
|
|
{
|
|
public:
|
|
XObject();
|
|
XObject(a8::XValue& val);
|
|
XObject(const a8::XObject& v);
|
|
~XObject();
|
|
|
|
unsigned char GetType();
|
|
bool IsSimple() { return GetType() == XOT_SIMPLE; };
|
|
bool IsArray() { return GetType() == XOT_ARRAY; };
|
|
bool IsObject() { return GetType() == XOT_OBJECT; };
|
|
int Size();
|
|
void Reset();
|
|
void DeepCopy(a8::XObject& to);
|
|
|
|
a8::XValue AsXValue();
|
|
std::shared_ptr<a8::XObject> operator[] (int i);
|
|
std::shared_ptr<a8::XObject> operator[] (const std::string& key);
|
|
std::shared_ptr<a8::XObject> At(int i);
|
|
std::shared_ptr<a8::XObject> At(const std::string& key);
|
|
std::shared_ptr<a8::XObject> At(const char* key);
|
|
a8::XValue Get(const std::string& key, a8::XValue defval="");
|
|
bool HasKey(const std::string& key);
|
|
bool HasKey(int i);
|
|
const a8::XObject& operator=(const a8::XObject& obj);
|
|
a8::XObject& Move(a8::XObject& a);
|
|
|
|
bool ReadFromFile(const std::string& filename);
|
|
bool ReadFromJsonFile(const std::string& filename);
|
|
bool ReadFromJsonString(const std::string& jsondata);
|
|
bool ReadFromXmlFile(const std::string& filename);
|
|
bool ReadFromXmlString(const std::string& xmldata);
|
|
void ReadFromUrlQueryString(const std::string& query_string);
|
|
void ToJsonStr(std::string& data);
|
|
std::string ToJsonStr();
|
|
void ToUrlEncodeStr(std::string& data);
|
|
void ToKVList(std::map<std::string, std::string>& kv_list);
|
|
void GetKeys(std::vector<std::string>& keys);
|
|
|
|
private:
|
|
void JsonValueToXObject(Json::Value& json_val, a8::XObject& xobject);
|
|
void XmlElementToXObject(tinyxml2::XMLElement* xml_ele, a8::XObject& xobject);
|
|
|
|
protected:
|
|
void ConvertObject();
|
|
void ConvertArray();
|
|
|
|
protected:
|
|
unsigned char type_ = a8::XOT_SIMPLE;
|
|
union {
|
|
a8::XValue* x_value;
|
|
std::vector<std::shared_ptr<a8::XObject>>* array_value;
|
|
std::map<std::string, std::shared_ptr<a8::XObject>>* object_value;
|
|
} value_ = {0};
|
|
|
|
};
|
|
|
|
}
|