00001 /* $Id: unit_id.cpp 52650 2012-01-18 15:48:17Z anonymissimus $ */ 00002 /* 00003 Copyright (C) 2008 - 2012 by David White <dave@whitevine.net> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #include "log.hpp" 00017 #include "unit_id.hpp" 00018 00019 #include <cassert> 00020 00021 static lg::log_domain log_unit("unit"); 00022 #define DBG_UT LOG_STREAM(debug, log_unit) 00023 00024 // The following line sets the value to less than maximum of size_t, 00025 // but is required since config can't hold size_t and so whiteboard 00026 // chops it anyway during serialization to config, leading to later 00027 // errors (and some slowdown). 00028 // Setting the initial value to 2^32-1 is a safe and easy way to fix this. 00029 static const size_t INITIAL_FAKE_ID = 4294967295u; 00030 00031 namespace n_unit { 00032 id_manager id_manager::manager_; 00033 00034 id_manager::id_manager() : next_id_(0), fake_id_(INITIAL_FAKE_ID) 00035 {} 00036 00037 id_manager& id_manager::instance() 00038 { 00039 return manager_; 00040 } 00041 00042 size_t id_manager::next_id() 00043 { 00044 assert(next_id_ != fake_id_); 00045 DBG_UT << "id: " << next_id_ << "\n"; 00046 return ++next_id_; 00047 } 00048 00049 size_t id_manager::next_fake_id() 00050 { 00051 assert(next_id_ != fake_id_); 00052 DBG_UT << "fake id: " << fake_id_ << "\n"; 00053 return --fake_id_; 00054 } 00055 00056 size_t id_manager::get_save_id() 00057 { 00058 return next_id_; 00059 } 00060 00061 void id_manager::set_save_id(size_t id) 00062 { 00063 clear(); 00064 DBG_UT << "set save id: " << id << "\n"; 00065 next_id_ = id; 00066 } 00067 00068 void id_manager::reset_fake() 00069 { 00070 fake_id_ = INITIAL_FAKE_ID; 00071 } 00072 00073 void id_manager::clear() 00074 { 00075 next_id_ = 0; 00076 reset_fake(); 00077 } 00078 }
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:14 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |