summaryrefslogtreecommitdiff
path: root/project2/json/presenter.h
blob: dbb2b7a3d62454f8c8af6304f0d9cdb96a43cbe0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef JSON_PRESENTER_H
#define JSON_PRESENTER_H

#include "../common/presenter.h"
#include "json.h"
#include "conversion.h"
#include "transform.h"
#include <stack>

class JsonPresenter : public MultiRowSetPresenter, public ContentPresenter, public SourceOf<json::Object>, public WritableContent, public SourceOf<WritableContent> {
	public:
		JsonPresenter(ScriptNodePtr s, ObjectSource, ExecContext *);
		JsonPresenter(ScriptNodePtr s, ObjectSource, const Glib::ustring &);
		void init(ExecContext * ec);
		typedef void (JsonPresenter::*ValueAdder)(const Glib::ustring &, const VariableType &) const;
		typedef std::stack<ValueAdder> ValueAdderStack;
		mutable ValueAdderStack vaStack;
		void addNamedValue(const Glib::ustring & name, const VariableType & value) const;
		void addValueToObject(const Glib::ustring & name, const VariableType & value) const;
		void addValueToArray(const Glib::ustring &, const VariableType & value) const;
		void addNewRow(const Glib::ustring &) const;
		void finishRow() const;
		void addNewRowSet(const Glib::ustring & name) const;
		void addNewRowSet(const Glib::ustring & name, const Glib::ustring & ns) const;
		void finishRowSet() const;
		void addNewArray(const Glib::ustring & name, bool) const;
		void finishArray(bool) const;
		operator const json::Object *() const;
		operator const WritableContent * () const;
		Glib::ustring getContentType(ExecContext *) const;
		Class getContentClass(ExecContext *) const;
		void writeTo(std::ostream & o, const std::string & encoding, ExecContext *) const;

	private:
		Variable returnObject;
		mutable json::Object object;
		mutable std::stack<json::Object *> curRowSet;
		mutable std::stack<json::Array *> curRowArray;
};

#endif