summaryrefslogtreecommitdiff
path: root/project2/definedColumns.cpp
blob: 13614535ce2a2d40e3fc88aff6f96885ed2c53b4 (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
#include "definedColumns.h"
#include <boost/foreach.hpp>
#include <libxml++/nodes/textnode.h>

DefinedColumns::DefinedColumns(const xmlpp::Element * p) :
	RowSet(p)
{
	unsigned int colNo = 0;
	BOOST_FOREACH(const xmlpp::Node * node, p->find("columns/column")) {
		const xmlpp::Element * elem = dynamic_cast<const xmlpp::Element *>(node);
		if (elem) {
			columns.insert(Column(colNo++, elem));
		}
	}
}

DefinedColumns::Column::Column(unsigned int i, const Glib::ustring & c) :
	idx(i),
	col(c),
	defValue(VariableType())
{
}

DefinedColumns::Column::Column(unsigned int i, const xmlpp::Element * p) :
	idx(i),
	col(p->get_child_text()->get_content()),
	defValue(p, "default", false)
{
}

void
DefinedColumns::Column::operator=(const VariableType & v) const
{
	value = v;
}

const Glib::ustring &
DefinedColumns::getColumnName(unsigned int col) const
{
	Columns::index<byColIdx>::type::iterator i = columns.get<byColIdx>().find(col);
	if (i != columns.get<byColIdx>().end()) {
		return i->col;
	}
	throw RowSet::FieldOutOfRange(col);
}

unsigned int
DefinedColumns::columnCount() const
{
	return columns.size();
}

VariableType
DefinedColumns::getCurrentValue(unsigned int col) const
{
	Columns::index<byColIdx>::type::iterator i = columns.get<byColIdx>().find(col);
	if (i != columns.get<byColIdx>().end()) {
		return i->value;
	}
	throw RowSet::FieldOutOfRange(col);
}

bool
DefinedColumns::isNull(unsigned int col) const
{
	return (columns.get<byColIdx>().find(col) == columns.get<byColIdx>().end());
}

bool
DefinedColumns::isNull(const Glib::ustring & col) const
{
	return (columns.get<byColName>().find(col) == columns.get<byColName>().end());
}

VariableType
DefinedColumns::getCurrentValue(const Glib::ustring & col) const
{
	Columns::const_iterator i = columns.get<byColName>().find(col);
	if (i != columns.end()) {
		return i->value;
	}
	throw RowSet::FieldDoesNotExist(col);
}