Add a filter-by-from/to-chunk in ExitManager::List.
[UnsignedByte.git] / src / DB / Savables / Exit.cpp
blob6b9fadc6d3565f4a97d191f88b6452817c73b3d0
1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "Exit.h"
22 #include "Global.h"
23 #include "FieldImpls.h"
24 #include "TableImpls.h"
26 using mud::Exit;
28 Exit::Exit(SavableManagerPtr exit) :
29 m_exit(exit)
31 Assert(m_exit);
34 Exit::~Exit(void)
36 Unlock();
39 value_type Exit::getFromChunk() const
41 return m_exit->getValue(db::TableImpls::Get()->EXITS->FKCHUNKSFROM)->getIntegerValue();
44 value_type Exit::getToChunk() const
46 return m_exit->getValue(db::TableImpls::Get()->EXITS->FKCHUNKSTO)->getIntegerValue();
49 Coordinate Exit::getDirection() const
51 int x = m_exit->getValue(db::TableImpls::Get()->EXITS->X)->getIntegerValue();
52 int y = m_exit->getValue(db::TableImpls::Get()->EXITS->Y)->getIntegerValue();
53 int z = m_exit->getValue(db::TableImpls::Get()->EXITS->Z)->getIntegerValue();
55 Coordinate result(x, y, z);
56 return result;
59 void Exit::setFromChunk(value_type room)
61 Lock();
62 ValuePtr value(new FieldValue(db::TableImpls::Get()->EXITS->FKCHUNKSFROM, room));
63 m_exit->setValue(value);
66 void Exit::setToChunk(value_type room)
68 Lock();
69 ValuePtr value(new FieldValue(db::TableImpls::Get()->EXITS->FKCHUNKSTO, room));
70 m_exit->setValue(value);
73 void Exit::setDirection(const Coordinate& direction)
75 Assert(direction.isDirection());
77 Lock();
78 ValuePtr value;
80 value = FieldValuePtr(new FieldValue(db::TableImpls::Get()->EXITS->X, direction.getXCoordinate()));
81 m_exit->setValue(value);
83 value = FieldValuePtr(new FieldValue(db::TableImpls::Get()->EXITS->Y, direction.getYCoordinate()));
84 m_exit->setValue(value);
86 value = FieldValuePtr(new FieldValue(db::TableImpls::Get()->EXITS->Z, direction.getZCoordinate()));
87 m_exit->setValue(value);
90 void Exit::Delete()
92 Lock();
93 m_exit->erase();
96 void Exit::Save()
98 Lock();
99 m_exit->save();
102 void Exit::Discard()
104 Lock();
105 m_exit->discard();
108 bool Exit::Exists()
110 return m_exit->exists();
113 SavableManagerPtr Exit::getManager() const
115 return m_exit;
118 TableImplPtr Exit::getTable() const
120 return m_exit->getTable();