This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
dmspine64backup/Relation.h

122 lines
2.6 KiB
C
Raw Normal View History

2015-09-15 20:17:52 -05:00
#include <iostream>
#include <vector>
#include "Attribute.h"
2015-09-15 21:31:19 -05:00
//Functional
2015-09-15 20:17:52 -05:00
class Relation {
string name; //The title the user gives it
2015-09-15 20:55:21 -05:00
vector<Attribute> att; //A vector of the columns
2015-09-15 22:20:14 -05:00
int size;
2015-09-15 20:17:52 -05:00
public:
2015-09-15 22:18:19 -05:00
Relation(string n, vector<Attribute> a) {
2015-09-15 20:17:52 -05:00
name = n;
att = a;
2015-09-15 22:27:32 -05:00
size = a.size();
2015-09-15 20:55:21 -05:00
}
2015-09-15 20:17:52 -05:00
2015-09-15 22:02:16 -05:00
int getSize() { return size; }
2015-09-15 23:44:58 -05:00
/*void addTuple(vector<string> tuple) {
2015-09-15 20:17:52 -05:00
//Loop through the attribute columns
for(int i = 0; i < att.size(); i++) {
//Loop through the elements in the i'th column
2015-09-15 22:23:41 -05:00
for(int j = 0; j < att[i].getValues().size(); j++){
2015-09-15 20:17:52 -05:00
//In this column, at this element's spot, assign an element from the tuple vector to this spot
2015-09-15 20:55:21 -05:00
att[i].addRow(tuple[i]);
2015-09-15 22:08:18 -05:00
size++;
2015-09-15 20:17:52 -05:00
}
}
}
2015-09-15 23:38:44 -05:00
void removeTuple(int tupleNum) {
2015-09-15 21:49:49 -05:00
if (tupleNum > att[0].getSize() || tupleNum < 0)
{
cout<<"ERROR! index out of bound"<<endl;
}
else
{
2015-09-15 23:38:44 -05:00
cout << "a" + att.size();
2015-09-15 21:49:49 -05:00
for(int i = 0; i < att.size(); ++i) //for all the attributes
{
2015-09-15 23:38:44 -05:00
cout << "SSSSSSSSSSSSSSSSSSSSSSSSSS" + tupleNum;
att[i].getValues().erase(att[i].getValues().begin()+ tupleNum);
2015-09-15 21:49:49 -05:00
}
}
2015-09-15 20:17:52 -05:00
}
2015-09-15 22:08:18 -05:00
2015-09-15 23:21:38 -05:00
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;
2015-09-15 23:44:58 -05:00
}*/
2015-09-15 23:21:38 -05:00
2015-09-15 20:55:21 -05:00
string getTableName() {
return name;
}
2015-09-15 20:17:52 -05:00
void displayTableName() {
cout << "The table name is: " << name << endl;
}
2015-09-15 21:31:19 -05:00
vector<Attribute> getAttributes() {
2015-09-15 20:17:52 -05:00
return att;
}
2015-09-15 23:13:28 -05:00
//assumes that all attribute titles are unique
2015-09-15 22:02:16 -05:00
void projectQuery(string input) {
2015-09-15 21:49:49 -05:00
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++) {
2015-09-15 22:23:41 -05:00
cout << att[i].getValues()[j] << endl;
2015-09-15 21:49:49 -05:00
}
break;
}
else
cout << "Attribute input not valid" << endl;
}
2015-09-15 20:17:52 -05:00
}
2015-09-15 21:49:49 -05:00
2015-09-15 22:02:16 -05:00
void display() {
2015-09-15 23:13:28 -05:00
cout<<"\nDisplay of relation--------------------------------"<<endl;
2015-09-15 20:23:47 -05:00
cout<<"Relation name: "<<name<<endl;
2015-09-15 22:23:41 -05:00
for (int i = 0; i < size; ++i)
2015-09-15 23:13:28 -05:00
{
cout<<"\n";
2015-09-15 20:36:33 -05:00
att[i].display();
2015-09-15 20:23:47 -05:00
}
}
2015-09-15 22:36:44 -05:00
//make this better
vector<string> getDomains() {
vector<string> ds;
for (int i = 0; i < size; ++i)
{
ds.push_back(att[i].getType());
}
return ds;
}
2015-09-15 20:17:52 -05:00
};