-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTuple.h
58 lines (49 loc) · 1.26 KB
/
Tuple.h
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
//
// Created by Matthew on 7/15/2022.
//
#ifndef CS236_TUPLE_H
#define CS236_TUPLE_H
#include <string>
#include <vector>
#include "Header.h"
#include <sstream>
using namespace std;
class Tuple {
private:
vector<string> values;
public:
Tuple() { }
Tuple(vector<string> values) : values(values) { }
bool operator<(const Tuple t) const {
return values < t.values;
}
// TODO: add more delegation functions as needed
// This goes in your tuple class, note that tuple must include Header.h
string toString(Header header) const {
if (size() != header.size()) {
throw "Failed in toString Tuple.h";
}
stringstream out;
string sep = "";
for (unsigned i = 0; i < size(); i++) {
string name = header.at(i);
string value = at(i);
out << sep << name << "=" << value;
sep = ", ";
}
return out.str();
}
unsigned int size() const {
return values.size();
}
string at(unsigned int index) const {
if (index >= size()) {
throw "Failed at 'at' Tuple.h";
}
return values.at(index);
}
void push_back(string value) {
values.push_back(value);
}
};
#endif //CS236_TUPLE_H