From fd3bf3f7a8b23a9998f74edfdc7e516faa3ab82d Mon Sep 17 00:00:00 2001 From: eleonore12345 Date: Wed, 7 Aug 2024 12:47:21 +0200 Subject: [PATCH] idem mais compile sans erreur --- src/DockerModule.cpp | 5 ++++- src/DockerModule.h | 4 ++-- src/Makefile | 4 ++-- src/Module.cpp | 5 +++++ src/Module.h | 2 ++ src/Modules.h | 4 +++- src/main.cpp | 14 +++++++------- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/DockerModule.cpp b/src/DockerModule.cpp index 8abf2f0..8985be2 100644 --- a/src/DockerModule.cpp +++ b/src/DockerModule.cpp @@ -6,7 +6,10 @@ #include "BashManager.h" //constructor and destructor inline - +DockerModule::DockerModule() +{ + name="Docker"; +} //public methods int DockerModule::prepare() { diff --git a/src/DockerModule.h b/src/DockerModule.h index ebc9a79..4aac63c 100644 --- a/src/DockerModule.h +++ b/src/DockerModule.h @@ -10,12 +10,12 @@ class DockerModule : public Module { public: - DockerModule(){} //inline + DockerModule();//inline ~DockerModule(){} //inline int prepare (); int deploy (string serviceUsername); int remove(string serviceUsername); int clean (); + string name; }; - #endif \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index 3a67a9f..d107cbd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,12 +1,12 @@ ECHO = @echo GCC = g++ RM = @rm -f -CCFLAGS = -c -O3 -g -std=c++11 -pedantic -Wall +CCFLAGS = -c -O3 -g -std=c++20 -pedantic -Wall SRC = $(wildcard *.cpp) BIN = ../bin EXE = deployer OBJECTS = $(patsubst %.cpp,$(BIN)/%.o,$(SRC)) -LIBRARIES = +LIBRARIES = -lstdc++fs $(EXE) : $(OBJECTS) $(ECHO) "-Linking $(EXE)-" diff --git a/src/Module.cpp b/src/Module.cpp index b1130db..61d5261 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -10,6 +10,11 @@ //destructor, could not be inline because pure virtual Module::~Module(){} +ostream & operator << (ostream & out, const Module & m) +{ + cout << "module " << m.name << endl; + return cout; +} diff --git a/src/Module.h b/src/Module.h index e0def5c..2510fc1 100644 --- a/src/Module.h +++ b/src/Module.h @@ -18,5 +18,7 @@ class Module virtual int deploy (string serviceUsername)=0; virtual int remove(string serviceUsername)=0; virtual int clean ()=0; + friend ostream & operator<< (ostream & out, const Module & m); + string name; }; #endif \ No newline at end of file diff --git a/src/Modules.h b/src/Modules.h index 2cba951..dad43b0 100644 --- a/src/Modules.h +++ b/src/Modules.h @@ -1,6 +1,8 @@ #include #include +#include "Module.h" +#include "DockerModule.h" using namespace std; DockerModule dockerModule=DockerModule(); -vector modules = {dockerModule}; \ No newline at end of file +vector modules={&dockerModule}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8c9475e..f7844b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,7 +9,6 @@ #include #include "Services.h" #include "Modules.h" -#include "DockerModule.h" #include "BashManager.h" using namespace std; @@ -67,10 +66,10 @@ int deployService(string serviceUsername){ //call to the deploy functionality of all modules //the modules themselves determine their course of action depending on the service if (userCreated && envCreated){ - for(Module * mod : modules){ - int modResult = (*mod).deploy(serviceUsername); + for(Module * mod_ptr : modules){ + int modResult = (*mod_ptr).deploy(serviceUsername); if (modResult!=0){ - cerr << "Error in module "<< mod << " when deploying " << serviceUsername << endl; + cerr << "Error in module " << (*mod_ptr) << " when deploying " << serviceUsername << endl; } } return 0; @@ -95,12 +94,12 @@ int main(int argc, char *argv[]) { //check number of arguments if (argc != 3){ - cout << "Invalid number of arguments. \n" << endl; + cerr << "Invalid number of arguments. \n" << endl; help(argv[0]); return -1; } else { //check that data is mounted on the server - if (!filesystem::exists("/data/mounted")) { + if (!(filesystem::exists("/data/mounted"))) { cerr << "Error. The data is not mounted on the server" << endl; return -1; } else { @@ -121,7 +120,8 @@ int main(int argc, char *argv[]) } } else { cerr << "Invalid argument. \n" << endl; - exit(1); + return -1; + } } } return 0;