mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-29 10:08:34 +00:00
Removing trailing underscores of public members.
Trailing underscores are used for _private_ members.
This commit is contained in:
parent
eb948eac6b
commit
087e711106
@ -73,7 +73,7 @@ unit_map::~unit_map() {
|
||||
unit_map::t_ilist::iterator unit_map::begin_core() const {
|
||||
self_check();
|
||||
t_ilist::iterator i = ilist_.begin();
|
||||
while (i != the_end_ && (i->unit_ == NULL)) { ++i; }
|
||||
while (i != the_end_ && (i->unit == NULL)) { ++i; }
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ std::pair<unit_map::unit_iterator, bool> unit_map::move(const map_location &src,
|
||||
if(src == dst){ return std::make_pair(make_unit_iterator(lit),true);}
|
||||
|
||||
//Fail if there is no unit to move
|
||||
unit *p = lit->unit_;
|
||||
unit *p = lit->unit;
|
||||
if(p == NULL){ return std::make_pair(make_unit_iterator(lit), false);}
|
||||
|
||||
p->set_location(dst);
|
||||
@ -148,8 +148,8 @@ std::pair<unit_map::unit_iterator, bool> unit_map::insert(unit *p) {
|
||||
}
|
||||
|
||||
unit_pod upod;
|
||||
upod.unit_ = p;
|
||||
upod.deleted_uid_ = unit_id;
|
||||
upod.unit = p;
|
||||
upod.deleted_uid = unit_id;
|
||||
ilist_.push_front(upod);
|
||||
t_ilist::iterator lit(ilist_.begin());
|
||||
|
||||
@ -160,13 +160,13 @@ std::pair<unit_map::unit_iterator, bool> unit_map::insert(unit *p) {
|
||||
|
||||
if (! uinsert.second) {
|
||||
//If the UID is empty reinsert the unit in the same list element
|
||||
if ( uinsert.first->second->unit_ == NULL) {
|
||||
if ( uinsert.first->second->unit == NULL) {
|
||||
ilist_.pop_front();
|
||||
lit = uinsert.first->second;
|
||||
lit->unit_ = p;
|
||||
assert(lit->ref_count_ != 0);
|
||||
lit->unit = p;
|
||||
assert(lit->ref_count != 0);
|
||||
} else {
|
||||
unit *q = uinsert.first->second->unit_;
|
||||
unit *q = uinsert.first->second->unit;
|
||||
ERR_NG << "Trying to add " << p->name()
|
||||
<< " - " << p->id() << " - " << p->underlying_id()
|
||||
<< " (" << loc << ") over " << q->name()
|
||||
@ -199,18 +199,18 @@ std::pair<unit_map::unit_iterator, bool> unit_map::insert(unit *p) {
|
||||
|
||||
//Fail if the location is occupied
|
||||
if(! linsert.second) {
|
||||
if(lit->ref_count_ == 0) {
|
||||
if(lit->ref_count == 0) {
|
||||
//Undo a virgin insertion
|
||||
ilist_.pop_front();
|
||||
///@todo replace with quick_erase(i) when wesnoth supports boost 1.42 min version
|
||||
umap_.erase(uinsert.first);
|
||||
} else {
|
||||
//undo a reinsertion
|
||||
uinsert.first->second->unit_ = NULL;
|
||||
uinsert.first->second->unit = NULL;
|
||||
}
|
||||
DBG_NG << "Trying to add " << p->name()
|
||||
<< " - " << p->id() << " at location ("<<loc <<"); Occupied by "
|
||||
<<(linsert.first->second)->unit_->name()<< " - " << linsert.first->second->unit_->id() <<"\n";
|
||||
<<(linsert.first->second)->unit->name()<< " - " << linsert.first->second->unit->id() <<"\n";
|
||||
|
||||
return std::make_pair(make_unit_iterator(the_end_), false);
|
||||
}
|
||||
@ -235,11 +235,11 @@ size_t unit_map::num_iters() const {
|
||||
size_t num_iters(0);
|
||||
t_ilist::const_iterator ii(ilist_.begin());
|
||||
for( ; ii != the_end_ ; ++ii){
|
||||
if(ii->ref_count_ < 0) {
|
||||
if(ii->ref_count < 0) {
|
||||
//Somewhere, someone generated 2^31 iterators to this unit
|
||||
bool a_reference_counter_overflowed(false);
|
||||
assert(a_reference_counter_overflowed); }
|
||||
num_iters += ii->ref_count_; }
|
||||
num_iters += ii->ref_count; }
|
||||
|
||||
return num_iters;
|
||||
}
|
||||
@ -249,8 +249,8 @@ void unit_map::clear(bool force) {
|
||||
|
||||
for (t_ilist::iterator i = ilist_.begin(); i != the_end_; ++i) {
|
||||
if (is_valid(i)) {
|
||||
DBG_NG << "Delete unit " << i->unit_->underlying_id() << "\n";
|
||||
delete i->unit_;
|
||||
DBG_NG << "Delete unit " << i->unit->underlying_id() << "\n";
|
||||
delete i->unit;
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,21 +266,21 @@ unit *unit_map::extract(const map_location &loc) {
|
||||
|
||||
t_ilist::iterator lit(i->second);
|
||||
|
||||
unit *u = lit->unit_;
|
||||
unit *u = lit->unit;
|
||||
size_t uid( u->underlying_id() );
|
||||
|
||||
DBG_NG << "Extract unit " << uid << " - " << u->id()
|
||||
<< " from location: (" << loc << ")\n";
|
||||
|
||||
if(lit->ref_count_ == 0){
|
||||
if(lit->ref_count == 0){
|
||||
assert(lit != the_end_);
|
||||
if(umap_.erase(uid) != 1){
|
||||
error_recovery_externally_changed_uid(lit); }
|
||||
ilist_.erase( lit );
|
||||
} else {
|
||||
//Soft extraction keeps the old lit item if any iterators reference it
|
||||
lit->unit_ = NULL;
|
||||
lit->deleted_uid_ = uid;
|
||||
lit->unit = NULL;
|
||||
lit->deleted_uid = uid;
|
||||
assert( uid != 0);
|
||||
}
|
||||
|
||||
@ -297,15 +297,15 @@ unit *unit_map::extract(const map_location &loc) {
|
||||
void unit_map::error_recovery_externally_changed_uid(t_ilist::iterator const & lit) const {
|
||||
std::string name, id ;
|
||||
size_t uid;
|
||||
if(lit->unit_ != NULL){
|
||||
unit const * u(lit->unit_);
|
||||
if(lit->unit != NULL){
|
||||
unit const * u(lit->unit);
|
||||
name = u->name();
|
||||
id = u->id();
|
||||
uid = u->underlying_id();
|
||||
} else {
|
||||
name = "unknown";
|
||||
id = "unknown";
|
||||
uid = lit->deleted_uid_;
|
||||
uid = lit->deleted_uid;
|
||||
}
|
||||
t_umap::iterator uit(umap_.begin());
|
||||
for(; uit != umap_.end(); ++uit){
|
||||
@ -337,7 +337,7 @@ size_t unit_map::erase(const map_location &loc) {
|
||||
unit_map::unit_iterator unit_map::find(size_t id) {
|
||||
self_check();
|
||||
t_umap::iterator i(umap_.find(id));
|
||||
if((i != umap_.end()) && i->second->unit_==NULL){ i = umap_.end() ;}
|
||||
if((i != umap_.end()) && i->second->unit==NULL){ i = umap_.end() ;}
|
||||
return make_unit_iterator<t_umap::iterator>( i ); }
|
||||
|
||||
unit_map::unit_iterator unit_map::find(const map_location &loc) {
|
||||
@ -390,18 +390,18 @@ bool unit_map::self_check() const {
|
||||
t_ilist::const_iterator lit(ilist_.begin());
|
||||
for(; lit != ilist_.end(); ++lit){
|
||||
if(lit == the_end_){ found_the_end = true; continue; }
|
||||
if(lit->ref_count_ < 0){
|
||||
if(lit->ref_count < 0){
|
||||
good=false;
|
||||
ERR_NG << "unit_map list element ref_count_ <0 is " << lit->ref_count_<<"\n"; }
|
||||
if(lit->unit_ != NULL){
|
||||
lit->unit_->id(); //crash if bad pointer
|
||||
ERR_NG << "unit_map list element ref_count <0 is " << lit->ref_count<<"\n"; }
|
||||
if(lit->unit != NULL){
|
||||
lit->unit->id(); //crash if bad pointer
|
||||
} else {
|
||||
if(lit->ref_count_ <= 0){
|
||||
if(lit->ref_count <= 0){
|
||||
good=false;
|
||||
ERR_NG << "unit_map list element ref_count_ <=0 is " << lit->ref_count_<<", when unit deleted.\n"; }
|
||||
if(lit->deleted_uid_ <= 0 ){
|
||||
ERR_NG << "unit_map list element ref_count <=0 is " << lit->ref_count<<", when unit deleted.\n"; }
|
||||
if(lit->deleted_uid <= 0 ){
|
||||
good=false;
|
||||
ERR_NG << "unit_map list element deleted_uid_ <=0 is " << lit->deleted_uid_<<"\n"; }
|
||||
ERR_NG << "unit_map list element deleted_uid <=0 is " << lit->deleted_uid<<"\n"; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,20 +417,20 @@ bool unit_map::self_check() const {
|
||||
if(uit->second == the_end_ ){
|
||||
good=false;
|
||||
ERR_NG << "unit_map umap element == the_end_ "<<"\n"; }
|
||||
if(uit->second->unit_ == NULL && uit->second->ref_count_ == 0 ){
|
||||
if(uit->second->unit == NULL && uit->second->ref_count == 0 ){
|
||||
good=false;
|
||||
ERR_NG << "unit_map umap unit_==NULL when refcount == 0 uid="<<uit->second->deleted_uid_<<"\n";
|
||||
ERR_NG << "unit_map umap unit==NULL when refcount == 0 uid="<<uit->second->deleted_uid<<"\n";
|
||||
}
|
||||
if(uit->second->unit_ && uit->second->unit_->underlying_id() != uit->first){
|
||||
if(uit->second->unit && uit->second->unit->underlying_id() != uit->first){
|
||||
good=false;
|
||||
ERR_NG << "unit_map umap uid("<<uit->first<<") != underlying_id()["<< uit->second->unit_->underlying_id()<< "]\n"; }
|
||||
ERR_NG << "unit_map umap uid("<<uit->first<<") != underlying_id()["<< uit->second->unit->underlying_id()<< "]\n"; }
|
||||
}
|
||||
t_lmap::const_iterator locit(lmap_.begin());
|
||||
for(; locit != lmap_.end(); ++locit){
|
||||
if(locit->second == the_end_ ){
|
||||
good=false;
|
||||
ERR_NG << "unit_map lmap element == the_end_ "<<"\n"; }
|
||||
if(locit->first != locit->second->unit_->get_location()){
|
||||
if(locit->first != locit->second->unit->get_location()){
|
||||
good=false;
|
||||
ERR_NG << "unit_map lmap location != unit->get_location() " <<"\n"; }
|
||||
}
|
||||
@ -445,7 +445,7 @@ bool unit_map::has_unit(const unit * const u)
|
||||
assert(u);
|
||||
|
||||
foreach(const unit_pod& item, ilist_) {
|
||||
if(item.unit_ == u) {
|
||||
if(item.unit == u) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -92,19 +92,19 @@ class unit_map {
|
||||
struct unit_pod {
|
||||
|
||||
unit_pod()
|
||||
: unit_(NULL)
|
||||
, ref_count_()
|
||||
, deleted_uid_(0)
|
||||
: unit(NULL)
|
||||
, ref_count()
|
||||
, deleted_uid(0)
|
||||
{
|
||||
}
|
||||
|
||||
unit * unit_;
|
||||
mutable n_ref_counter::t_ref_counter<signed int> ref_count_;
|
||||
class unit * unit;
|
||||
mutable n_ref_counter::t_ref_counter<signed int> ref_count;
|
||||
|
||||
unsigned deleted_uid_; ///UID of the deleted, moved, added, or otherwise invalidated iterator to facilitate a new lookup.
|
||||
unsigned deleted_uid; ///UID of the deleted, moved, added, or otherwise invalidated iterator to facilitate a new lookup.
|
||||
};
|
||||
|
||||
/// A list pointing to unit and their reference counters. Dead units have a unit_ pointer equal to NULL.
|
||||
/// 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
|
||||
///iterators pointing to this unit.
|
||||
typedef std::list<unit_pod> t_ilist;
|
||||
@ -187,16 +187,16 @@ public:
|
||||
pointer operator->() const {
|
||||
assert(valid());
|
||||
tank_->self_check();
|
||||
return i_->unit_; }
|
||||
return i_->unit; }
|
||||
reference operator*() const {
|
||||
tank_->self_check();
|
||||
if(!valid()){
|
||||
if(!tank_){std::cerr<<"tank is NULL"<<"\n";}
|
||||
if(i_==the_end()){std::cerr<<"i_ is the end"<<"\n";}
|
||||
if(i_->unit_==NULL){std::cerr<<"i_ unit is NULL with uid="<<i_->deleted_uid_<<"\n";}
|
||||
if(i_->unit==NULL){std::cerr<<"i_ unit is NULL with uid="<<i_->deleted_uid<<"\n";}
|
||||
}
|
||||
assert(valid());
|
||||
return *i_->unit_; }
|
||||
return *i_->unit; }
|
||||
|
||||
iterator_base& operator++() {
|
||||
assert( valid_entry() );
|
||||
@ -204,7 +204,7 @@ public:
|
||||
iterator_type new_i(i_);
|
||||
do{
|
||||
++new_i;
|
||||
}while ((new_i->unit_ == NULL) && (new_i != the_end() )) ;
|
||||
}while ((new_i->unit == NULL) && (new_i != the_end() )) ;
|
||||
dec();
|
||||
i_ = new_i;
|
||||
inc();
|
||||
@ -225,7 +225,7 @@ public:
|
||||
dec();
|
||||
do {
|
||||
--i_ ;
|
||||
}while(i_ != begin && (i_->unit_ == NULL));
|
||||
}while(i_ != begin && (i_->unit == NULL));
|
||||
inc();
|
||||
|
||||
valid_exit();
|
||||
@ -240,9 +240,9 @@ public:
|
||||
|
||||
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; }
|
||||
|
||||
@ -261,24 +261,24 @@ public:
|
||||
assert(!the_list().empty());
|
||||
assert(i_ != the_list().end());
|
||||
if(i_ != the_end()){
|
||||
assert(i_->ref_count_ > 0);
|
||||
assert(i_->ref_count > 0);
|
||||
} else {
|
||||
assert(i_->ref_count_ == 1);
|
||||
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_); } }
|
||||
void inc() { if(valid_ref_count()) { ++(i_->ref_count); } }
|
||||
|
||||
///Decrement the reference counter
|
||||
///Delete the list element and the dangling umap reference 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) ){
|
||||
if(tank_->umap_.erase(i_->deleted_uid_) != 1){
|
||||
assert(i_->ref_count != 0);
|
||||
if( (--(i_->ref_count) == 0) && (i_->unit == NULL) ){
|
||||
if(tank_->umap_.erase(i_->deleted_uid) != 1){
|
||||
tank_->error_recovery_externally_changed_uid(i_); }
|
||||
i_ = the_list().erase(i_);
|
||||
} } }
|
||||
@ -294,8 +294,8 @@ public:
|
||||
* @pre deleted_uid != 0
|
||||
*/
|
||||
void recover_unit_iterator() const {
|
||||
assert(i_->deleted_uid_ != 0);
|
||||
iterator_base new_this( tank_->find( i_->deleted_uid_ ));
|
||||
assert(i_->deleted_uid != 0);
|
||||
iterator_base new_this( tank_->find( i_->deleted_uid ));
|
||||
const_cast<iterator_base *>(this)->operator=( new_this );
|
||||
}
|
||||
friend class unit_map;
|
||||
@ -431,9 +431,9 @@ private:
|
||||
void init_end(){
|
||||
assert(ilist_.empty());
|
||||
unit_pod upod;
|
||||
upod.unit_ = NULL;
|
||||
upod.deleted_uid_ = 0;
|
||||
++upod.ref_count_; //dummy count
|
||||
upod.unit = NULL;
|
||||
upod.deleted_uid = 0;
|
||||
++upod.ref_count; //dummy count
|
||||
ilist_.push_front(upod);
|
||||
the_end_ = ilist_.begin();
|
||||
};
|
||||
@ -441,11 +441,11 @@ private:
|
||||
t_ilist::iterator begin_core() const ;
|
||||
|
||||
bool is_valid(const t_ilist::const_iterator &i) const {
|
||||
return i != the_end_ && is_found(i) && (i->unit_ != NULL); }
|
||||
return i != the_end_ && is_found(i) && (i->unit != NULL); }
|
||||
bool is_valid(const t_umap::const_iterator &i) const {
|
||||
return is_found(i) && (i->second->unit_ != NULL); }
|
||||
return is_found(i) && (i->second->unit != NULL); }
|
||||
bool is_valid(const t_lmap::const_iterator &i) const {
|
||||
return is_found(i) && (i->second->unit_ != NULL); }
|
||||
return is_found(i) && (i->second->unit != NULL); }
|
||||
|
||||
bool is_found(const t_ilist::const_iterator &i) const { return i != ilist_.end(); }
|
||||
bool is_found(const t_umap::const_iterator &i) const { return i != umap_.end() ; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user