Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MAKE_FLAGS += -j

SRC := $(wildcard src/*.cpp) $(wildcard src/Pizza/*.cpp) $(wildcard src/Pizza/Pizzas/*.cpp) $(wildcard src/IPC/*.cpp) $(wildcard src/Logger/*.cpp)
SRC := $(wildcard src/*.cpp) $(wildcard src/Pizza/*.cpp) $(wildcard src/Pizza/Pizzas/*.cpp) $(wildcard src/IPC/*.cpp) $(wildcard src/Logger/*.cpp) $(wildcard src/Parsing_orders/*.cpp)

BUILD_DIR := .build

Expand All @@ -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
CXXFLAGS += -Isrc/IPC
CXXFLAGS += -Isrc/Logger

Expand Down
17 changes: 17 additions & 0 deletions src/Parsing_orders/Order.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
** EPITECH PROJECT, 2026
** plazza
** File description:
** Order
*/

#include "Order.hpp"

plazza::Order::Order(size_t nb, std::unique_ptr<plazza::IPizza> 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; }
36 changes: 36 additions & 0 deletions src/Parsing_orders/Order.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
** EPITECH PROJECT, 2026
** plazza
** File description:
** Order
*/

#ifndef ORDER_HPP_
#define ORDER_HPP_

#include "IPizza.hpp"
#include <cstdio>
#include <iomanip>
#include <memory>
#include <string>

namespace plazza {
class Order {
public:
Order(size_t nb, std::unique_ptr<plazza::IPizza> pizza);
// move constructor
Order(Order &&) = default;
~Order();

size_t getNb();
const plazza::IPizza &getPizza() const;

protected:
size_t _nb;
std::unique_ptr<plazza::IPizza> _pizza;

private:
};
} // namespace plazza

#endif /* !ORDER_HPP_ */
88 changes: 88 additions & 0 deletions src/Parsing_orders/Parsing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
** EPITECH PROJECT, 2026
** plazza
** File description:
** Parsing
*/

#include "Parsing.hpp"

std::vector<std::string> orderLineToArray(std::string orderLine) {
std::vector<std::string> arrayOrders;
std::stringstream ss(orderLine);
std::string tmp;

while (std::getline(ss, tmp, ';')) {
arrayOrders.push_back(tmp);
}
return arrayOrders;
}

std::vector<std::string> decompositionOrder(std::string order) {
std::vector<std::string> 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::Order>
plazza::Parsing::parsingOrder(std::string orderLine) {
std::vector<std::string> arrayOrders = orderLineToArray(orderLine);
std::vector<plazza::Order> orders;
std::vector<std::string> 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<std::string>(sectionOrder[0])],
stringToPizzaSize[static_cast<std::string>(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;
}
39 changes: 39 additions & 0 deletions src/Parsing_orders/Parsing.hpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>

static inline std::map<std::string, PizzaType> stringToPizzaType = {
{"americana", Americana},
{"fantasia", Fantasia},
{"margarita", Margarita},
{"regina", Regina}};

static inline std::map<std::string, PizzaSize> stringToPizzaSize = {
{"S", PizzaSize::S},
{"M", PizzaSize::M},
{"L", PizzaSize::L},
{"XL", PizzaSize::XL},
{"XXL", PizzaSize::XXL}};

namespace plazza {
class Parsing {
public:
static std::vector<plazza::Order> parsingOrder(std::string orderLine);

protected:
private:
};
} // namespace plazza

#endif /* !PARSING_HPP_ */
4 changes: 4 additions & 0 deletions src/Pizza/APizza.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ std::vector<std::string> plazza::APizza::getIngredientsList() const {
}
return listIngredients;
}

std::string plazza::APizza::getType() const { return _type; }

size_t plazza::APizza::getBakingTime() const { return _bakingTime; }
5 changes: 5 additions & 0 deletions src/Pizza/APizza.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ class APizza : public plazza::IPizza {
Ingredients getIngredients() const override;
std::vector<std::string> 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:
};
Expand Down
3 changes: 3 additions & 0 deletions src/Pizza/IPizza.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class IPizza {
virtual Ingredients getIngredients() const = 0;
virtual std::vector<std::string> getIngredientsList() const = 0;

virtual std::string getType() const = 0;
virtual size_t getBakingTime() const = 0;

protected:
private:
};
Expand Down
2 changes: 2 additions & 0 deletions src/Pizza/Pizzas/Americana.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
plazza::Americana::Americana(PizzaSize size) : APizza(size) {
_size = size;
_ingredients = static_cast<Ingredients>(DOUGH | TOMATO | GRUYERE | STEAK);
_type = "Americana";
_bakingTime = 2;
}

plazza::Americana::~Americana() {}
2 changes: 2 additions & 0 deletions src/Pizza/Pizzas/Fantasia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plazza::Fantasia::Fantasia(PizzaSize size) : APizza(size) {
_size = size;
_ingredients = static_cast<Ingredients>(DOUGH | TOMATO | EGGPLANT |
GOATCHEESE | CHIEFLOVE);
_type = "Fantasia";
_bakingTime = 4;
}

plazza::Fantasia::~Fantasia() {}
2 changes: 2 additions & 0 deletions src/Pizza/Pizzas/Margarita.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
plazza::Margarita::Margarita(PizzaSize size) : APizza(size) {
_size = size;
_ingredients = static_cast<Ingredients>(DOUGH | TOMATO | GRUYERE);
_type = "Margarita";
_bakingTime = 1;
}

plazza::Margarita::~Margarita() {}
2 changes: 2 additions & 0 deletions src/Pizza/Pizzas/Regina.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plazza::Regina::Regina(PizzaSize size) : APizza(size) {
_size = size;
_ingredients =
static_cast<Ingredients>(DOUGH | TOMATO | GRUYERE | HAM | MUSHROOMS);
_type = "Regina";
_bakingTime = 2;
}

plazza::Regina::~Regina() {}
16 changes: 16 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "Parsing.hpp"
#include "PizzaFactory.hpp"
#include <iostream>

Expand All @@ -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<plazza::Order> 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;
}
}
}