LCOV - code coverage report
Current view: top level - src - staticobject.cpp (source / functions) Hit Total Coverage
Test: report Lines: 1 34 2.9 %
Date: 2015-07-11 18:23:49 Functions: 2 6 33.3 %

          Line data    Source code
       1             : /*
       2             : Minetest
       3             : Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
       4             : 
       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.
       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 Lesser General Public License for more details.
      14             : 
      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.
      18             : */
      19             : 
      20             : #include "staticobject.h"
      21             : #include "util/serialize.h"
      22             : 
      23           0 : void StaticObject::serialize(std::ostream &os)
      24             : {
      25             :         // type
      26           0 :         writeU8(os, type);
      27             :         // pos
      28           0 :         writeV3F1000(os, pos);
      29             :         // data
      30           0 :         os<<serializeString(data);
      31           0 : }
      32           0 : void StaticObject::deSerialize(std::istream &is, u8 version)
      33             : {
      34             :         // type
      35           0 :         type = readU8(is);
      36             :         // pos
      37           0 :         pos = readV3F1000(is);
      38             :         // data
      39           0 :         data = deSerializeString(is);
      40           0 : }
      41             : 
      42           0 : void StaticObjectList::serialize(std::ostream &os)
      43             : {
      44             :         // version
      45           0 :         u8 version = 0;
      46           0 :         writeU8(os, version);
      47             :         // count
      48           0 :         u16 count = m_stored.size() + m_active.size();
      49           0 :         writeU16(os, count);
      50           0 :         for(std::vector<StaticObject>::iterator
      51           0 :                         i = m_stored.begin();
      52           0 :                         i != m_stored.end(); ++i) {
      53           0 :                 StaticObject &s_obj = *i;
      54           0 :                 s_obj.serialize(os);
      55             :         }
      56           0 :         for(std::map<u16, StaticObject>::iterator
      57           0 :                         i = m_active.begin();
      58           0 :                         i != m_active.end(); ++i)
      59             :         {
      60           0 :                 StaticObject s_obj = i->second;
      61           0 :                 s_obj.serialize(os);
      62             :         }
      63           0 : }
      64           0 : void StaticObjectList::deSerialize(std::istream &is)
      65             : {
      66             :         // version
      67           0 :         u8 version = readU8(is);
      68             :         // count
      69           0 :         u16 count = readU16(is);
      70           0 :         for(u16 i = 0; i < count; i++) {
      71           0 :                 StaticObject s_obj;
      72           0 :                 s_obj.deSerialize(is, version);
      73           0 :                 m_stored.push_back(s_obj);
      74             :         }
      75           3 : }
      76             : 

Generated by: LCOV version 1.11