protected:
RPCValueType type;
void *value;
-
+
double *CastInteger()
{
return (double*)value;
}
-
+
std::string *CastString()
{
return (std::string*)value;
}
-
+
RPCObjectContainer *CastObject()
{
return (RPCObjectContainer*)value;
}
-
+
RPCArrayContainer *CastArray()
{
return (RPCArrayContainer*)value;
}
-
+
void DestroyValue()
{
// Some versions of GCC complain about declaration in switch statements
default:
break;
}
-
+
value = NULL;
}
-
+
void InitValue()
{
switch (type)
break;
}
}
-
+
RPCValue(const RPCValue &v) { }
-
+
public:
RPCValue *parent;
- RPCValue(RPCValue *parent = NULL) : type(RPCNull), value(NULL), parent(parent) { }
- RPCValue(RPCValueType type, RPCValue *parent = NULL) : type(type), value(NULL), parent(parent) { InitValue(); }
- RPCValue(bool nvalue, RPCValue *parent = NULL) : type(RPCBoolean), value((void*)nvalue), parent(parent) { }
- RPCValue(double nvalue, RPCValue *parent = NULL) : type(RPCInteger), parent(parent) { value = new double(nvalue); }
- RPCValue(const std::string &nvalue, RPCValue *parent = NULL) : type(RPCString), parent(parent) { value = new std::string(nvalue); }
-
+ RPCValue(RPCValue *rparent = NULL) : type(RPCNull), value(NULL), parent(rparent) { }
+ RPCValue(RPCValueType ttype, RPCValue *rparent = NULL) : type(ttype), value(NULL), parent(rparent) { InitValue(); }
+ RPCValue(bool nvalue, RPCValue *rparent = NULL) : type(RPCBoolean), value((void*)nvalue), parent(rparent) { }
+ RPCValue(double nvalue, RPCValue *rparent = NULL) : type(RPCInteger), parent(rparent) { value = new double(nvalue); }
+ RPCValue(const std::string &nvalue, RPCValue *rparent = NULL) : type(RPCString), parent(rparent) { value = new std::string(nvalue); }
+
virtual ~RPCValue()
{
DestroyValue();
}
-
+
RPCValueType GetType()
{
return type;
}
-
+
void SetNull()
{
DestroyValue();
type = RPCNull;
}
-
+
void SetBoolean(bool nvalue)
{
DestroyValue();
value = (void*)nvalue;
type = RPCBoolean;
}
-
+
void SetInteger(double nvalue)
{
if (type == RPCInteger)
type = RPCInteger;
}
}
-
+
void SetString(const std::string &nvalue)
{
if (type == RPCString)
type = RPCString;
}
}
-
+
void SetArray()
{
if (type == RPCArray)
InitValue();
}
}
-
+
void SetObject()
{
if (type == RPCObject)
InitValue();
}
}
-
+
void ArrayAdd(RPCValue *nvalue)
{
if (type != RPCArray)
a->push_back(nvalue);
nvalue->parent = this;
}
-
+
void ObjectAdd(const std::string &key, RPCValue *nvalue)
{
if (type != RPCObject)
o->insert(std::make_pair(key, nvalue));
nvalue->parent = this;
}
-
+
RPCValue *GetArray(int i)
{
if (type != RPCArray)
return NULL;
return a->at(i);
}
-
+
int ArraySize()
{
if (type != RPCArray)
RPCArrayContainer *a = this->CastArray();
return a->size();
}
-
+
RPCValue *GetObject(const std::string &key)
{
if (type != RPCObject)
return NULL;
return it->second;
}
-
+
std::pair<RPCObjectContainer::iterator,RPCObjectContainer::iterator> GetObjectIterator()
{
if (type != RPCObject)
RPCObjectContainer *o = this->CastObject();
return std::make_pair(o->begin(), o->end());
}
-
+
std::string GetString()
{
if (type != RPCString)
return std::string();
return *this->CastString();
}
-
+
double GetInt()
{
if (type != RPCInteger)
return 0;
return *this->CastInteger();
}
-
+
bool GetBool()
{
if (type != RPCBoolean)
class RPCRequest : public classbase
{
protected:
-
+
public:
std::string method;
RPCValue *parameters;
std::string provider;
bool claimed;
std::string error;
-
- RPCRequest(const std::string &provider, const std::string &method, RPCValue *parameters)
- : method(method), parameters(parameters), provider(provider), claimed(false)
+
+ RPCRequest(const std::string &sprovider, const std::string &smethod, RPCValue *rparameters)
+ : method(smethod), parameters(rparameters), provider(sprovider), claimed(false)
{
result = new RPCValue();
}
-
+
~RPCRequest()
{
if (result)