From 52349ae9ff6e581fc09a79f6abc2b92411f24685 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 May 2024 21:11:30 +0300 Subject: [PATCH] fix --- src/TimedDoor.cpp | 23 ++++++++++++++++------- src/main.cpp | 1 - 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/TimedDoor.cpp b/src/TimedDoor.cpp index 5d084f5..bd96387 100644 --- a/src/TimedDoor.cpp +++ b/src/TimedDoor.cpp @@ -6,26 +6,34 @@ #include #include // NOLINT [build/c++11] +// DoorTimerAdapter Implementation DoorTimerAdapter::DoorTimerAdapter(TimedDoor& door_) : door(door_) {} void DoorTimerAdapter::Timeout() { - if (door.isDoorOpened()) throw std::runtime_error("Time's up!"); - return; + if (door.isDoorOpened()) { + throw std::runtime_error("Time's up!"); + } } -TimedDoor::TimedDoor(int timeout_) : iTimeout(timeout_), isOpened(false) { - adapter = new DoorTimerAdapter(*this); -} +// TimedDoor Implementation +TimedDoor::TimedDoor(int timeout_) + : iTimeout(timeout_), + isOpened(false), + adapter(new DoorTimerAdapter(*this)) {} bool TimedDoor::isDoorOpened() { return isOpened; } void TimedDoor::unlock() { - if (isOpened) throw std::logic_error("Door is already opened"); + if (isOpened) { + throw std::logic_error("Door is already opened"); + } isOpened = true; } void TimedDoor::lock() { - if (!isOpened) throw std::logic_error("Door is already closed"); + if (!isOpened) { + throw std::logic_error("Door is already closed"); + } isOpened = false; } @@ -33,6 +41,7 @@ int TimedDoor::getTimeOut() const { return iTimeout; } void TimedDoor::throwState() { adapter->Timeout(); } +// Timer Implementation void Timer::sleep(int time_) { std::this_thread::sleep_for(std::chrono::seconds(time_)); } diff --git a/src/main.cpp b/src/main.cpp index afb6311..4faf2c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,6 @@ #include "TimedDoor.h" - int main() { TimedDoor tDoor(5); tDoor.lock();