-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchema.cpp
More file actions
executable file
·99 lines (78 loc) · 1.71 KB
/
Schema.cpp
File metadata and controls
executable file
·99 lines (78 loc) · 1.71 KB
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
#include <algorithm>
#include "Schema.h"
Schema::Schema() :
m_size(0)
{
}
Schema::Schema(const std::vector<const Attribute *> * columns)
: m_size(0)
{
reserve(columns->size());
std::vector<const Attribute *>::const_iterator i = columns->begin();
for ( ; i != columns->end(); i++)
{
add(*i);
}
}
Schema::~Schema()
{
std::for_each(begin(), end(), free);
}
void Schema::add(const Attribute * a)
{
Attribute * attribute =
new Attribute(a->id(), size(), a->name(), a->table(), a->size(), a->type());
push_back(attribute);
m_offset[attribute->qualified_name()] = m_size;
m_size += attribute->size();
}
bool Schema::contains(const std::string & name) const
{
return m_offset.find(name) != m_offset.end();
}
int Schema::offset(const Attribute * attribute) const
{
return m_offset.find(attribute->qualified_name())->second;
}
int Schema::offset(const std::string & column) const
{
return m_offset.find(column)->second;
}
int Schema::offset(int fid) const
{
int position = 0;
for (int i = 0; i < fid; i++)
{
position += at(i)->size();
}
return position;
}
size_t Schema::rsize() const
{
return m_size;
}
size_t Schema::nitems() const
{
return size();
}
const Attribute * Schema::operator[](const std::string & name) const
{
const Attribute * attribute = NULL;
for (int i = 0; i < size(); i++)
{
if (name == (attribute = at(i))->name() || // TODO: will use only q-name
name == attribute->qualified_name())
{
return attribute;
}
}
return NULL;
}
const Attribute * Schema::operator[](int fid) const
{
return std::vector<Attribute *>::at(fid);
}
const Attribute * Schema::at(int fid) const
{
return std::vector<Attribute *>::at(fid);
}