diff --git a/Attribute.cpp b/Attribute.cpp new file mode 100755 index 0000000..9a66043 --- /dev/null +++ b/Attribute.cpp @@ -0,0 +1,57 @@ +#include +#include +#include "Attribute.h" + +Attribute::Attribute(string n, string t, bool k){ + name = n; + type = t; + key = k; + size = 0; +} + +void Attribute::addCell(string v){ + values.push_back(v); + size++; +} + +string Attribute::operator[](int i){ + return values[i]; +} + +vector Attribute::getValues(){ + return values; +} + +string Attribute::getName(){ + return name; +} + +string Attribute::getType(){ + return type; +} + +bool Attribute::isKey(){ + return key; +} + +void Attribute::setName(string s){ + name = s; +} + +//may need to change primary key implementation +int Attribute::getSize(){ + return size; +} + +void Attribute::display(){ + cout << "-------------\n"; + cout << name << "\n" << type << "\n\n"; + + vector::iterator it = values.begin(); + while (it != values.end()){ + cout << *it << "\n"; + it++; + } + + cout << "-------------\n"; +} \ No newline at end of file diff --git a/Attribute.h b/Attribute.h index 084706a..30f10ee 100755 --- a/Attribute.h +++ b/Attribute.h @@ -3,9 +3,6 @@ using namespace std; -//Funtional, might need more functionality - -//template class Attribute{ vector values; string name; @@ -14,35 +11,14 @@ class Attribute{ int size; public: - Attribute(string n, string t, bool k){ - name = n; - type = t; - key = k; - size = 0; - } - - void addCell(string v){ - values.push_back(v); - size++; - } - - string operator[](int i){ return values[i]; } - vector getValues(){ return values; } - string getName(){ return name; } - string getType(){ return type; } - bool isKey(){ return key; } - int getSize(){ return size; } //may need to change primary key implementation - - void display(){ - cout << "-------------\n"; - cout << name << "\n" << type << "\n\n"; - - vector::iterator it = values.begin(); - while (it != values.end()){ - cout << *it << "\n"; - it++; - } - - cout << "-------------\n"; - } + Attribute(string n, string t, bool k); + void addCell(string v); + string operator[](int i); + vector getValues(); + string getName(); + string getType(); + bool isKey(); + int getSize(); + void setName(string s); + void display(); }; diff --git a/DBEngine.cpp b/DBEngine.cpp new file mode 100755 index 0000000..a813c90 --- /dev/null +++ b/DBEngine.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include "DBEngine.h" + +DBEngine::DBEngine(){ + size = 0; +} + +void DBEngine::createTable(string n){ + Relation r(n); + tables.push_back(r); + size++; +} + +void DBEngine::createTable(string n, vector a){ + Relation r(n, a); + tables.push_back(r); + size++; +} + +void DBEngine::createTable(Relation r){ + tables.push_back(r); + size++; +} + +vector DBEngine::getRelations(){ + return tables; +} + +Relation DBEngine::getTableFromName(string n){ + //will return first occurence + for(int i = 0; i < tables.size(); i++){ + if (tables[i].getTableName() == n){ + return tables[i]; + } + } +} + +void DBEngine::saveToFile(vector cmds){ + //writes nothing meaningful + ofstream file; + file.open("savefile.db"); + + for(int i = 0; i < cmds.size(); ++i){ + file << cmds[i] << endl; + } + + file.close(); +} + +//assumes that all attribute titles are unique +Relation DBEngine::projection(vector input, Relation r){ + + +// for(int i = 0; i < input.size(); i++) { +// it = find(r.getAttributes().begin(), r.getAttributes().end(), input[i]) + + //if(r[i].getName == input[]) +// } +} +/* +void renameAttribute(vector v, string o, string s){ + for(int i = 0; i < v.size(); ++i){ + if(v[i].getName() == o){ + v[i].setName(s); + } + } +} +*/ diff --git a/DBEngine.h b/DBEngine.h index 792c36b..f2e5e3f 100755 --- a/DBEngine.h +++ b/DBEngine.h @@ -4,53 +4,25 @@ #include "Relation.h" //still in progress -class DBEngine { +class DBEngine{ vector tables; int size; public: - DBEngine(){ - size = 0; - } - - void createTable(string n) { - Relation r(n); - tables.push_back(r); - size++; - } - - void createTable(string n, vector a) { - Relation r(n, a); - tables.push_back(r); - size++; - } + DBEngine(); + void createTable(string n); + void createTable(string n, vector a); + void createTable(Relation r); + vector getRelations(); + //void showTable(Relation r); + Relation getTableFromName(string n); + void saveToFile(vector cmds); - void createTable(Relation r){ - tables.push_back(r); - size++; - } - - vector getRelations(){ return tables; } - //void showTable(Relation r){} - - Relation getTableFromName(string n){ - //will return first occurence - for(int i = 0; i < tables.size(); i++){ - if (tables[i].getTableName() == n){ - return tables[i]; - } - } - } - - void saveToFile(vector cmds){ - //writes nothing meaningful - ofstream file; - file.open("savefile.db"); - - for(int i = 0; i < cmds.size(); ++i){ - file << cmds[i] << endl; - } - - file.close(); - } + //operations + //void selection(); + Relation projection(vector input, Relation r); + //void renaming(); + //void setUnion(); + //void setDiff(); + //void crossProduct(); }; diff --git a/Relation.cpp b/Relation.cpp new file mode 100755 index 0000000..09eeaf7 --- /dev/null +++ b/Relation.cpp @@ -0,0 +1,44 @@ +#include +#include +#include "Relation.h" + +Relation::Relation(string n){ + name = n; + size = 0; +} + +Relation::Relation(string n, vector a){ + name = n; + att = a; + size = a.size(); +} + +string Relation::getTableName(){ + return name; +} + +vector Relation::getAttributes(){ + return att; +} + +vector Relation::getAttributeNames(){ + vector temp; + for(int i = 0; i < size; ++i){ + temp.push_back(att[i].getName()); + } + return temp; +} + +int Relation::getSize(){ + return size; +} + +void Relation::display(){ + cout << "--------------------------\n"; + cout << name << "\n"; + for (int i = 0; i < att.size(); ++i){ + att[i].display(); + } + + cout << "--------------------------\n"; +} diff --git a/Relation.h b/Relation.h index a404706..75ef810 100755 --- a/Relation.h +++ b/Relation.h @@ -2,53 +2,17 @@ #include #include "Attribute.h" -//Functional -class Relation { - string name; //The title the user gives it - vector att; //A vector of the columns +class Relation{ + string name; + vector att; int size; public: - Relation(string n) { - name = n; - size = 0; - } - Relation(string n, vector a) { - name = n; - att = a; - size = a.size(); - } - - //addAttribute - - string getTableName() { return name; } - vector getAttributes() { return att; } - int getSize() { return size; } - - //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 << "--------------------------\n"; - cout << name << "\n"; - for (int i = 0; i < att.size(); ++i){ - att[i].display(); - } - - cout << "--------------------------\n"; - } + Relation(string n); + Relation(string n, vector a); + string getTableName(); + vector getAttributes(); + vector getAttributeNames(); + int getSize(); + void display(); }; diff --git a/a.out b/a.out deleted file mode 100755 index 1a24079..0000000 Binary files a/a.out and /dev/null differ diff --git a/test.cpp b/test.cpp index ad5181f..af3d9b4 100755 --- a/test.cpp +++ b/test.cpp @@ -35,4 +35,10 @@ int main() { //vector rs = engine.getRelations(); Relation r2 = engine.getTableFromName("Food"); r2.display(); + + vector v1 = r2.getAttributeNames(); + + for (int i = 0; i < v.size(); ++i){ + cout << v1[i]; + } }