summaryrefslogtreecommitdiff
path: root/project2/basics/views/autotree.h
blob: 48f46be5bd3ada0053fbe59cdbb3cb2f873d141e (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef AUTOTREE_H
#define AUTOTREE_H

#include <boost/intrusive_ptr.hpp>
#include "rowProcessor.h"
#include "view.h"
#include "aggregate.h"

class AutoTreeNode;
typedef boost::intrusive_ptr<const AutoTreeNode> AutoTreeNodePtr;

class AutoTreeState {
	public:
		typedef boost::tuple<bool, bool> Opened;

		std::vector<Opened> opened;
		std::vector<VariableType> values;
};

class AutoTreeNode : public IntrusivePtrBase {
	public:
		typedef std::map<Glib::ustring, Variable> Values;

		AutoTreeNode(ScriptNodePtr, unsigned int pos, unsigned int depth);

		void rowReady(const RowState *, const MultiRowSetPresenter *, ExecContext *, AutoTreeState & state) const;
		void openArray(const MultiRowSetPresenter * p, ExecContext *, AutoTreeState & state) const;
		void openObject(const MultiRowSetPresenter * p, ExecContext *, AutoTreeState & state) const;
		void closeArray(const MultiRowSetPresenter * p, ExecContext *, AutoTreeState & state) const;
		void closeObject(const MultiRowSetPresenter * p, ExecContext *, AutoTreeState & state) const;
		AutoTreeNodePtr child() const;
		
	protected:

	private:
		Values keys;
		Values includes;
		AutoTreeNodePtr tree;
		Variable rootName;
		Variable objectName;

		const unsigned int pos;
		const unsigned int depth;
};

/// Project2 component to create tree output based on a records in a row set
class AutoTree : public View, public RowProcessor {
	public:
		AutoTree(ScriptNodePtr);
		virtual ~AutoTree();

		void loadComplete(const CommonObjects *);
		void execute(const MultiRowSetPresenter *, ExecContext *) const;

	protected:
		typedef std::map<Glib::ustring, Variable> Columns;
		Columns viewColumns;

		void executeChildren(const MultiRowSetPresenter * presenter, ExecContext *) const;

		AutoTreeNodePtr root;
		unsigned int depth;
};

#endif