/**
 * Resets the internal unit pointer to match the given pointer.
 * The value of my_manager_ is preserved -- the old unit is deregistered,
 * and the new unit is registered with the same manager.
 */
void fake_unit_ptr::reset(const internal_ptr & ptr)
{
	if (unit_.get() != ptr.get()) {
		fake_unit_manager * mgr = my_manager_;

		remove_from_fake_unit_manager();
		unit_ = ptr;
		if (mgr)
			place_on_fake_unit_manager(mgr);
	}
}
Esempio n. 2
0
/**
 * Assignment operator, taking a unit.
 * If already in the queue, @a this will be moved to the end of the
 * queue (drawn last).
 *
 * This function is unsuitable for derived classes and MUST be overridden.
 * Furthermore, derived classes must not explicitly call this version.
 *
 * The overriding function can be almost the same, except "new (this)" should
 * be followed by the derived class instead of "fake_unit(a)".
 */
fake_unit & fake_unit::operator=(unit const & a)
{
	if ( this != &a ) {
		fake_unit_manager * mgr = my_manager_;

		// Use the copy constructor to make sure we are coherent.
		// (Methodology copied from unit::operator=)
		this->~fake_unit();
		new (this) fake_unit(a);
		// Restore our old manager.
		if ( mgr != NULL )
			place_on_fake_unit_manager(mgr);
	}
	return *this;
}
fake_unit_ptr::fake_unit_ptr(const internal_ptr & u, fake_unit_manager * mgr) : unit_(u), my_manager_(NULL)
{
	place_on_fake_unit_manager(mgr);
}