| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "RoomAccess.h" |
| 10 |
|
| 11 |
#include "Room.h" |
| 12 |
#include "LogicException.h" |
| 13 |
|
| 14 |
//----------------------------------------------------------------- |
| 15 |
/** |
| 16 |
* Room is not set. |
| 17 |
*/ |
| 18 |
RoomAccess::RoomAccess() |
| 19 |
{ |
| 20 |
m_room = NULL; |
| 21 |
} |
| 22 |
//----------------------------------------------------------------- |
| 23 |
RoomAccess::~RoomAccess() |
| 24 |
{ |
| 25 |
cleanRoom(); |
| 26 |
} |
| 27 |
//----------------------------------------------------------------- |
| 28 |
void |
| 29 |
RoomAccess::takeRoom(Room *new_room) |
| 30 |
{ |
| 31 |
cleanRoom(); |
| 32 |
m_room = new_room; |
| 33 |
} |
| 34 |
//----------------------------------------------------------------- |
| 35 |
/** |
| 36 |
* Remove old room. |
| 37 |
*/ |
| 38 |
void |
| 39 |
RoomAccess::cleanRoom() |
| 40 |
{ |
| 41 |
if (m_room) { |
| 42 |
delete m_room; |
| 43 |
m_room = NULL; |
| 44 |
} |
| 45 |
} |
| 46 |
//----------------------------------------------------------------- |
| 47 |
/** |
| 48 |
* Check whether room is ready. |
| 49 |
* @throws LogicException when room is not ready |
| 50 |
*/ |
| 51 |
void |
| 52 |
RoomAccess::checkRoom() const |
| 53 |
{ |
| 54 |
if (NULL == m_room) { |
| 55 |
throw LogicException(ExInfo("room is not ready")); |
| 56 |
} |
| 57 |
} |
| 58 |
//----------------------------------------------------------------- |
| 59 |
/** |
| 60 |
* Returns room or throws exception. |
| 61 |
*/ |
| 62 |
Room * |
| 63 |
RoomAccess::room() |
| 64 |
{ |
| 65 |
checkRoom(); |
| 66 |
return m_room; |
| 67 |
} |
| 68 |
//----------------------------------------------------------------- |
| 69 |
/** |
| 70 |
* Returns room or throws exception. |
| 71 |
*/ |
| 72 |
const Room * |
| 73 |
RoomAccess::const_room() const |
| 74 |
{ |
| 75 |
checkRoom(); |
| 76 |
return m_room; |
| 77 |
} |
| 78 |
|