initial commit, lordsawar source, slightly modified
[lordsawar] / src / UniquelyIdentified.cpp
1 // Copyright (C) 2001, 2002, 2003 Michael Bartl
2 // Copyright (C) 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2005 Andrea Paternesi
4 // Copyright (C) 2007, 2008 Ben Asselstine
5 //
6 //  This program is free software; you can redistribute it and/or modify
7 //  it under the terms of the GNU General Public License as published by
8 //  the Free Software Foundation; either version 3 of the License, or
9 //  (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU Library General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
19 //  02110-1301, USA.
20
21 #include "config.h"
22 #include "UniquelyIdentified.h"
23 #include "counter.h"
24 #include "xmlhelper.h"
25
26 UniquelyIdentified::UniquelyIdentified()
27 {
28     d_id = fl_counter->getNextId();
29     d_unique = true;
30 }
31
32 UniquelyIdentified::UniquelyIdentified(const UniquelyIdentified& obj)
33     :d_id(obj.d_id), d_unique(false)
34 {
35 }
36
37 UniquelyIdentified::UniquelyIdentified(guint32 id)
38 {
39     d_id = id;
40     d_unique = false;
41     syncNewId();
42 }
43
44 UniquelyIdentified::UniquelyIdentified(XML_Helper* helper)
45 {
46     helper->getData(d_id, "id");
47     //only unique objects are saved.
48     d_unique = true;
49 }
50
51 UniquelyIdentified::~UniquelyIdentified()
52 {
53 }
54
55 void UniquelyIdentified::syncNewId()
56 {
57   //we sync to the one after, so we don't reuse the same id
58   fl_counter->syncToId(d_id + 1);
59 }
60
61 void UniquelyIdentified::assignNewId()
62 {
63   d_id = fl_counter->getNextId();
64   d_unique = true;
65 }