This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
BWMirror-Generator/bwapi4-includes/BWAPI/PositionUnit.h

80 lines
2.5 KiB
C
Raw Normal View History

#pragma once
#include <BWAPI/Position.h>
namespace BWAPI
{
class UnitInterface;
typedef UnitInterface *Unit;
2016-02-28 08:49:15 -05:00
/// <summary>PositionOrUnit is a class that is either a Position <b>or</b> a Unit.</summary>
/// 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:
2016-02-28 08:49:15 -05:00
/// <summary>Unit constructor. Assigns this class to contain a unit.</summary>
///
/// <param name="unit">
/// The unit to assign to this class.
/// </param>
PositionOrUnit(Unit unit = nullptr);
2016-02-28 08:49:15 -05:00
/// <summary>Position constructor. Assigns this class to contain a position.</summary>
///
/// <param name="pos">
/// The position to assign to this class.
/// </param>
PositionOrUnit(Position pos);
2016-02-28 08:49:15 -05:00
/// <summary>Unit assignment operator. Assigns a unit to this class.</summary>
PositionOrUnit &operator =(Unit pUnit);
2016-02-28 08:49:15 -05:00
/// <summary>Position assignment operator. Assigns a position to this class.</summary>
PositionOrUnit &operator =(Position pos);
2016-02-28 08:49:15 -05:00
/// <summary>Indicates if a Unit is currently held in this class.</summary>
///
/// @returns true if the value contained within this class is considered a unit, and false if
/// it is a position.
bool isUnit() const;
2016-02-28 08:49:15 -05:00
/// <summary>Retrieves the Unit attached to this class, if there is one.</summary>
///
/// @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;
2016-02-28 08:49:15 -05:00
/// <summary>Indicates if a Position is currently held in this class.</summary>
///
/// @returns true if the value contained within this class is considered a position, and false
/// if it is a unit.
bool isPosition() const;
2016-02-28 08:49:15 -05:00
/// <summary>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.</summary>
///
/// @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;
2016-02-28 08:49:15 -05:00
private:
2016-02-28 08:49:15 -05:00
/// @cond HIDDEN
union
{
struct
{
int x, y;
} position;
struct
{
Unit pUnit;
int y;
} unit;
};
2016-02-28 08:49:15 -05:00
/// @endcond
};
}