Used a more uniform of logging and added a commandline parser.
[UnsignedByte.git] / src / DB / Savables / Detail.cpp
blob4f92fb094da54a4dace91e1cdc473474bc542748
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 "Detail.h"
22 #include "Global.h"
23 #include "FieldImpls.h"
24 #include "Trace.h"
25 #include "TraceManager.h"
26 #include "Managers.h"
27 #include "TableImpls.h"
29 using mud::Detail;
31 Detail::Detail(SavableManagerPtr detail) :
32 m_detail(detail)
34 Assert(detail);
37 Detail::~Detail(void)
39 Unlock();
42 value_type Detail::getID() const
44 return m_detail->getValue(db::TableImpls::Get()->DETAILS->DETAILID)->getIntegerValue();
47 const std::string& Detail::getKey() const
49 return m_detail->getValue(db::TableImpls::Get()->DETAILS->KEY)->getStringValue();
52 const std::string& Detail::getDescription() const
54 return m_detail->getValue(db::TableImpls::Get()->DETAILS->DESCRIPTION)->getStringValue();
57 void Detail::setKey(const std::string& key)
59 Lock();
60 ValuePtr value(new FieldValue(db::TableImpls::Get()->DETAILS->KEY, key));
61 m_detail->setValue(value);
64 void Detail::setDescription(const std::string& description)
66 Lock();
67 ValuePtr value(new FieldValue(db::TableImpls::Get()->DETAILS->DESCRIPTION, description));
68 m_detail->setValue(value);
71 void Detail::Delete()
73 Lock();
74 m_detail->erase();
77 void Detail::Save()
79 Lock();
80 m_detail->save();
83 void mud::Detail::Delete(value_type accountid, const std::string& description)
85 Assert(!"Not yet implemented.");
88 void mud::Detail::Save(value_type accountid, const std::string& description)
90 if(!m_detail->isDirty())
91 return;
93 Lock();
95 KeysPtr keys = mud::Managers::Get()->Trace->Add();
96 mud::TracePtr trace = mud::Managers::Get()->Trace->GetByKey(keys->first()->getIntegerValue());
98 if(accountid)
100 trace->setAccount(accountid);
102 if(description != Global::Get()->EmptyString)
103 trace->setDescription(description);
106 trace->setDiff(m_detail->getDiff());
107 trace->setTime(time(NULL));
108 trace->Save(); // create the Trace
110 RelationPtr relation(new Relation(db::TableImpls::Get()->TRACEDETAIL));
111 relation->addKey(db::TableImpls::Get()->TRACEDETAIL->FKDETAILS, getID());
112 relation->addKey(db::TableImpls::Get()->TRACEDETAIL->FKTRACES, keys->first()->getIntegerValue());
113 relation->save(); // create the relation
115 m_detail->save(); // save the room
118 void Detail::Discard()
120 Lock();
121 m_detail->discard();
124 bool Detail::Exists()
126 return m_detail->exists();
129 SavableManagerPtr Detail::getManager() const
131 return m_detail;
134 TableImplPtr Detail::getTable() const
136 return m_detail->getTable();