diff --git a/Makefile b/Makefile index 0f4caaeac024b243de3a80445b314262beac6b13..50f64c41e9d0dee9c4a7565886676345cae24f38 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,47 @@ -CXX = g++ -CXXFLAGS = -Wall -O2 -LDLIBS = -lm -SRC = $(wildcard ./sources/*.cpp) -OBJ = $(SRC:.c=.o) -TARGET = biblioteca +include variables.mk -all: $(TARGET) +HEADER_DIR = $(PROJECT_HEADER_DIR) +SRC_DIR = $(PROJECT_SRC_DIR) +OBJ_DIR = $(PROJECT_OBJ_DIR) + +TEST_DIR = $(PROJECT_TEST_DIR) +TARGET = $(PROJECT_TARGET) + +HEADER_SUB_DIRS = $(shell find $(HEADER_DIR) -type d) + +HEADER_PATHS = $(addprefix -I ,$(HEADER_DIR)) +HEADER_PATHS += $(addprefix -I ,$(HEADER_SUB_DIRS)) + +CLI_FLAGS = +CC = $(PROJECT_CC) +CFLAGS = $(HEADER_PATHS) $(PROJECT_CFLAGS) $(CLI_FLAGS) + +SRC = $(shell find $(SRC_DIR) -type f -name '*.cpp') +OBJ = $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC)) +OBJ_SUB_DIRS = $(sort $(dir $(OBJ))) + +$(shell mkdir -p $(OBJ_SUB_DIRS)) $(TARGET): $(OBJ) + $(CC) $(CFLAGS) -o $(TARGET) $(OBJ) $(OBJ_PATHS) -debug: CXXFLAGS += -DDEBUG -g -debug: all +$(OBJ): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.cpp + $(CC) $(CFLAGS) -c $< -o $@ -run: all +.PHONY: run +run: $(TARGET) ./$(TARGET) +.PHONY: clean clean: - -rm -f ./sources/*.o vgcore* + @rm -rf $(OBJ_DIR) vgcore* + @$(MAKE) --no-print-directory -C $(TEST_DIR) clean +.PHONY: purge purge: clean - -rm -f $(TARGET) + @rm -f $(TARGET) + @$(MAKE) --no-print-directory -C $(TEST_DIR) purge +.PHONY: test +test: $(TARGET) + @$(MAKE) --no-print-directory -C $(TEST_DIR) diff --git a/TDD/Makefile b/TDD/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..edb91eafc4941add46de52a157308e7c5b9ba326 --- /dev/null +++ b/TDD/Makefile @@ -0,0 +1,45 @@ +include variables.mk +include $(PROJECT_DIR)/variables.mk + +HEADER_DIR = $(TEST_HEADER_DIR) +SRC_DIR = $(TEST_SRC_DIR) +OBJ_DIR = $(TEST_OBJ_DIR) + +TARGET ?= $(TEST_TARGET) + +HEADER_DIRS = $(shell find $(HEADER_DIR) -type d) +HEADER_PATHS = $(addprefix -I ,$(HEADER_DIRS)) +PROJECT_HEADER_SUB_DIRS = $(shell find $(PROJECT_DIR)/$(PROJECT_HEADER_DIR) -type d) + +PROJECT_HEADER_PATHS = $(addprefix -I ,$(PROJECT_HEADER_DIR)) +PROJECT_HEADER_PATHS += $(addprefix -I ,$(PROJECT_HEADER_SUB_DIRS)) + +PROJECT_OBJ_PATHS = $(shell find $(PROJECT_DIR) -type f -name '*.o') +PROJECT_OBJ_PATHS := $(filter-out %/main.o, $(PROJECT_OBJ_PATHS)) + +CC = $(TEST_CC) +CFLAGS = $(HEADER_PATHS) $(PROJECT_HEADER_PATHS) $(TEST_CFLAGS) + +SRC = $(shell find $(SRC_DIR) -type f -name '*.cpp') +OBJ = $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC)) +OBJ_SUB_DIRS = $(sort $(dir $(OBJ))) + +$(shell mkdir -p $(OBJ_SUB_DIRS)) + +.PHONY: test +test: $(TARGET) + ./$(TARGET) + +$(TARGET): $(OBJ) $(PROJECT_OBJ_PATHS) + $(CC) $(CFLAGS) -o $(TARGET) $(OBJ) $(PROJECT_OBJ_PATHS) + +$(OBJ): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +.PHONY: clean +clean: + @rm -rf $(OBJ_DIR) vgcore* + +.PHONY: purge +purge: clean + @rm -f $(TARGET) diff --git a/TDD/biblioteca_test b/TDD/biblioteca_test new file mode 100755 index 0000000000000000000000000000000000000000..5fa6b4a1ff76cde638fcf9cacb11eedc32b9228b Binary files /dev/null and b/TDD/biblioteca_test differ diff --git a/tdd/doctest.h b/TDD/header/doctest.h similarity index 100% rename from tdd/doctest.h rename to TDD/header/doctest.h diff --git a/tdd/biblioteca-test.cpp b/TDD/sources/biblioteca-test.cpp similarity index 96% rename from tdd/biblioteca-test.cpp rename to TDD/sources/biblioteca-test.cpp index 88fb9ef2341dcd7958013cc29cb71de873721bc8..05603404d0656da8a4cb8212eb6510c0fa61ad1c 100644 --- a/tdd/biblioteca-test.cpp +++ b/TDD/sources/biblioteca-test.cpp @@ -2,11 +2,11 @@ #include <tuple> #include <chrono> #include "doctest.h" -#include "../sources/ControladorObras.hpp" -#include "../sources/ControladorUsuarios.hpp" -#include "../sources/Biblioteca.hpp" -#include "../sources/Livro.hpp" -#include "../sources/Periodico.hpp" +#include "ControladorObras.hpp" +#include "ControladorUsuarios.hpp" +#include "Biblioteca.hpp" +#include "Livro.hpp" +#include "Periodico.hpp" TEST_CASE("Biblioteca") { cout << "=> Instanciando Biblioteca" << endl; diff --git a/tdd/main.cpp b/TDD/sources/main.cpp similarity index 100% rename from tdd/main.cpp rename to TDD/sources/main.cpp diff --git a/TDD/variables.mk b/TDD/variables.mk new file mode 100644 index 0000000000000000000000000000000000000000..b6d48cb44e7e0ff7d031d1e407910be77f2266a0 --- /dev/null +++ b/TDD/variables.mk @@ -0,0 +1,10 @@ +TEST_HEADER_DIR = header +TEST_SRC_DIR = sources +TEST_OBJ_DIR = obj + +PROJECT_DIR = .. + +TEST_TARGET ?= biblioteca_test + +TEST_CC = g++ +TEST_CFLAGS = -std=c++20 -g -Wall -Wextra -O2 diff --git a/biblioteca b/biblioteca new file mode 100755 index 0000000000000000000000000000000000000000..3621ce5dc50facf4c977390de080e6a4186d24f8 Binary files /dev/null and b/biblioteca differ diff --git a/sources/Biblioteca.hpp b/sources/Biblioteca.hpp index 76c559b346edd93abd88b77ff5d610e3316860a9..0355532df2013cd662ab82f1c7a6692cd84d724d 100644 --- a/sources/Biblioteca.hpp +++ b/sources/Biblioteca.hpp @@ -1,8 +1,8 @@ #ifndef __BIBLIOTECA__ #define __BIBLIOTECA__ -#include "./ControladorUsuarios.hpp" -#include "./ControladorObras.hpp" +#include "ControladorUsuarios.hpp" +#include "ControladorObras.hpp" using namespace std; diff --git a/sources/ControladorObras.cpp b/sources/ControladorObras.cpp index 67bb6d5bf1a856abcf0d26f721531c079ce636ef..76b457767c049648de8570a225a0bca652d7e6c9 100644 --- a/sources/ControladorObras.cpp +++ b/sources/ControladorObras.cpp @@ -1,7 +1,7 @@ #include <iostream> #include <algorithm> -#include "./ControladorObras.hpp" +#include "ControladorObras.hpp" using namespace std; @@ -18,7 +18,7 @@ ControladorObras& ControladorObras::getInstance() { void ControladorObras::mostrarDetalhes() const { cout << endl << "> LISTANDO OBRAS DO SISTEMA:" << endl << endl; for (const auto& obra : this->obras) { - obra.mostrarDetalhes(); + (&obra)->mostrarDetalhes(); cout << endl << "-----" << endl << endl; } } diff --git a/sources/ControladorObras.hpp b/sources/ControladorObras.hpp index f05afa0f5ede7e04a6f1fcdc522e3368aaba6860..757a317288c190bb7b64629a85acd32ed3826238 100644 --- a/sources/ControladorObras.hpp +++ b/sources/ControladorObras.hpp @@ -4,8 +4,8 @@ #include <vector> #include <string> -#include "./Obra.hpp" -#include "./DescricaoObra.hpp" +#include "Obra.hpp" +#include "DescricaoObra.hpp" using namespace std; diff --git a/sources/ControladorUsuarios.cpp b/sources/ControladorUsuarios.cpp index fad1460d3b474b70fdd223bb5cce2487420f22c6..bb89a168ef1d6fe8e13feb109185298951f99c0f 100644 --- a/sources/ControladorUsuarios.cpp +++ b/sources/ControladorUsuarios.cpp @@ -2,7 +2,7 @@ #include <algorithm> #include <chrono> -#include "./ControladorUsuarios.hpp" +#include "ControladorUsuarios.hpp" #include "Usuario.hpp" using namespace std; diff --git a/sources/DescricaoObra.cpp b/sources/DescricaoObra.cpp index 189eb106d5c1fccdecd8400b92569ff95accac23..17653075e4429b36b38b74783f7563ef19697a0e 100644 --- a/sources/DescricaoObra.cpp +++ b/sources/DescricaoObra.cpp @@ -1,6 +1,6 @@ #include <iostream> -#include "./DescricaoObra.hpp" +#include "DescricaoObra.hpp" using namespace std; diff --git a/sources/DescricaoObra.hpp b/sources/DescricaoObra.hpp index 7e839f07425c923198ce5e104bd3a9c0dd7d24b7..a58d412a563dcc6121d04b4826006b0f9c837b62 100644 --- a/sources/DescricaoObra.hpp +++ b/sources/DescricaoObra.hpp @@ -17,7 +17,7 @@ class DescricaoObra { // Contructor DescricaoObra() {}; DescricaoObra(const string& tipo, const string& titulo, int ano); - virtual void mostrarDetalhes() const; + virtual void mostrarDetalhes() const = 0; // Methods string getTitulo() const ; diff --git a/sources/Emprestimo.cpp b/sources/Emprestimo.cpp index b967c78b28edf3fb9ccbc9f4c534b39497bdcfb8..1a6ca08a85dec1f0468f7cf80bac1609b7d05b11 100644 --- a/sources/Emprestimo.cpp +++ b/sources/Emprestimo.cpp @@ -1,9 +1,9 @@ #include <iostream> #include <chrono> -#include "./Emprestimo.hpp" -#include "./DescricaoObra.hpp" -#include "./ControladorObras.hpp" +#include "Emprestimo.hpp" +#include "DescricaoObra.hpp" +#include "ControladorObras.hpp" using namespace std; diff --git a/sources/Emprestimo.hpp b/sources/Emprestimo.hpp index 2eace1d1432c8c4c04919c38515a2736b9f54e4f..92394761bc06811e5884c4b2546147d4ad646315 100644 --- a/sources/Emprestimo.hpp +++ b/sources/Emprestimo.hpp @@ -2,7 +2,7 @@ #define __EMPRESTIMO__ #include <chrono> -#include "./DescricaoObra.hpp" +#include "DescricaoObra.hpp" class Emprestimo { private: diff --git a/sources/Livro.cpp b/sources/Livro.cpp index 463378b9b56477a599c1d5eed147a7eb69231e70..a1996ff5f16eb1a092a87052ebe21fe24daea5c2 100644 --- a/sources/Livro.cpp +++ b/sources/Livro.cpp @@ -1,7 +1,7 @@ #include <iostream> #include <string> -#include "./Livro.hpp" +#include "Livro.hpp" using namespace std; diff --git a/sources/Livro.hpp b/sources/Livro.hpp index c164a3c17fd5ed70cba2a47d730313840389f76f..f3b8d4182c9762f2edd546f8364f0f2536907179 100644 --- a/sources/Livro.hpp +++ b/sources/Livro.hpp @@ -1,8 +1,8 @@ #ifndef __LIVRO__ #define __LIVRO__ -#include "./DescricaoObra.hpp" #include <string> +#include "DescricaoObra.hpp" using namespace std; diff --git a/sources/Obra.cpp b/sources/Obra.cpp index cf399e835168fdcbc100f46d699e9b228b28c727..333ef874e1a8e67a4381fa3986a6701ad99f24d4 100644 --- a/sources/Obra.cpp +++ b/sources/Obra.cpp @@ -1,9 +1,9 @@ #include <iostream> -#include "./Obra.hpp" -#include "./DescricaoObra.hpp" -#include "./Livro.hpp" -#include "./Periodico.hpp" +#include "Obra.hpp" +#include "DescricaoObra.hpp" +#include "Livro.hpp" +#include "Periodico.hpp" // Constructor Obra::Obra(DescricaoObra& descricao) diff --git a/sources/Periodico.cpp b/sources/Periodico.cpp index fd2e836afa90cb2f2acec240923f65a1895cf7f8..b1b0e62e79151b17db0b5194d23ee6d2353c1e2b 100644 --- a/sources/Periodico.cpp +++ b/sources/Periodico.cpp @@ -1,6 +1,6 @@ #include <iostream> -#include "./Periodico.hpp" +#include "Periodico.hpp" // Contructor Periodico::Periodico(const DescricaoObra& outro) { diff --git a/sources/Periodico.hpp b/sources/Periodico.hpp index c3142c2e165076da9cc7f8584dd7be40f0939722..879a3109c771fcd08dfb8a57ae0e8581ca892e30 100644 --- a/sources/Periodico.hpp +++ b/sources/Periodico.hpp @@ -1,7 +1,7 @@ #ifndef __PERIODICO__ #define __PERIODICO__ -#include "./DescricaoObra.hpp" +#include "DescricaoObra.hpp" using namespace std; diff --git a/sources/Usuario.hpp b/sources/Usuario.hpp index 965f612ff4ea812295886b7b587f9f605395132b..eac1f58fba0a291e9516d40d924481b7b13103a2 100644 --- a/sources/Usuario.hpp +++ b/sources/Usuario.hpp @@ -5,8 +5,8 @@ #include <vector> #include <chrono> -#include "./DescricaoObra.hpp" -#include "./Emprestimo.hpp" +#include "DescricaoObra.hpp" +#include "Emprestimo.hpp" using namespace std; diff --git a/biblioteca.cpp b/sources/main.cpp similarity index 98% rename from biblioteca.cpp rename to sources/main.cpp index 1b79a3865217e948f65b3fc1a6fdf52a8a15627f..6da14af43610febb4a7751f7b649a5f5e0e80fe9 100644 --- a/biblioteca.cpp +++ b/sources/main.cpp @@ -2,9 +2,9 @@ #include <string> #include <limits> -#include "./sources/Biblioteca.hpp" -#include "./sources/Livro.hpp" -#include "./sources/Periodico.hpp" +#include "Biblioteca.hpp" +#include "Livro.hpp" +#include "Periodico.hpp" using namespace std; diff --git a/tdd/Makefile b/tdd/Makefile deleted file mode 100644 index c64d2a492751fed48b07fcac6e6d538537d1c576..0000000000000000000000000000000000000000 --- a/tdd/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -# Variáveis -CXX = g++ -CXXFLAGS = -I../sources -std=c++20 -LDFLAGS = -lm -SRCS = main.cpp biblioteca-test.cpp \ - ../sources/ControladorObras.cpp \ - ../sources/Usuario.cpp \ - ../sources/Emprestimo.cpp \ - ../sources/ControladorUsuarios.cpp \ - ../sources/Periodico.cpp \ - ../sources/Livro.cpp \ - ../sources/DescricaoObra.cpp \ - ../sources/Obra.cpp \ - ../sources/Biblioteca.cpp -OBJ = $(SRCS:.cpp=.o) -TARGET = biblioteca - -# Regras -all: $(TARGET) - -$(TARGET): $(OBJ) - $(CXX) $(OBJ) $(LDFLAGS) -o $(TARGET) - -# Regra para compilar arquivos .cpp para .o -%.o: %.cpp - $(CXX) $(CXXFLAGS) -c $< -o $@ - -# Limpar arquivos gerados -clean: - rm -f $(OBJ) $(TARGET) - -# Rebuild completo -rebuild: clean all - -.PHONY: all clean rebuild - diff --git a/tdd/biblioteca b/tdd/biblioteca deleted file mode 100755 index 4032ea25dbabc1452ed248bf2889b0d0c4328efb..0000000000000000000000000000000000000000 Binary files a/tdd/biblioteca and /dev/null differ diff --git a/variables.mk b/variables.mk new file mode 100644 index 0000000000000000000000000000000000000000..6d35897d53e4da3f686242d265aada5b66f3f3be --- /dev/null +++ b/variables.mk @@ -0,0 +1,9 @@ +PROJECT_HEADER_DIR = sources +PROJECT_SRC_DIR = sources +PROJECT_OBJ_DIR = obj + +PROJECT_TEST_DIR = TDD +PROJECT_TARGET ?= biblioteca + +PROJECT_CC = g++ +PROJECT_CFLAGS = -std=c++20 -g -Wall -Wextra -O2