15 #ifndef SAMPLES_XML_RPC_XMLRPC_VALUE_H_ // NOLINT 16 #define SAMPLES_XML_RPC_XMLRPC_VALUE_H_ 24 #define N(x) NLIB_EXI_LITERAL(x) 25 #define M(x) NLIB_EXI_UTF8(x) 26 typedef std::basic_string< ::nlib_ns::exi::ExiChar> StdString;
52 StdString* value_string;
53 XmlRpcArray* value_array;
54 XmlRpcStruct* value_struct;
56 ValueType value_type_;
62 value_holder_.value_int = 0;
64 ~XmlRpcValue() { this->Invalidate(); }
65 void SetInt(
const int& rhs) {
68 value_holder_.value_int = rhs;
70 void SetBool(
const bool& rhs) {
72 value_type_ = BOOLEAN;
73 value_holder_.value_bool = rhs;
75 void SetDouble(
const double& rhs) {
78 value_holder_.value_double = rhs;
80 void SetString(
const StdString& rhs) {
83 value_holder_.value_string =
new StdString(rhs);
88 value_holder_.value_string =
new StdString(rhs);
94 ValueType GetValueType()
const {
return value_type_; }
96 int* AsInt() {
return (value_type_ == INT) ? &value_holder_.value_int : NULL; }
97 const int* AsInt()
const {
return (value_type_ == INT) ? &value_holder_.value_int : NULL; }
99 bool* AsBool() {
return (value_type_ == BOOLEAN) ? &value_holder_.value_bool : NULL; }
100 const bool* AsBool()
const {
101 return (value_type_ == BOOLEAN) ? &value_holder_.value_bool : NULL;
104 double* AsDouble() {
return (value_type_ == DOUBLE) ? &value_holder_.value_double : NULL; }
105 const double* AsDouble()
const {
106 return (value_type_ == DOUBLE) ? &value_holder_.value_double : NULL;
109 StdString* AsString() {
return (value_type_ == STRING) ? value_holder_.value_string : NULL; }
110 const StdString* AsString()
const {
111 return (value_type_ == STRING) ? value_holder_.value_string : NULL;
114 XmlRpcArray* AsArray() {
return (value_type_ == ARRAY) ? value_holder_.value_array : NULL; }
115 const XmlRpcArray* AsArray()
const {
116 return (value_type_ == ARRAY) ? value_holder_.value_array : NULL;
119 XmlRpcStruct* AsStruct() {
return (value_type_ == STRUCT) ? value_holder_.value_struct : NULL; }
120 const XmlRpcStruct* AsStruct()
const {
121 return (value_type_ == STRUCT) ? value_holder_.value_struct : NULL;
124 bool IsValid()
const {
return value_type_ != NONE; }
125 bool IsNil()
const {
return value_type_ == NIL; }
126 bool Read(nlib_ns::exi::XmlStreamReader* reader) {
127 if (nlib_ns::exi::XmlStreamReader::START_ELEMENT != reader->Next())
return false;
128 return this->Read_(reader);
130 void Write(nlib_ns::exi::XmlStreamWriter* writer)
const;
133 XmlRpcValue(
const XmlRpcValue& rhs);
134 XmlRpcValue& operator=(
const XmlRpcValue& rhs);
136 bool Read_(nlib_ns::exi::XmlStreamReader* reader);
138 friend class XmlRpcArray;
139 friend class XmlRpcStruct;
143 typedef std::vector<XmlRpcValue*> ArrayValue;
144 ArrayValue array_value_;
147 XmlRpcValue* Append() {
148 XmlRpcValue* p =
new XmlRpcValue();
149 array_value_.push_back(p);
152 std::size_t Size()
const {
return array_value_.size(); }
153 XmlRpcValue* Get(std::size_t idx) {
154 return idx < array_value_.size() ? array_value_[idx] : NULL;
156 const XmlRpcValue* Get(std::size_t idx)
const {
157 return idx < array_value_.size() ? array_value_[idx] : NULL;
159 XmlRpcValue* operator[](std::size_t idx) {
return this->Get(idx); }
160 const XmlRpcValue* operator[](std::size_t idx)
const {
return this->Get(idx); }
161 bool Read(nlib_ns::exi::XmlStreamReader* reader);
162 void Write(nlib_ns::exi::XmlStreamWriter* writer)
const;
167 XmlRpcArray(
const XmlRpcArray& rhs);
168 XmlRpcArray& operator=(
const XmlRpcArray& rhs);
170 friend class XmlRpcValue;
174 typedef std::map<StdString, XmlRpcValue*> StructValue;
175 StructValue struct_value_;
178 XmlRpcValue& operator[](
const StdString& rhs);
179 XmlRpcValue* Insert(
const StdString& rhs) {
return &operator[](rhs); }
180 XmlRpcValue* Get(
const StdString& rhs)
const {
181 StructValue::const_iterator it = struct_value_.find(rhs);
182 return it != struct_value_.end() ? it->second : NULL;
184 bool HasMember(
const StdString& rhs)
const {
185 return struct_value_.end() != struct_value_.find(rhs);
187 bool Read(nlib_ns::exi::XmlStreamReader* reader);
188 void Write(nlib_ns::exi::XmlStreamWriter* writer)
const;
193 XmlRpcStruct(
const XmlRpcStruct& rhs);
194 XmlRpcStruct& operator=(
const XmlRpcStruct& rhs);
196 friend class XmlRpcValue;
199 #endif // SAMPLES_XML_RPC_XMLRPC_VALUE_H_ // NOLINT bool Write(BinaryWriter *w, T x)
この関数テンプレートを特殊化することで、ユーザー定義クラスを書きこむことができます。 ...
ディレクトリnn/nlib/exi内のヘッダを全てインクルードするためのヘッダです。
bool Read(BinaryReader *r, T *x)
この関数テンプレートを特殊化することで、ユーザー定義クラスに読み込むことができます。 ...
wchar_t ExiChar
XMLパーサーの内部文字列型のtypedefです。