1 # ###################################################
2 # Copyright (C) 2008 The OpenAnno Team
4 # This file is part of OpenAnno.
6 # OpenAnno 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 2 of the License, or
9 # (at your option) any later version.
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 General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # ###################################################
23 from changelistener
import Changelistener
25 class WorldObject(Changelistener
):
27 __objects
= weakref
.WeakValueDictionary()
28 def __init__(self
, **kwargs
):
29 super(WorldObject
, self
).__init
__(**kwargs
)
32 if not hasattr(self
, "_WorldObject__id"):
33 assert WorldObject
.__next
_id
not in WorldObject
.__objects
34 self
.__id
= WorldObject
.__next
_id
35 WorldObject
.__next
_id
= WorldObject
.__next
_id
+ 1
36 WorldObject
.__objects
[self
.__id
] = self
40 def getObjectById(cls
, id):
41 return cls
.__objects
[id]
51 def load(self
, db
, worldid
):
52 assert not hasattr(self
, '_WorldObject__id')
53 assert worldid
not in WorldObject
.__objects
54 print 'loading worldobject', worldid
, self
57 WorldObject
.__objects
[worldid
] = self
59 # Make sure that new WorldIDs are always higher than every other WorldObject
60 WorldObject
.__next
_id
= max(self
.__next
_id
, worldid
+ 1)
64 def get_objs(self
): return self
.__objects