mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-06 18:50:15 +00:00
Strip trailing whitespace.
This commit is contained in:
parent
b357fb6188
commit
da684d9f0b
@ -51,7 +51,7 @@ public:
|
||||
* and parse several (usually, 1) aspects out of it
|
||||
*/
|
||||
virtual void do_parse_aspect_from_config( const config &cfg, const std::string &id, std::back_insert_iterator<std::vector< aspect_ptr > > b );
|
||||
|
||||
|
||||
virtual void do_parse_goal_from_config(const config &cfg, std::back_insert_iterator<std::vector< goal_ptr > > b );
|
||||
|
||||
virtual std::string evaluate(const std::string &str);
|
||||
@ -74,7 +74,7 @@ private:
|
||||
* The underlying lua code
|
||||
*/
|
||||
std::string code_;
|
||||
|
||||
|
||||
//There is one lua engine per AI. So, it can hold state
|
||||
boost::shared_ptr<lua_ai_context> lua_ai_context_;
|
||||
|
||||
|
@ -306,7 +306,7 @@ lua_goal::lua_goal(readonly_context &context, const config &cfg)
|
||||
if (cfg.has_attribute("code")) {
|
||||
code_ = cfg["code"].str();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// report failure
|
||||
}
|
||||
@ -319,17 +319,17 @@ void lua_goal::on_create(boost::shared_ptr<ai::lua_ai_context> l_ctx)
|
||||
|
||||
void lua_goal::add_targets(std::back_insert_iterator< std::vector< target > > target_list)
|
||||
{
|
||||
boost::shared_ptr< lua_object< std::vector < target > > > l_obj
|
||||
boost::shared_ptr< lua_object< std::vector < target > > > l_obj
|
||||
= boost::shared_ptr< lua_object< std::vector < target > > >(new lua_object< std::vector < target > >());
|
||||
config c = config();
|
||||
handler_->handle(c, true, l_obj);
|
||||
std::vector < target > targets = *(l_obj->get());
|
||||
|
||||
|
||||
foreach (target tg, targets)
|
||||
{
|
||||
*target_list = tg;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
class terrain_filter;
|
||||
|
||||
namespace ai {
|
||||
|
||||
|
||||
class lua_ai_context;
|
||||
class lua_ai_action_handler;
|
||||
|
||||
@ -171,7 +171,7 @@ public:
|
||||
lua_goal(readonly_context& context, const config& cfg);
|
||||
virtual void add_targets(std::back_insert_iterator< std::vector< target > > target_list);
|
||||
void on_create(boost::shared_ptr<ai::lua_ai_context>);
|
||||
|
||||
|
||||
private:
|
||||
std::string code_;
|
||||
boost::shared_ptr<lua_ai_action_handler> handler_;
|
||||
|
@ -59,7 +59,7 @@ static char const aisKey = 0;
|
||||
namespace ai {
|
||||
|
||||
static void push_map_location(lua_State *L, const map_location& ml);
|
||||
|
||||
|
||||
void lua_ai_context::init(lua_State *L)
|
||||
{
|
||||
// Create the ai elements table.
|
||||
@ -71,21 +71,21 @@ void lua_ai_context::init(lua_State *L)
|
||||
void lua_ai_context::get_persistent_data(config &cfg) const
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
|
||||
lua_pushlightuserdata(L, (void *)&aisKey);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
lua_rawgeti(L, -1, num_);
|
||||
|
||||
|
||||
lua_getfield(L, -1, "data");
|
||||
luaW_toconfig(L, -1, cfg);
|
||||
|
||||
|
||||
lua_settop(L, top);
|
||||
}
|
||||
|
||||
void lua_ai_context::set_persistent_data(const config &cfg)
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
|
||||
lua_pushlightuserdata(L, (void *)&aisKey);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
lua_rawgeti(L, -1, num_);
|
||||
@ -292,28 +292,28 @@ static int cfun_ai_get_targets(lua_State *L)
|
||||
move_map enemy_dst_src = get_readonly_context(L).get_enemy_dstsrc();
|
||||
std::vector<target> targets = get_engine(L).get_ai_context()->find_targets(enemy_dst_src);
|
||||
int i = 1;
|
||||
|
||||
|
||||
lua_createtable(L, 0, 0);
|
||||
for (std::vector<target>::iterator it = targets.begin(); it != targets.end(); it++)
|
||||
{
|
||||
lua_pushinteger(L, i);
|
||||
|
||||
|
||||
//to factor out
|
||||
lua_createtable(L, 3, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
lua_pushstring(L, "type");
|
||||
lua_pushnumber(L, it->type);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
|
||||
lua_pushstring(L, "loc");
|
||||
push_map_location(L, it->loc);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
|
||||
lua_pushstring(L, "value");
|
||||
lua_pushnumber(L, it->value);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
|
||||
lua_rawset(L, -3);
|
||||
++i;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "resources.hpp"
|
||||
|
||||
namespace ai {
|
||||
|
||||
|
||||
|
||||
class lua_object_base {
|
||||
|
||||
@ -153,43 +153,43 @@ inline boost::shared_ptr<std::vector<target> > lua_object< std::vector<target> >
|
||||
boost::shared_ptr<std::vector<target> > targets = boost::shared_ptr<std::vector<target> >(new std::vector<target>());
|
||||
std::back_insert_iterator< std::vector<target> > tg(*targets);
|
||||
int l = lua_objlen(L, n);
|
||||
|
||||
|
||||
for (int i = 1; i <= l; ++i)
|
||||
{
|
||||
lua_rawgeti(L, n, i); // st n + 1 TABLE @ N table @ n + 1
|
||||
|
||||
lua_rawgeti(L, n, i); // st n + 1 TABLE @ N table @ n + 1
|
||||
|
||||
lua_pushstring(L, "loc"); // st n + 2
|
||||
lua_rawget(L, -2); // st n + 2
|
||||
|
||||
lua_rawget(L, -2); // st n + 2
|
||||
|
||||
lua_pushstring(L, "x"); // st n + 3
|
||||
lua_rawget(L, -2); // st n + 3
|
||||
int x = lua_tointeger(L, -1); // st n + 3
|
||||
int x = lua_tointeger(L, -1); // st n + 3
|
||||
lua_pop(L, 1); // st n + 2
|
||||
|
||||
|
||||
lua_pushstring(L, "y"); // st n + 3
|
||||
lua_rawget(L, -2); // st n + 3
|
||||
int y = lua_tointeger(L, -1); // st n + 3
|
||||
|
||||
int y = lua_tointeger(L, -1); // st n + 3
|
||||
|
||||
lua_pop(L, 2); // st n + 1
|
||||
|
||||
|
||||
lua_pushstring(L, "type"); // st n + 2
|
||||
lua_rawget(L, -2); // st n + 2
|
||||
target::TYPE type = (target::TYPE)lua_tointeger(L, -1); // st n + 2
|
||||
lua_pop(L, 1); // st n + 1
|
||||
|
||||
|
||||
|
||||
|
||||
lua_pushstring(L, "value");
|
||||
lua_rawget(L, -2);
|
||||
int value = lua_tointeger(L, -1);
|
||||
|
||||
|
||||
map_location ml(x - 1, y - 1);
|
||||
|
||||
|
||||
*tg = target(ml, value, type);
|
||||
}
|
||||
|
||||
|
||||
lua_settop(L, n);
|
||||
return targets;
|
||||
}
|
||||
}
|
||||
|
||||
} // end of namespace ai
|
||||
|
||||
|
@ -96,13 +96,13 @@ void holder::init( side_number side )
|
||||
modify_ai(mod_ai);
|
||||
}
|
||||
cfg_.clear_children("modify_ai");
|
||||
|
||||
|
||||
std::vector<engine_ptr> engines = ai_->get_engines();
|
||||
for (std::vector<engine_ptr>::iterator it = engines.begin(); it != engines.end(); ++it)
|
||||
{
|
||||
(*it)->set_ai_context(&(ai_->get_ai_context()));
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
ERR_AI_MANAGER << describe_ai()<<"AI lazy initialization error!" << std::endl;
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ static register_goal_factory<protect_my_unit_goal>
|
||||
|
||||
static register_goal_factory<protect_unit_goal>
|
||||
goal_factory_protect_unit("protect_unit");
|
||||
|
||||
|
||||
static register_goal_factory<lua_goal>
|
||||
goal_factory_lua_goal("lua_goal");
|
||||
|
||||
|
@ -880,7 +880,7 @@ void get_villages_phase::execute()
|
||||
}
|
||||
|
||||
if(leader_move.second.valid()) {
|
||||
if((find_visible_unit(leader_move.first , current_team()) == units_.end())
|
||||
if((find_visible_unit(leader_move.first , current_team()) == units_.end())
|
||||
&& resources::game_map->is_village(leader_move.first)) {
|
||||
move_result_ptr move_res = execute_move_action(leader_move.second,leader_move.first,true);
|
||||
if (!move_res->is_ok()) {
|
||||
|
@ -700,8 +700,8 @@ std::vector<surface> display::get_terrain_images(const map_location &loc,
|
||||
if(is_same_as_global ) {
|
||||
// It's the same as global ToD, don't use local light
|
||||
use_local_light = false;
|
||||
} else if ((tod.red + color_adjust_red_) != 0
|
||||
|| (tod.green + color_adjust_green_) != 0
|
||||
} else if ((tod.red + color_adjust_red_) != 0
|
||||
|| (tod.green + color_adjust_green_) != 0
|
||||
|| (tod.blue + color_adjust_blue_) != 0) {
|
||||
// simply color it if needed
|
||||
mod << "~CS("
|
||||
|
@ -168,9 +168,9 @@ public:
|
||||
/** A temporary unit that can be placed on the map.
|
||||
Temporary units can overlap units.
|
||||
Adding the same unit twice isn't allowed.
|
||||
The temp_unit owns its underlying unit and when
|
||||
The temp_unit owns its underlying unit and when
|
||||
it goes out of scope it removes itself from the temp_units list.
|
||||
The intent is to provide exception safety when the code
|
||||
The intent is to provide exception safety when the code
|
||||
creating the temp unit is unexpectedly forced out of scope.
|
||||
*/
|
||||
class temp_unit : public unit {
|
||||
|
@ -41,11 +41,11 @@ tlistbox_definition::tresolution::tresolution(const config& cfg)
|
||||
* @begin{parent}{name="gui/"}
|
||||
* @begin{tag}{name="listbox_definition"}{min=0}{max=-1}{super="generic/widget_definition"}
|
||||
* == Listbox ==
|
||||
*
|
||||
*
|
||||
* @macro = listbox_description
|
||||
*
|
||||
* The definition of a listbox contains the definition of its scrollbar.
|
||||
*
|
||||
*
|
||||
* The resolution for a listbox also contains the following keys:
|
||||
* @begin{tag}{name="resolution"}{min=0}{max=-1}{super=generic/widget_definition/resolution}
|
||||
* @begin{table}{config}
|
||||
|
@ -43,7 +43,7 @@ tpanel_definition::tresolution::tresolution(const config& cfg)
|
||||
* == Panel ==
|
||||
*
|
||||
* @macro = panel_description
|
||||
*
|
||||
*
|
||||
* @begin{parent}{name="gui/"}
|
||||
* @begin{tag}{name="panel_definition"}{min=0}{max=-1}{super="generic/widget_definition"}
|
||||
* A panel is always enabled and can't be disabled. Instead it uses the
|
||||
|
@ -42,7 +42,7 @@ tscroll_label_definition::tresolution::tresolution(const config& cfg)
|
||||
* == Scroll label ==
|
||||
*
|
||||
* @macro = scroll_label_description
|
||||
*
|
||||
*
|
||||
* @begin{parent}{name="gui/"}
|
||||
* This widget is slower as a normal label widget so only use this widget
|
||||
* when the scrollbar is required (or expected to become required).
|
||||
|
@ -350,7 +350,7 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
|
||||
* @begin{tag}{name="tooltip"}{min=0}{max=1}
|
||||
* A tooltip and helptip section have the following field:
|
||||
* @begin{table}{config}
|
||||
* id & string & & The id of the tip to show.
|
||||
* id & string & & The id of the tip to show.
|
||||
* Note more fields will probably be added later on.
|
||||
* @end{table}{config}
|
||||
* @end{tag}{name=tooltip}
|
||||
|
@ -481,19 +481,19 @@ surface locator::load_image_sub_file() const
|
||||
surf = (*mod)(surf);
|
||||
delete mod;
|
||||
}
|
||||
|
||||
|
||||
if(val_.loc_.valid()) {
|
||||
SDL_Rect srcrect = create_rect(
|
||||
((tile_size*3) / 4) * val_.loc_.x
|
||||
, tile_size * val_.loc_.y + (tile_size / 2) * (val_.loc_.x % 2)
|
||||
, tile_size
|
||||
, tile_size);
|
||||
|
||||
|
||||
if(val_.center_x_ >= 0 && val_.center_y_>= 0){
|
||||
srcrect.x += surf->w/2 - val_.center_x_;
|
||||
srcrect.y += surf->h/2 - val_.center_y_;
|
||||
}
|
||||
|
||||
|
||||
surface cut(cut_surface(surf, srcrect));
|
||||
surf = mask_surface(cut, get_hexmask());
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ std::ostream &operator<<(std::ostream &s, map_location const &l);
|
||||
std::ostream &operator<<(std::ostream &s, std::vector<map_location> const &v);
|
||||
|
||||
/** Inlined bodies **/
|
||||
inline std::size_t hash_value(map_location const & a){
|
||||
inline std::size_t hash_value(map_location const & a){
|
||||
boost::hash<size_t> h;
|
||||
return h( (a.x << 16) ^ a.y );
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ std::pair<unit_map::unit_iterator, bool> unit_map::add(const map_location &l, co
|
||||
}
|
||||
|
||||
std::pair<unit_map::unit_iterator, bool> unit_map::move(const map_location &src, const map_location &dst) {
|
||||
DBG_NG << "Unit map: Moving unit from " << src << " to " << dst << "\n";
|
||||
DBG_NG << "Unit map: Moving unit from " << src << " to " << dst << "\n";
|
||||
|
||||
t_lmap::iterator i = lmap_.find(src);
|
||||
if(i == lmap_.end()) { return std::make_pair(make_unit_iterator(the_end_), false);}
|
||||
@ -95,14 +95,14 @@ std::pair<unit_map::unit_iterator, bool> unit_map::move(const map_location &src,
|
||||
t_ilist::iterator lit(i->second);
|
||||
|
||||
///@todo upgrade to quick_erase when boost 1.42 supported by wesnoth
|
||||
lmap_.erase(i);
|
||||
lmap_.erase(i);
|
||||
|
||||
p->set_location(dst);
|
||||
|
||||
std::pair<t_lmap::iterator,bool> res = lmap_.insert(std::make_pair(dst, lit));
|
||||
if(res.second == false) {
|
||||
std::pair<t_lmap::iterator,bool> res = lmap_.insert(std::make_pair(dst, lit));
|
||||
if(res.second == false) {
|
||||
p->set_location(src);
|
||||
lmap_.insert(std::make_pair(src, lit));
|
||||
lmap_.insert(std::make_pair(src, lit));
|
||||
return std::make_pair(make_unit_iterator(lit), false);
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ std::pair<unit_map::unit_iterator, bool> unit_map::move(const map_location &src,
|
||||
/** Inserts the unit pointed to by @a p into the unit_map.
|
||||
|
||||
1. Inserts the unit into the ilist.
|
||||
2. Inserts the iterator from ilist into the lmap at the desired location.
|
||||
2. Inserts the iterator from ilist into the lmap at the desired location.
|
||||
If it fails it remove the unit from ilist.
|
||||
3. Inserts the iterator to the ilist into the umap with a unique id,
|
||||
creating a new one if necessary.
|
||||
@ -138,14 +138,14 @@ std::pair<unit_map::unit_iterator, bool> unit_map::insert(unit *p)
|
||||
DBG_NG << "Adding unit " << p->underlying_id() << " - " << p->id()
|
||||
<< " to location: (" << loc << ")\n";
|
||||
|
||||
std::pair<t_lmap::iterator,bool> res = lmap_.insert(std::make_pair(loc, lit ));
|
||||
std::pair<t_lmap::iterator,bool> res = lmap_.insert(std::make_pair(loc, lit ));
|
||||
|
||||
if(!res.second){
|
||||
ilist_.pop_front();
|
||||
DBG_NG << "Trying to add " << p->name()
|
||||
<< " - " << p->id() << " at location ("<<loc <<"); Occupied by "
|
||||
<<(res.first->second)->unit_->name()<< " - " << res.first->second->unit_->id() <<"\n";
|
||||
return std::make_pair(make_unit_iterator(the_end_), false);
|
||||
return std::make_pair(make_unit_iterator(the_end_), false);
|
||||
}
|
||||
|
||||
std::pair<t_umap::iterator, bool> biter =
|
||||
@ -164,14 +164,14 @@ std::pair<unit_map::unit_iterator, bool> unit_map::insert(unit *p)
|
||||
<< "). The new unit will be assigned underlying_id="
|
||||
<< (1 + n_unit::id_manager::instance().get_save_id())
|
||||
<< " to prevent duplicate id conflicts.\n";
|
||||
|
||||
|
||||
p->clone(false);
|
||||
biter = umap_.insert(std::make_pair(p->underlying_id(), lit ));
|
||||
if (!biter.second) { bool never_happen(false); assert(never_happen); }
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair( make_unit_iterator( lit ), true);
|
||||
return std::make_pair( make_unit_iterator( lit ), true);
|
||||
}
|
||||
|
||||
std::pair<unit_map::unit_iterator, bool> unit_map::replace(const map_location &l, const unit &u)
|
||||
@ -226,14 +226,14 @@ unit *unit_map::extract(const map_location &loc) {
|
||||
|
||||
i->second->unit_ = NULL;
|
||||
i->second->deleted_uid_ = res->underlying_id();
|
||||
if(i->second->ref_count_ == 0){
|
||||
if(i->second->ref_count_ == 0){
|
||||
assert(i->second != the_end_);
|
||||
ilist_.erase( i->second );
|
||||
ilist_.erase( i->second );
|
||||
}
|
||||
|
||||
///@todo replace with quick_erase(i) when wesnoth supports boost 1.42 min version
|
||||
///@todo replace with quick_erase(i) when wesnoth supports boost 1.42 min version
|
||||
umap_.erase(res->underlying_id());
|
||||
lmap_.erase(i);
|
||||
lmap_.erase(i);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -33,15 +33,15 @@ class unit;
|
||||
* An indirection location -> underlying_id -> unit ensures that iterators
|
||||
* stay valid even if WML modifies or moves units on the fly. They even stay
|
||||
* valid if a unit is erased from the map and another unit with the same
|
||||
* underlying id is inserted in the map. In other words it is a doubly indexed ordered map
|
||||
* underlying id is inserted in the map. In other words it is a doubly indexed ordered map
|
||||
with persistent iterators (that never invalidate)
|
||||
|
||||
@note The unit_map is implemented as 2 unordered maps storing iterators from a list of reference counted pointers to units.
|
||||
The unordered maps provide O(1) find times. The list allows arbitrary ordering of units (not yet implemented).
|
||||
The reference counting is what guarrantees the persistent iterators.
|
||||
The unordered maps provide O(1) find times. The list allows arbitrary ordering of units (not yet implemented).
|
||||
The reference counting is what guarrantees the persistent iterators.
|
||||
Storing an iterator prevents only that dead unit's list location from being recovered.
|
||||
|
||||
@note Prefered usages for tight loops follows.
|
||||
@note Prefered usages for tight loops follows.
|
||||
Use the std::pair<iterator, bool> format which checks the preconditions and returns
|
||||
false in the bool to indicate failure with no change to the unit_map. true indicates sucess and the new iterator is in first.
|
||||
Storing the result iterator prevents the old iterator from entering the fallback recovery code.
|
||||
@ -69,11 +69,11 @@ if(try_add.second){i = try_add.first;}
|
||||
|
||||
|
||||
|
||||
@note The previous implementation was 2 binary tree based maps one the location map pointing to the other.
|
||||
Lookups were O(2*log(N)) and O(log(N)). Order was implicit in the id map choosen as the base.
|
||||
Persistence was provided by reference counting all iterators collectively and only recovering space when
|
||||
there were no iterators outstanding. Even 1 iterator being stored caused a leak, because
|
||||
all space for dead units is not recovered.
|
||||
@note The previous implementation was 2 binary tree based maps one the location map pointing to the other.
|
||||
Lookups were O(2*log(N)) and O(log(N)). Order was implicit in the id map choosen as the base.
|
||||
Persistence was provided by reference counting all iterators collectively and only recovering space when
|
||||
there were no iterators outstanding. Even 1 iterator being stored caused a leak, because
|
||||
all space for dead units is not recovered.
|
||||
|
||||
* @note Units are owned by the container.
|
||||
* @note The indirection does not involve map lookups whenever an iterator
|
||||
@ -105,15 +105,15 @@ class unit_map {
|
||||
};
|
||||
|
||||
/// A list pointing to unit and their reference counters. Dead units have a unit_ pointer equal to NULL.
|
||||
/// The list element is remove iff the reference counter equals zero and there are no more
|
||||
/// The list element is remove iff the reference counter equals zero and there are no more
|
||||
///iterators pointing to this unit.
|
||||
typedef std::list<unit_pod> t_ilist;
|
||||
|
||||
///Maps of id and location to list iterator.
|
||||
///Maps of id and location to list iterator.
|
||||
///@note list iterators never invalidate due to resizing or deletion.
|
||||
typedef boost::unordered_map<size_t, t_ilist::iterator> t_umap;
|
||||
typedef boost::unordered_map<size_t, t_ilist::iterator> t_umap;
|
||||
typedef boost::unordered_map<map_location, t_ilist::iterator> t_lmap;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// ~~~ Begin iterator code ~~~
|
||||
@ -145,13 +145,13 @@ public:
|
||||
|
||||
iterator_base(): i_(), tank_(NULL) { }
|
||||
|
||||
iterator_base(iterator_type i, container_type *m) : i_(i), tank_(m) {
|
||||
inc();
|
||||
iterator_base(iterator_type i, container_type *m) : i_(i), tank_(m) {
|
||||
inc();
|
||||
valid_exit();
|
||||
}
|
||||
|
||||
iterator_base(const iterator_base &that) : i_(that.i_), tank_(that.tank_) {
|
||||
inc();
|
||||
iterator_base(const iterator_base &that) : i_(that.i_), tank_(that.tank_) {
|
||||
inc();
|
||||
valid_exit();
|
||||
}
|
||||
|
||||
@ -172,22 +172,22 @@ public:
|
||||
|
||||
private:
|
||||
///Construct an iterator from the uid map
|
||||
iterator_base(t_umap::iterator ui, container_type *m) : i_(ui->second), tank_(m) {
|
||||
inc();
|
||||
iterator_base(t_umap::iterator ui, container_type *m) : i_(ui->second), tank_(m) {
|
||||
inc();
|
||||
valid_exit();
|
||||
}
|
||||
|
||||
///Construct an iterator from the location map
|
||||
iterator_base(t_lmap::iterator ui, container_type *m) : i_(ui->second), tank_(m) {
|
||||
inc();
|
||||
iterator_base(t_lmap::iterator ui, container_type *m) : i_(ui->second), tank_(m) {
|
||||
inc();
|
||||
valid_exit();
|
||||
}
|
||||
|
||||
public:
|
||||
pointer operator->() const {
|
||||
pointer operator->() const {
|
||||
assert(valid());
|
||||
return i_->unit_; }
|
||||
reference operator*() const {
|
||||
reference operator*() const {
|
||||
assert(valid());
|
||||
return *i_->unit_; }
|
||||
|
||||
@ -214,7 +214,7 @@ public:
|
||||
assert( tank_ && i_ != the_list().begin() );
|
||||
iterator_type begin(the_list().begin());
|
||||
dec();
|
||||
do {
|
||||
do {
|
||||
--i_ ;
|
||||
}while(i_ != begin && (i_->unit_ == NULL));
|
||||
inc();
|
||||
@ -229,11 +229,11 @@ public:
|
||||
return temp;
|
||||
}
|
||||
|
||||
bool valid() const {
|
||||
bool valid() const {
|
||||
if(valid_for_dereference()) {
|
||||
if(i_->unit_ == NULL){
|
||||
if(i_->unit_ == NULL){
|
||||
recover_unit_iterator(); }
|
||||
return i_->unit_ != NULL;
|
||||
return i_->unit_ != NULL;
|
||||
}
|
||||
return false; }
|
||||
|
||||
@ -247,7 +247,7 @@ public:
|
||||
private:
|
||||
bool valid_for_dereference() const { return (tank_ != NULL) && (i_ != the_end()); }
|
||||
bool valid_entry() const { return ((tank_ != NULL) && (i_ != the_end())) ; }
|
||||
void valid_exit() const {
|
||||
void valid_exit() const {
|
||||
if(tank_ != NULL) {
|
||||
assert(!the_list().empty());
|
||||
assert(i_ != the_list().end());
|
||||
@ -255,31 +255,31 @@ public:
|
||||
assert(i_->ref_count_ > 0);
|
||||
} else {
|
||||
assert(i_->ref_count_ == 1);
|
||||
}
|
||||
}
|
||||
}}
|
||||
bool valid_ref_count() const { return (tank_ != NULL) && (i_ != the_end()) ; }
|
||||
|
||||
///Increment the reference counter
|
||||
void inc() { if(valid_ref_count()) { ++(i_->ref_count_); } }
|
||||
|
||||
///Decrement the reference counter
|
||||
|
||||
///Decrement the reference counter
|
||||
///Delete the list element if the unit is gone and the reference counter is zero
|
||||
///@note this deletion will advance i_ to the next list element.
|
||||
void dec() {
|
||||
if( valid_ref_count() ){
|
||||
assert(i_->ref_count_ != 0);
|
||||
if( (--(i_->ref_count_) == 0) && (i_->unit_ == NULL) ){
|
||||
i_ = the_list().erase(i_);
|
||||
i_ = the_list().erase(i_);
|
||||
} } }
|
||||
|
||||
unit_map::t_ilist & the_list() const { return tank_->ilist_; }
|
||||
|
||||
|
||||
///Returns the sentinel at the end of the list.
|
||||
///This provides a stable unit_iterator for hoisting out of loops
|
||||
iterator_type the_end() const { return tank_->the_end_; }
|
||||
|
||||
/**
|
||||
* Attempt to find a deleted unit in the unit_map, by looking up the stored UID.
|
||||
/**
|
||||
* Attempt to find a deleted unit in the unit_map, by looking up the stored UID.
|
||||
* @pre deleted_uid != 0
|
||||
*/
|
||||
void recover_unit_iterator() const {
|
||||
@ -341,20 +341,20 @@ public:
|
||||
|
||||
/**
|
||||
* Adds a copy of unit @a u at location @a l of the map.
|
||||
@return std::pair<unit_iterator, bool> a bool indicating success and
|
||||
@return std::pair<unit_iterator, bool> a bool indicating success and
|
||||
an iterator pointing to the new unit, or the unit already occupying location.
|
||||
@note It is 3 times as fast to attempt to insert a unit at @a l and check for
|
||||
success than it is to verify that the location is empty, insert the unit check the
|
||||
success than it is to verify that the location is empty, insert the unit check the
|
||||
location for the unit.
|
||||
*/
|
||||
std::pair<unit_iterator, bool> add(const map_location &l, const unit &u);
|
||||
|
||||
/**
|
||||
* Adds the unit to the map.
|
||||
@return std::pair<unit_iterator, bool> a bool indicating success and
|
||||
@return std::pair<unit_iterator, bool> a bool indicating success and
|
||||
an iterator pointing to the new unit, or the unit already occupying location.
|
||||
@note It is 3 times as fast to attempt to insert a unit at @a l and check for
|
||||
success than it is to verify that the location is empty, insert the unit check the
|
||||
success than it is to verify that the location is empty, insert the unit check the
|
||||
location for the unit.
|
||||
* @note If the unit::underlying_id is already in use, a new one
|
||||
* will be generated.
|
||||
@ -364,17 +364,17 @@ public:
|
||||
|
||||
/**
|
||||
* Moves a unit from location @a src to location @a dst.
|
||||
@return std::pair<unit_iterator, bool> a bool indicating success and
|
||||
@return std::pair<unit_iterator, bool> a bool indicating success and
|
||||
an iterator pointing to the new unit, or the unit already occupying location.
|
||||
@note It is 3 times as fast to attempt to insert a unit at @a l and check for
|
||||
success than it is to verify that the location is empty, insert the unit check the
|
||||
success than it is to verify that the location is empty, insert the unit check the
|
||||
location for the unit.
|
||||
*/
|
||||
std::pair<unit_iterator, bool> move(const map_location &src, const map_location &dst);
|
||||
|
||||
/**
|
||||
* Works like unit_map::add; but @a l is emptied first, if needed.
|
||||
@return std::pair<unit_iterator, bool> a bool indicating success and
|
||||
@return std::pair<unit_iterator, bool> a bool indicating success and
|
||||
an iterator pointing to the new unit, or the unit already occupying location.
|
||||
*/
|
||||
std::pair<unit_iterator, bool> replace(const map_location &l, const unit &u);
|
||||
@ -410,14 +410,14 @@ private:
|
||||
ilist_.push_front(upod);
|
||||
the_end_ = ilist_.begin();
|
||||
};
|
||||
|
||||
|
||||
t_ilist::iterator begin_core() const ;
|
||||
|
||||
bool is_valid(const t_ilist::const_iterator &i) const {
|
||||
bool is_valid(const t_ilist::const_iterator &i) const {
|
||||
return i != the_end_ && is_found(i) && (i->unit_ != NULL); }
|
||||
bool is_valid(const t_umap::const_iterator &i) const {
|
||||
bool is_valid(const t_umap::const_iterator &i) const {
|
||||
return is_found(i) && (i->second->unit_ != NULL); }
|
||||
bool is_valid(const t_lmap::const_iterator &i) const {
|
||||
bool is_valid(const t_lmap::const_iterator &i) const {
|
||||
return is_found(i) && (i->second->unit_ != NULL); }
|
||||
|
||||
bool is_found(const t_ilist::const_iterator &i) const { return i != ilist_.end(); }
|
||||
@ -433,7 +433,7 @@ private:
|
||||
if (!is_found( i )) { return const_unit_iterator(the_end_, this); }
|
||||
return const_unit_iterator(i , this); }
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* underlying_id -> ilist::iterator. This requires that underlying_id be
|
||||
* unique (which is enforced in unit_map::insert).
|
||||
@ -450,8 +450,8 @@ private:
|
||||
*/
|
||||
mutable t_ilist ilist_;
|
||||
|
||||
/// The last list item, a sentinel that allows BOOST::foreach to hoist end()
|
||||
t_ilist::iterator the_end_;
|
||||
/// The last list item, a sentinel that allows BOOST::foreach to hoist end()
|
||||
t_ilist::iterator the_end_;
|
||||
|
||||
};
|
||||
|
||||
|
@ -39,10 +39,10 @@ template <typename T_integral> class t_ref_counter {
|
||||
BOOST_STATIC_ASSERT( std::numeric_limits<T_integral>::is_signed);
|
||||
|
||||
T_integral count_;
|
||||
|
||||
|
||||
public:
|
||||
enum {NEW=0, NOT_COUNTED = -1};
|
||||
|
||||
|
||||
explicit t_ref_counter(T_integral x = 0) : count_(x) {}
|
||||
t_ref_counter(t_ref_counter const &a) : count_(a.count_) {}
|
||||
t_ref_counter & operator=(t_ref_counter const a){count_ = a.count_; return *this;}
|
||||
@ -50,7 +50,7 @@ public:
|
||||
operator T_integral const () const {return count_;}
|
||||
|
||||
T_integral const set(T_integral const a) { count_=a; return count_; }
|
||||
T_integral const inc(){
|
||||
T_integral const inc(){
|
||||
if (count_ >= 0) { count_ += 1; }
|
||||
return count_; }
|
||||
T_integral const dec(){
|
||||
@ -63,9 +63,9 @@ public:
|
||||
count_= NOT_COUNTED;
|
||||
return count_; }
|
||||
|
||||
T_integral const operator++(){return inc();}
|
||||
T_integral const operator++(int){T_integral ret(count_); inc(); return ret;}
|
||||
T_integral const operator--(){return dec();}
|
||||
T_integral const operator++(){return inc();}
|
||||
T_integral const operator++(int){T_integral ret(count_); inc(); return ret;}
|
||||
T_integral const operator--(){return dec();}
|
||||
T_integral const operator--(int){T_integral ret(count_); dec(); return ret;}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user