2 #ifndef SAMPLES_XML_RPC_XMLRPC_VALUE_H_ // NOLINT 3 #define SAMPLES_XML_RPC_XMLRPC_VALUE_H_ 11 #define N(x) NLIB_EXI_LITERAL(x) 12 #define M(x) NLIB_EXI_UTF8(x) 13 typedef std::basic_string< ::nlib_ns::exi::ExiChar> StdString;
39 StdString* valueString;
40 XmlRpcArray* valueArray;
41 XmlRpcStruct* valueStruct;
43 ValueType value_type_;
49 value_holder_.valueInt = 0;
51 ~XmlRpcValue() { this->Invalidate(); }
52 void SetInt(
const int& rhs) {
55 value_holder_.valueInt = rhs;
57 void SetBool(
const bool& rhs) {
59 value_type_ = BOOLEAN;
60 value_holder_.valueBool = rhs;
62 void SetDouble(
const double& rhs) {
65 value_holder_.valueDouble = rhs;
67 void SetString(
const StdString& rhs) {
70 value_holder_.valueString =
new StdString(rhs);
75 value_holder_.valueString =
new StdString(rhs);
81 ValueType GetValueType()
const {
return value_type_; }
83 int* AsInt() {
return (value_type_ == INT) ? &value_holder_.valueInt : NULL; }
84 const int* AsInt()
const {
return (value_type_ == INT) ? &value_holder_.valueInt : NULL; }
86 bool* AsBool() {
return (value_type_ == BOOLEAN) ? &value_holder_.valueBool : NULL; }
87 const bool* AsBool()
const {
88 return (value_type_ == BOOLEAN) ? &value_holder_.valueBool : NULL;
91 double* AsDouble() {
return (value_type_ == DOUBLE) ? &value_holder_.valueDouble : NULL; }
92 const double* AsDouble()
const {
93 return (value_type_ == DOUBLE) ? &value_holder_.valueDouble : NULL;
96 StdString* AsString() {
return (value_type_ == STRING) ? value_holder_.valueString : NULL; }
97 const StdString* AsString()
const {
98 return (value_type_ == STRING) ? value_holder_.valueString : NULL;
101 XmlRpcArray* AsArray() {
return (value_type_ == ARRAY) ? value_holder_.valueArray : NULL; }
102 const XmlRpcArray* AsArray()
const {
103 return (value_type_ == ARRAY) ? value_holder_.valueArray : NULL;
106 XmlRpcStruct* AsStruct() {
return (value_type_ == STRUCT) ? value_holder_.valueStruct : NULL; }
107 const XmlRpcStruct* AsStruct()
const {
108 return (value_type_ == STRUCT) ? value_holder_.valueStruct : NULL;
111 bool IsValid()
const {
return value_type_ != NONE; }
112 bool IsNil()
const {
return value_type_ == NIL; }
113 bool Read(nlib_ns::exi::XmlStreamReader* reader) {
114 if (nlib_ns::exi::XmlStreamReader::START_ELEMENT != reader->Next())
return false;
115 return this->Read_(reader);
117 void Write(nlib_ns::exi::XmlStreamWriter* writer)
const;
120 XmlRpcValue(
const XmlRpcValue& rhs);
121 XmlRpcValue& operator=(
const XmlRpcValue& rhs);
123 bool Read_(nlib_ns::exi::XmlStreamReader* reader);
125 friend class XmlRpcArray;
126 friend class XmlRpcStruct;
130 typedef std::vector<XmlRpcValue*> ArrayValue;
131 ArrayValue array_value_;
134 XmlRpcValue* Append() {
135 XmlRpcValue* p =
new XmlRpcValue();
136 array_value_.push_back(p);
139 std::size_t Size()
const {
return array_value_.size(); }
140 XmlRpcValue* Get(std::size_t idx) {
141 return idx < array_value_.size() ? array_value_[idx] : NULL;
143 const XmlRpcValue* Get(std::size_t idx)
const {
144 return idx < array_value_.size() ? array_value_[idx] : NULL;
146 XmlRpcValue* operator[](std::size_t idx) {
return this->Get(idx); }
147 const XmlRpcValue* operator[](std::size_t idx)
const {
return this->Get(idx); }
148 bool Read(nlib_ns::exi::XmlStreamReader* reader);
149 void Write(nlib_ns::exi::XmlStreamWriter* writer)
const;
154 XmlRpcArray(
const XmlRpcArray& rhs);
155 XmlRpcArray& operator=(
const XmlRpcArray& rhs);
157 friend class XmlRpcValue;
161 typedef std::map<StdString, XmlRpcValue*> StructValue;
162 StructValue struct_value_;
165 XmlRpcValue& operator[](
const StdString& rhs);
166 XmlRpcValue* Insert(
const StdString& rhs) {
return &operator[](rhs); }
167 XmlRpcValue* Get(
const StdString& rhs)
const {
168 StructValue::const_iterator it = struct_value_.find(rhs);
169 return it != struct_value_.end() ? it->second : NULL;
171 bool HasMember(
const StdString& rhs)
const {
172 return struct_value_.end() != struct_value_.find(rhs);
174 bool Read(nlib_ns::exi::XmlStreamReader* reader);
175 void Write(nlib_ns::exi::XmlStreamWriter* writer)
const;
180 XmlRpcStruct(
const XmlRpcStruct& rhs);
181 XmlRpcStruct& operator=(
const XmlRpcStruct& rhs);
183 friend class XmlRpcValue;
186 #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です。