merged with brandon
This commit is contained in:
commit
903b6c98d5
4 changed files with 132 additions and 57 deletions
36
Attribute.h
36
Attribute.h
|
@ -5,33 +5,43 @@ using namespace std;
|
|||
|
||||
//Funtional, might need more functionality
|
||||
|
||||
template<typename T>
|
||||
//template<typename T>
|
||||
class Attribute {
|
||||
//a named column of a relation
|
||||
string name;
|
||||
vector<T> values;
|
||||
|
||||
bool isKey;
|
||||
int size;
|
||||
|
||||
public:
|
||||
Attribute(){ }
|
||||
|
||||
Attribute(vector<T> v){
|
||||
this.values = v;
|
||||
}
|
||||
vector<string> values;
|
||||
|
||||
Attribute(const Attribute<T>& a){
|
||||
this.values = a.getAll();
|
||||
}
|
||||
void initializeAttribute(string n, vector<string> a){
|
||||
|
||||
Attribute& operator=(const Attribute<T>& a){
|
||||
this.values = a.getAll();
|
||||
name = n;
|
||||
values = a;
|
||||
}
|
||||
|
||||
string getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
vector<T> getAll(){
|
||||
return this.values;
|
||||
Attribute(){ }
|
||||
|
||||
void display()
|
||||
{
|
||||
cout<<"Atribute name:\t"<<name<<"\n";
|
||||
cout<<"Elements: ";
|
||||
for (int i = 0; i < values.size(); ++i)
|
||||
{
|
||||
cout<<values[i]<<" ";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
vector<string> getElements(){
|
||||
return values;
|
||||
}
|
||||
*/
|
||||
};
|
39
Relation.h
39
Relation.h
|
@ -7,10 +7,41 @@ using namespace std;
|
|||
//NOT DONE
|
||||
class Relation {
|
||||
//a table with rows and columns
|
||||
string name;
|
||||
vector< Attribute<T> > att;
|
||||
string name; //The title the user gives it
|
||||
vector< Attribute > att; //A vector of the columns
|
||||
|
||||
public:
|
||||
Relation();
|
||||
Relation(vector< Attribute<T> > a) { att = a; }
|
||||
void addTuple(vector< Attribute<T> > tuple);
|
||||
|
||||
//constructor
|
||||
Relation(string n, vector< Attribute > a) {
|
||||
name = n;
|
||||
att = a;
|
||||
}
|
||||
|
||||
void addTuple(vector< string > tuple) {
|
||||
|
||||
//Loop through the attribute columns
|
||||
for(int i = 0; i < att.size(); i++) {
|
||||
|
||||
//Loop through the elements in the i'th column
|
||||
for(int j = 0; j < att[i].values.size(); j++){
|
||||
|
||||
//In this column, at this element's spot, assign an element from the tuple vector to this spot
|
||||
(att[i].values[j]).assign(tuple[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void displayTableName() {
|
||||
cout << "The table name is: " << name << endl;
|
||||
}
|
||||
|
||||
vector< Attribute > getAttributes(){
|
||||
return att;
|
||||
}
|
||||
|
||||
int getSize() {
|
||||
return att.size();
|
||||
}
|
||||
};
|
36
test.cpp
36
test.cpp
|
@ -1,10 +1,44 @@
|
|||
#include <iostream>
|
||||
#include "DBEngine.h"
|
||||
//#include "DBEngine.h"
|
||||
#include <vector>
|
||||
#include "Attribute.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
/*
|
||||
DBEngine engine;
|
||||
Relation r;
|
||||
Attribute<int> a;
|
||||
*/
|
||||
|
||||
vector<string> shamWow;
|
||||
shamWow.push_back("rag");
|
||||
shamWow.push_back("sponge");
|
||||
shamWow.push_back("wooow");
|
||||
shamWow.push_back("cloth");
|
||||
|
||||
Attribute atributo;
|
||||
atributo.initializeAttribute("atributo",shamWow);
|
||||
atributo.display();
|
||||
|
||||
vector<string> doom;
|
||||
doom.push_back("zombieman");
|
||||
doom.push_back("revenant");
|
||||
doom.push_back("imp");
|
||||
doom.push_back("archvile");
|
||||
|
||||
Attribute atributo2;
|
||||
atributo2.initializeAttribute("attribute_2", doom);
|
||||
atributo2.display();
|
||||
|
||||
|
||||
|
||||
|
||||
string line1 = "Table_1";
|
||||
|
||||
|
||||
|
||||
//Relation r(line1, my_attributes);
|
||||
}
|
||||
|
|
Reference in a new issue