#pragma once #include namespace BWAPI { class UnitInterface; typedef UnitInterface *Unit; /// PositionOrUnit is a class that is either a Position or a Unit. /// The purpose of this class is to reduce interface overhead by combining two commonly passed /// values into one, and to allow more function overloads with less effort. class PositionOrUnit { public: /// Unit constructor. Assigns this class to contain a unit. /// /// /// The unit to assign to this class. /// PositionOrUnit(Unit unit = nullptr); /// Position constructor. Assigns this class to contain a position. /// /// /// The position to assign to this class. /// PositionOrUnit(Position pos); /// Unit assignment operator. Assigns a unit to this class. PositionOrUnit &operator =(Unit pUnit); /// Position assignment operator. Assigns a position to this class. PositionOrUnit &operator =(Position pos); /// Indicates if a Unit is currently held in this class. /// /// @returns true if the value contained within this class is considered a unit, and false if /// it is a position. bool isUnit() const; /// Retrieves the Unit attached to this class, if there is one. /// /// @returns The Unit that was assigned to this class. /// @retval nullptr If this class does not contain a unit, or if nullptr was assigned to /// this class as a Unit. Unit getUnit() const; /// Indicates if a Position is currently held in this class. /// /// @returns true if the value contained within this class is considered a position, and false /// if it is a unit. bool isPosition() const; /// Retrieves the position if it was assigned to this class, otherwise it will /// retrieve the position of the unit contained within this class if there is one. /// /// @returns Position that was stored if there is one. If not, then the position of the unit /// will be used instead. /// @retval Positions::None if a nullptr Unit was assigned to this class. Position getPosition() const; private: /// @cond HIDDEN union { struct { int x, y; } position; struct { Unit pUnit; int y; } unit; }; /// @endcond }; }