00001 /* 00002 * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net) 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 */ 00009 #include "RoomAccess.h" 00010 00011 #include "Room.h" 00012 #include "LogicException.h" 00013 00014 //----------------------------------------------------------------- 00015 /** 00016 * Room is not set. 00017 */ 00018 RoomAccess::RoomAccess() 00019 { 00020 m_room = NULL; 00021 } 00022 //----------------------------------------------------------------- 00023 RoomAccess::~RoomAccess() 00024 { 00025 cleanRoom(); 00026 } 00027 //----------------------------------------------------------------- 00028 void 00029 RoomAccess::takeRoom(Room *new_room) 00030 { 00031 cleanRoom(); 00032 m_room = new_room; 00033 } 00034 //----------------------------------------------------------------- 00035 /** 00036 * Remove old room. 00037 */ 00038 void 00039 RoomAccess::cleanRoom() 00040 { 00041 if (m_room) { 00042 delete m_room; 00043 m_room = NULL; 00044 } 00045 } 00046 //----------------------------------------------------------------- 00047 /** 00048 * Check whether room is ready. 00049 * @throws LogicException when room is not ready 00050 */ 00051 void 00052 RoomAccess::checkRoom() const 00053 { 00054 if (NULL == m_room) { 00055 throw LogicException(ExInfo("room is not ready")); 00056 } 00057 } 00058 //----------------------------------------------------------------- 00059 /** 00060 * Returns room or throws exception. 00061 */ 00062 Room * 00063 RoomAccess::room() 00064 { 00065 checkRoom(); 00066 return m_room; 00067 } 00068 //----------------------------------------------------------------- 00069 /** 00070 * Returns room or throws exception. 00071 */ 00072 const Room * 00073 RoomAccess::const_room() const 00074 { 00075 checkRoom(); 00076 return m_room; 00077 } 00078