3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "staticobject.h"
21 #include "util/serialize.h"
24 void StaticObject::serialize(std::ostream
&os
)
29 writeV3F1000(os
, pos
);
31 os
<<serializeString(data
);
33 void StaticObject::deSerialize(std::istream
&is
, u8 version
)
38 pos
= readV3F1000(is
);
40 data
= deSerializeString(is
);
43 void StaticObjectList::serialize(std::ostream
&os
)
50 size_t count
= m_stored
.size() + m_active
.size();
51 // Make sure it fits into u16, else it would get truncated and cause e.g.
52 // issue #2610 (Invalid block data in database: unsupported NameIdMapping version).
53 if (count
> U16_MAX
) {
54 errorstream
<< "StaticObjectList::serialize(): "
55 << "too many objects (" << count
<< ") in list, "
56 << "not writing them to disk." << std::endl
;
57 writeU16(os
, 0); // count = 0
62 for(std::vector
<StaticObject
>::iterator
64 i
!= m_stored
.end(); ++i
) {
65 StaticObject
&s_obj
= *i
;
68 for(std::map
<u16
, StaticObject
>::iterator
70 i
!= m_active
.end(); ++i
)
72 StaticObject s_obj
= i
->second
;
76 void StaticObjectList::deSerialize(std::istream
&is
)
79 u8 version
= readU8(is
);
81 u16 count
= readU16(is
);
82 for(u16 i
= 0; i
< count
; i
++) {
84 s_obj
.deSerialize(is
, version
);
85 m_stored
.push_back(s_obj
);