121 lines
2.6 KiB
C++
Executable file
121 lines
2.6 KiB
C++
Executable file
#include <iostream>
|
|
#include <vector>
|
|
#include "Attribute.h"
|
|
|
|
//Functional
|
|
class Relation {
|
|
string name; //The title the user gives it
|
|
vector<Attribute> att; //A vector of the columns
|
|
int size;
|
|
|
|
public:
|
|
Relation(string n, vector<Attribute> a) {
|
|
name = n;
|
|
att = a;
|
|
size = a.size();
|
|
}
|
|
|
|
int getSize() { return size; }
|
|
|
|
/*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].getValues().size(); j++){
|
|
|
|
//In this column, at this element's spot, assign an element from the tuple vector to this spot
|
|
att[i].addRow(tuple[i]);
|
|
size++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void removeTuple(int tupleNum) {
|
|
if (tupleNum > att[0].getSize() || tupleNum < 0)
|
|
{
|
|
cout<<"ERROR! index out of bound"<<endl;
|
|
}
|
|
|
|
else
|
|
{
|
|
cout << "a" + att.size();
|
|
for(int i = 0; i < att.size(); ++i) //for all the attributes
|
|
{
|
|
cout << "SSSSSSSSSSSSSSSSSSSSSSSSSS" + tupleNum;
|
|
att[i].getValues().erase(att[i].getValues().begin()+ tupleNum);
|
|
}
|
|
}
|
|
}
|
|
|
|
vector<int> findTuple(string attributeType, string type)
|
|
{
|
|
vector<int> tupleSlot; // tuples that have the attribute in question
|
|
for (int i = 0; i < att.size(); ++i)// find attribute in question
|
|
{
|
|
if(att[i].getName() == attributeType)
|
|
{
|
|
for (int j = 0; j < att[i].getSize(); ++j)//search through all the values of the attribute column
|
|
{
|
|
if (att[i].getElementAt(j) == type)
|
|
{
|
|
tupleSlot.push_back(j);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
return tupleSlot;
|
|
}*/
|
|
|
|
string getTableName() {
|
|
return name;
|
|
}
|
|
|
|
void displayTableName() {
|
|
cout << "The table name is: " << name << endl;
|
|
}
|
|
|
|
vector<Attribute> getAttributes() {
|
|
return att;
|
|
}
|
|
|
|
//assumes that all attribute titles are unique
|
|
void projectQuery(string input) {
|
|
cout << "-----------Initiated Query Projection---------" << endl;
|
|
for(int i = 0; i < att.size(); i++) {
|
|
if(att[i].getName() == input) {
|
|
cout << "Column Title: " << input << endl;
|
|
for(int j = 0; j < att[i].getSize(); j++) {
|
|
cout << att[i].getValues()[j] << endl;
|
|
}
|
|
|
|
break;
|
|
}
|
|
else
|
|
cout << "Attribute input not valid" << endl;
|
|
}
|
|
}
|
|
|
|
void display() {
|
|
cout<<"\nDisplay of relation--------------------------------"<<endl;
|
|
cout<<"Relation name: "<<name<<endl;
|
|
for (int i = 0; i < size; ++i)
|
|
{
|
|
cout<<"\n";
|
|
att[i].display();
|
|
}
|
|
}
|
|
|
|
//make this better
|
|
vector<string> getDomains() {
|
|
vector<string> ds;
|
|
|
|
for (int i = 0; i < size; ++i)
|
|
{
|
|
ds.push_back(att[i].getType());
|
|
}
|
|
|
|
return ds;
|
|
}
|
|
};
|