Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

42 check pointer not null #44

Closed
wants to merge 2 commits into from
Closed
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
120 changes: 61 additions & 59 deletions cmake/sources.cmake
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
set(CONTROLLER_HEADERS
${CMAKE_SOURCE_DIR}/controllers/init_game_controller.h
${CMAKE_SOURCE_DIR}/controllers/create_game_controller.h
${CMAKE_SOURCE_DIR}/controllers/clear_game_controller.h
${CMAKE_SOURCE_DIR}/controllers/create_game_controller.h
${CMAKE_SOURCE_DIR}/controllers/init_game_controller.h
)
set(CONTROLLER_SOURCES
${CMAKE_SOURCE_DIR}/controllers/create_game_controller.cpp
${CMAKE_SOURCE_DIR}/controllers/clear_game_controller.cpp
${CMAKE_SOURCE_DIR}/controllers/create_game_controller.cpp
${CMAKE_SOURCE_DIR}/controllers/init_game_controller.cpp
)
set(PRESENTER_HEADERS
${CMAKE_SOURCE_DIR}/presenters/create_game_present.h
${CMAKE_SOURCE_DIR}/presenters/clear_game_present.h
${CMAKE_SOURCE_DIR}/presenters/presenter.h
${CMAKE_SOURCE_DIR}/presenters/create_game_present.h
${CMAKE_SOURCE_DIR}/presenters/init_game_present.h
${CMAKE_SOURCE_DIR}/presenters/presenter.h
)
set(PRESENTER_SOURCES
${CMAKE_SOURCE_DIR}/presenters/clear_game_present.cpp
${CMAKE_SOURCE_DIR}/presenters/create_game_present.cpp
${CMAKE_SOURCE_DIR}/presenters/init_game_present.cpp
${CMAKE_SOURCE_DIR}/presenters/clear_game_present.cpp
)
set(LOGGER_HEADERS
${CMAKE_SOURCE_DIR}/loggers/logger_base.h
${CMAKE_SOURCE_DIR}/loggers/logger.h
${CMAKE_SOURCE_DIR}/loggers/logger_base.h
)
set(LOGGER_SOURCES
${CMAKE_SOURCE_DIR}/loggers/logger.cpp
Expand All @@ -34,94 +34,96 @@ set(REPO_SOURCES
${CMAKE_SOURCE_DIR}/repos/memory_repository.cpp
)
set(UTIL_HEADERS
${CMAKE_SOURCE_DIR}/utils/util_base.h
${CMAKE_SOURCE_DIR}/utils/util.h
${CMAKE_SOURCE_DIR}/utils/util_base.h
)
set(UTIL_SOURCES
${CMAKE_SOURCE_DIR}/utils/util.cpp
)
set(USECASE_HEADERS
${CMAKE_SOURCE_DIR}/usecases/create_game.h
${CMAKE_SOURCE_DIR}/usecases/clear_game.h
${CMAKE_SOURCE_DIR}/usecases/create_game.h
${CMAKE_SOURCE_DIR}/usecases/init_game.h
)
set(USECASE_SOURCES
${CMAKE_SOURCE_DIR}/usecases/clear_game.cpp
${CMAKE_SOURCE_DIR}/usecases/create_game.cpp
${CMAKE_SOURCE_DIR}/usecases/init_game.cpp
${CMAKE_SOURCE_DIR}/usecases/clear_game.cpp
)
set(MODEL_HEADERS
${CMAKE_SOURCE_DIR}/models/dice.h
${CMAKE_SOURCE_DIR}/models/bank.h
${CMAKE_SOURCE_DIR}/models/machikoro_game.h
${CMAKE_SOURCE_DIR}/models/architecture_market.h
${CMAKE_SOURCE_DIR}/models/dice_base.h
${CMAKE_SOURCE_DIR}/models/player.h
${CMAKE_SOURCE_DIR}/models/events/init_game_event.h
${CMAKE_SOURCE_DIR}/models/events/create_game_event.h
${CMAKE_SOURCE_DIR}/models/events/clear_game_event.h
${CMAKE_SOURCE_DIR}/models/events/event.h
${CMAKE_SOURCE_DIR}/models/hand.h
${CMAKE_SOURCE_DIR}/models/cards/radio_tower.h
${CMAKE_SOURCE_DIR}/models/cards/stadium.h
${CMAKE_SOURCE_DIR}/models/cards/card.h
${CMAKE_SOURCE_DIR}/models/cards/ranch.h
${CMAKE_SOURCE_DIR}/models/bank.h
${CMAKE_SOURCE_DIR}/models/cards/amusement_park.h
${CMAKE_SOURCE_DIR}/models/cards/mine.h
${CMAKE_SOURCE_DIR}/models/cards/tv_station.h
${CMAKE_SOURCE_DIR}/models/cards/wheat_field.h
${CMAKE_SOURCE_DIR}/models/cards/cafe.h
${CMAKE_SOURCE_DIR}/models/cards/family_restaurant.h
${CMAKE_SOURCE_DIR}/models/cards/apple_orchard.h
${CMAKE_SOURCE_DIR}/models/cards/business_center.h
${CMAKE_SOURCE_DIR}/models/cards/landmark.h
${CMAKE_SOURCE_DIR}/models/cards/bakery.h
${CMAKE_SOURCE_DIR}/models/cards/building.h
${CMAKE_SOURCE_DIR}/models/cards/business_center.h
${CMAKE_SOURCE_DIR}/models/cards/cafe.h
${CMAKE_SOURCE_DIR}/models/cards/card.h
${CMAKE_SOURCE_DIR}/models/cards/cheese_factory.h
${CMAKE_SOURCE_DIR}/models/cards/bakery.h
${CMAKE_SOURCE_DIR}/models/cards/fruit_and_vegetable_market.h
${CMAKE_SOURCE_DIR}/models/cards/shopping_mall.h
${CMAKE_SOURCE_DIR}/models/cards/convenient_store.h
${CMAKE_SOURCE_DIR}/models/cards/furniture_factory.h
${CMAKE_SOURCE_DIR}/models/cards/family_restaurant.h
${CMAKE_SOURCE_DIR}/models/cards/forest.h
${CMAKE_SOURCE_DIR}/models/cards/fruit_and_vegetable_market.h
${CMAKE_SOURCE_DIR}/models/cards/furniture_factory.h
${CMAKE_SOURCE_DIR}/models/cards/landmark.h
${CMAKE_SOURCE_DIR}/models/cards/mine.h
${CMAKE_SOURCE_DIR}/models/cards/radio_tower.h
${CMAKE_SOURCE_DIR}/models/cards/ranch.h
${CMAKE_SOURCE_DIR}/models/cards/shopping_mall.h
${CMAKE_SOURCE_DIR}/models/cards/stadium.h
${CMAKE_SOURCE_DIR}/models/cards/train_station.h
${CMAKE_SOURCE_DIR}/models/cards/tv_station.h
${CMAKE_SOURCE_DIR}/models/cards/wheat_field.h
${CMAKE_SOURCE_DIR}/models/dice.h
${CMAKE_SOURCE_DIR}/models/dice_base.h
${CMAKE_SOURCE_DIR}/models/events/clear_game_event.h
${CMAKE_SOURCE_DIR}/models/events/create_game_event.h
${CMAKE_SOURCE_DIR}/models/events/event.h
${CMAKE_SOURCE_DIR}/models/events/event_player.h
${CMAKE_SOURCE_DIR}/models/events/init_game_event.h
${CMAKE_SOURCE_DIR}/models/hand.h
${CMAKE_SOURCE_DIR}/models/machikoro_game.h
${CMAKE_SOURCE_DIR}/models/player.h
)
set(MODEL_SOURCES
${CMAKE_SOURCE_DIR}/models/dice.cpp
${CMAKE_SOURCE_DIR}/models/machikoro_game.cpp
${CMAKE_SOURCE_DIR}/models/architecture_market.cpp
${CMAKE_SOURCE_DIR}/models/bank.cpp
${CMAKE_SOURCE_DIR}/models/player.cpp
${CMAKE_SOURCE_DIR}/models/hand.cpp
${CMAKE_SOURCE_DIR}/models/cards/convenient_store.cpp
${CMAKE_SOURCE_DIR}/models/cards/landmark.cpp
${CMAKE_SOURCE_DIR}/models/cards/forest.cpp
${CMAKE_SOURCE_DIR}/models/cards/radio_tower.cpp
${CMAKE_SOURCE_DIR}/models/cards/bakery.cpp
${CMAKE_SOURCE_DIR}/models/cards/shopping_mall.cpp
${CMAKE_SOURCE_DIR}/models/cards/mine.cpp
${CMAKE_SOURCE_DIR}/models/cards/cheese_factory.cpp
${CMAKE_SOURCE_DIR}/models/cards/family_restaurant.cpp
${CMAKE_SOURCE_DIR}/models/cards/wheat_field.cpp
${CMAKE_SOURCE_DIR}/models/cards/amusement_park.cpp
${CMAKE_SOURCE_DIR}/models/cards/tv_station.cpp
${CMAKE_SOURCE_DIR}/models/cards/cafe.cpp
${CMAKE_SOURCE_DIR}/models/cards/train_station.cpp
${CMAKE_SOURCE_DIR}/models/cards/business_center.cpp
${CMAKE_SOURCE_DIR}/models/cards/apple_orchard.cpp
${CMAKE_SOURCE_DIR}/models/cards/ranch.cpp
${CMAKE_SOURCE_DIR}/models/cards/bakery.cpp
${CMAKE_SOURCE_DIR}/models/cards/building.cpp
${CMAKE_SOURCE_DIR}/models/cards/furniture_factory.cpp
${CMAKE_SOURCE_DIR}/models/cards/business_center.cpp
${CMAKE_SOURCE_DIR}/models/cards/cafe.cpp
${CMAKE_SOURCE_DIR}/models/cards/card.cpp
${CMAKE_SOURCE_DIR}/models/cards/cheese_factory.cpp
${CMAKE_SOURCE_DIR}/models/cards/convenient_store.cpp
${CMAKE_SOURCE_DIR}/models/cards/family_restaurant.cpp
${CMAKE_SOURCE_DIR}/models/cards/forest.cpp
${CMAKE_SOURCE_DIR}/models/cards/fruit_and_vegetable_market.cpp
${CMAKE_SOURCE_DIR}/models/cards/furniture_factory.cpp
${CMAKE_SOURCE_DIR}/models/cards/landmark.cpp
${CMAKE_SOURCE_DIR}/models/cards/mine.cpp
${CMAKE_SOURCE_DIR}/models/cards/radio_tower.cpp
${CMAKE_SOURCE_DIR}/models/cards/ranch.cpp
${CMAKE_SOURCE_DIR}/models/cards/shopping_mall.cpp
${CMAKE_SOURCE_DIR}/models/cards/stadium.cpp
${CMAKE_SOURCE_DIR}/models/architecture_market.cpp
${CMAKE_SOURCE_DIR}/models/cards/train_station.cpp
${CMAKE_SOURCE_DIR}/models/cards/tv_station.cpp
${CMAKE_SOURCE_DIR}/models/cards/wheat_field.cpp
${CMAKE_SOURCE_DIR}/models/dice.cpp
${CMAKE_SOURCE_DIR}/models/events/init_game_event.cpp
${CMAKE_SOURCE_DIR}/models/hand.cpp
${CMAKE_SOURCE_DIR}/models/player.cpp
${CMAKE_SOURCE_DIR}/models/machikoro_game.cpp
)
set(E2E_SOURCES
${CMAKE_SOURCE_DIR}/tests/e2e_test/e2e_create_game.cpp
${CMAKE_SOURCE_DIR}/tests/e2e_test/e2e_init_game.cpp
${CMAKE_SOURCE_DIR}/tests/e2e_test/e2e_main.cpp
${CMAKE_SOURCE_DIR}/tests/e2e_test/test_def.h
${CMAKE_SOURCE_DIR}/tests/e2e_test/e2e_init_game.cpp
${CMAKE_SOURCE_DIR}/tests/e2e_test/e2e_create_game.cpp
)
set(UNIT_SOURCES
${CMAKE_SOURCE_DIR}/tests/unittest/unit_operate_effect.cpp
${CMAKE_SOURCE_DIR}/tests/unittest/unit_game.cpp
${CMAKE_SOURCE_DIR}/tests/unittest/unit_operate_effect.cpp
)
14 changes: 8 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

int main()
{
// Set HTTP listener address and port
drogon::app().addListener("127.0.0.1", 8080);
const std::string strConfig =
"{\"listeners\":[{\"address\":\"127.0.0.1\",\"port\":8080}],\"app\":{\"log\":{\"use_"
"spdlog\":true,\"log_level\":\"TRACE\"}},\"plugins\":[{\"name\":\"drogon::plugin::"
"AccessLogger\",\"config\":{\"use_spdlog\":true}}]}";
Json::Value jsonConfig;
Json::Reader reader;
reader.parse(strConfig, jsonConfig);

// Load config file
// drogon::app().loadConfigFile("../config.json");

// Run HTTP framework,the method will block in the internal event loop
drogon::app().loadConfigJson(jsonConfig);
drogon::app().run();

return 0;
Expand Down
13 changes: 7 additions & 6 deletions models/architecture_market.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "architecture_market.h"
#include <optional>

#include "models/cards/wheat_field.h"
#include "models/cards/ranch.h"
Expand Down Expand Up @@ -40,21 +41,21 @@ ArchitectureMarket::ArchitectureMarket()
generateBuildingsTemp<FruitAndVegetableMarket>(6);
}

BuildingPtr ArchitectureMarket::drawCard(const CardName& name)
std::optional<BuildingPtr> ArchitectureMarket::drawCard(CardName name)
{
if (cards_[name].empty()) return std::nullopt;

auto res = std::move(cards_[name].back());
cards_[name].pop_back();
return res;
}

std::map<CardName, std::vector<Building*>> ArchitectureMarket::cards() const
std::map<CardName, int> ArchitectureMarket::cards() const
{
std::map<CardName, std::vector<Building*>> res;
std::map<CardName, int> res;
for (const auto& card : cards_)
{
std::vector<Building*> buildings;
for (const auto& building : card.second) buildings.push_back(building.get());
res[card.first] = buildings;
res[card.first] = card.second.size();
}
return res;
}
5 changes: 3 additions & 2 deletions models/architecture_market.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <map>
#include <memory>
#include <functional>
#include <optional>

#include "cards/building.h"

Expand All @@ -17,9 +18,9 @@ class ArchitectureMarket {

~ArchitectureMarket() = default;

BuildingPtr drawCard(const CardName& name);
std::optional<BuildingPtr> drawCard(CardName name);

std::map<CardName, std::vector<Building*>> cards() const;
std::map<CardName, int> cards() const;

private:
// All the building cards.
Expand Down
2 changes: 1 addition & 1 deletion models/cards/amusement_park.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ AmusementPark::AmusementPark()
void AmusementPark::OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> players,
Bank* bank)
std::shared_ptr<Bank> bank)
{
}
2 changes: 1 addition & 1 deletion models/cards/amusement_park.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AmusementPark : public Landmark {
void OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> players,
Bank* bank) override;
std::shared_ptr<Bank> bank) override;
};

#endif
2 changes: 1 addition & 1 deletion models/cards/apple_orchard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ AppleOrchard::AppleOrchard()
void AppleOrchard::OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> players,
Bank* bank)
std::shared_ptr<Bank> bank)
{
}
2 changes: 1 addition & 1 deletion models/cards/apple_orchard.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AppleOrchard : public Building {
void OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> players,
Bank* bank) override;
std::shared_ptr<Bank> bank) override;
};

#endif
2 changes: 1 addition & 1 deletion models/cards/bakery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Bakery::Bakery()
void Bakery::OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> players,
Bank* bank)
std::shared_ptr<Bank> bank)
{
}
2 changes: 1 addition & 1 deletion models/cards/bakery.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Bakery : public Building {
void OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> players,
Bank* bank) override;
std::shared_ptr<Bank> bank) override;
};

#endif
6 changes: 3 additions & 3 deletions models/cards/building.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include <vector>

Building::Building(const CardName& name,
const CardType& type,
Building::Building(CardName name,
CardType type,
int price,
const IndustryType& ind,
IndustryType ind,
std::vector<int>&& points)
: Card(name, type, price)
, ind_type_(ind)
Expand Down
8 changes: 2 additions & 6 deletions models/cards/building.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ BuildingPtrs generateBuildingsTemp(int count)

class Building : public Card {
public:
Building(const CardName& name,
const CardType& type,
int price,
const IndustryType& ind,
std::vector<int>&& points);
Building(CardName name, CardType type, int price, IndustryType ind, std::vector<int>&& points);

~Building() = default;

virtual void OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> others,
Bank* bank) = 0;
std::shared_ptr<Bank> bank) = 0;

IndustryType industryType() const { return ind_type_; }

Expand Down
2 changes: 1 addition & 1 deletion models/cards/business_center.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ BusinessCenter::BusinessCenter()
void BusinessCenter::OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> players,
Bank* bank)
std::shared_ptr<Bank> bank)
{
}
2 changes: 1 addition & 1 deletion models/cards/business_center.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BusinessCenter : public Building {
void OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> players,
Bank* bank) override;
std::shared_ptr<Bank> bank) override;
};

#endif
2 changes: 1 addition & 1 deletion models/cards/cafe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Cafe::Cafe()
void Cafe::OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> players,
Bank* bank)
std::shared_ptr<Bank> bank)
{
}
2 changes: 1 addition & 1 deletion models/cards/cafe.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Cafe : public Building {
void OperateEffect(Player* owner,
Player* dice_roller,
std::vector<Player*> players,
Bank* bank) override;
std::shared_ptr<Bank> bank) override;
};

#endif
2 changes: 1 addition & 1 deletion models/cards/card.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "card.h"

Card::Card(const CardName& name, const CardType& type, int price)
Card::Card(CardName name, CardType type, int price)
: card_name_(name)
, card_type_(type)
, price_(price)
Expand Down
Loading