Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RootContext
- {
- public:
- RootContext(std::iostream out_){}
- };
- template <class ParentContext>
- class InsideArrayContext;
- template <class ParentContext>
- class InsideObjectExpectingValue;
- template <class ParentContext>
- class InsideObjectExpectingKey;
- template <class ParentContext>
- class EmptyContext;
- template <class ParentContext>
- class InsideArrayContext
- {
- private:
- std::ostream &out_;
- bool is_closed_;
- bool is_started_;
- void checkForComma()
- {
- if (!is_started_)
- {
- is_started_ = true;
- }
- else
- {
- out_.put(',');
- }
- }
- public:
- InsideArrayContext(std::ostream &out) : out_(out),
- is_closed_(false),
- is_started_(false)
- {
- out_.put('[');
- }
- ~InsideArrayContext()
- {
- if (!is_closed_)
- {
- out_.put(']');
- }
- }
- InsideArrayContext<ParentContext> &Number(int64_t number)
- {
- checkForComma();
- out_ << number;
- return (*this);
- }
- InsideArrayContext<ParentContext> &String(std::string_view text)
- {
- checkForComma();
- out_.put('"');
- out_ << text;
- out_.put('"');
- return (*this);
- }
- // InsideArrayContext<ParentContext> Boolean(bool)
- // {
- // // return something
- // }
- // InsideArrayContext<ParentContext> Null()
- // {
- // // return something
- // }
- // InsideArrayContext<InsideArrayContext> BeginArray()
- // {
- // InsideArrayContext<InsideArrayContext> inner(out_, this);
- // return inner;
- // }
- ParentContext EndArray()
- {
- is_closed_ = true;
- out_.put(']');
- ParentContext context
- // return ;
- }
- // InsideObjectExpectingKey<InsideArrayContext> BeginObject()
- // {
- // // return something
- // }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement