diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-03-09 23:07:27 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-03-09 23:07:27 +0900 |
| commit | 7338a2503547ae1310d018d0fc2903fb85b309ea (patch) | |
| tree | c7111eb641f6bf1b661c03270a8f4407d2fada21 /src/ValueBase.h | |
| parent | d541b350d21cd7747479f21b7c4b6d363248a450 (diff) | |
Added initial JSON-RPC support.
JSON-RPC is enabled using --enable-xml-rpc. We are implementing
JSON-RPC based on JSON-RPC 2.0 draft spec.
Diffstat (limited to 'src/ValueBase.h')
| -rw-r--r-- | src/ValueBase.h | 71 |
1 files changed, 57 insertions, 14 deletions
diff --git a/src/ValueBase.h b/src/ValueBase.h index a262b853..e13d12d2 100644 --- a/src/ValueBase.h +++ b/src/ValueBase.h @@ -58,19 +58,19 @@ public: class String; class Integer; +class Bool; +class Null; class List; class Dict; class ValueBaseVisitor { public: virtual ~ValueBaseVisitor() {} - virtual void visit(const String& string) = 0; - virtual void visit(const Integer& integer) = 0; - + virtual void visit(const Bool& boolValue) = 0; + virtual void visit(const Null& nullValue) = 0; virtual void visit(const List& list) = 0; - virtual void visit(const Dict& dict) = 0; }; @@ -133,6 +133,34 @@ private: ValueType integer_; }; +class Bool:public ValueBase { +public: + static SharedHandle<Bool> gTrue(); + static SharedHandle<Bool> gFalse(); + bool val() const; + virtual void accept(ValueBaseVisitor& visitor) const; +private: + Bool(bool val); + // Don't allow copying + Bool(const Bool&); + Bool& operator=(const Bool&); + bool val_; + static const SharedHandle<Bool> trueValue_; + static const SharedHandle<Bool> falseValue_; +}; + +class Null:public ValueBase { +public: + static SharedHandle<Null> g(); + virtual void accept(ValueBaseVisitor& visitor) const; +private: + Null(); + // Don't allow copying + Null(const Null&); + Null& operator=(const Null&); + static const SharedHandle<Null> nullValue_; +}; + class List:public ValueBase { public: typedef std::vector<SharedHandle<ValueBase> > ValueType; @@ -256,10 +284,19 @@ private: ValueType dict_; }; -template<typename T, typename T1, typename T2, typename T3> -class DowncastValueBaseVisitor:public ValueBaseVisitor { -private: - const T* result_; +class EmptyDowncastValueBaseVisitor:public ValueBaseVisitor { +public: + EmptyDowncastValueBaseVisitor() {} + virtual void visit(const String& v) {} + virtual void visit(const Integer& v) {} + virtual void visit(const Bool& v) {} + virtual void visit(const Null& v) {} + virtual void visit(const List& v) {} + virtual void visit(const Dict& v) {} +}; + +template<typename T> +class DowncastValueBaseVisitor:public EmptyDowncastValueBaseVisitor { public: DowncastValueBaseVisitor():result_(0) {} @@ -268,10 +305,6 @@ public: result_ = &t; } - virtual void visit(const T1& t1) {} - virtual void visit(const T2& t2) {} - virtual void visit(const T3& t3) {} - const T* getResult() const { return result_; @@ -281,12 +314,14 @@ public: { result_ = r; } +private: + const T* result_; }; -template<typename T, typename T1, typename T2, typename T3, typename VPtr> +template<typename T, typename VPtr> const T* downcast(const VPtr& v) { - DowncastValueBaseVisitor<T, T1, T2, T3> visitor; + DowncastValueBaseVisitor<T> visitor; v->accept(visitor); return visitor.getResult(); } @@ -303,6 +338,14 @@ Integer* asInteger(ValueBase* v); Integer* asInteger(const SharedHandle<ValueBase>& v); +const Bool* asBool(const ValueBase* v); + +Bool* asBool(const SharedHandle<ValueBase>& v); + +const Null* asNull(const ValueBase* v); + +Null* asNull(const SharedHandle<ValueBase>& v); + const List* asList(const ValueBase* v); List* asList(ValueBase* v); |
