summaryrefslogtreecommitdiff
path: root/project2/common/rowView.cpp
blob: c0e5cae7d72bf7ab9b698bfe0088cd64ace33b26 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <pch.hpp>
#include "rowView.h"
#include "presenter.h"
#include "scopeObject.h"
#include "scriptLoader.h"
#include "scopeObject.h"
#include <boost/foreach.hpp>
#include <boost/bind.hpp>

DECLARE_LOADER("view", RowView);

RowView::RowView(ScriptNodePtr p) :
	SourceObject(p),
	View(p),
	RowProcessor(p),
	rootName(p, "rootname", Null()),
	recordName(p, "recordname"),
	required(p, "required", false),
	isObject(p, "isobject", true),
	presenter(NULL),
	rowsFound(false)
{
	BOOST_FOREACH(ScriptNodePtr node, p->childrenIn("columns")) {
		viewColumns.insert(Columns::value_type(node->get_name(), Variable(node)));
	}
	p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&subViews));
	p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&valueAggregates));
	p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&setAggregates));
}

RowView::~RowView()
{
}

void
RowView::loadComplete(const CommonObjects * co)
{
	RowProcessor::loadComplete(co);
}

void
RowView::rowReady(const RowState * rs) const
{
	rowsFound = true;
	if (isObject()) {
		presenter->addNewRow(recordName());
	}
	if (viewColumns.empty()) {
		rs->foreachColumn(boost::bind(&RowSetPresenter::addNamedValue, presenter, _2, _3));
	}
	else {
		BOOST_FOREACH(const Columns::value_type & col, viewColumns) {
			presenter->addNamedValue(col.first, col.second);
		}
	}
	if (isObject()) {
		executeChildren();
		presenter->finishRow();
	}
	BOOST_FOREACH(SetAggregateCPtr s, setAggregates) {
		s->pushValue();
	}
	BOOST_FOREACH(ValueAggregateCPtr a, valueAggregates) {
		a->pushValue();
	}
}

void
RowView::execute(const MultiRowSetPresenter * p) const
{
	rowsFound = false;
	presenter = p;
	if (!rootName().isNull()) {
		presenter->addNewRowSet(rootName());
	}
	ScopeObject pres(rootName().isNull() ? ScopeObject::Event() : boost::bind(&MultiRowSetPresenter::finishRowSet, p));
	{
		presenter->addNewArray(recordName(), true);
		ScopeObject pres(boost::bind(&MultiRowSetPresenter::finishArray, p, true));
		RowProcessor::execute();
	}
	if (required() && !rowsFound) {
		throw EmptyRequiredRows(name);
	}

	BOOST_FOREACH(SetAggregateCPtr s, setAggregates) {
		presenter->addNewArray(s->name, false);
		ScopeObject pres(boost::bind(&MultiRowSetPresenter::finishArray, p, false));
		s->onResultValues(boost::bind(&MultiRowSetPresenter::addNamedValue, p, "value", _1));
		s->reset();
	}
	BOOST_FOREACH(ValueAggregateCPtr a, valueAggregates) {
		presenter->addNamedValue(a->name, a->resultValue());
		a->reset();
	}
}

void
RowView::executeChildren() const
{
	BOOST_FOREACH(const SubViews::value_type & sq, subViews) {
		sq->execute(presenter);
	}
}