From 31bb026844997a3dfdd3d3fef6cf699d509f6e6a Mon Sep 17 00:00:00 2001 From: Alice Duvillier Date: Wed, 20 May 2026 16:05:45 +0200 Subject: [PATCH] add(parsing_getline): add parsing for orders - can parse orders - send a vector of Order with the nb and the pizza --- Makefile | 3 +- src/Parsing_orders/Order.cpp | 17 +++++++ src/Parsing_orders/Order.hpp | 36 ++++++++++++++ src/Parsing_orders/Parsing.cpp | 88 ++++++++++++++++++++++++++++++++++ src/Parsing_orders/Parsing.hpp | 39 +++++++++++++++ src/Pizza/APizza.cpp | 4 ++ src/Pizza/APizza.hpp | 5 ++ src/Pizza/IPizza.hpp | 3 ++ src/Pizza/Pizzas/Americana.cpp | 2 + src/Pizza/Pizzas/Fantasia.cpp | 2 + src/Pizza/Pizzas/Margarita.cpp | 2 + src/Pizza/Pizzas/Regina.cpp | 2 + src/main.cpp | 16 +++++++ 13 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 src/Parsing_orders/Order.cpp create mode 100644 src/Parsing_orders/Order.hpp create mode 100644 src/Parsing_orders/Parsing.cpp create mode 100644 src/Parsing_orders/Parsing.hpp diff --git a/Makefile b/Makefile index 957fcde..e01a334 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ MAKE_FLAGS += -j -SRC := $(wildcard src/*.cpp) $(wildcard src/Pizza/*.cpp) $(wildcard src/Pizza/Pizzas/*.cpp) +SRC := $(wildcard src/*.cpp) $(wildcard src/Pizza/*.cpp) $(wildcard src/Pizza/Pizzas/*.cpp) $(wildcard src/Parsing_orders/*.cpp) BUILD_DIR := .build @@ -13,6 +13,7 @@ CXXFLAGS += -Wwrite-strings -Werror=format-nonliteral -Werror=return-type CXXFLAGS += -std=c++20 -iquote src -iquote src/Server -iquote src/Client -iquote libs/myteams CXXFLAGS += -Isrc/Pizza CXXFLAGS += -Isrc/Pizza/Pizzas +CXXFLAGS += -Isrc/Parsing_orders include utils.mk diff --git a/src/Parsing_orders/Order.cpp b/src/Parsing_orders/Order.cpp new file mode 100644 index 0000000..8ea6599 --- /dev/null +++ b/src/Parsing_orders/Order.cpp @@ -0,0 +1,17 @@ +/* +** EPITECH PROJECT, 2026 +** plazza +** File description: +** Order +*/ + +#include "Order.hpp" + +plazza::Order::Order(size_t nb, std::unique_ptr pizza) + : _nb(nb), _pizza(std::move(pizza)) {} + +plazza::Order::~Order() {} + +size_t plazza::Order::getNb() { return _nb; } + +const plazza::IPizza &plazza::Order::getPizza() const { return *_pizza; } diff --git a/src/Parsing_orders/Order.hpp b/src/Parsing_orders/Order.hpp new file mode 100644 index 0000000..0af01cc --- /dev/null +++ b/src/Parsing_orders/Order.hpp @@ -0,0 +1,36 @@ +/* +** EPITECH PROJECT, 2026 +** plazza +** File description: +** Order +*/ + +#ifndef ORDER_HPP_ +#define ORDER_HPP_ + +#include "IPizza.hpp" +#include +#include +#include +#include + +namespace plazza { +class Order { +public: + Order(size_t nb, std::unique_ptr pizza); + // move constructor + Order(Order &&) = default; + ~Order(); + + size_t getNb(); + const plazza::IPizza &getPizza() const; + +protected: + size_t _nb; + std::unique_ptr _pizza; + +private: +}; +} // namespace plazza + +#endif /* !ORDER_HPP_ */ diff --git a/src/Parsing_orders/Parsing.cpp b/src/Parsing_orders/Parsing.cpp new file mode 100644 index 0000000..81345ac --- /dev/null +++ b/src/Parsing_orders/Parsing.cpp @@ -0,0 +1,88 @@ +/* +** EPITECH PROJECT, 2026 +** plazza +** File description: +** Parsing +*/ + +#include "Parsing.hpp" + +std::vector orderLineToArray(std::string orderLine) { + std::vector arrayOrders; + std::stringstream ss(orderLine); + std::string tmp; + + while (std::getline(ss, tmp, ';')) { + arrayOrders.push_back(tmp); + } + return arrayOrders; +} + +std::vector decompositionOrder(std::string order) { + std::vector sectionOrder; + std::stringstream ss(order); + std::string tmp; + + while (std::getline(ss, tmp, ' ')) { + if (!tmp.empty()) { + sectionOrder.push_back(tmp); + } + } + return sectionOrder; +} + +bool isDigitString(std::string string) { + for (size_t i = 0; i < string.size(); i++) { + if (isdigit(string[i]) == 0) { + return false; + } + } + return true; +} + +std::vector +plazza::Parsing::parsingOrder(std::string orderLine) { + std::vector arrayOrders = orderLineToArray(orderLine); + std::vector orders; + std::vector sectionOrder; + + for (size_t i = 0; i < arrayOrders.size(); i++) { + sectionOrder = decompositionOrder(arrayOrders[i]); + if (sectionOrder.size() != 3) { + std::cout << "Not enough parameters for the order n°" << i + 1 << " !" + << std::endl; + continue; + } + std::cout << "type: [" << sectionOrder[0] << "] size: [" << sectionOrder[1] + << "] number: [" << sectionOrder[2] << "]" << std::endl; + if (sectionOrder[0] == "americana" || sectionOrder[0] == "fantasia" || + sectionOrder[0] == "margarita" || sectionOrder[0] == "regina") { + if (sectionOrder[1] == "S" || sectionOrder[1] == "L" || + sectionOrder[1] == "M" || sectionOrder[1] == "XL" || + sectionOrder[1] == "XXL") { + sectionOrder[2].erase(0, 1); + if (isDigitString(sectionOrder[2]) == true) { + if (stoi(sectionOrder[2]) > 0) { + auto pizza = plazza::PizzaFactory::createPizza( + stringToPizzaType[static_cast(sectionOrder[0])], + stringToPizzaSize[static_cast(sectionOrder[1])]); + orders.push_back(Order(stoi(sectionOrder[2]), std::move(pizza))); + } + } else { + std::cout << "This order is not acceptable(number of pizza) : [" + << arrayOrders[i] << "] !" << std::endl; + continue; + } + } else { + std::cout << "This order is not acceptable(size of pizza): [" + << arrayOrders[i] << "] !" << std::endl; + continue; + } + } else { + std::cout << "This order is not acceptable(type of pizza): [" + << arrayOrders[i] << "] !" << std::endl; + continue; + } + } + return orders; +} diff --git a/src/Parsing_orders/Parsing.hpp b/src/Parsing_orders/Parsing.hpp new file mode 100644 index 0000000..8c8e465 --- /dev/null +++ b/src/Parsing_orders/Parsing.hpp @@ -0,0 +1,39 @@ +/* +** EPITECH PROJECT, 2026 +** plazza +** File description: +** Parsing +*/ + +#ifndef PARSING_HPP_ +#define PARSING_HPP_ + +#include "Order.hpp" +#include "PizzaFactory.hpp" +#include "map" +#include + +static inline std::map stringToPizzaType = { + {"americana", Americana}, + {"fantasia", Fantasia}, + {"margarita", Margarita}, + {"regina", Regina}}; + +static inline std::map stringToPizzaSize = { + {"S", PizzaSize::S}, + {"M", PizzaSize::M}, + {"L", PizzaSize::L}, + {"XL", PizzaSize::XL}, + {"XXL", PizzaSize::XXL}}; + +namespace plazza { +class Parsing { +public: + static std::vector parsingOrder(std::string orderLine); + +protected: +private: +}; +} // namespace plazza + +#endif /* !PARSING_HPP_ */ diff --git a/src/Pizza/APizza.cpp b/src/Pizza/APizza.cpp index 15e7d55..f4bc307 100644 --- a/src/Pizza/APizza.cpp +++ b/src/Pizza/APizza.cpp @@ -30,3 +30,7 @@ std::vector plazza::APizza::getIngredientsList() const { } return listIngredients; } + +std::string plazza::APizza::getType() const { return _type; } + +size_t plazza::APizza::getBakingTime() const { return _bakingTime; } diff --git a/src/Pizza/APizza.hpp b/src/Pizza/APizza.hpp index 5b98e2c..f9a2e60 100644 --- a/src/Pizza/APizza.hpp +++ b/src/Pizza/APizza.hpp @@ -22,9 +22,14 @@ class APizza : public plazza::IPizza { Ingredients getIngredients() const override; std::vector getIngredientsList() const override; + std::string getType() const override; + size_t getBakingTime() const override; + protected: PizzaSize _size; Ingredients _ingredients; + std::string _type; + size_t _bakingTime; private: }; diff --git a/src/Pizza/IPizza.hpp b/src/Pizza/IPizza.hpp index d2d814a..7a53440 100644 --- a/src/Pizza/IPizza.hpp +++ b/src/Pizza/IPizza.hpp @@ -57,6 +57,9 @@ class IPizza { virtual Ingredients getIngredients() const = 0; virtual std::vector getIngredientsList() const = 0; + virtual std::string getType() const = 0; + virtual size_t getBakingTime() const = 0; + protected: private: }; diff --git a/src/Pizza/Pizzas/Americana.cpp b/src/Pizza/Pizzas/Americana.cpp index e565ac0..675b15e 100644 --- a/src/Pizza/Pizzas/Americana.cpp +++ b/src/Pizza/Pizzas/Americana.cpp @@ -10,6 +10,8 @@ plazza::Americana::Americana(PizzaSize size) : APizza(size) { _size = size; _ingredients = static_cast(DOUGH | TOMATO | GRUYERE | STEAK); + _type = "Americana"; + _bakingTime = 2; } plazza::Americana::~Americana() {} diff --git a/src/Pizza/Pizzas/Fantasia.cpp b/src/Pizza/Pizzas/Fantasia.cpp index 56b7fca..dece2b8 100644 --- a/src/Pizza/Pizzas/Fantasia.cpp +++ b/src/Pizza/Pizzas/Fantasia.cpp @@ -4,6 +4,8 @@ plazza::Fantasia::Fantasia(PizzaSize size) : APizza(size) { _size = size; _ingredients = static_cast(DOUGH | TOMATO | EGGPLANT | GOATCHEESE | CHIEFLOVE); + _type = "Fantasia"; + _bakingTime = 4; } plazza::Fantasia::~Fantasia() {} diff --git a/src/Pizza/Pizzas/Margarita.cpp b/src/Pizza/Pizzas/Margarita.cpp index a77127b..bb925b6 100644 --- a/src/Pizza/Pizzas/Margarita.cpp +++ b/src/Pizza/Pizzas/Margarita.cpp @@ -3,6 +3,8 @@ plazza::Margarita::Margarita(PizzaSize size) : APizza(size) { _size = size; _ingredients = static_cast(DOUGH | TOMATO | GRUYERE); + _type = "Margarita"; + _bakingTime = 1; } plazza::Margarita::~Margarita() {} diff --git a/src/Pizza/Pizzas/Regina.cpp b/src/Pizza/Pizzas/Regina.cpp index dc171c0..07cf045 100644 --- a/src/Pizza/Pizzas/Regina.cpp +++ b/src/Pizza/Pizzas/Regina.cpp @@ -4,6 +4,8 @@ plazza::Regina::Regina(PizzaSize size) : APizza(size) { _size = size; _ingredients = static_cast(DOUGH | TOMATO | GRUYERE | HAM | MUSHROOMS); + _type = "Regina"; + _bakingTime = 2; } plazza::Regina::~Regina() {} diff --git a/src/main.cpp b/src/main.cpp index cc7aa89..893bd81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include "Parsing.hpp" #include "PizzaFactory.hpp" #include @@ -18,4 +19,19 @@ int main(void) { std::cout << listIngredients[i] << ","; } std::cout << "] !" << std::endl; + + std::cout << "Let's order !" << std::endl; + std::string line; + std::vector order; + while (1) { + getline(std::cin, line); + order = plazza::Parsing::parsingOrder(line); + std::cout << "Get : " << std::endl; + for (size_t i = 0; i < order.size(); i++) { + std::cout << "---------" << std::endl; + std::cout << order[i].getPizza().getType() << std::endl; + std::cout << order[i].getNb() << std::endl; + std::cout << "---------" << std::endl; + } + } }