Updated user.h
This commit is contained in:
commit
48a18872c2
19 changed files with 2544 additions and 0 deletions
92
Attribute.cpp
Executable file
92
Attribute.cpp
Executable file
|
@ -0,0 +1,92 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "Attribute.h"
|
||||
|
||||
Attribute::Attribute(){
|
||||
name = "";
|
||||
type = "";
|
||||
key = 0;
|
||||
size = 0;
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
Attribute::Attribute(string n, string t, bool k){
|
||||
name = n;
|
||||
type = t;
|
||||
key = k;
|
||||
size = 0;
|
||||
limit = 20;
|
||||
}
|
||||
|
||||
Attribute::Attribute(string n, string t, bool k, int s){
|
||||
name = n;
|
||||
type = t;
|
||||
key = k;
|
||||
size = 0;
|
||||
limit = s;
|
||||
}
|
||||
|
||||
void Attribute::addCell(string v){
|
||||
values.push_back(v);
|
||||
size++;
|
||||
}
|
||||
|
||||
void Attribute::removeCell(int index){
|
||||
values.erase(values.begin() + index);
|
||||
size--;
|
||||
}
|
||||
|
||||
string Attribute::operator[](int i){
|
||||
return values[i];
|
||||
}
|
||||
|
||||
vector<string> Attribute::getValues(){
|
||||
return values;
|
||||
}
|
||||
|
||||
string Attribute::getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
void Attribute::setName(string s){
|
||||
name = s;
|
||||
}
|
||||
|
||||
void Attribute::setValue(string s, int index)
|
||||
{
|
||||
values[index] = s;
|
||||
}
|
||||
|
||||
string Attribute::getType(){
|
||||
return type;
|
||||
}
|
||||
|
||||
bool Attribute::isKey(){
|
||||
return key;
|
||||
}
|
||||
|
||||
int Attribute::getSize(){
|
||||
return size;
|
||||
}
|
||||
|
||||
void Attribute::display(){
|
||||
cout << "-------------\n";
|
||||
cout << name << "\n" << type;
|
||||
if(type == "VARCHAR")
|
||||
{
|
||||
cout << "(" << limit << ")";
|
||||
}
|
||||
cout << "\n\n";
|
||||
|
||||
vector<string>::iterator it = values.begin();
|
||||
while (it != values.end()){
|
||||
cout << *it << "\n";
|
||||
it++;
|
||||
}
|
||||
|
||||
cout << "-------------\n";
|
||||
}
|
||||
|
||||
void Attribute::clearAllValues(){
|
||||
values.clear();
|
||||
}
|
31
Attribute.h
Executable file
31
Attribute.h
Executable file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Attribute{
|
||||
vector<string> values;
|
||||
string name;
|
||||
string type;
|
||||
bool key;
|
||||
int size;
|
||||
int limit;
|
||||
|
||||
public:
|
||||
Attribute();
|
||||
Attribute(string n, string t, bool k);
|
||||
Attribute(string n, string t, bool k, int s);
|
||||
void addCell(string v);
|
||||
void removeCell(int index);
|
||||
string operator[](int i);
|
||||
vector<string> getValues();
|
||||
string getName();
|
||||
void setName(string s);
|
||||
void setValue(string s, int index);
|
||||
string getType();
|
||||
bool isKey();
|
||||
int getSize();
|
||||
void display();
|
||||
void clearAllValues();
|
||||
};
|
59
Condition.cpp
Executable file
59
Condition.cpp
Executable file
|
@ -0,0 +1,59 @@
|
|||
#include <iostream>
|
||||
#include "Attribute.h"
|
||||
#include "Relation.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
Relation equality(string attName, string s, Relation r){
|
||||
Attribute att = r.getAttributeByName(attName);
|
||||
vector<Attribute> r_atts = r.getAttributes();
|
||||
vector<Attribute> new_atts = r_atts;
|
||||
|
||||
for (int i = 0; i < new_atts.size(); ++i) {
|
||||
new_atts[i].clearAllValues();
|
||||
}
|
||||
|
||||
for (int i = 0; i < att.getSize(); ++i) {
|
||||
if (att[i] == s){
|
||||
for (int j = 0; j < r_atts.size(); ++j){
|
||||
new_atts[j].addCell(r_atts[j][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//currently all returned relations are called TEMP
|
||||
Relation new_r("TEMP", new_atts);
|
||||
return new_r;
|
||||
}
|
||||
|
||||
/*
|
||||
vector<Attribute> equality(Attribute a, int i){
|
||||
for (int i = 0; i < a.getSize(); ++i) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
vector<Attribute> gt(Attribute a, int i){
|
||||
for (int i = 0; i < a.getSize(); ++i) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
vector<Attribute> lt(Attribute a, int i){
|
||||
for (int i = 0; i < a.getSize(); ++i) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
vector<Attribute> gte(Attribute a, int i){
|
||||
for (int i = 0; i < a.getSize(); ++i) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
vector<Attribute> lte(Attribute a, int i){
|
||||
for (int i = 0; i < a.getSize(); ++i) {
|
||||
//
|
||||
}
|
||||
}
|
||||
*/
|
7
Condition.h
Executable file
7
Condition.h
Executable file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
#include "Relation.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//currently only implementing for comparison
|
||||
Relation equality(string attName, string s, Relation r);
|
40
DBApp.cpp
Executable file
40
DBApp.cpp
Executable file
|
@ -0,0 +1,40 @@
|
|||
#include <string> // std::string
|
||||
#include <iostream> // std::cout
|
||||
#include <sstream> // std::stringstream
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Parser.h"
|
||||
#include "DBEngine.h"
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
int main()
|
||||
{
|
||||
cout << "**********************" << endl;
|
||||
cout << "* Generic Restaurant *" << endl;
|
||||
cout << "**********************" << endl;
|
||||
cout << "- Login -" << endl;
|
||||
cout << "1. Login" << endl;
|
||||
cout << "2. Request new account" << endl;
|
||||
cout << "Enter coice: ";
|
||||
int n;
|
||||
cin >> n;
|
||||
string u;
|
||||
string p;
|
||||
switch(n)
|
||||
{
|
||||
case 1: cout << "- Login -" << endl;
|
||||
cout << "Enter username: ";
|
||||
cin >> u;
|
||||
cout << "Enter password: ";
|
||||
cin >> p;
|
||||
// implement user database.
|
||||
break;
|
||||
case 2: cout << "Not implemented." << endl;
|
||||
break; // not implemented.
|
||||
default: cout << "Not an option." << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
126
DBAppV2.cpp
Executable file
126
DBAppV2.cpp
Executable file
|
@ -0,0 +1,126 @@
|
|||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
|
||||
void yourAccount()
|
||||
{
|
||||
cout<<"name: yourName"<<endl;
|
||||
cout<<"other stuff related to this user\n\n"<<endl;
|
||||
//somehow display user information
|
||||
// int choice;
|
||||
// cin>>choice;
|
||||
cout<<"0. Return to main menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
}
|
||||
|
||||
void goToBoard()
|
||||
{
|
||||
cout<<"Board x"<<endl;
|
||||
// int choice;
|
||||
// cin>>choice;
|
||||
cout<<"0. Return to main menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
}
|
||||
|
||||
void boardList()
|
||||
{
|
||||
cout<<"Showing all boards:"<<endl;
|
||||
// int choice;
|
||||
// cin>>choice;
|
||||
cout<<"0. Return to main menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
}
|
||||
|
||||
|
||||
void BoardMenu()
|
||||
{
|
||||
int choice;
|
||||
cin>>choice;
|
||||
cout<<"Boards will be displayed soon"<<endl;
|
||||
//do some stuff to display boards
|
||||
cout<<"1. List of boards"<<endl;
|
||||
cout<<"2. Go to board (enter shortcut[first few characters])"<<endl;
|
||||
cout<<"0. Return to main menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
switch(choice)
|
||||
{
|
||||
case 1: boardList();
|
||||
case 2: goToBoard();
|
||||
}
|
||||
}
|
||||
|
||||
void showMessages()
|
||||
{
|
||||
cout<<"Messages will be displayed soon"<<endl;
|
||||
//do some stuff to display messages
|
||||
// int choice;
|
||||
// cin>>choice;
|
||||
cout<<"0. Return to main menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
}
|
||||
|
||||
void showGroups()
|
||||
{
|
||||
cout<<"Groups will be displayed soon"<<endl;
|
||||
//do some stuff to display groups
|
||||
// int choice;
|
||||
// cin>>choice;
|
||||
cout<<"0. Return to main menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
}
|
||||
|
||||
void mainMenu()
|
||||
{
|
||||
|
||||
|
||||
cout<<"***************"<<endl;
|
||||
cout<<"** Main Menu **"<<endl;
|
||||
cout<<"***************\n\n"<<endl;
|
||||
cout<<"1. Your account"<<endl;
|
||||
cout<<"2. Boards"<<endl;
|
||||
cout<<"3. Messages"<<endl;
|
||||
cout<<"4. Groups\n"<<endl;
|
||||
cout<<"Enter choice: ";
|
||||
int choice;
|
||||
cin>>choice;
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
case 1: yourAccount();
|
||||
case 2: BoardMenu();
|
||||
case 3: showMessages();
|
||||
case 4: showGroups();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
cout<<"***************************************"<<endl;
|
||||
cout<<"Welcome to our BBS "<<endl;
|
||||
cout<<"***************************************"<<endl;
|
||||
|
||||
cout<<"** Enter BBS **"<<endl;
|
||||
cout<<"1. Login"<<endl;
|
||||
cout<<"2. Request new account\n\n";
|
||||
cout<<"Enter choice: ";
|
||||
int choice;
|
||||
cin>>choice;
|
||||
|
||||
|
||||
if (choice == 1)
|
||||
{
|
||||
cout<<"ramera"<<endl;
|
||||
mainMenu();
|
||||
}
|
||||
else {cout<<"oops";}
|
||||
}
|
||||
|
||||
*/
|
290
DBEngine.cpp
Executable file
290
DBEngine.cpp
Executable file
|
@ -0,0 +1,290 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "Condition.h"
|
||||
#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<Attribute> a){
|
||||
Relation r(n, a);
|
||||
tables.push_back(r);
|
||||
size++;
|
||||
}
|
||||
|
||||
void DBEngine::createTable(Relation r){
|
||||
tables.push_back(r);
|
||||
size++;
|
||||
}
|
||||
|
||||
void DBEngine::insertValues(string r, vector<string> v)
|
||||
{
|
||||
for(int i = 0; i < tables.size(); i++)
|
||||
{
|
||||
if (tables[i].getTableName() == r)
|
||||
{
|
||||
tables[i].insertTuple(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DBEngine::storeCommands(string s){
|
||||
commands.push_back(s);
|
||||
}
|
||||
|
||||
void DBEngine::save(){
|
||||
|
||||
ofstream file;
|
||||
file.open("savefile.txt");
|
||||
|
||||
for(int i = 0; i < commands.size(); ++i){
|
||||
file << commands[i] << endl;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void DBEngine::deleteRelation(string n)
|
||||
{
|
||||
// to conserve memory after closing a file.
|
||||
for(int i = 0; i < tables.size(); i++)
|
||||
{
|
||||
if (tables[i].getTableName() == n)
|
||||
{
|
||||
tables.erase(tables.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DBEngine::save(string n){
|
||||
|
||||
ofstream file;
|
||||
string name = n + ".txt";
|
||||
file.open(name);
|
||||
|
||||
for(int i = 0; i < commands.size() - 1; ++i)
|
||||
{
|
||||
if(commands[i].substr(0, 4) == "SAVE")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(commands[i].substr(0, 4) == "SHOW")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(commands[i].substr(0, 4) == "OPEN")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(commands[i].substr(0, 5) == "CLOSE")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
file << commands[i] << endl;
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
vector<Relation> DBEngine::getRelations(){
|
||||
return tables;
|
||||
}
|
||||
|
||||
bool DBEngine::isRelation(string n)
|
||||
{
|
||||
for(int i = 0; i < tables.size(); i++)
|
||||
{
|
||||
if (tables[i].getTableName() == n)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Relation& DBEngine::getTableFromName(string n)
|
||||
{
|
||||
for(int i = 0; i < tables.size(); i++){
|
||||
if (tables[i].getTableName() == n){
|
||||
return tables[i];
|
||||
}
|
||||
}
|
||||
|
||||
cout << "FAILURE TO FIND: could not locate a Relation with this name.";
|
||||
return tables[0];
|
||||
}
|
||||
|
||||
Relation DBEngine::selection(string attName, string s, Relation r){
|
||||
return equality(attName, s, r);
|
||||
}
|
||||
|
||||
//assumes that all attribute titles are unique
|
||||
Relation DBEngine::projection(vector<string> input, Relation r){
|
||||
|
||||
vector<Attribute> v;
|
||||
string new_name = r.getTableName() + " Projection";
|
||||
|
||||
for(int i = 0; i < input.size(); ++i)
|
||||
{
|
||||
for(int j = 0; j < r.getSize(); ++j)
|
||||
{
|
||||
if((r.getAttributes())[j].getName() == input[i])
|
||||
{
|
||||
v.push_back((r.getAttributes())[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Relation temp(new_name, v);
|
||||
return temp;
|
||||
}
|
||||
|
||||
//test error matching
|
||||
Relation DBEngine::rename(vector<string> newnames, Relation &r)
|
||||
{
|
||||
vector<string> temp;
|
||||
if (r.getSize() != newnames.size()) {
|
||||
cout << "FAILURE TO RENAME: number of attributes do not match.\n";
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = r.getAttributeNames();
|
||||
for(int i = 0; i < temp.size(); ++i)
|
||||
{
|
||||
r.renameAttribute(temp[i], newnames[i]);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Relation DBEngine::setUnion(Relation r1, Relation r2){
|
||||
if (r1.getAttributeNames() != r2.getAttributeNames()){
|
||||
cout << "Failure to union: the relations are not union-compatible.\nreturning the first relation.\n";
|
||||
return r1;
|
||||
}
|
||||
|
||||
else {
|
||||
//currently all returned relations are called TEMP
|
||||
Relation new_r = r1;
|
||||
new_r.setTableName("TEMP");
|
||||
vector<string> temp;
|
||||
bool duplicate = false;
|
||||
|
||||
for (int i = 0; i < r2.getAttributes()[0].getSize(); ++i) {
|
||||
temp = r2.getTuple(i);
|
||||
|
||||
for (int j = 0; j < new_r.getAttributes()[0].getSize(); ++j){
|
||||
if (temp == new_r.getTuple(j)){
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!duplicate) {
|
||||
new_r.insertTuple(temp);
|
||||
}
|
||||
|
||||
duplicate = false;
|
||||
}
|
||||
|
||||
return new_r;
|
||||
}
|
||||
}
|
||||
|
||||
Relation DBEngine::setDiff(Relation r1, Relation r2){
|
||||
if (r1.getAttributeNames() != r2.getAttributeNames()){
|
||||
cout << "Failure to diff: the relations are not union-compatible.\nreturning the first relation.\n";
|
||||
return r1;
|
||||
}
|
||||
|
||||
else {
|
||||
//currently all returned relations are called TEMP
|
||||
Relation new_r = r1;
|
||||
new_r.setTableName("TEMP");
|
||||
vector<string> temp;
|
||||
//bool duplicate = false;
|
||||
|
||||
int size = 0;
|
||||
|
||||
|
||||
for(int x = 0; x < r2.getAttributes().size(); ++x)
|
||||
{
|
||||
|
||||
for (int i = 0; i < r2.getAttributes()[x].getSize(); ++i)
|
||||
{
|
||||
|
||||
temp = r2.getTuple(i);
|
||||
|
||||
for(int y = 0; y < new_r.getAttributes().size(); ++y)
|
||||
{
|
||||
size = new_r.getAttributes()[y].getSize();
|
||||
new_r.getAttributes()[y].getSize();
|
||||
for (int j = 0; j < size; ++j)
|
||||
{
|
||||
for(int a = 0; a < temp.size(); ++a)
|
||||
{
|
||||
for(int b = 0; b < new_r.getTuple(j).size(); ++b)
|
||||
{
|
||||
if (temp[a] == new_r.getTuple(j)[b])
|
||||
{
|
||||
new_r.removeFromTuple(b, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
size = new_r.getAttributes()[y].getSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new_r;
|
||||
}
|
||||
}
|
||||
|
||||
Relation DBEngine::crossProduct(Relation r1, Relation r2){
|
||||
vector<Attribute> new_atts = r1.getAttributes();
|
||||
int r1_attsize = r1.getAttributes()[0].getSize();
|
||||
int r2_attsize = r2.getAttributes()[0].getSize();
|
||||
|
||||
for (int i = 0; i < r2_attsize; ++i) {
|
||||
new_atts.push_back(r2.getAttributes()[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < new_atts.size(); ++i) {
|
||||
new_atts[i].clearAllValues();
|
||||
}
|
||||
|
||||
//currently all returned relations are called TEMP
|
||||
Relation new_r("TEMP", new_atts);
|
||||
|
||||
vector<string> r1_tuple;
|
||||
vector<string> r2_tuple;
|
||||
vector<string> temp;
|
||||
|
||||
for (int i = 0; i < r1_attsize; ++i) {
|
||||
r1_tuple = r1.getTuple(i);
|
||||
|
||||
for (int j = 0; j < r2_attsize; ++j) {
|
||||
r2_tuple = r2.getTuple(j);
|
||||
temp = r1_tuple;
|
||||
temp.insert(temp.end(), r2_tuple.begin(), r2_tuple.end());
|
||||
|
||||
new_r.insertTuple(temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new_r;
|
||||
}
|
34
DBEngine.h
Executable file
34
DBEngine.h
Executable file
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "Relation.h"
|
||||
|
||||
//still in progress
|
||||
class DBEngine{
|
||||
vector<Relation> tables;
|
||||
vector<string> commands;
|
||||
int size;
|
||||
|
||||
public:
|
||||
DBEngine();
|
||||
void createTable(string n);
|
||||
void createTable(string n, vector<Attribute> a);
|
||||
void createTable(Relation r);
|
||||
void insertValues(string r, vector <string> v);
|
||||
vector<Relation> getRelations();
|
||||
bool isRelation(string n);
|
||||
Relation& getTableFromName(string n);
|
||||
void saveToFile(vector<string> cmds);
|
||||
Relation selection(string attName, string s, Relation r);
|
||||
Relation projection(vector<string> input, Relation r);
|
||||
Relation product(string s1, Relation r1, Relation r2);
|
||||
void deleteRelation(string n);
|
||||
void save();
|
||||
void save(string n);
|
||||
void storeCommands(string s);
|
||||
Relation rename(vector<string> newnames, Relation &r);
|
||||
Relation setUnion(Relation r1, Relation r2);
|
||||
Relation setDiff(Relation r1, Relation r2);
|
||||
Relation crossProduct(Relation r1, Relation r2);
|
||||
};
|
1126
Parser.cpp
Executable file
1126
Parser.cpp
Executable file
File diff suppressed because it is too large
Load diff
419
Parser.h
Executable file
419
Parser.h
Executable file
|
@ -0,0 +1,419 @@
|
|||
#include <string> // std::string
|
||||
#include <iostream> // std::cout
|
||||
#include <sstream> // std::stringstream
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "DBEngine.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class PRelation
|
||||
{
|
||||
string name;
|
||||
|
||||
public:
|
||||
PRelation()
|
||||
{
|
||||
name = "~";
|
||||
}
|
||||
|
||||
PRelation(string str)
|
||||
{
|
||||
name = str;
|
||||
}
|
||||
|
||||
void setPRelation(string str)
|
||||
{
|
||||
name = str;
|
||||
}
|
||||
string getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
};
|
||||
|
||||
class PAttribute
|
||||
{
|
||||
string name;
|
||||
string type;
|
||||
bool key;
|
||||
int size;
|
||||
|
||||
public:
|
||||
PAttribute()
|
||||
{
|
||||
name = "~";
|
||||
type = "~";
|
||||
key = false;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
PAttribute(string str, string t)
|
||||
{
|
||||
name = str;
|
||||
type = t;
|
||||
key = false;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
PAttribute(string str, string t, int s)
|
||||
{
|
||||
name = str;
|
||||
type = t;
|
||||
key = false;
|
||||
size = s;
|
||||
}
|
||||
|
||||
void setPAttributeName(string str)
|
||||
{
|
||||
name = str;
|
||||
}
|
||||
|
||||
void setPAttributeType(string t)
|
||||
{
|
||||
type = t;
|
||||
}
|
||||
|
||||
void setPAttributeKey()
|
||||
{
|
||||
key = true;
|
||||
}
|
||||
|
||||
void setPAttributeSize(int s)
|
||||
{
|
||||
size = s;
|
||||
}
|
||||
|
||||
string getPAttribute()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
string getPAttributeType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
bool getPAttributeKey()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
int getPAttributeSize()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
};
|
||||
|
||||
class PUnion
|
||||
{
|
||||
string Un1;
|
||||
string Un2;
|
||||
|
||||
public:
|
||||
PUnion()
|
||||
{
|
||||
Un1 = "~";
|
||||
Un2 = "~";
|
||||
}
|
||||
|
||||
PUnion (string s1, string s2)
|
||||
{
|
||||
Un1 = s1;
|
||||
Un2 = s2;
|
||||
}
|
||||
|
||||
string getPUnion()
|
||||
{
|
||||
return "Union of " + Un1 + " and " + Un2;
|
||||
}
|
||||
};
|
||||
|
||||
class PProduct
|
||||
{
|
||||
string Pr1;
|
||||
string Pr2;
|
||||
|
||||
public:
|
||||
PProduct()
|
||||
{
|
||||
Pr1 = "~";
|
||||
Pr2 = "~";
|
||||
}
|
||||
|
||||
PProduct(string s1, string s2)
|
||||
{
|
||||
Pr1 = s1;
|
||||
Pr2 = s2;
|
||||
}
|
||||
|
||||
string getPProduct()
|
||||
{
|
||||
return "Product of " + Pr1 + " and " + Pr2;
|
||||
}
|
||||
};
|
||||
|
||||
class PDifference
|
||||
{
|
||||
string D1;
|
||||
string D2;
|
||||
|
||||
public:
|
||||
PDifference()
|
||||
{
|
||||
D1 = "~";
|
||||
D2 = "~";
|
||||
}
|
||||
|
||||
PDifference(string s1, string s2)
|
||||
{
|
||||
D1 = s1;
|
||||
D2 = s2;
|
||||
}
|
||||
|
||||
string getPDifference()
|
||||
{
|
||||
return "Difference of " + D1 + " and " + D2;
|
||||
}
|
||||
};
|
||||
|
||||
class PRenaming
|
||||
{
|
||||
string newName;
|
||||
string oldName;
|
||||
|
||||
public:
|
||||
PRenaming()
|
||||
{
|
||||
newName = "~";
|
||||
oldName = "~";
|
||||
}
|
||||
|
||||
PRenaming(string s1, string s2)
|
||||
{
|
||||
newName = s1;
|
||||
oldName = s2;
|
||||
}
|
||||
|
||||
string doRename()
|
||||
{
|
||||
return "Renaming " + oldName + " to " + newName;
|
||||
}
|
||||
};
|
||||
|
||||
class PProjection
|
||||
{
|
||||
string newName;
|
||||
string oldName;
|
||||
|
||||
public:
|
||||
PProjection()
|
||||
{
|
||||
newName = "~";
|
||||
oldName = "~";
|
||||
}
|
||||
|
||||
PProjection(string s1, string s2)
|
||||
{
|
||||
newName = s1;
|
||||
oldName = s2;
|
||||
}
|
||||
|
||||
string doPProjection()
|
||||
{
|
||||
return "Projecting " + oldName + " onto " + newName;
|
||||
}
|
||||
};
|
||||
|
||||
class POperand
|
||||
{
|
||||
string op;
|
||||
|
||||
public:
|
||||
|
||||
POperand()
|
||||
{
|
||||
op = "~";
|
||||
}
|
||||
|
||||
POperand(string str)
|
||||
{
|
||||
op = str;
|
||||
}
|
||||
|
||||
void setPOperand(string str)
|
||||
{
|
||||
op = str;
|
||||
}
|
||||
|
||||
string getPOperand()
|
||||
{
|
||||
return op;
|
||||
}
|
||||
};
|
||||
|
||||
class POp
|
||||
{
|
||||
string op;
|
||||
|
||||
public:
|
||||
POp()
|
||||
{
|
||||
op = "~";
|
||||
}
|
||||
|
||||
POp(string str)
|
||||
{
|
||||
op = str;
|
||||
}
|
||||
|
||||
void setPOp(string str)
|
||||
{
|
||||
op = str;
|
||||
}
|
||||
|
||||
string getPOp()
|
||||
{
|
||||
return op;
|
||||
}
|
||||
};
|
||||
|
||||
class PComparison
|
||||
{
|
||||
POp op;
|
||||
POperand operand1;
|
||||
POperand operand2;
|
||||
|
||||
public:
|
||||
PComparison()
|
||||
{
|
||||
op.setPOp("~");
|
||||
operand1.setPOperand("~");
|
||||
operand2.setPOperand("~");
|
||||
}
|
||||
|
||||
PComparison(string str1, string str2, string str3)
|
||||
{
|
||||
operand1.setPOperand(str1);
|
||||
op.setPOp(str2);
|
||||
operand2.setPOperand(str3);
|
||||
}
|
||||
|
||||
void setPComparison(string str1, string str2, string str3)
|
||||
{
|
||||
operand1.setPOperand(str1);
|
||||
op.setPOp(str2);
|
||||
operand2.setPOperand(str3);
|
||||
}
|
||||
|
||||
string getPComparison()
|
||||
{
|
||||
return operand1.getPOperand() + " " + op.getPOp() + " " + operand2.getPOperand();
|
||||
}
|
||||
};
|
||||
|
||||
class PConjunction
|
||||
{
|
||||
string conj;
|
||||
public:
|
||||
PConjunction()
|
||||
{
|
||||
conj = "~";
|
||||
}
|
||||
|
||||
PConjunction(string str)
|
||||
{
|
||||
conj = str;
|
||||
}
|
||||
|
||||
void setPConjunction(string str)
|
||||
{
|
||||
conj = str;
|
||||
}
|
||||
|
||||
string getPConjunction()
|
||||
{
|
||||
return conj;
|
||||
}
|
||||
};
|
||||
|
||||
class PCondition
|
||||
{
|
||||
string cond;
|
||||
public:
|
||||
|
||||
PCondition()
|
||||
{
|
||||
cond = "~";
|
||||
}
|
||||
|
||||
PCondition(string str)
|
||||
{
|
||||
cond = str;
|
||||
}
|
||||
|
||||
void setPCondition(string str)
|
||||
{
|
||||
cond = str;
|
||||
}
|
||||
|
||||
string getPCondition()
|
||||
{
|
||||
return cond;
|
||||
}
|
||||
};
|
||||
|
||||
class PSelection
|
||||
{
|
||||
string select;
|
||||
public:
|
||||
PSelection()
|
||||
{
|
||||
select = "~";
|
||||
}
|
||||
|
||||
PSelection(string str)
|
||||
{
|
||||
select = str;
|
||||
}
|
||||
|
||||
string getPSelection()
|
||||
{
|
||||
return select;
|
||||
}
|
||||
};
|
||||
|
||||
class PExpression
|
||||
{
|
||||
PRelation rel;
|
||||
PSelection sel;
|
||||
PProjection proj;
|
||||
PRenaming ren;
|
||||
PUnion un;
|
||||
PDifference diff;
|
||||
PProduct prod;
|
||||
string temp;
|
||||
|
||||
public:
|
||||
|
||||
PExpression()
|
||||
{
|
||||
}
|
||||
|
||||
PExpression(string str)
|
||||
{
|
||||
temp = str;
|
||||
}
|
||||
|
||||
void setPExpression(string str)
|
||||
{
|
||||
temp = str;
|
||||
}
|
||||
|
||||
string getPExpression()
|
||||
{
|
||||
return temp;
|
||||
}
|
||||
};
|
||||
|
||||
void parse(string s, DBEngine &e);
|
40
README.txt
Executable file
40
README.txt
Executable file
|
@ -0,0 +1,40 @@
|
|||
//---IMPORTANT---//
|
||||
|
||||
The function stoi() is used in the parser .cpp file to parse integers from the input.
|
||||
When compiling things with the parser included, make sure you compile using:
|
||||
|
||||
g++ -std=c++11 *.cpp
|
||||
|
||||
ALSO, now that we are compiling into a standalone executable, compile using this command:
|
||||
|
||||
g++ -o test -std=c++11 *.cpp
|
||||
|
||||
"test" can be anything you want, but for now our executable is "test".
|
||||
|
||||
//---------------//
|
||||
|
||||
I changed the name of the repo. To make everything pretty, rename your working folder, and type this line:
|
||||
|
||||
git remote set-url origin https://github.tamu.edu/USERNAME/DMS.git
|
||||
|
||||
I also set up development branches for each of us. I think this is the way we’re supposed to have it, but this is my first GitHub project so I’m not at all positive.
|
||||
When beginning to work:
|
||||
|
||||
git checkout beccadev
|
||||
|
||||
This switches to your development branch. At any time, just type git status to see what’s going on.
|
||||
Before doing anything, type:
|
||||
|
||||
git merge beccadev master
|
||||
git push
|
||||
|
||||
This updates your branch with the master branch, and pushes the update to GitHub. There is probably definitely a better way to do this. (I’m pretty sure you can use git clone somehow)
|
||||
Don’t forgot to use git add filename.txt to add any files you want saved to git. Or just use git add * to grab them all. For some reason it’s making me do this every time I edit anything, which is weird.
|
||||
Commit changes with git commit –m “something descriptive”.
|
||||
|
||||
If everything works the way you’ve anticipated and it compiles properly and completely done, return to master with git checkout master and merge:
|
||||
|
||||
git merge master beccadev
|
||||
|
||||
Type git push and you’re done.
|
||||
|
154
Relation.cpp
Executable file
154
Relation.cpp
Executable file
|
@ -0,0 +1,154 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "Relation.h"
|
||||
|
||||
Relation::Relation(string n){
|
||||
name = n;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
Relation::Relation(string n, vector<Attribute> a){
|
||||
name = n;
|
||||
att = a;
|
||||
size = a.size();
|
||||
}
|
||||
|
||||
void Relation::insertAttributes(vector<Attribute> a){
|
||||
for (int i = 0; i < a.size(); ++i){
|
||||
att.push_back(a[i]);
|
||||
}
|
||||
}
|
||||
|
||||
string Relation::getTableName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
void Relation::setTableName(string s){
|
||||
name = s;
|
||||
}
|
||||
|
||||
Attribute Relation::operator[](int i){
|
||||
return att[i];
|
||||
}
|
||||
|
||||
vector<string> Relation::getTuple(int index){
|
||||
vector<string> temp;
|
||||
|
||||
for (int i = 0; i < att.size(); ++i){
|
||||
temp.push_back(att[i][index]);
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
vector<Attribute> Relation::getAttributes(){
|
||||
return att;
|
||||
}
|
||||
|
||||
vector<string> Relation::getAttributeNames(){
|
||||
vector<string> temp;
|
||||
for(int i = 0; i < size; ++i){
|
||||
temp.push_back(att[i].getName());
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
Attribute& Relation::getAttributeByName(string s) {
|
||||
for(int i = 0; i < size; ++i){
|
||||
if (att[i].getName() == s) {
|
||||
return att[i];
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Failure to return: the requested attribute does not exist.";
|
||||
}
|
||||
|
||||
bool Relation::isAttribute(string s) {
|
||||
for(int i = 0; i < size; ++i){
|
||||
if (att[i].getName() == s) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
//cout << "Failure to return: the requested attribute does not exist.";
|
||||
}
|
||||
|
||||
void Relation::renameAttribute(string oldstr, string newstr){
|
||||
this->getAttributeByName(oldstr).setName(newstr);
|
||||
}
|
||||
|
||||
int Relation::getSize(){
|
||||
return size;
|
||||
}
|
||||
|
||||
void Relation::display(){
|
||||
cout << "--------------------------\n";
|
||||
cout << getTableName() << "\n";
|
||||
for (int i = 0; i < att.size(); ++i){
|
||||
att[i].display();
|
||||
}
|
||||
|
||||
cout << "--------------------------\n";
|
||||
}
|
||||
|
||||
void Relation::insertTuple(vector<string> tuple){
|
||||
if (tuple.size() != this->size) {
|
||||
cout << "Failure to insert: the sizes do not match.";
|
||||
}
|
||||
|
||||
else {
|
||||
for (int i = 0; i < att.size(); ++i) {
|
||||
att[i].addCell(tuple[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Relation::insertFromRelation(Relation r){
|
||||
if (r.size != this->size) {
|
||||
cout << "Failure to insert: the sizes do not match.";
|
||||
return;
|
||||
}
|
||||
|
||||
else if (this->getAttributeNames() != r.getAttributeNames()) {
|
||||
cout << "Failure to insert: the attributes do not match.";
|
||||
return;
|
||||
}
|
||||
|
||||
else {
|
||||
vector<Attribute> newAtts = r.getAttributes();
|
||||
|
||||
for (int i = 0; i < newAtts.size(); ++i) {
|
||||
for (int j = 0; j < newAtts[i].getSize(); ++j) {
|
||||
this->att[i].addCell(newAtts[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Relation::removeTuple(int index){
|
||||
if (index >= this->size)
|
||||
{
|
||||
cout << "Failure to delete: the requested index is out of bounds." << endl;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < att.size(); ++i)
|
||||
{
|
||||
att[i].removeCell(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Relation::removeFromTuple(int rindex, int aindex)
|
||||
{
|
||||
if (rindex >= this->size)
|
||||
{
|
||||
cout << "Failure to delete: the requested index is out of bounds." << endl;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
att[rindex].removeCell(aindex);
|
||||
}
|
||||
}
|
30
Relation.h
Executable file
30
Relation.h
Executable file
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "Attribute.h"
|
||||
|
||||
class Relation{
|
||||
string name;
|
||||
vector<Attribute> att;
|
||||
int size;
|
||||
|
||||
public:
|
||||
Relation(string n);
|
||||
Relation(string n, vector<Attribute> a);
|
||||
void insertAttributes(vector<Attribute> a);
|
||||
string getTableName();
|
||||
void setTableName(string s);
|
||||
Attribute operator[](int i);
|
||||
vector<string> getTuple(int index);
|
||||
vector<Attribute> getAttributes();
|
||||
vector<string> getAttributeNames();
|
||||
Attribute& getAttributeByName(string s);
|
||||
bool isAttribute(string s);
|
||||
void renameAttribute(string oldstr, string newstr);
|
||||
int getSize();
|
||||
void display();
|
||||
void insertTuple(vector<string> tuple); //assuming they are in order
|
||||
void insertFromRelation(Relation r);
|
||||
void removeTuple(int index);
|
||||
void removeFromTuple(int rindex, int aindex);
|
||||
};
|
BIN
a.out
Executable file
BIN
a.out
Executable file
Binary file not shown.
3
savefile.txt
Executable file
3
savefile.txt
Executable file
|
@ -0,0 +1,3 @@
|
|||
SHOW Food ;
|
||||
SHOW MoarFood ;
|
||||
SAVE ;
|
BIN
test
Executable file
BIN
test
Executable file
Binary file not shown.
12
test.cpp
Executable file
12
test.cpp
Executable file
|
@ -0,0 +1,12 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "Parser.h"
|
||||
//#include "Condition.h"
|
||||
#include "DBEngine.h"
|
||||
#include "user.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main () {
|
||||
|
||||
}
|
37
user.cpp
Executable file
37
user.cpp
Executable file
|
@ -0,0 +1,37 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "user.h"
|
||||
|
||||
User::User(){
|
||||
name = "";
|
||||
password = "";
|
||||
phone_number = "";
|
||||
fax_number = "";
|
||||
postal_address = "";
|
||||
is_admin = false;
|
||||
}
|
||||
|
||||
User::User(string n, string pass, string phone, string fax, string postal, bool admin){
|
||||
name = n;
|
||||
password = pass;
|
||||
phone_number = phone;
|
||||
fax_number = fax;
|
||||
postal_address = postal;
|
||||
is_admin = admin;
|
||||
}
|
||||
|
||||
string User::getName() {return name;}
|
||||
string User::getPassword() {return password;}
|
||||
string User::getPhoneNumber() {return phone_number;}
|
||||
string User::getFaxNumber() {return fax_number;}
|
||||
string User::getPostalAddress() {return postal_address;}
|
||||
bool User::confirmAdmin() {return is_admin;}
|
||||
bool User::checkLogin() {return is_logged_in;}
|
||||
vector<string> User::getGroups(){return groups;}
|
||||
vector<string> User::getMessages(){return messages;}
|
||||
|
||||
void User::setName(string new_name) {name = new_name;}
|
||||
void User::setPassword(string new_password) {password = new_password;}
|
||||
void User::setPhone(string new_phone) {phone_number = new_phone;}
|
||||
void User::setFax(string new_fax) {fax_number = new_fax;}
|
||||
void User::setPostal(string new_postal) {postal_address = new_postal;}
|
44
user.h
Executable file
44
user.h
Executable file
|
@ -0,0 +1,44 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
class User {
|
||||
string name;
|
||||
string password;
|
||||
string phone_number;
|
||||
string fax_number;
|
||||
string postal_address;
|
||||
vector<string> groups;
|
||||
vector<string> messages;
|
||||
|
||||
bool is_admin;
|
||||
bool is_logged_in;
|
||||
|
||||
public:
|
||||
User();
|
||||
User(string n, string pass, string phone, string fax, string postal, bool admin);
|
||||
string getName();
|
||||
string getPassword();
|
||||
string getPhoneNumber();
|
||||
string getFaxNumber();
|
||||
string getPostalAddress();
|
||||
vector<string> getGroups();
|
||||
vector<string> getMessages();
|
||||
bool confirmAdmin();
|
||||
bool checkLogin();
|
||||
void setName(string new_name);
|
||||
void setPassword(string new_name);
|
||||
void setPhone(string new_phone);
|
||||
void setFax(string new_fax);
|
||||
void setPostal(string new_postal);
|
||||
};
|
||||
|
||||
class Message {
|
||||
string timestamp;
|
||||
string text;
|
||||
|
||||
public:
|
||||
Message();
|
||||
Message(string time, string t);
|
||||
};
|
||||
|
Reference in a new issue