forked from University/epr24pr5-ojanssen2
feat: added on handling commands, started working on implementing data models
This commit is contained in:
parent
471524ceb9
commit
8d356391ae
15 changed files with 222 additions and 1 deletions
9
AddCommand.cpp
Normal file
9
AddCommand.cpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include "AddCommand.h"
|
||||
|
||||
namespace commands {
|
||||
AddCommand::AddCommand() : SubCommand("add", 100) {}
|
||||
|
||||
void AddCommand::run(int argc, stringstream& args) {
|
||||
cout << "Add!\n";
|
||||
}
|
||||
}
|
14
AddCommand.h
Normal file
14
AddCommand.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "std_lib_inc.h"
|
||||
#include "SubCommand.h"
|
||||
#ifndef ADDCOMMAND_H
|
||||
#define ADDCOMMAND_H
|
||||
|
||||
namespace commands {
|
||||
class AddCommand: public SubCommand {
|
||||
public:
|
||||
AddCommand();
|
||||
void run(int argc, stringstream& args) override;
|
||||
};
|
||||
}
|
||||
#endif // ADDCOMMAND_H
|
||||
|
10
HelpCommand.cpp
Normal file
10
HelpCommand.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "HelpCommand.h"
|
||||
|
||||
namespace commands {
|
||||
HelpCommand::HelpCommand(): SubCommand("help", 100) {}
|
||||
|
||||
void HelpCommand::run(int argc, stringstream& args) {
|
||||
cout << "Projekt 5\n";
|
||||
cout << "epr24pr5-ojanssen2 <add/delete/list/show/assign/unassign/active/help>\n";
|
||||
}
|
||||
}
|
14
HelpCommand.h
Normal file
14
HelpCommand.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "std_lib_inc.h"
|
||||
#include "SubCommand.h"
|
||||
#ifndef HELPCOMMAND_H
|
||||
#define HELPCOMMAND_H
|
||||
|
||||
namespace commands {
|
||||
class HelpCommand: public SubCommand {
|
||||
public:
|
||||
HelpCommand();
|
||||
void run(int argc, stringstream& args) override;
|
||||
};
|
||||
}
|
||||
#endif // HELPCOMMAND_H
|
||||
|
15
Model.cpp
Normal file
15
Model.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "Model.h"
|
||||
|
||||
namespace models {
|
||||
Model::Model() {}
|
||||
|
||||
Model* Model::operator>>(stringstream& stream) {
|
||||
cout << "Default << operator was not overwritten!\n";
|
||||
return new Model();
|
||||
}
|
||||
|
||||
string Model::operator<<(Model* model) {
|
||||
cout << "Default >> operator was not overwritten!\n";
|
||||
return "";
|
||||
}
|
||||
}
|
16
Model.h
Normal file
16
Model.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "std_lib_inc.h"
|
||||
#ifndef MODEL_H
|
||||
#define MODEL_H
|
||||
|
||||
namespace models {
|
||||
class Model {
|
||||
public:
|
||||
Model();
|
||||
|
||||
virtual Model* operator>>(stringstream& stream);
|
||||
virtual string operator<<(Model* model);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // MODEL_H
|
||||
|
14
SubCommand.cpp
Normal file
14
SubCommand.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "SubCommand.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace commands {
|
||||
SubCommand::SubCommand(const string& name, const int& return_value): name(name), return_value(return_value) {}
|
||||
|
||||
void SubCommand::run(int argc, stringstream& args) {
|
||||
cout << "Not impl!\n";
|
||||
}
|
||||
|
||||
string SubCommand::get_name() {
|
||||
return this->name;
|
||||
}
|
||||
}
|
20
SubCommand.h
Normal file
20
SubCommand.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "std_lib_inc.h"
|
||||
#include "parameter_reader.h"
|
||||
#ifndef SUBCOMMAND_H
|
||||
#define SUBCOMMAND_H
|
||||
|
||||
namespace commands {
|
||||
class SubCommand {
|
||||
string name;
|
||||
int return_value;
|
||||
|
||||
public:
|
||||
SubCommand(const string& indicator, const int& value);
|
||||
string get_name();
|
||||
int get_value();
|
||||
virtual void run(int argc, stringstream& args);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SUBCOMMAND_H
|
||||
|
5
Task.cpp
Normal file
5
Task.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include "Task.h"
|
||||
|
||||
namespace models {
|
||||
Task::Task(const int& id, const string& name, const string& description, const vector<int>& children): Model(), id(id), name(name), description(description), children(children){}
|
||||
}
|
21
Task.h
Normal file
21
Task.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "std_lib_inc.h"
|
||||
#include "Model.h"
|
||||
#ifndef TASK_H
|
||||
#define TASK_H
|
||||
|
||||
namespace models {
|
||||
class Task : public Model {
|
||||
private:
|
||||
int id;
|
||||
string name;
|
||||
string description;
|
||||
vector<int> children;
|
||||
public:
|
||||
Task(const int& id, const string& name, const string& description, const vector<int>& children);
|
||||
Model* operator>>(stringstream& stream) override;
|
||||
string operator<<(Model& model) override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TASK_H
|
||||
|
11
User.cpp
Normal file
11
User.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "User.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace models {
|
||||
User::User(const int& id, const string& name, const string& surname): Model(), id(id), name(name), surname(surname) {}
|
||||
Model* User::operator>>(stringstream& stream) {
|
||||
cout << "Custom impl.";
|
||||
return new User(0, "", "");
|
||||
}
|
||||
|
||||
}
|
21
User.h
Normal file
21
User.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "std_lib_inc.h"
|
||||
#include "Model.h"
|
||||
#ifndef USER_H
|
||||
#define USER_H
|
||||
|
||||
namespace models {
|
||||
class User : public Model {
|
||||
private:
|
||||
int id;
|
||||
string name;
|
||||
string surname;
|
||||
|
||||
public:
|
||||
User(const int& id, const string& name, const string& surname);
|
||||
Model* operator>>(stringstream& stream) override;
|
||||
string operator<<(Model* model) override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // USER_H
|
||||
|
5
UserTaskIndex.cpp
Normal file
5
UserTaskIndex.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include "UserTaskIndex.h"
|
||||
|
||||
namespace models {
|
||||
UserTaskIndex::UserTaskIndex(const int& user_id, const int& task_id) : Model(), user_id(user_id), task_id(task_id) {}
|
||||
}
|
19
UserTaskIndex.h
Normal file
19
UserTaskIndex.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "std_lib_inc.h"
|
||||
#include "Model.h"
|
||||
#ifndef USERTASKINDEX_H
|
||||
#define USERTASKINDEX_H
|
||||
|
||||
namespace models {
|
||||
class UserTaskIndex : public Model{
|
||||
private:
|
||||
int user_id;
|
||||
int task_id;
|
||||
public:
|
||||
UserTaskIndex(const int& user_id, const int& task_id);
|
||||
Model* operator>>(stringstream& stream) override;
|
||||
string operator<<(Model& model) override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // USERTASKINDEX_H
|
||||
|
29
main.cpp
29
main.cpp
|
@ -1,8 +1,35 @@
|
|||
#include "std_lib_inc.h"
|
||||
#include "parameter_reader.h"
|
||||
#include "SubCommand.h"
|
||||
#include "HelpCommand.h"
|
||||
#include "AddCommand.h"
|
||||
|
||||
using commands::SubCommand;
|
||||
using commands::HelpCommand;
|
||||
using commands::AddCommand;
|
||||
|
||||
const vector<SubCommand*> handlers = { new HelpCommand(), new AddCommand() };
|
||||
|
||||
// Mein Leben auf IMDB, nur 7/10.
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
stringstream stream = make_string_stream(argc, argv);
|
||||
if (argc < 2) {
|
||||
cout << "There are not enough args!\n";
|
||||
return 0;
|
||||
}
|
||||
stringstream parameter = make_string_stream(argc, argv);
|
||||
string command;
|
||||
parameter >> command;
|
||||
|
||||
for (SubCommand* sc : handlers) {
|
||||
if (sc->get_name() == command) {
|
||||
sc->run(argc, parameter);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "I don't know this command!\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue