Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewStiks committed May 30, 2024
1 parent f469cf7 commit 52349ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 16 additions & 7 deletions src/TimedDoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,42 @@
#include <stdexcept>
#include <thread> // 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;
}

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_));
}
Expand Down
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "TimedDoor.h"


int main() {
TimedDoor tDoor(5);
tDoor.lock();
Expand Down

0 comments on commit 52349ae

Please sign in to comment.