OpenTTD Source  20240915-master-g3784a3d3d6
bitmath_func.hpp File Reference

Go to the source code of this file.

Data Structures

struct  SetBitIterator< Tbitpos, Tbitset >
 Iterable ensemble of each set bit in a value. More...
 
struct  SetBitIterator< Tbitpos, Tbitset >::Iterator
 

Macros

#define SETBITS(x, y)   ((x) |= (y))
 Sets several bits in a variable. More...
 
#define CLRBITS(x, y)   ((x) &= ~(y))
 Clears several bits in a variable. More...
 

Functions

template<typename T >
constexpr static debug_inline uint GB (const T x, const uint8_t s, const uint8_t n)
 Fetch n bits from x, started at bit s. More...
 
template<typename T , typename U >
constexpr T SB (T &x, const uint8_t s, const uint8_t n, const U d)
 Set n bits in x starting at bit s to d. More...
 
template<typename T , typename U >
constexpr T AB (T &x, const uint8_t s, const uint8_t n, const U i)
 Add i to n bits of x starting at bit s. More...
 
template<typename T >
constexpr debug_inline bool HasBit (const T x, const uint8_t y)
 Checks if a bit in a value is set. More...
 
template<typename T >
constexpr T SetBit (T &x, const uint8_t y)
 Set a bit in a variable. More...
 
template<typename T >
constexpr T ClrBit (T &x, const uint8_t y)
 Clears a bit in a variable. More...
 
template<typename T >
constexpr T ToggleBit (T &x, const uint8_t y)
 Toggles a bit in a variable. More...
 
template<typename T >
constexpr T AssignBit (T &x, const uint8_t y, bool value)
 Assigns a bit in a variable. More...
 
template<typename T >
constexpr uint8_t FindFirstBit (T x)
 Search the first set bit in a value. More...
 
template<typename T >
constexpr uint8_t FindLastBit (T x)
 Search the last set bit in a value. More...
 
template<typename T >
constexpr T KillFirstBit (T value)
 Clear the first bit in an integer. More...
 
template<typename T >
constexpr uint CountBits (T value)
 Counts the number of set bits in a variable. More...
 
template<typename T >
constexpr bool HasExactlyOneBit (T value)
 Test whether value has exactly 1 bit set. More...
 
template<typename T >
constexpr bool HasAtMostOneBit (T value)
 Test whether value has at most 1 bit set. More...
 
static uint32_t BSWAP32 (uint32_t x)
 Perform a 32 bits endianness bitswap on x. More...
 
static uint16_t BSWAP16 (uint16_t x)
 Perform a 16 bits endianness bitswap on x. More...
 

Detailed Description

Functions related to bit mathematics.

Definition in file bitmath_func.hpp.

Macro Definition Documentation

◆ CLRBITS

#define CLRBITS (   x,
 
)    ((x) &= ~(y))

Clears several bits in a variable.

This macro clears several bits in a variable. The bits to clear are provided by a value. The new value is also returned.

Parameters
xThe variable to clear some bits
yThe value with set bits for clearing them in the variable
Returns
The new value of x

Definition at line 166 of file bitmath_func.hpp.

◆ SETBITS

#define SETBITS (   x,
 
)    ((x) |= (y))

Sets several bits in a variable.

This macro sets several bits in a variable. The bits to set are provided by a value. The new value is also returned.

Parameters
xThe variable to set some bits
yThe value with set bits for setting them in the variable
Returns
The new value of x

Definition at line 136 of file bitmath_func.hpp.

Function Documentation

◆ AB()

template<typename T , typename U >
constexpr T AB ( T &  x,
const uint8_t  s,
const uint8_t  n,
const U  i 
)
constexpr

Add i to n bits of x starting at bit s.

This adds the value of i on n bits of x starting at bit s. The parameters x, s, i are similar to GB. Besides, \ a x must be a variable as the result are saved there. An overflow does not affect the following bits of the given bit window and is simply ignored.

Note
Parameter x must be a variable as the result is saved there.
Parameters
xThe variable to add some bits at some position
sThe start position of the addition
nThe size/window for the addition
Precondition
n < sizeof(T) * 8
s + n <= sizeof(T) * 8
Parameters
iThe value to add at the given start position in the given window.
Returns
The new value of x

Definition at line 83 of file bitmath_func.hpp.

Referenced by IncHouseConstructionTick(), and IncreaseRoadWorksCounter().

◆ AssignBit()

template<typename T >
constexpr T AssignBit ( T &  x,
const uint8_t  y,
bool  value 
)
constexpr

Assigns a bit in a variable.

This function assigns a single bit in a variable. The variable is changed and the value is also returned. Parameter y defines the bit to assign and starts at the LSB with 0.

Parameters
xThe variable to assign the bit
yThe bit position to assign
valueThe new bit value
Precondition
y < sizeof(T) * 8
Returns
The new value of the old value with the bit assigned

Definition at line 200 of file bitmath_func.hpp.

Referenced by CmdSetVehicleVisibility(), VehicleOrderSaver::Restore(), SetCrossingBarred(), SetCrossingReservation(), SetDepotReservation(), SetDockingTile(), SetHasSignals(), SetRailStationReservation(), SetStationTileBlocked(), SetStationTileHavePylons(), SetStationTileHaveWires(), SetTrackReservation(), and SetTunnelBridgeReservation().

◆ BSWAP16()

static uint16_t BSWAP16 ( uint16_t  x)
inlinestatic

Perform a 16 bits endianness bitswap on x.

Parameters
xthe variable to bitswap
Returns
the bitswapped value.

Definition at line 379 of file bitmath_func.hpp.

◆ BSWAP32()

◆ ClrBit()

template<typename T >
constexpr T ClrBit ( T &  x,
const uint8_t  y 
)
constexpr

◆ CountBits()

template<typename T >
constexpr uint CountBits ( value)
constexpr

Counts the number of set bits in a variable.

Parameters
valuethe value to count the number of bits in.
Returns
the number of bits.

Definition at line 262 of file bitmath_func.hpp.

Referenced by AfterLoadCompanyStats(), CalculateCompanyAssetValue(), CmdConvertRail(), DrawRoadTypeCatenary(), RailTypeScopeResolver::GetRandomBits(), RoadTypeScopeResolver::GetRandomBits(), and CYapfFollowShipT< Types >::GetRandomTrackdir().

◆ FindFirstBit()

template<typename T >
constexpr uint8_t FindFirstBit ( x)
constexpr

◆ FindLastBit()

template<typename T >
constexpr uint8_t FindLastBit ( x)
constexpr

Search the last set bit in a value.

When no bit is set, it returns 0.

Parameters
xThe value to search.
Returns
The position of the last bit set.

Definition at line 232 of file bitmath_func.hpp.

◆ GB()

template<typename T >
constexpr static debug_inline uint GB ( const T  x,
const uint8_t  s,
const uint8_t  n 
)
staticconstexpr

Fetch n bits from x, started at bit s.

This function can be used to fetch n bits from the value x. The s value set the start position to read. The start position is count from the LSB and starts at 0. The result starts at a LSB, as this isn't just an and-bitmask but also some bit-shifting operations. GB(0xFF, 2, 1) will so return 0x01 (0000 0001) instead of 0x04 (0000 0100).

Parameters
xThe value to read some bits.
sThe start position to read some bits.
nThe number of bits to read.
Precondition
n < sizeof(T) * 8
s + n <= sizeof(T) * 8
Returns
The selected bits, aligned to a LSB.

Definition at line 32 of file bitmath_func.hpp.

Referenced by Buffer::AppendUtf8(), AreCompanyManagerFaceBitsValid(), BmpRead1(), BmpRead24(), BmpRead4(), BmpRead8(), BuildObject(), ChangeTrainDirRandomly(), CheckPartialPixelZ(), CmdBuildObjectArea(), CmdClearArea(), CmdLevelLand(), ConvertFromOldCompanyManagerFace(), DecodeMonitorCargoType(), DecodeMonitorCompany(), Disaster_CoalMine_Init(), DisasterTick_Submarine(), DrawCommonTileSeq(), DrawSpriteToRgbaBuffer(), AIInfo::DummyConstructor(), FormatLabel(), AI::GameLoop(), GetBridgeAxis(), GetBridgeType(), GetCleanHouseType(), GetCleanIndustryGfx(), GetClearCounter(), GetClearDensity(), StoryPageButtonData::GetColour(), GetCompanyManagerFaceBits(), GetCompanyManagerFaceSprite(), Order::GetConditionComparator(), Order::GetConditionVariable(), GetCrossingRoadAxis(), StoryPageButtonData::GetCursor(), GetCustomRoadStopSpecIndex(), Order::GetDepotActionType(), Order::GetDepotOrderType(), GetDisallowedRoadDirections(), GetDistanceFromNearbyHouse(), GetFeatureIndex(), GetFeatureNum(), GetFieldType(), GetGlobalVariable(), GetHouseBuildingStage(), GetHouseConstructionTick(), GetHouseProcessingTime(), GetHouseTriggers(), GetIndustryConstructionCounter(), GetIndustryConstructionStage(), GetIndustryTriggers(), GetLiftDestination(), GetLiftPosition(), Order::GetLoadType(), GetLockDirection(), GetLockPart(), Waypoint::GetNewGRFVariable(), Order::GetNonStopType(), GetPresentSignals(), GetRailDepotDirection(), GetRailReservationTrackBits(), GetRailType(), RailTypeScopeResolver::GetRandomBits(), RoadTypeScopeResolver::GetRandomBits(), GetRawClearGround(), GetRoadDepotDirection(), GetRoadside(), GetRoadWaypointRoadside(), VehicleResolverObject::GetScope(), GetShipDepotAxis(), GetShipDepotPart(), GetSignalStates(), GetStationTileRandomBits(), GetStationType(), Order::GetStopLocation(), GetTileOwner(), GetTrackBits(), GetTreeCount(), GetTreeDensity(), GetTreeGround(), GetTreeGrowth(), GetTropicZone(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), Order::GetType(), Order::GetUnloadType(), GRFParameterInfo::GetValue(), GetVarFileType(), IndustriesScopeResolver::GetVariable(), TownScopeResolver::GetVariable(), VehicleScopeResolver::GetVariable(), GetVarMemType(), StoryPageButtonData::GetVehicleType(), GetWaterClass(), GetWaterTileType(), HandleAutoSignalPlacement(), HandleCrashedAircraft(), RoadStop::HasFreeBay(), IncHouseConstructionTick(), IncreaseRoadWorksCounter(), IsBridgeAbove(), IsCustomRoadStopSpecIndex(), MirrorRoadBits(), MoveWaypointsToBaseStations(), TimetableWindow::OnInvalidateData(), OrdersWindow::OnInvalidateData(), PlaceTree(), Packet::PrepareToSend(), ResetRestoreAllTransparency(), RotateRoadBits(), ScaleAllCompanyManagerFaceBits(), SeedChance(), Packet::Send_uint32(), Packet::Send_uint64(), SetHouseType(), SetIndustryGfx(), VehicleListIdentifier::UnpackIfValid(), Utf8Decode(), Utf8EncodedCharLen(), StoryPageButtonData::ValidateColour(), StoryPageButtonData::ValidateCursor(), and StoryPageButtonData::ValidateVehicleType().

◆ HasAtMostOneBit()

template<typename T >
constexpr bool HasAtMostOneBit ( value)
constexpr

Test whether value has at most 1 bit set.

Parameters
valuethe value to test.
Returns
does value have at most 1 bit set?

Definition at line 290 of file bitmath_func.hpp.

Referenced by GetNewCargoTypeForReplace(), MaskWireBits(), and Vehicle::NeedsServicing().

◆ HasBit()

template<typename T >
constexpr debug_inline bool HasBit ( const T  x,
const uint8_t  y 
)
constexpr

Checks if a bit in a value is set.

This function checks if a bit inside a value is set or not. The y value specific the position of the bit, started at the LSB and count from 0.

Parameters
xThe value to check
yThe position of the bit to check, started from the LSB
Precondition
y < sizeof(T) * 8
Returns
True if the bit is set, false else.

Definition at line 103 of file bitmath_func.hpp.

Referenced by AddArticulatedParts(), NewGRFWindow::AddGRFToActive(), LinkGraph::AddNode(), AfterLoadRoadStops(), AircraftHandleDestTooFar(), RoadStop::AllocateBay(), AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback, TileAnimationFrameAnimationHelper< Industry > >::AnimateTile(), TimetableWindow::BuildArrivalDepartureList(), BuildObject(), PickerWindow::BuildPickerClassList(), PickerWindow::BuildPickerTypeList(), RefitWindow::BuildRefitList(), CompanyStationsWindow::BuildStationsList(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CanStationTileHavePylons(), CanStationTileHaveWires(), CargoAndEngineFilter(), ChangeIndustryProduction(), ChangeOwnershipOfCompanyItems(), CheckAutoreplaceValidity(), CheckBuildableTile(), CheckIfIndustryTilesAreFree(), RoadStop::Entry::CheckIntegrity(), BuildRailStationWindow::CheckSelectedSize(), ChooseShipTrack(), CmdAlterGroup(), CmdAutoreplaceVehicle(), CmdBuyCompany(), CmdForceTrainProceed(), CmdReverseTrainDirection(), CmdSetVehicleOnTime(), CmdStartStopVehicle(), CargoesField::ConnectCargo(), ConvertFromOldCompanyManagerFace(), ConvertOldMultiheadToNew(), BaseConsist::CopyConsistPropertiesFrom(), CountArticulatedParts(), Train::Crash(), NetworkAuthenticationServerHandler::Create(), DisasterTick_Helicopter_Rotors(), DisasterTick_Submarine(), DisasterTick_Ufo(), DisasterTick_Zeppeliner(), TownAuthorityWindow::DrawActions(), TimetableWindow::DrawArrivalDeparturePanel(), DrawBridgeMiddle(), DrawCommonTileSeq(), IndustryViewWindow::DrawInfo(), TownAuthorityWindow::DrawRatings(), EngineReplacement(), FillNewGRFVehicleCache(), RoadWaypointPickerCallbacks::FillUsedItems(), WaypointPickerCallbacks::FillUsedItems(), FindDeletedWaypointCloseTo(), FindGRFConfig(), FindJoiningWaypoint(), FindTrainOnTrackEnum(), Train::GetAccelerationStatus(), GetAcceptanceMask(), GetBestFittingSubType(), GetCanalSpriteOffset(), GetCargoSubtypeText(), GetCargoSuffix(), HousePickerCallbacks::GetClassName(), GetCompanyRailTypes(), GetCompanyRoadTypes(), RoadStop::GetEntry(), GetFoundation_Town(), GetIfStopIsForType(), GetIncompatibleRefitOrderIdForAutoreplace(), GetIndustryProbabilityCallback(), Airport::GetNumHangars(), GetRailReservationTrackBits(), GetRailStationAxis(), GetRailTypes(), GetRoadTypes(), GetSingleSignalState(), GetTLG(), CompanyInfrastructureWindow::GetTotalMaintenanceCost(), HousePickerCallbacks::GetTypeName(), BaseGraphWindow::GetValuesInterval(), StationScopeResolver::GetVariable(), GetWaterTileType(), GRFLoadConfig(), GroundSpritePaletteTransform(), HandleBankruptcyTakeover(), Vehicle::HandlePathfindingResult(), LinkRefresher::HandleRefit(), HandleSavegameLoadCrash(), HasCPUIDFlag(), HasCrossingReservation(), HasDepotReservation(), HasGrfMiscBit(), HasPowerOnRail(), HasPowerOnRoad(), HasRailCatenary(), HasRailTypeAvail(), GoodsEntry::HasRating(), HasRoadCatenary(), HasStationReservation(), HasTrack(), HasTrackdir(), HasTunnelBridgeReservation(), HasTunnelBridgeSnowOrDesert(), IndustryTemporarilyRefusesCargo(), IsArticulatedEngine(), Vehicle::IsArticulatedPart(), IsArticulatedVehicleRefittable(), IsBridge(), IsCompatibleRail(), IsCrossingBarred(), NWidgetCore::IsDisabled(), IsDockingTile(), Engine::IsEnabled(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsEngine(), IsEngineBuildable(), IsEngineRefittable(), RoadStop::IsEntranceBusy(), ObjectSpec::IsEverAvailable(), RoadStop::IsFreeBay(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsFreeWagon(), IsGoodGRFConfigList(), Engine::IsHidden(), NWidgetCore::IsHighlighted(), IsHouseCompleted(), IsIndustryCompleted(), IsInvisibilitySet(), IsLoggableGrfConfig(), NWidgetCore::IsLowered(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsMultiheaded(), IsOnSnow(), IsRoadWaypointOnSnowOrDesert(), IsSignalPresent(), IsSnowTile(), IsStationAvailable(), IsStationTileBlocked(), IsTransparencySet(), IsTunnel(), IsValidCompanyManagerFace(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsWagon(), RoadStop::Leave(), LiftHasDestination(), MapSpriteMappingRecolour(), MarkTrainAsStuck(), MonitorMonitorsIndustry(), MoveWaypointsToBaseStations(), Vehicle::NeedsServicing(), NetworkAfterNewGRFScan(), NetworkAutoCleanCompanies(), NewVehicleAvailable(), TownAuthorityWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), VehicleListWindow::OnInvalidateData(), TownAuthorityWindow::OnPaint(), SelectCompanyManagerFaceWindow::OnPaint(), SignList::OwnerVisibilityFilter(), ParamSet(), PerformStationTileSlopeCheck(), LinkRefresher::PredictNextOrder(), PrepareUnload(), Rail90DegTurnDisallowed(), RailNoLevelCrossings(), ReadSpriteLayout(), RoadStop::Entry::Rebuild(), RefitVehicle(), RoadNoLevelCrossing(), ScaleAllCompanyManagerFaceBits(), ServerNetworkGameSocketHandler::SendNewGRFCheck(), BuildVehicleWindow::SetCargoFilterArray(), SetYearEngineAgingStops(), ShowDropDownMenu(), ShowMissingContentWindow(), ShowNewGrfVehicleError(), Vehicle::ShowVisualEffect(), SlReadSimpleGamma(), SpriteLayoutPaletteTransform(), SubtractMoneyFromAnyCompany(), SurveyGrfs(), TileLoop_Water(), TownDirectoryWindow::TownRatingSorter(), TownTickHandler(), TrackOverlapsTracks(), TrainController(), TriggerObjectAnimation(), TriggerObjectTileAnimation(), TriggerRoadStopRandomisation(), TriggerWatchedCargoCallbacks(), TryPathReserve(), OrdersWindow::UpdateAutoRefitState(), UpdateCompanyGroupLiveries(), Train::UpdateDeltaXY(), UpdateObjectColours(), OskWindow::UpdateOskState(), UpdateTownGrowthRate(), Vehicle::UpdateVisualEffect(), GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPosition(), Utf8Decode(), VehicleExitDir(), VehicleLengthChanged(), VerifyAutoreplaceRefitForOrders(), WaypointWindow::WaypointWindow(), and RoadStop::~RoadStop().

◆ HasExactlyOneBit()

template<typename T >
constexpr bool HasExactlyOneBit ( value)
constexpr

Test whether value has exactly 1 bit set.

Parameters
valuethe value to test.
Returns
does value have exactly 1 bit set?

Definition at line 278 of file bitmath_func.hpp.

◆ KillFirstBit()

template<typename T >
constexpr T KillFirstBit ( value)
constexpr

Clear the first bit in an integer.

This function returns a value where the first bit (from LSB) is cleared. So, 110100 returns 110000, 000001 returns 000000, etc.

Parameters
valueThe value to clear the first bit
Returns
The new value with the first bit cleared

Definition at line 250 of file bitmath_func.hpp.

Referenced by CYapfBaseT< Types >::AddMultipleNodes(), ExtendTrainReservation(), CYapfOriginTileT< Types >::PfSetStartupNodes(), TrackBitsToTrack(), and TracksOverlap().

◆ SB()

template<typename T , typename U >
constexpr T SB ( T &  x,
const uint8_t  s,
const uint8_t  n,
const U  d 
)
constexpr

Set n bits in x starting at bit s to d.

This function sets n bits from x which started as bit s to the value of d. The parameters x, s and n works the same as the parameters of GB. The result is saved in x again. Unused bits in the window provided by n are set to 0 if the value of d isn't "big" enough. This is not a bug, its a feature.

Note
Parameter x must be a variable as the result is saved there.
To avoid unexpected results the value of d should not use more space as the provided space of n bits (log2)
Parameters
xThe variable to change some bits
sThe start position for the new bits
nThe size/window for the new bits
dThe actually new bits to save in the defined position.
Precondition
n < sizeof(T) * 8
s + n <= sizeof(T) * 8
Returns
The new value of x

Definition at line 58 of file bitmath_func.hpp.

Referenced by ClearEnginesHiddenFlagOfCompany(), EncodeCargoIndustryMonitor(), EncodeCargoTownMonitor(), RoadStop::Enter(), HaltLift(), MakeBridgeRamp(), MakeField(), MakeLockTile(), MakeObject(), MakeRailDepot(), MakeRailTunnel(), MakeRoadCrossing(), MakeRoadDepot(), MakeRoadNormal(), MakeRoadTunnel(), MakeShipDepot(), MakeShore(), MakeStation(), MakeTree(), MakeWater(), MoveBuoysToWaypoints(), ResetIndustryConstructionStage(), SetClearCounter(), SetClearDensity(), SetCompanyManagerFaceBits(), Order::SetConditionComparator(), Order::SetConditionVariable(), SetCustomRoadStopSpecIndex(), Order::SetDepotActionType(), Order::SetDepotOrderType(), SetDisallowedRoadDirections(), RoadStop::SetEntranceBusy(), SetFieldType(), SetHouseCompleted(), SetHouseProcessingTime(), SetHouseTriggers(), SetHouseType(), SetIndustryConstructionCounter(), SetIndustryConstructionStage(), SetIndustryGfx(), SetIndustryTriggers(), SetLiftDestination(), SetLiftPosition(), Order::SetLoadType(), Order::SetNonStopType(), SetPresentSignals(), SetRailDepotExitDirection(), SetRailType(), SetRoadDepotExitDirection(), SetRoadside(), SetRoadWaypointRoadside(), SetSignalStates(), SetStationTileRandomBits(), Order::SetStopLocation(), GRFConfig::SetSuitablePalette(), SetTileOwner(), SetTileType(), SetTrackBits(), SetTrackReservation(), SetTreeGroundDensity(), SetTreeGrowth(), SetTropicZone(), SetTunnelBridgeSnowOrDesert(), Order::SetUnloadType(), GRFParameterInfo::SetValue(), StoryPageButtonData::SetVehicleType(), SetWaterClass(), TerminateRoadWorks(), and UpdateStationAcceptance().

◆ SetBit()

template<typename T >
constexpr T SetBit ( T &  x,
const uint8_t  y 
)
constexpr

Set a bit in a variable.

This function sets a bit in a variable. The variable is changed and the value is also returned. Parameter y defines the bit and starts at the LSB with 0.

Parameters
xThe variable to set a bit
yThe bit position to set
Precondition
y < sizeof(T) * 8
Returns
The new value of the old value with the bit set

Definition at line 121 of file bitmath_func.hpp.

Referenced by AddAcceptedCargoSetMask(), AircraftHandleDestTooFar(), CalculateRefitMasks(), CalculateRoadStopCost(), ChangeOwnershipOfCompanyItems(), ChangeTownRating(), CmdAutofillTimetable(), CargoesField::ConnectCargo(), ConvertFromOldCompanyManagerFace(), ConvertOldMultiheadToNew(), BaseConsist::CopyConsistPropertiesFrom(), CopyGRFConfigList(), DEFINE_POOL_METHOD(), DrawCommonTileSeq(), EnableEngineForCompany(), EncodeCargoIndustryMonitor(), RoadStop::Enter(), RoadStop::FreeBay(), GetAcceptanceMask(), GetAvailableVehicleCargoTypes(), GetCompanyRailTypes(), GetCompanyRoadTypes(), GetCountAndDistanceOfClosestInstance(), GetEmptyMask(), GetMaskOfAllowedCurrencies(), Airport::GetNumHangars(), GetRailTypes(), GetRoadTypes(), GRFLoadConfig(), GRFUnsafe(), HandleBankruptcyTakeover(), Vehicle::HandlePathfindingResult(), InitializeSortedCargoSpecs(), IsEngineRefittable(), IsGoodGRFConfigList(), LookupManyOfMany(), RoadStop::MakeDriveThrough(), MakeSnow(), MapSpriteMappingRecolour(), MarkTrainAsStuck(), NetworkAutoCleanCompanies(), GraphLegendWindow::OnInvalidateData(), PrepareUnload(), ReadGRFSpriteOffsets(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetArticulatedPart(), SetBridgeMiddle(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetEngine(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetFreeWagon(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetFrontEngine(), SetGroupFlag(), SetIndustryCompleted(), SetLiftDestination(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetMultiheaded(), SmallMapWindow::SetOverlayCargoMask(), SettingsDisableElrail(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetWagon(), ShowNewGrfVehicleError(), ToggleInvisibilityWithTransparency(), TownActionBuildStatue(), TriggerRoadStopRandomisation(), TriggerWatchedCargoCallbacks(), GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPositionAndInclination(), and FreeUnitIDGenerator::UseID().

◆ ToggleBit()

template<typename T >
constexpr T ToggleBit ( T &  x,
const uint8_t  y 
)
constexpr

Toggles a bit in a variable.

This function toggles a bit in a variable. The variable is changed and the value is also returned. Parameter y defines the bit to toggle and starts at the LSB with 0.

Parameters
xThe variable to toggle the bit
yThe bit position to toggle
Precondition
y < sizeof(T) * 8
Returns
The new value of the old value with the bit toggled

Definition at line 181 of file bitmath_func.hpp.

Referenced by BaseConsist::CopyConsistPropertiesFrom(), ToggleInvisibility(), ToggleRoadWaypointOnSnowOrDesert(), ToggleSnow(), ToggleTransparency(), and ToggleTransparencyLock().