BWAPI
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
UnitFilter Struct Reference

#include <UnitFilter.h>

Collaboration diagram for UnitFilter:
Collaboration graph
[legend]

List of all members.

Classes

struct  UnitFilterTypeDef

Public Member Functions

 UnitFilter ()
 UnitFilter (BWAPI::UnitType type)
 UnitFilter (UnitFilterFlags::type flags)
 UnitFilter (const UnitFilter &other)
UnitFilteroperator= (const UnitFilter &other)
UnitFilter operator|| (const UnitFilter &other) const
UnitFilter operator&& (const UnitFilter &other) const
bool passesFilter (const Unit &unit) const
UnitFilteroperator! ()
bool operator!= (const UnitFilter &other) const
bool operator== (const UnitFilter &other) const
bool operator< (const UnitFilter &other) const

Private Types

typedef SafeEnum
< UnitFilterTypeDef
UnitFilterType

Private Member Functions

bool filter (const Unit &unit) const
 UnitFilter (const UnitFilter &left, OperatorType::type opType, const UnitFilter &right)

Private Attributes

UnitFilterType mType
OperatorType mOperatorType
boost::scoped_ptr< UnitFiltermLFilter
boost::scoped_ptr< UnitFiltermRFilter
bool mExpectedValue
BWAPI::UnitType mUnitType
UnitFilterFlags::type mUnitFlags

Detailed Description

Definition at line 28 of file UnitFilter.h.


Member Typedef Documentation

Definition at line 97 of file UnitFilter.h.


Constructor & Destructor Documentation

Definition at line 16 of file UnitFilter.cpp.

        : mType(UnitFilterType::UnitOfType)
        , mOperatorType(OperatorType::None)
        , mLFilter()
        , mRFilter()
        , mExpectedValue(true)
        , mUnitType(type)
        , mUnitFlags(UnitFilterFlags::None)
{
}

Definition at line 27 of file UnitFilter.cpp.

        : mType(UnitFilterType::PassesFlags)
        , mOperatorType(OperatorType::None)
        , mLFilter()
        , mRFilter()
        , mExpectedValue(true)
        , mUnitType(BWAPI::UnitTypes::None)
        , mUnitFlags(flags)
{
}
UnitFilter::UnitFilter ( const UnitFilter other) [inline]

Definition at line 35 of file UnitFilter.h.

                : mType(other.mType)
                , mOperatorType(other.mOperatorType)
                , mLFilter(other.mLFilter ? new UnitFilter(*other.mLFilter) : NULL)
                , mRFilter(other.mRFilter ? new UnitFilter(*other.mRFilter) : NULL)
                , mExpectedValue(other.mExpectedValue)
                , mUnitType(other.mUnitType)
                , mUnitFlags(other.mUnitFlags)
        {}
UnitFilter::UnitFilter ( const UnitFilter left,
OperatorType::type  opType,
const UnitFilter right 
) [inline, private]

Member Function Documentation

bool UnitFilter::filter ( const Unit unit) const [private]

Definition at line 109 of file UnitFilter.cpp.

References UnitFilterFlags::CanAttackAir, UnitFilterFlags::CanAttackGround, UnitFilterFlags::HasAddon, UnitHelper::isArmyUnit(), UnitFilterFlags::IsArmyUnit, UnitFilterFlags::IsComplete, UnitFilterFlags::IsLifted, UnitFilterFlags::IsSpellCaster, UnitFilterFlags::IsWorker, mExpectedValue, mType, mUnitFlags, mUnitType, BWAPI::BulletTypes::None, and SafeEnum< def, inner >::underlying().

{
        switch(mType.underlying())
        {
        case UnitFilterType::None:
                return mExpectedValue;
        case UnitFilterType::UnitOfType:
                return (unit->getType() == mUnitType) == mExpectedValue;
        case UnitFilterType::PassesFlags:
                {
                        if((mUnitFlags & UnitFilterFlags::IsComplete) != 0 && unit->isCompleted() != mExpectedValue)
                                return false;
                        if((mUnitFlags & UnitFilterFlags::HasAddon) != 0 && unit->hasAddon() != mExpectedValue)
                                return false;
                        if((mUnitFlags & UnitFilterFlags::IsLifted) != 0 && unit->isLifted() != mExpectedValue)
                                return false;
                        if((mUnitFlags & UnitFilterFlags::IsWorker) != 0 && unit->getType().isWorker() != mExpectedValue)
                                return false;
                        if((mUnitFlags & UnitFilterFlags::IsArmyUnit) != 0 && UnitHelper::isArmyUnit(unit->getType()) != mExpectedValue)
                                return false;
                        if((mUnitFlags & UnitFilterFlags::CanAttackGround) != 0 && unit->canAttackGround() != mExpectedValue)
                                return false;
                        if((mUnitFlags & UnitFilterFlags::CanAttackAir) != 0 && unit->canAttackAir() != mExpectedValue)
                                return false;
                        if((mUnitFlags & UnitFilterFlags::IsSpellCaster) != 0 && unit->getType().isSpellcaster() != mExpectedValue)
                                return false;

                        return true;
                }
        }

        return false;
}

Here is the call graph for this function:

Definition at line 38 of file UnitFilter.cpp.

References mExpectedValue.

{
        mExpectedValue = !mExpectedValue;
        return *this;
}
bool UnitFilter::operator!= ( const UnitFilter other) const

Definition at line 44 of file UnitFilter.cpp.

References operator==().

{
        return !operator==(other);
}

Here is the call graph for this function:

UnitFilter UnitFilter::operator&& ( const UnitFilter other) const [inline]

Definition at line 65 of file UnitFilter.h.

References OperatorTypeDef::And.

        {
                return UnitFilter(*this, OperatorType::And, other);
        }
bool UnitFilter::operator< ( const UnitFilter other) const

Definition at line 69 of file UnitFilter.cpp.

References mExpectedValue, mLFilter, mOperatorType, mRFilter, mType, mUnitFlags, and mUnitType.

{
        if(mType < other.mType)
                return true;
        else if(mType != other.mType)
                return false;

        if(mOperatorType < other.mOperatorType)
                return true;
        else if(mOperatorType != other.mOperatorType)
                return false;

        if(*mLFilter < *other.mLFilter)
                return true;
        else if(*mLFilter != *other.mLFilter)
                return false;

        if(*mRFilter < *other.mRFilter)
                return true;
        else if(*mRFilter != *other.mRFilter)
                return false;

        if(mExpectedValue < other.mExpectedValue)
                return true;
        else if(mExpectedValue != other.mExpectedValue)
                return false;

        if(mUnitType < other.mUnitType)
                return true;
        else if(mUnitType != other.mUnitType)
                return false;

        if(mUnitFlags < other.mUnitFlags)
                return true;
        else if(mUnitFlags != other.mUnitFlags)
                return false;

        return false;
}
UnitFilter& UnitFilter::operator= ( const UnitFilter other) [inline]

Definition at line 45 of file UnitFilter.h.

References mExpectedValue, mLFilter, mOperatorType, mRFilter, mType, mUnitFlags, and mUnitType.

        {
                mType = other.mType;
                mOperatorType = other.mOperatorType;

                mExpectedValue = other.mExpectedValue;

                mUnitType = other.mUnitType;
                mUnitFlags = other.mUnitFlags;

                mLFilter.reset(other.mLFilter ? new UnitFilter(*other.mLFilter) : NULL);
                mRFilter.reset(other.mRFilter ? new UnitFilter(*other.mRFilter) : NULL);

                return *this;
        }
bool UnitFilter::operator== ( const UnitFilter other) const

Definition at line 49 of file UnitFilter.cpp.

References mExpectedValue, mLFilter, mOperatorType, mRFilter, mType, mUnitFlags, and mUnitType.

Referenced by operator!=().

{
        if(mType != other.mType)
                return false;
        else if(mOperatorType != other.mOperatorType)
                return false;
        else if(*mLFilter != *other.mLFilter)
                return false;
        else if(*mRFilter != *other.mRFilter)
                return false;
        else if(mExpectedValue != other.mExpectedValue)
                return false;
        else if(mUnitType != other.mUnitType)
                return false;
        else if(mUnitFlags != other.mUnitFlags)
                return false;
        else
                return true;
}

Here is the caller graph for this function:

UnitFilter UnitFilter::operator|| ( const UnitFilter other) const [inline]

Definition at line 61 of file UnitFilter.h.

References OperatorTypeDef::Or.

        {
                return UnitFilter(*this, OperatorType::Or, other);
        }
bool UnitFilter::passesFilter ( const Unit unit) const [inline]

Definition at line 70 of file UnitFilter.h.

References OperatorTypeDef::And, OperatorTypeDef::None, and OperatorTypeDef::Or.

Referenced by Requirement::earliestUnitTime().

        {
                if(mOperatorType == OperatorType::None)
                        return filter(unit);
                else if(mOperatorType == OperatorType::And)
                        return mLFilter->passesFilter(unit) == mExpectedValue && mRFilter->passesFilter(unit) == mExpectedValue;
                else if(mOperatorType == OperatorType::Or)
                        return mLFilter->passesFilter(unit) == mExpectedValue || mRFilter->passesFilter(unit) == mExpectedValue;

                return false;
        }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 105 of file UnitFilter.h.

Referenced by filter(), operator!(), operator<(), operator=(), and operator==().

boost::scoped_ptr<UnitFilter> UnitFilter::mLFilter [private]

Definition at line 102 of file UnitFilter.h.

Referenced by operator<(), operator=(), and operator==().

Definition at line 101 of file UnitFilter.h.

Referenced by operator<(), operator=(), and operator==().

boost::scoped_ptr<UnitFilter> UnitFilter::mRFilter [private]

Definition at line 103 of file UnitFilter.h.

Referenced by operator<(), operator=(), and operator==().

Definition at line 99 of file UnitFilter.h.

Referenced by filter(), operator<(), operator=(), and operator==().

Definition at line 108 of file UnitFilter.h.

Referenced by filter(), operator<(), operator=(), and operator==().

Definition at line 107 of file UnitFilter.h.

Referenced by filter(), operator<(), operator=(), and operator==().


The documentation for this struct was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines