20 typedef std::map<std::string,RPCValue*> RPCObjectContainer;
21 typedef std::vector<RPCValue*> RPCArrayContainer;
23 class RPCValue : public classbase
31 return (double*)value;
34 std::string *CastString()
36 return (std::string*)value;
39 RPCObjectContainer *CastObject()
41 return (RPCObjectContainer*)value;
44 RPCArrayContainer *CastArray()
46 return (RPCArrayContainer*)value;
51 // Some versions of GCC complain about declaration in switch statements
53 RPCObjectContainer *o;
57 delete this->CastInteger();
60 delete this->CastString();
63 a = this->CastArray();
64 for (RPCArrayContainer::iterator i = a->begin(); i != a->end(); i++)
69 o = this->CastObject();
70 for (RPCObjectContainer::iterator i = o->begin(); i != o->end(); i++)
93 value = new std::string;
96 value = new RPCArrayContainer;
99 value = new RPCObjectContainer;
104 RPCValue(const RPCValue &v) { }
109 RPCValue(RPCValue *rparent = NULL) : type(RPCNull), value(NULL), parent(rparent) { }
110 RPCValue(RPCValueType ttype, RPCValue *rparent = NULL) : type(ttype), value(NULL), parent(rparent) { InitValue(); }
111 RPCValue(bool nvalue, RPCValue *rparent = NULL) : type(RPCBoolean), value((void*)nvalue), parent(rparent) { }
112 RPCValue(double nvalue, RPCValue *rparent = NULL) : type(RPCInteger), parent(rparent) { value = new double(nvalue); }
113 RPCValue(const std::string &nvalue, RPCValue *rparent = NULL) : type(RPCString), parent(rparent) { value = new std::string(nvalue); }
120 RPCValueType GetType()
131 void SetBoolean(bool nvalue)
134 value = (void*)nvalue;
138 void SetInteger(double nvalue)
140 if (type == RPCInteger)
142 *this->CastInteger() = nvalue;
147 value = new double(nvalue);
152 void SetString(const std::string &nvalue)
154 if (type == RPCString)
156 this->CastString()->assign(nvalue);
161 value = new std::string(nvalue);
168 if (type == RPCArray)
170 this->CastArray()->clear();
182 if (type == RPCObject)
184 this->CastObject()->clear();
194 void ArrayAdd(RPCValue *nvalue)
196 if (type != RPCArray)
198 RPCArrayContainer *a = this->CastArray();
199 a->push_back(nvalue);
200 nvalue->parent = this;
203 void ObjectAdd(const std::string &key, RPCValue *nvalue)
205 if (type != RPCObject)
207 RPCObjectContainer *o = this->CastObject();
208 o->insert(std::make_pair(key, nvalue));
209 nvalue->parent = this;
212 RPCValue *GetArray(int i)
214 if (type != RPCArray)
216 RPCArrayContainer *a = this->CastArray();
217 if ((i < 0) || (i >= (signed)a->size()))
224 if (type != RPCArray)
226 RPCArrayContainer *a = this->CastArray();
230 RPCValue *GetObject(const std::string &key)
232 if (type != RPCObject)
234 RPCObjectContainer *o = this->CastObject();
235 RPCObjectContainer::iterator it = o->find(key);
241 std::pair<RPCObjectContainer::iterator,RPCObjectContainer::iterator> GetObjectIterator()
243 if (type != RPCObject)
244 throw std::runtime_error("Cannot get iterator for a non-object RPC value");
245 RPCObjectContainer *o = this->CastObject();
246 return std::make_pair(o->begin(), o->end());
249 std::string GetString()
251 if (type != RPCString)
252 return std::string();
253 return *this->CastString();
258 if (type != RPCInteger)
260 return *this->CastInteger();
265 if (type != RPCBoolean)
267 return (value != NULL);
271 class RPCRequest : public classbase
277 RPCValue *parameters;
279 std::string provider;
283 RPCRequest(const std::string &sprovider, const std::string &smethod, RPCValue *rparameters)
284 : method(smethod), parameters(rparameters), provider(sprovider), claimed(false)
286 result = new RPCValue();