return static_cast<const JsonObjVal&>(*this);
}
+void JsonVal::accept(JsonValVisitor& visitor) const
+{
+ this->_accept(visitor);
+}
+
JsonNullVal::JsonNullVal(TextLoc loc) noexcept : JsonVal {Type::Null, std::move(loc)}
{
}
+void JsonNullVal::_accept(JsonValVisitor& visitor) const
+{
+ visitor.visit(*this);
+}
+
#ifdef BT_DEBUG_MODE
namespace {
#endif
}
+void JsonArrayVal::_accept(JsonValVisitor& visitor) const
+{
+ visitor.visit(*this);
+}
+
JsonObjVal::JsonObjVal(Container&& vals, TextLoc loc) :
JsonCompoundVal {std::move(vals), std::move(loc)}
{
#endif
}
+void JsonObjVal::_accept(JsonValVisitor& visitor) const
+{
+ visitor.visit(*this);
+}
+
JsonNullVal::UP createJsonVal(TextLoc loc)
{
return bt2s::make_unique<const JsonNullVal>(std::move(loc));
class JsonArrayVal;
class JsonObjVal;
+/*
+ * Visitor of JSON value.
+ */
+class JsonValVisitor
+{
+protected:
+ explicit JsonValVisitor() = default;
+
+public:
+ virtual ~JsonValVisitor() = default;
+
+ virtual void visit(const JsonNullVal&)
+ {
+ }
+
+ virtual void visit(const JsonBoolVal&)
+ {
+ }
+
+ virtual void visit(const JsonSIntVal&)
+ {
+ }
+
+ virtual void visit(const JsonUIntVal&)
+ {
+ }
+
+ virtual void visit(const JsonRealVal&)
+ {
+ }
+
+ virtual void visit(const JsonStrVal&)
+ {
+ }
+
+ virtual void visit(const JsonArrayVal&)
+ {
+ }
+
+ virtual void visit(const JsonObjVal&)
+ {
+ }
+};
+
/*
* Abstract base class for any JSON value.
*/
JsonVal& operator=(const JsonVal&) = delete;
JsonVal& operator=(JsonVal&&) = delete;
+ virtual ~JsonVal() = default;
+
/*
* Type of this JSON value.
*/
*/
const JsonObjVal& asObj() const noexcept;
+ /*
+ * Accepts the visitor `visitor` to visit this JSON value.
+ */
+ void accept(JsonValVisitor& visitor) const;
+
private:
+ virtual void _accept(JsonValVisitor& visitor) const = 0;
+
/* JSON value type */
Type _mType;
* Builds a JSON null value located at `loc`.
*/
explicit JsonNullVal(TextLoc loc) noexcept;
+
+private:
+ void _accept(JsonValVisitor& visitor) const override;
};
/*
return _mVal;
}
+private:
+ void _accept(JsonValVisitor& visitor) const override
+ {
+ visitor.visit(*this);
+ }
+
private:
/* Raw value */
ValT _mVal;
BT_ASSERT_DBG(index < this->_mVals.size());
return *_mVals[index];
}
+
+private:
+ void _accept(JsonValVisitor& visitor) const override;
};
/*
{
return _mVals.find(key) != _mVals.end();
}
+
+private:
+ void _accept(JsonValVisitor& visitor) const override;
};
/*