diff --git a/AddCommand.cpp b/AddCommand.cpp new file mode 100644 index 0000000..c19bb7a --- /dev/null +++ b/AddCommand.cpp @@ -0,0 +1,9 @@ +#include "AddCommand.h" + +namespace commands { + AddCommand::AddCommand() : SubCommand("add", 100) {} + + void AddCommand::run(int argc, stringstream& args) { + cout << "Add!\n"; + } +} diff --git a/AddCommand.h b/AddCommand.h new file mode 100644 index 0000000..bef2bd8 --- /dev/null +++ b/AddCommand.h @@ -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 + diff --git a/HelpCommand.cpp b/HelpCommand.cpp new file mode 100644 index 0000000..96e713d --- /dev/null +++ b/HelpCommand.cpp @@ -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 \n"; + } +} diff --git a/HelpCommand.h b/HelpCommand.h new file mode 100644 index 0000000..910a91f --- /dev/null +++ b/HelpCommand.h @@ -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 + diff --git a/Model.cpp b/Model.cpp new file mode 100644 index 0000000..4c82500 --- /dev/null +++ b/Model.cpp @@ -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 ""; + } +} diff --git a/Model.h b/Model.h new file mode 100644 index 0000000..af38b3f --- /dev/null +++ b/Model.h @@ -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 + diff --git a/SubCommand.cpp b/SubCommand.cpp new file mode 100644 index 0000000..6e39e2a --- /dev/null +++ b/SubCommand.cpp @@ -0,0 +1,14 @@ +#include "SubCommand.h" +#include + +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; + } +} diff --git a/SubCommand.h b/SubCommand.h new file mode 100644 index 0000000..4f85771 --- /dev/null +++ b/SubCommand.h @@ -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 + diff --git a/Task.cpp b/Task.cpp new file mode 100644 index 0000000..2a6c509 --- /dev/null +++ b/Task.cpp @@ -0,0 +1,5 @@ +#include "Task.h" + +namespace models { + Task::Task(const int& id, const string& name, const string& description, const vector& children): Model(), id(id), name(name), description(description), children(children){} +} diff --git a/Task.h b/Task.h new file mode 100644 index 0000000..a976256 --- /dev/null +++ b/Task.h @@ -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 children; + public: + Task(const int& id, const string& name, const string& description, const vector& children); + Model* operator>>(stringstream& stream) override; + string operator<<(Model& model) override; + }; +} + +#endif // TASK_H + diff --git a/User.cpp b/User.cpp new file mode 100644 index 0000000..bbe66b9 --- /dev/null +++ b/User.cpp @@ -0,0 +1,11 @@ +#include "User.h" +#include + +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, "", ""); + } + +} diff --git a/User.h b/User.h new file mode 100644 index 0000000..3e2afec --- /dev/null +++ b/User.h @@ -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 + diff --git a/UserTaskIndex.cpp b/UserTaskIndex.cpp new file mode 100644 index 0000000..ed7e0f5 --- /dev/null +++ b/UserTaskIndex.cpp @@ -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) {} +} diff --git a/UserTaskIndex.h b/UserTaskIndex.h new file mode 100644 index 0000000..2bffb2d --- /dev/null +++ b/UserTaskIndex.h @@ -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 + diff --git a/main.cpp b/main.cpp index e135a8d..a2e63d6 100644 --- a/main.cpp +++ b/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 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; } +