mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
QOL changes from DEVELOP
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
--- **Utilities** Enumerators.
|
||||
--
|
||||
--
|
||||
-- An enumerator is a variable that holds a constant value. Enumerators are very useful because they make the code easier to read and to change in general.
|
||||
--
|
||||
--
|
||||
-- For example, instead of using the same value at multiple different places in your code, you should use a variable set to that value.
|
||||
-- If, for whatever reason, the value needs to be changed, you only have to change the variable once and do not have to search through you code and reset
|
||||
-- every value by hand.
|
||||
--
|
||||
--
|
||||
-- Another big advantage is that the LDT intellisense "knows" the enumerators. So you can use the autocompletion feature and do not have to keep all the
|
||||
-- values in your head or look them up in the docs.
|
||||
--
|
||||
-- values in your head or look them up in the docs.
|
||||
--
|
||||
-- DCS itself provides a lot of enumerators for various things. See [Enumerators](https://wiki.hoggitworld.com/view/Category:Enumerators) on Hoggit.
|
||||
--
|
||||
--
|
||||
-- Other Moose classes also have enumerators. For example, the AIRBASE class has enumerators for airbase names.
|
||||
--
|
||||
--
|
||||
-- @module ENUMS
|
||||
-- @image MOOSE.JPG
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
-- @type ENUMS
|
||||
|
||||
--- Because ENUMS are just better practice.
|
||||
--
|
||||
--
|
||||
-- The ENUMS class adds some handy variables, which help you to make your code better and more general.
|
||||
--
|
||||
-- @field #ENUMS
|
||||
@@ -30,16 +30,16 @@ ENUMS = {}
|
||||
-- @type ENUMS.ROE
|
||||
-- @field #number WeaponFree AI will engage any enemy group it detects. Target prioritization is based based on the threat of the target.
|
||||
-- @field #number OpenFireWeaponFree AI will engage any enemy group it detects, but will prioritize targets specified in the groups tasking.
|
||||
-- @field #number OpenFire AI will engage only targets specified in its tasking.
|
||||
-- @field #number OpenFire AI will engage only targets specified in its taskings.
|
||||
-- @field #number ReturnFire AI will only engage threats that shoot first.
|
||||
-- @field #number WeaponHold AI will hold fire under all circumstances.
|
||||
ENUMS.ROE = {
|
||||
WeaponFree = 0,
|
||||
OpenFireWeaponFree = 1,
|
||||
OpenFire = 2,
|
||||
ReturnFire = 3,
|
||||
WeaponHold = 4,
|
||||
}
|
||||
WeaponFree=0,
|
||||
OpenFireWeaponFree=1,
|
||||
OpenFire=2,
|
||||
ReturnFire=3,
|
||||
WeaponHold=4,
|
||||
}
|
||||
|
||||
--- Reaction On Threat.
|
||||
-- @type ENUMS.ROT
|
||||
@@ -49,11 +49,11 @@ ENUMS.ROE = {
|
||||
-- @field #number BypassAndEscape AI will attempt to avoid enemy threat zones all together. This includes attempting to fly above or around threats.
|
||||
-- @field #number AllowAbortMission If a threat is deemed severe enough the AI will abort its mission and return to base.
|
||||
ENUMS.ROT = {
|
||||
NoReaction = 0,
|
||||
PassiveDefense = 1,
|
||||
EvadeFire = 2,
|
||||
BypassAndEscape = 3,
|
||||
AllowAbortMission = 4,
|
||||
NoReaction=0,
|
||||
PassiveDefense=1,
|
||||
EvadeFire=2,
|
||||
BypassAndEscape=3,
|
||||
AllowAbortMission=4,
|
||||
}
|
||||
|
||||
--- Alarm state.
|
||||
@@ -62,12 +62,12 @@ ENUMS.ROT = {
|
||||
-- @field #number Green Group is not combat ready. Sensors are stowed if possible.
|
||||
-- @field #number Red Group is combat ready and actively searching for targets. Some groups like infantry will not move in this state.
|
||||
ENUMS.AlarmState = {
|
||||
Auto = 0,
|
||||
Green = 1,
|
||||
Red = 2,
|
||||
Auto=0,
|
||||
Green=1,
|
||||
Red=2,
|
||||
}
|
||||
|
||||
--- Weapon types. See the [Weapon Flag](https://wiki.hoggitworld.com/view/DCS_enum_weapon_flag) enumerator on Hoggit wiki.
|
||||
--- Weapon types. See the [Weapon Flag](https://wiki.hoggitworld.com/view/DCS_enum_weapon_flag) enumerotor on hoggit wiki.
|
||||
-- @type ENUMS.WeaponFlag
|
||||
ENUMS.WeaponFlag={
|
||||
-- Bombs
|
||||
@@ -111,7 +111,7 @@ ENUMS.WeaponFlag={
|
||||
--
|
||||
-- Bombs
|
||||
GuidedBomb = 14, -- (LGB + TvGB + SNSGB)
|
||||
AnyUnguidedBomb = 2147485680, -- (HeBomb + Penetrator + NapalmBomb + FAEBomb + ClusterBomb + Dispenser + CandleBomb + ParachuteBomb)
|
||||
AnyUnguidedBomb = 2147485680, -- (HeBomb + Penetrator + NapalmBomb + FAEBomb + ClusterBomb + Dispencer + CandleBomb + ParachuteBomb)
|
||||
AnyBomb = 2147485694, -- (GuidedBomb + AnyUnguidedBomb)
|
||||
--- Rockets
|
||||
AnyRocket = 30720, -- LightRocket + MarkerRocket + CandleRocket + HeavyRocket
|
||||
@@ -123,9 +123,11 @@ ENUMS.WeaponFlag={
|
||||
--- Air-To-Air Missiles
|
||||
AnyAAM = 264241152, -- IR_AAM + SAR_AAM + AR_AAM + SRAAM + MRAAM + LRAAM
|
||||
AnyAutonomousMissile = 36012032, -- IR_AAM + AntiRadarMissile + AntiShipMissile + FireAndForgetASM + CruiseMissile
|
||||
AnyMissile = 268402688, -- AnyASM + AnyAAM
|
||||
AnyMissile = 268402688, -- AnyASM + AnyAAM
|
||||
--- Guns
|
||||
Cannons = 805306368, -- GUN_POD + BuiltInCannon
|
||||
--- Torpedo
|
||||
Torpedo = 4294967296,
|
||||
---
|
||||
-- Even More Genral
|
||||
Auto = 3221225470, -- Any Weapon (AnyBomb + AnyRocket + AnyMissile + Cannons)
|
||||
@@ -133,9 +135,96 @@ ENUMS.WeaponFlag={
|
||||
AnyAG = 2956984318, -- Any Air-To-Ground Weapon
|
||||
AnyAA = 264241152, -- Any Air-To-Air Weapon
|
||||
AnyUnguided = 2952822768, -- Any Unguided Weapon
|
||||
AnyGuided = 268402702, -- Any Guided Weapon
|
||||
AnyGuided = 268402702, -- Any Guided Weapon
|
||||
}
|
||||
|
||||
--- Weapon types by category. See the [Weapon Flag](https://wiki.hoggitworld.com/view/DCS_enum_weapon_flag) enumerator on hoggit wiki.
|
||||
-- @type ENUMS.WeaponType
|
||||
-- @field #table Bomb Bombs.
|
||||
-- @field #table Rocket Rocket.
|
||||
-- @field #table Gun Guns.
|
||||
-- @field #table Missile Missiles.
|
||||
-- @field #table AAM Air-to-Air missiles.
|
||||
-- @field #table Torpedo Torpedos.
|
||||
-- @field #table Any Combinations.
|
||||
ENUMS.WeaponType={}
|
||||
ENUMS.WeaponType.Bomb={
|
||||
-- Bombs
|
||||
LGB = 2,
|
||||
TvGB = 4,
|
||||
SNSGB = 8,
|
||||
HEBomb = 16,
|
||||
Penetrator = 32,
|
||||
NapalmBomb = 64,
|
||||
FAEBomb = 128,
|
||||
ClusterBomb = 256,
|
||||
Dispencer = 512,
|
||||
CandleBomb = 1024,
|
||||
ParachuteBomb = 2147483648,
|
||||
-- Combinations
|
||||
GuidedBomb = 14, -- (LGB + TvGB + SNSGB)
|
||||
AnyUnguidedBomb = 2147485680, -- (HeBomb + Penetrator + NapalmBomb + FAEBomb + ClusterBomb + Dispencer + CandleBomb + ParachuteBomb)
|
||||
AnyBomb = 2147485694, -- (GuidedBomb + AnyUnguidedBomb)
|
||||
}
|
||||
ENUMS.WeaponType.Rocket={
|
||||
-- Rockets
|
||||
LightRocket = 2048,
|
||||
MarkerRocket = 4096,
|
||||
CandleRocket = 8192,
|
||||
HeavyRocket = 16384,
|
||||
-- Combinations
|
||||
AnyRocket = 30720, -- LightRocket + MarkerRocket + CandleRocket + HeavyRocket
|
||||
}
|
||||
ENUMS.WeaponType.Gun={
|
||||
-- Guns
|
||||
GunPod = 268435456,
|
||||
BuiltInCannon = 536870912,
|
||||
-- Combinations
|
||||
Cannons = 805306368, -- GUN_POD + BuiltInCannon
|
||||
}
|
||||
ENUMS.WeaponType.Missile={
|
||||
-- Missiles
|
||||
AntiRadarMissile = 32768,
|
||||
AntiShipMissile = 65536,
|
||||
AntiTankMissile = 131072,
|
||||
FireAndForgetASM = 262144,
|
||||
LaserASM = 524288,
|
||||
TeleASM = 1048576,
|
||||
CruiseMissile = 2097152,
|
||||
AntiRadarMissile2 = 1073741824,
|
||||
-- Combinations
|
||||
GuidedASM = 1572864, -- (LaserASM + TeleASM)
|
||||
TacticalASM = 1835008, -- (GuidedASM + FireAndForgetASM)
|
||||
AnyASM = 4161536, -- (AntiRadarMissile + AntiShipMissile + AntiTankMissile + FireAndForgetASM + GuidedASM + CruiseMissile)
|
||||
AnyASM2 = 1077903360, -- 4161536+1073741824,
|
||||
AnyAutonomousMissile = 36012032, -- IR_AAM + AntiRadarMissile + AntiShipMissile + FireAndForgetASM + CruiseMissile
|
||||
AnyMissile = 268402688, -- AnyASM + AnyAAM
|
||||
}
|
||||
ENUMS.WeaponType.AAM={
|
||||
-- Air-To-Air Missiles
|
||||
SRAM = 4194304,
|
||||
MRAAM = 8388608,
|
||||
LRAAM = 16777216,
|
||||
IR_AAM = 33554432,
|
||||
SAR_AAM = 67108864,
|
||||
AR_AAM = 134217728,
|
||||
-- Combinations
|
||||
AnyAAM = 264241152, -- IR_AAM + SAR_AAM + AR_AAM + SRAAM + MRAAM + LRAAM
|
||||
}
|
||||
ENUMS.WeaponType.Torpedo={
|
||||
-- Torpedo
|
||||
Torpedo = 4294967296,
|
||||
}
|
||||
ENUMS.WeaponType.Any={
|
||||
-- General combinations
|
||||
Weapon = 3221225470, -- Any Weapon (AnyBomb + AnyRocket + AnyMissile + Cannons)
|
||||
AG = 2956984318, -- Any Air-To-Ground Weapon
|
||||
AA = 264241152, -- Any Air-To-Air Weapon
|
||||
Unguided = 2952822768, -- Any Unguided Weapon
|
||||
Guided = 268402702, -- Any Guided Weapon
|
||||
}
|
||||
|
||||
|
||||
--- Mission tasks.
|
||||
-- @type ENUMS.MissionTask
|
||||
-- @field #string NOTHING No special task. Group can perform the minimal tasks: Orbit, Refuelling, Follow and Aerobatics.
|
||||
@@ -173,7 +262,7 @@ ENUMS.MissionTask={
|
||||
TRANSPORT="Transport",
|
||||
}
|
||||
|
||||
--- Formations (new). See the [Formations](https://wiki.hoggitworld.com/view/DCS_enum_formation) on Hoggit wiki.
|
||||
--- Formations (new). See the [Formations](https://wiki.hoggitworld.com/view/DCS_enum_formation) on hoggit wiki.
|
||||
-- @type ENUMS.Formation
|
||||
ENUMS.Formation={}
|
||||
ENUMS.Formation.FixedWing={}
|
||||
@@ -216,23 +305,23 @@ ENUMS.Formation.FixedWing.FighterVic.Close = 917505
|
||||
ENUMS.Formation.FixedWing.FighterVic.Open = 917506
|
||||
ENUMS.Formation.RotaryWing={}
|
||||
ENUMS.Formation.RotaryWing.Column={}
|
||||
ENUMS.Formation.RotaryWing.Column.D70 = 720896
|
||||
ENUMS.Formation.RotaryWing.Column.D70=720896
|
||||
ENUMS.Formation.RotaryWing.Wedge={}
|
||||
ENUMS.Formation.RotaryWing.Wedge.D70 = 8
|
||||
ENUMS.Formation.RotaryWing.Wedge.D70=8
|
||||
ENUMS.Formation.RotaryWing.FrontRight={}
|
||||
ENUMS.Formation.RotaryWing.FrontRight.D300 = 655361
|
||||
ENUMS.Formation.RotaryWing.FrontRight.D600 = 655362
|
||||
ENUMS.Formation.RotaryWing.FrontRight.D300=655361
|
||||
ENUMS.Formation.RotaryWing.FrontRight.D600=655362
|
||||
ENUMS.Formation.RotaryWing.FrontLeft={}
|
||||
ENUMS.Formation.RotaryWing.FrontLeft.D300 = 655617
|
||||
ENUMS.Formation.RotaryWing.FrontLeft.D600 = 655618
|
||||
ENUMS.Formation.RotaryWing.FrontLeft.D300=655617
|
||||
ENUMS.Formation.RotaryWing.FrontLeft.D600=655618
|
||||
ENUMS.Formation.RotaryWing.EchelonRight={}
|
||||
ENUMS.Formation.RotaryWing.EchelonRight.D70 = 589825
|
||||
ENUMS.Formation.RotaryWing.EchelonRight.D300 = 589826
|
||||
ENUMS.Formation.RotaryWing.EchelonRight.D600 = 589827
|
||||
ENUMS.Formation.RotaryWing.EchelonRight.D70 =589825
|
||||
ENUMS.Formation.RotaryWing.EchelonRight.D300=589826
|
||||
ENUMS.Formation.RotaryWing.EchelonRight.D600=589827
|
||||
ENUMS.Formation.RotaryWing.EchelonLeft={}
|
||||
ENUMS.Formation.RotaryWing.EchelonLeft.D70 = 590081
|
||||
ENUMS.Formation.RotaryWing.EchelonLeft.D300 = 590082
|
||||
ENUMS.Formation.RotaryWing.EchelonLeft.D600 = 590083
|
||||
ENUMS.Formation.RotaryWing.EchelonLeft.D70 =590081
|
||||
ENUMS.Formation.RotaryWing.EchelonLeft.D300=590082
|
||||
ENUMS.Formation.RotaryWing.EchelonLeft.D600=590083
|
||||
ENUMS.Formation.Vehicle={}
|
||||
ENUMS.Formation.Vehicle.Vee="Vee"
|
||||
ENUMS.Formation.Vehicle.EchelonRight="EchelonR"
|
||||
@@ -244,34 +333,34 @@ ENUMS.Formation.Vehicle.Cone="Cone"
|
||||
ENUMS.Formation.Vehicle.Diamond="Diamond"
|
||||
|
||||
--- Formations (old). The old format is a simplified version of the new formation enums, which allow more sophisticated settings.
|
||||
-- See the [Formations](https://wiki.hoggitworld.com/view/DCS_enum_formation) on Hoggit wiki.
|
||||
-- See the [Formations](https://wiki.hoggitworld.com/view/DCS_enum_formation) on hoggit wiki.
|
||||
-- @type ENUMS.FormationOld
|
||||
ENUMS.FormationOld={}
|
||||
ENUMS.FormationOld.FixedWing={}
|
||||
ENUMS.FormationOld.FixedWing.LineAbreast = 1
|
||||
ENUMS.FormationOld.FixedWing.Trail = 2
|
||||
ENUMS.FormationOld.FixedWing.Wedge = 3
|
||||
ENUMS.FormationOld.FixedWing.EchelonRight = 4
|
||||
ENUMS.FormationOld.FixedWing.EchelonLeft = 5
|
||||
ENUMS.FormationOld.FixedWing.FingerFour = 6
|
||||
ENUMS.FormationOld.FixedWing.SpreadFour = 7
|
||||
ENUMS.FormationOld.FixedWing.BomberElement = 12
|
||||
ENUMS.FormationOld.FixedWing.BomberElementHeight = 13
|
||||
ENUMS.FormationOld.FixedWing.FighterVic = 14
|
||||
ENUMS.FormationOld.FixedWing.LineAbreast=1
|
||||
ENUMS.FormationOld.FixedWing.Trail=2
|
||||
ENUMS.FormationOld.FixedWing.Wedge=3
|
||||
ENUMS.FormationOld.FixedWing.EchelonRight=4
|
||||
ENUMS.FormationOld.FixedWing.EchelonLeft=5
|
||||
ENUMS.FormationOld.FixedWing.FingerFour=6
|
||||
ENUMS.FormationOld.FixedWing.SpreadFour=7
|
||||
ENUMS.FormationOld.FixedWing.BomberElement=12
|
||||
ENUMS.FormationOld.FixedWing.BomberElementHeight=13
|
||||
ENUMS.FormationOld.FixedWing.FighterVic=14
|
||||
ENUMS.FormationOld.RotaryWing={}
|
||||
ENUMS.FormationOld.RotaryWing.Wedge = 8
|
||||
ENUMS.FormationOld.RotaryWing.Echelon = 9
|
||||
ENUMS.FormationOld.RotaryWing.Front = 10
|
||||
ENUMS.FormationOld.RotaryWing.Column = 11
|
||||
ENUMS.FormationOld.RotaryWing.Wedge=8
|
||||
ENUMS.FormationOld.RotaryWing.Echelon=9
|
||||
ENUMS.FormationOld.RotaryWing.Front=10
|
||||
ENUMS.FormationOld.RotaryWing.Column=11
|
||||
|
||||
|
||||
--- Morse Code. See the [Wikipedia](https://en.wikipedia.org/wiki/Morse_code).
|
||||
--
|
||||
--
|
||||
-- * Short pulse "*"
|
||||
-- * Long pulse "-"
|
||||
--
|
||||
--
|
||||
-- Pulses are separated by a blank character " ".
|
||||
--
|
||||
--
|
||||
-- @type ENUMS.Morse
|
||||
ENUMS.Morse={}
|
||||
ENUMS.Morse.A="* -"
|
||||
@@ -313,9 +402,9 @@ ENUMS.Morse.N0="- - - - -"
|
||||
ENUMS.Morse[" "]=" "
|
||||
|
||||
--- ISO (639-1) 2-letter Language Codes. See the [Wikipedia](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
|
||||
--
|
||||
--
|
||||
-- @type ENUMS.ISOLang
|
||||
ENUMS.ISOLang =
|
||||
ENUMS.ISOLang =
|
||||
{
|
||||
Arabic = 'AR',
|
||||
Chinese = 'ZH',
|
||||
@@ -329,7 +418,7 @@ ENUMS.ISOLang =
|
||||
}
|
||||
|
||||
--- Phonetic Alphabet (NATO). See the [Wikipedia](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet).
|
||||
--
|
||||
--
|
||||
-- @type ENUMS.Phonetic
|
||||
ENUMS.Phonetic =
|
||||
{
|
||||
@@ -359,4 +448,50 @@ ENUMS.Phonetic =
|
||||
X = 'Xray',
|
||||
Y = 'Yankee',
|
||||
Z = 'Zulu',
|
||||
}
|
||||
}
|
||||
|
||||
--- Reporting Names (NATO). See the [Wikipedia](https://en.wikipedia.org/wiki/List_of_NATO_reporting_names_for_fighter_aircraft).
|
||||
-- DCS known aircraft types
|
||||
--
|
||||
-- @type ENUMS.ReportingName
|
||||
ENUMS.ReportingName =
|
||||
{
|
||||
NATO = {
|
||||
-- Fighters
|
||||
Dragon = "JF-17", -- China, correct?
|
||||
Fagot = "MiG-15",
|
||||
Farmer = "MiG-19", -- Shenyang J-6 and Mikoyan-Gurevich MiG-19
|
||||
Felon = "Su-57",
|
||||
Fencer = "Su-24",
|
||||
Fishbed = "MiG-21",
|
||||
Fitter = "Su-17", -- Sukhoi Su-7 and Su-17/Su-20/Su-22
|
||||
Flogger = "MiG-23", --and MiG-27
|
||||
Flogger_D = "MiG-27", --and MiG-23
|
||||
Flagon = "Su-15",
|
||||
Foxbat = "MiG-25",
|
||||
Fulcrum = "MiG-29",
|
||||
Foxhound = "MiG-31",
|
||||
Flanker = "Su-27", -- Sukhoi Su-27/Su-30/Su-33/Su-35/Su-37 and Shenyang J-11/J-15/J-16
|
||||
Flanker_C = "Su-30",
|
||||
Flanker_E = "Su-35",
|
||||
Flanker_F = "Su-37",
|
||||
Flanker_Dragon = "J-11A",
|
||||
Sea_Flanker = "Su-33",
|
||||
Fullback = "Su-32", -- also Su-34
|
||||
Frogfoot = "Su-25",
|
||||
Tomcat = "F-14", -- Iran
|
||||
Mirage = "Mirage", -- various non-NATO
|
||||
-- Bomber
|
||||
H6J = "H6-J",
|
||||
Sea_Bear = "Tu-142", -- also Tu-95
|
||||
Bear = "Tu-95", -- also Tu-142
|
||||
Blinder = "Tu-22",
|
||||
Blackjack = "Tu-160",
|
||||
-- AIC / Transport / Other
|
||||
Clank = "An-30",
|
||||
Curl = "An-26",
|
||||
Candid = "IL-76",
|
||||
Midas = "IL-78",
|
||||
Mainstay = "A-50", -- KJ-2000 China
|
||||
}
|
||||
}
|
||||
|
||||
769
Moose Development/Moose/Utilities/FiFo.lua
Normal file
769
Moose Development/Moose/Utilities/FiFo.lua
Normal file
@@ -0,0 +1,769 @@
|
||||
--- **UTILS** - ClassicFiFo Stack.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ## Main Features:
|
||||
--
|
||||
-- * Build a simple multi-purpose FiFo (First-In, First-Out) stack for generic data.
|
||||
-- * [Wikipedia](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **applevangelist**
|
||||
-- @module Utils.FiFo
|
||||
-- @image MOOSE.JPG
|
||||
|
||||
-- Date: April 2022
|
||||
|
||||
do
|
||||
--- FIFO class.
|
||||
-- @type FIFO
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field #string version Version of FiFo
|
||||
-- @field #number counter
|
||||
-- @field #number pointer
|
||||
-- @field #table stackbypointer
|
||||
-- @field #table stackbyid
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
---
|
||||
-- @type FIFO.IDEntry
|
||||
-- @field #number pointer
|
||||
-- @field #table data
|
||||
-- @field #table uniqueID
|
||||
|
||||
---
|
||||
-- @field #FIFO
|
||||
FIFO = {
|
||||
ClassName = "FIFO",
|
||||
lid = "",
|
||||
version = "0.0.5",
|
||||
counter = 0,
|
||||
pointer = 0,
|
||||
stackbypointer = {},
|
||||
stackbyid = {}
|
||||
}
|
||||
|
||||
--- Instantiate a new FIFO Stack
|
||||
-- @param #FIFO self
|
||||
-- @return #FIFO self
|
||||
function FIFO:New()
|
||||
-- Inherit everything from BASE class.
|
||||
local self=BASE:Inherit(self, BASE:New())
|
||||
self.pointer = 0
|
||||
self.counter = 0
|
||||
self.stackbypointer = {}
|
||||
self.stackbyid = {}
|
||||
self.uniquecounter = 0
|
||||
-- Set some string id for output to DCS.log file.
|
||||
self.lid=string.format("%s (%s) | ", "FiFo", self.version)
|
||||
self:T(self.lid .."Created.")
|
||||
return self
|
||||
end
|
||||
|
||||
--- Empty FIFO Stack
|
||||
-- @param #FIFO self
|
||||
-- @return #FIFO self
|
||||
function FIFO:Clear()
|
||||
self:T(self.lid.."Clear")
|
||||
self.pointer = 0
|
||||
self.counter = 0
|
||||
self.stackbypointer = nil
|
||||
self.stackbyid = nil
|
||||
self.stackbypointer = {}
|
||||
self.stackbyid = {}
|
||||
self.uniquecounter = 0
|
||||
return self
|
||||
end
|
||||
|
||||
--- FIFO Push Object to Stack
|
||||
-- @param #FIFO self
|
||||
-- @param #table Object
|
||||
-- @param #string UniqueID (optional) - will default to current pointer + 1. Note - if you intend to use `FIFO:GetIDStackSorted()` keep the UniqueID numerical!
|
||||
-- @return #FIFO self
|
||||
function FIFO:Push(Object,UniqueID)
|
||||
self:T(self.lid.."Push")
|
||||
self:T({Object,UniqueID})
|
||||
self.pointer = self.pointer + 1
|
||||
self.counter = self.counter + 1
|
||||
local uniID = UniqueID
|
||||
if not UniqueID then
|
||||
self.uniquecounter = self.uniquecounter + 1
|
||||
uniID = self.uniquecounter
|
||||
end
|
||||
self.stackbyid[uniID] = { pointer = self.pointer, data = Object, uniqueID = uniID }
|
||||
self.stackbypointer[self.pointer] = { pointer = self.pointer, data = Object, uniqueID = uniID }
|
||||
return self
|
||||
end
|
||||
|
||||
--- FIFO Pull Object from Stack
|
||||
-- @param #FIFO self
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function FIFO:Pull()
|
||||
self:T(self.lid.."Pull")
|
||||
if self.counter == 0 then return nil end
|
||||
--local object = self.stackbypointer[self.pointer].data
|
||||
--self.stackbypointer[self.pointer] = nil
|
||||
local object = self.stackbypointer[1].data
|
||||
self.stackbypointer[1] = nil
|
||||
self.counter = self.counter - 1
|
||||
--self.pointer = self.pointer - 1
|
||||
self:Flatten()
|
||||
return object
|
||||
end
|
||||
|
||||
--- FIFO Pull Object from Stack by Pointer
|
||||
-- @param #FIFO self
|
||||
-- @param #number Pointer
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function FIFO:PullByPointer(Pointer)
|
||||
self:T(self.lid.."PullByPointer " .. tostring(Pointer))
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbypointer[Pointer] -- #FIFO.IDEntry
|
||||
self.stackbypointer[Pointer] = nil
|
||||
if object then self.stackbyid[object.uniqueID] = nil end
|
||||
self.counter = self.counter - 1
|
||||
self:Flatten()
|
||||
if object then
|
||||
return object.data
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- FIFO Read, not Pull, Object from Stack by Pointer
|
||||
-- @param #FIFO self
|
||||
-- @param #number Pointer
|
||||
-- @return #table Object or nil if stack is empty or pointer does not exist
|
||||
function FIFO:ReadByPointer(Pointer)
|
||||
self:T(self.lid.."ReadByPointer " .. tostring(Pointer))
|
||||
if self.counter == 0 or not Pointer or not self.stackbypointer[Pointer] then return nil end
|
||||
local object = self.stackbypointer[Pointer] -- #FIFO.IDEntry
|
||||
if object then
|
||||
return object.data
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
--- FIFO Read, not Pull, Object from Stack by UniqueID
|
||||
-- @param #FIFO self
|
||||
-- @param #number UniqueID
|
||||
-- @return #table Object data or nil if stack is empty or ID does not exist
|
||||
function FIFO:ReadByID(UniqueID)
|
||||
self:T(self.lid.."ReadByID " .. tostring(UniqueID))
|
||||
if self.counter == 0 or not UniqueID or not self.stackbyid[UniqueID] then return nil end
|
||||
local object = self.stackbyid[UniqueID] -- #FIFO.IDEntry
|
||||
if object then
|
||||
return object.data
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
--- FIFO Pull Object from Stack by UniqueID
|
||||
-- @param #FIFO self
|
||||
-- @param #tableUniqueID
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function FIFO:PullByID(UniqueID)
|
||||
self:T(self.lid.."PullByID " .. tostring(UniqueID))
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbyid[UniqueID] -- #FIFO.IDEntry
|
||||
--self.stackbyid[UniqueID] = nil
|
||||
if object then
|
||||
return self:PullByPointer(object.pointer)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
--- FIFO Housekeeping
|
||||
-- @param #FIFO self
|
||||
-- @return #FIFO self
|
||||
function FIFO:Flatten()
|
||||
self:T(self.lid.."Flatten")
|
||||
-- rebuild stacks
|
||||
local pointerstack = {}
|
||||
local idstack = {}
|
||||
local counter = 0
|
||||
for _ID,_entry in pairs(self.stackbypointer) do
|
||||
counter = counter + 1
|
||||
pointerstack[counter] = { pointer = counter, data = _entry.data, uniqueID = _entry.uniqueID}
|
||||
end
|
||||
for _ID,_entry in pairs(pointerstack) do
|
||||
idstack[_entry.uniqueID] = { pointer = _entry.pointer , data = _entry.data, uniqueID = _entry.uniqueID}
|
||||
end
|
||||
self.stackbypointer = nil
|
||||
self.stackbypointer = pointerstack
|
||||
self.stackbyid = nil
|
||||
self.stackbyid = idstack
|
||||
self.counter = counter
|
||||
self.pointer = counter
|
||||
return self
|
||||
end
|
||||
|
||||
--- FIFO Check Stack is empty
|
||||
-- @param #FIFO self
|
||||
-- @return #boolean empty
|
||||
function FIFO:IsEmpty()
|
||||
self:T(self.lid.."IsEmpty")
|
||||
return self.counter == 0 and true or false
|
||||
end
|
||||
|
||||
--- FIFO Get stack size
|
||||
-- @param #FIFO self
|
||||
-- @return #number size
|
||||
function FIFO:GetSize()
|
||||
self:T(self.lid.."GetSize")
|
||||
return self.counter
|
||||
end
|
||||
|
||||
--- FIFO Get stack size
|
||||
-- @param #FIFO self
|
||||
-- @return #number size
|
||||
function FIFO:Count()
|
||||
self:T(self.lid.."Count")
|
||||
return self.counter
|
||||
end
|
||||
|
||||
--- FIFO Check Stack is NOT empty
|
||||
-- @param #FIFO self
|
||||
-- @return #boolean notempty
|
||||
function FIFO:IsNotEmpty()
|
||||
self:T(self.lid.."IsNotEmpty")
|
||||
return not self:IsEmpty()
|
||||
end
|
||||
|
||||
--- FIFO Get the data stack by pointer
|
||||
-- @param #FIFO self
|
||||
-- @return #table Table of #FIFO.IDEntry entries
|
||||
function FIFO:GetPointerStack()
|
||||
self:T(self.lid.."GetPointerStack")
|
||||
return self.stackbypointer
|
||||
end
|
||||
|
||||
--- FIFO Check if a certain UniqeID exists
|
||||
-- @param #FIFO self
|
||||
-- @return #boolean exists
|
||||
function FIFO:HasUniqueID(UniqueID)
|
||||
self:T(self.lid.."HasUniqueID")
|
||||
return self.stackbyid[UniqueID] and true or false
|
||||
end
|
||||
|
||||
--- FIFO Get the data stack by UniqueID
|
||||
-- @param #FIFO self
|
||||
-- @return #table Table of #FIFO.IDEntry entries
|
||||
function FIFO:GetIDStack()
|
||||
self:T(self.lid.."GetIDStack")
|
||||
return self.stackbyid
|
||||
end
|
||||
|
||||
--- FIFO Get table of UniqueIDs sorted smallest to largest
|
||||
-- @param #FIFO self
|
||||
-- @return #table Table with index [1] to [n] of UniqueID entries
|
||||
function FIFO:GetIDStackSorted()
|
||||
self:T(self.lid.."GetIDStackSorted")
|
||||
|
||||
local stack = self:GetIDStack()
|
||||
local idstack = {}
|
||||
for _id,_entry in pairs(stack) do
|
||||
idstack[#idstack+1] = _id
|
||||
|
||||
self:T({"pre",_id})
|
||||
end
|
||||
|
||||
local function sortID(a, b)
|
||||
return a < b
|
||||
end
|
||||
|
||||
table.sort(idstack)
|
||||
|
||||
return idstack
|
||||
end
|
||||
|
||||
--- FIFO Get table of data entries
|
||||
-- @param #FIFO self
|
||||
-- @return #table Raw table indexed [1] to [n] of object entries - might be empty!
|
||||
function FIFO:GetDataTable()
|
||||
self:T(self.lid.."GetDataTable")
|
||||
local datatable = {}
|
||||
for _,_entry in pairs(self.stackbypointer) do
|
||||
datatable[#datatable+1] = _entry.data
|
||||
end
|
||||
return datatable
|
||||
end
|
||||
|
||||
--- FIFO Get sorted table of data entries by UniqueIDs (must be numerical UniqueIDs only!)
|
||||
-- @param #FIFO self
|
||||
-- @return #table Table indexed [1] to [n] of sorted object entries - might be empty!
|
||||
function FIFO:GetSortedDataTable()
|
||||
self:T(self.lid.."GetSortedDataTable")
|
||||
local datatable = {}
|
||||
local idtablesorted = self:GetIDStackSorted()
|
||||
for _,_entry in pairs(idtablesorted) do
|
||||
datatable[#datatable+1] = self:ReadByID(_entry)
|
||||
end
|
||||
return datatable
|
||||
end
|
||||
|
||||
--- Iterate the FIFO and call an iterator function for the given FIFO data, providing the object for each element of the stack and optional parameters.
|
||||
-- @param #FIFO self
|
||||
-- @param #function IteratorFunction The function that will be called.
|
||||
-- @param #table Arg (Optional) Further Arguments of the IteratorFunction.
|
||||
-- @param #function Function (Optional) A function returning a #boolean true/false. Only if true, the IteratorFunction is called.
|
||||
-- @param #table FunctionArguments (Optional) Function arguments.
|
||||
-- @return #FIFO self
|
||||
function FIFO:ForEach( IteratorFunction, Arg, Function, FunctionArguments )
|
||||
self:T(self.lid.."ForEach")
|
||||
|
||||
local Set = self:GetPointerStack() or {}
|
||||
Arg = Arg or {}
|
||||
|
||||
local function CoRoutine()
|
||||
local Count = 0
|
||||
for ObjectID, ObjectData in pairs( Set ) do
|
||||
local Object = ObjectData.data
|
||||
self:T( {Object} )
|
||||
if Function then
|
||||
if Function( unpack( FunctionArguments or {} ), Object ) == true then
|
||||
IteratorFunction( Object, unpack( Arg ) )
|
||||
end
|
||||
else
|
||||
IteratorFunction( Object, unpack( Arg ) )
|
||||
end
|
||||
Count = Count + 1
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local co = CoRoutine
|
||||
|
||||
local function Schedule()
|
||||
|
||||
local status, res = co()
|
||||
self:T( { status, res } )
|
||||
|
||||
if status == false then
|
||||
error( res )
|
||||
end
|
||||
if res == false then
|
||||
return true -- resume next time the loop
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
Schedule()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- FIFO Print stacks to dcs.log
|
||||
-- @param #FIFO self
|
||||
-- @return #FIFO self
|
||||
function FIFO:Flush()
|
||||
self:T(self.lid.."FiFo Flush")
|
||||
self:I("FIFO Flushing Stack by Pointer")
|
||||
for _id,_data in pairs (self.stackbypointer) do
|
||||
local data = _data -- #FIFO.IDEntry
|
||||
self:I(string.format("Pointer: %s | Entry: Number = %s Data = %s UniqueID = %s",tostring(_id),tostring(data.pointer),tostring(data.data),tostring(data.uniqueID)))
|
||||
end
|
||||
self:I("FIFO Flushing Stack by ID")
|
||||
for _id,_data in pairs (self.stackbyid) do
|
||||
local data = _data -- #FIFO.IDEntry
|
||||
self:I(string.format("ID: %s | Entry: Number = %s Data = %s UniqueID = %s",tostring(_id),tostring(data.pointer),tostring(data.data),tostring(data.uniqueID)))
|
||||
end
|
||||
self:I("Counter = " .. self.counter)
|
||||
self:I("Pointer = ".. self.pointer)
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- End FIFO
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- LIFO
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
do
|
||||
--- **UTILS** - LiFo Stack.
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Build a simple multi-purpose LiFo (Last-In, First-Out) stack for generic data.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **applevangelist**
|
||||
|
||||
--- LIFO class.
|
||||
-- @type LIFO
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field #string version Version of LiFo
|
||||
-- @field #number counter
|
||||
-- @field #number pointer
|
||||
-- @field #table stackbypointer
|
||||
-- @field #table stackbyid
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
---
|
||||
-- @type LIFO.IDEntry
|
||||
-- @field #number pointer
|
||||
-- @field #table data
|
||||
-- @field #table uniqueID
|
||||
|
||||
---
|
||||
-- @field #LIFO
|
||||
LIFO = {
|
||||
ClassName = "LIFO",
|
||||
lid = "",
|
||||
version = "0.0.5",
|
||||
counter = 0,
|
||||
pointer = 0,
|
||||
stackbypointer = {},
|
||||
stackbyid = {}
|
||||
}
|
||||
|
||||
--- Instantiate a new LIFO Stack
|
||||
-- @param #LIFO self
|
||||
-- @return #LIFO self
|
||||
function LIFO:New()
|
||||
-- Inherit everything from BASE class.
|
||||
local self=BASE:Inherit(self, BASE:New())
|
||||
self.pointer = 0
|
||||
self.counter = 0
|
||||
self.uniquecounter = 0
|
||||
self.stackbypointer = {}
|
||||
self.stackbyid = {}
|
||||
-- Set some string id for output to DCS.log file.
|
||||
self.lid=string.format("%s (%s) | ", "LiFo", self.version)
|
||||
self:T(self.lid .."Created.")
|
||||
return self
|
||||
end
|
||||
|
||||
--- Empty LIFO Stack
|
||||
-- @param #LIFO self
|
||||
-- @return #LIFO self
|
||||
function LIFO:Clear()
|
||||
self:T(self.lid.."Clear")
|
||||
self.pointer = 0
|
||||
self.counter = 0
|
||||
self.stackbypointer = nil
|
||||
self.stackbyid = nil
|
||||
self.stackbypointer = {}
|
||||
self.stackbyid = {}
|
||||
self.uniquecounter = 0
|
||||
return self
|
||||
end
|
||||
|
||||
--- LIFO Push Object to Stack
|
||||
-- @param #LIFO self
|
||||
-- @param #table Object
|
||||
-- @param #string UniqueID (optional) - will default to current pointer + 1
|
||||
-- @return #LIFO self
|
||||
function LIFO:Push(Object,UniqueID)
|
||||
self:T(self.lid.."Push")
|
||||
self:T({Object,UniqueID})
|
||||
self.pointer = self.pointer + 1
|
||||
self.counter = self.counter + 1
|
||||
local uniID = UniqueID
|
||||
if not UniqueID then
|
||||
self.uniquecounter = self.uniquecounter + 1
|
||||
uniID = self.uniquecounter
|
||||
end
|
||||
self.stackbyid[uniID] = { pointer = self.pointer, data = Object, uniqueID = uniID }
|
||||
self.stackbypointer[self.pointer] = { pointer = self.pointer, data = Object, uniqueID = uniID }
|
||||
return self
|
||||
end
|
||||
|
||||
--- LIFO Pull Object from Stack
|
||||
-- @param #LIFO self
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function LIFO:Pull()
|
||||
self:T(self.lid.."Pull")
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbypointer[self.pointer].data
|
||||
self.stackbypointer[self.pointer] = nil
|
||||
--local object = self.stackbypointer[1].data
|
||||
--self.stackbypointer[1] = nil
|
||||
self.counter = self.counter - 1
|
||||
self.pointer = self.pointer - 1
|
||||
self:Flatten()
|
||||
return object
|
||||
end
|
||||
|
||||
--- LIFO Pull Object from Stack by Pointer
|
||||
-- @param #LIFO self
|
||||
-- @param #number Pointer
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function LIFO:PullByPointer(Pointer)
|
||||
self:T(self.lid.."PullByPointer " .. tostring(Pointer))
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbypointer[Pointer] -- #FIFO.IDEntry
|
||||
self.stackbypointer[Pointer] = nil
|
||||
if object then self.stackbyid[object.uniqueID] = nil end
|
||||
self.counter = self.counter - 1
|
||||
self:Flatten()
|
||||
if object then
|
||||
return object.data
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
--- LIFO Read, not Pull, Object from Stack by Pointer
|
||||
-- @param #LIFO self
|
||||
-- @param #number Pointer
|
||||
-- @return #table Object or nil if stack is empty or pointer does not exist
|
||||
function LIFO:ReadByPointer(Pointer)
|
||||
self:T(self.lid.."ReadByPointer " .. tostring(Pointer))
|
||||
if self.counter == 0 or not Pointer or not self.stackbypointer[Pointer] then return nil end
|
||||
local object = self.stackbypointer[Pointer] -- #LIFO.IDEntry
|
||||
if object then
|
||||
return object.data
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
--- LIFO Read, not Pull, Object from Stack by UniqueID
|
||||
-- @param #LIFO self
|
||||
-- @param #number UniqueID
|
||||
-- @return #table Object or nil if stack is empty or ID does not exist
|
||||
function LIFO:ReadByID(UniqueID)
|
||||
self:T(self.lid.."ReadByID " .. tostring(UniqueID))
|
||||
if self.counter == 0 or not UniqueID or not self.stackbyid[UniqueID] then return nil end
|
||||
local object = self.stackbyid[UniqueID] -- #LIFO.IDEntry
|
||||
if object then
|
||||
return object.data
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
--- LIFO Pull Object from Stack by UniqueID
|
||||
-- @param #LIFO self
|
||||
-- @param #tableUniqueID
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function LIFO:PullByID(UniqueID)
|
||||
self:T(self.lid.."PullByID " .. tostring(UniqueID))
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbyid[UniqueID] -- #LIFO.IDEntry
|
||||
--self.stackbyid[UniqueID] = nil
|
||||
if object then
|
||||
return self:PullByPointer(object.pointer)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
--- LIFO Housekeeping
|
||||
-- @param #LIFO self
|
||||
-- @return #LIFO self
|
||||
function LIFO:Flatten()
|
||||
self:T(self.lid.."Flatten")
|
||||
-- rebuild stacks
|
||||
local pointerstack = {}
|
||||
local idstack = {}
|
||||
local counter = 0
|
||||
for _ID,_entry in pairs(self.stackbypointer) do
|
||||
counter = counter + 1
|
||||
pointerstack[counter] = { pointer = counter, data = _entry.data, uniqueID = _entry.uniqueID}
|
||||
end
|
||||
for _ID,_entry in pairs(pointerstack) do
|
||||
idstack[_entry.uniqueID] = { pointer = _entry.pointer , data = _entry.data, uniqueID = _entry.uniqueID}
|
||||
end
|
||||
self.stackbypointer = nil
|
||||
self.stackbypointer = pointerstack
|
||||
self.stackbyid = nil
|
||||
self.stackbyid = idstack
|
||||
self.counter = counter
|
||||
self.pointer = counter
|
||||
return self
|
||||
end
|
||||
|
||||
--- LIFO Check Stack is empty
|
||||
-- @param #LIFO self
|
||||
-- @return #boolean empty
|
||||
function LIFO:IsEmpty()
|
||||
self:T(self.lid.."IsEmpty")
|
||||
return self.counter == 0 and true or false
|
||||
end
|
||||
|
||||
--- LIFO Get stack size
|
||||
-- @param #LIFO self
|
||||
-- @return #number size
|
||||
function LIFO:GetSize()
|
||||
self:T(self.lid.."GetSize")
|
||||
return self.counter
|
||||
end
|
||||
|
||||
--- LIFO Get stack size
|
||||
-- @param #LIFO self
|
||||
-- @return #number size
|
||||
function LIFO:Count()
|
||||
self:T(self.lid.."Count")
|
||||
return self.counter
|
||||
end
|
||||
|
||||
--- LIFO Check Stack is NOT empty
|
||||
-- @param #LIFO self
|
||||
-- @return #boolean notempty
|
||||
function LIFO:IsNotEmpty()
|
||||
self:T(self.lid.."IsNotEmpty")
|
||||
return not self:IsEmpty()
|
||||
end
|
||||
|
||||
--- LIFO Get the data stack by pointer
|
||||
-- @param #LIFO self
|
||||
-- @return #table Table of #LIFO.IDEntry entries
|
||||
function LIFO:GetPointerStack()
|
||||
self:T(self.lid.."GetPointerStack")
|
||||
return self.stackbypointer
|
||||
end
|
||||
|
||||
--- LIFO Get the data stack by UniqueID
|
||||
-- @param #LIFO self
|
||||
-- @return #table Table of #LIFO.IDEntry entries
|
||||
function LIFO:GetIDStack()
|
||||
self:T(self.lid.."GetIDStack")
|
||||
return self.stackbyid
|
||||
end
|
||||
|
||||
--- LIFO Get table of UniqueIDs sorted smallest to largest
|
||||
-- @param #LIFO self
|
||||
-- @return #table Table of #LIFO.IDEntry entries
|
||||
function LIFO:GetIDStackSorted()
|
||||
self:T(self.lid.."GetIDStackSorted")
|
||||
|
||||
local stack = self:GetIDStack()
|
||||
local idstack = {}
|
||||
for _id,_entry in pairs(stack) do
|
||||
idstack[#idstack+1] = _id
|
||||
|
||||
self:T({"pre",_id})
|
||||
end
|
||||
|
||||
local function sortID(a, b)
|
||||
return a < b
|
||||
end
|
||||
|
||||
table.sort(idstack)
|
||||
|
||||
return idstack
|
||||
end
|
||||
|
||||
--- LIFO Check if a certain UniqeID exists
|
||||
-- @param #LIFO self
|
||||
-- @return #boolean exists
|
||||
function LIFO:HasUniqueID(UniqueID)
|
||||
self:T(self.lid.."HasUniqueID")
|
||||
return self.stackbyid[UniqueID] and true or false
|
||||
end
|
||||
|
||||
--- LIFO Print stacks to dcs.log
|
||||
-- @param #LIFO self
|
||||
-- @return #LIFO self
|
||||
function LIFO:Flush()
|
||||
self:T(self.lid.."FiFo Flush")
|
||||
self:I("LIFO Flushing Stack by Pointer")
|
||||
for _id,_data in pairs (self.stackbypointer) do
|
||||
local data = _data -- #LIFO.IDEntry
|
||||
self:I(string.format("Pointer: %s | Entry: Number = %s Data = %s UniqueID = %s",tostring(_id),tostring(data.pointer),tostring(data.data),tostring(data.uniqueID)))
|
||||
end
|
||||
self:I("LIFO Flushing Stack by ID")
|
||||
for _id,_data in pairs (self.stackbyid) do
|
||||
local data = _data -- #LIFO.IDEntry
|
||||
self:I(string.format("ID: %s | Entry: Number = %s Data = %s UniqueID = %s",tostring(_id),tostring(data.pointer),tostring(data.data),tostring(data.uniqueID)))
|
||||
end
|
||||
self:I("Counter = " .. self.counter)
|
||||
self:I("Pointer = ".. self.pointer)
|
||||
return self
|
||||
end
|
||||
|
||||
--- LIFO Get table of data entries
|
||||
-- @param #LIFO self
|
||||
-- @return #table Raw table indexed [1] to [n] of object entries - might be empty!
|
||||
function LIFO:GetDataTable()
|
||||
self:T(self.lid.."GetDataTable")
|
||||
local datatable = {}
|
||||
for _,_entry in pairs(self.stackbypointer) do
|
||||
datatable[#datatable+1] = _entry.data
|
||||
end
|
||||
return datatable
|
||||
end
|
||||
|
||||
--- LIFO Get sorted table of data entries by UniqueIDs (must be numerical UniqueIDs only!)
|
||||
-- @param #LIFO self
|
||||
-- @return #table Table indexed [1] to [n] of sorted object entries - might be empty!
|
||||
function LIFO:GetSortedDataTable()
|
||||
self:T(self.lid.."GetSortedDataTable")
|
||||
local datatable = {}
|
||||
local idtablesorted = self:GetIDStackSorted()
|
||||
for _,_entry in pairs(idtablesorted) do
|
||||
datatable[#datatable+1] = self:ReadByID(_entry)
|
||||
end
|
||||
return datatable
|
||||
end
|
||||
|
||||
--- Iterate the LIFO and call an iterator function for the given LIFO data, providing the object for each element of the stack and optional parameters.
|
||||
-- @param #LIFO self
|
||||
-- @param #function IteratorFunction The function that will be called.
|
||||
-- @param #table Arg (Optional) Further Arguments of the IteratorFunction.
|
||||
-- @param #function Function (Optional) A function returning a #boolean true/false. Only if true, the IteratorFunction is called.
|
||||
-- @param #table FunctionArguments (Optional) Function arguments.
|
||||
-- @return #LIFO self
|
||||
function LIFO:ForEach( IteratorFunction, Arg, Function, FunctionArguments )
|
||||
self:T(self.lid.."ForEach")
|
||||
|
||||
local Set = self:GetPointerStack() or {}
|
||||
Arg = Arg or {}
|
||||
|
||||
local function CoRoutine()
|
||||
local Count = 0
|
||||
for ObjectID, ObjectData in pairs( Set ) do
|
||||
local Object = ObjectData.data
|
||||
self:T( {Object} )
|
||||
if Function then
|
||||
if Function( unpack( FunctionArguments or {} ), Object ) == true then
|
||||
IteratorFunction( Object, unpack( Arg ) )
|
||||
end
|
||||
else
|
||||
IteratorFunction( Object, unpack( Arg ) )
|
||||
end
|
||||
Count = Count + 1
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local co = CoRoutine
|
||||
|
||||
local function Schedule()
|
||||
|
||||
local status, res = co()
|
||||
self:T( { status, res } )
|
||||
|
||||
if status == false then
|
||||
error( res )
|
||||
end
|
||||
if res == false then
|
||||
return true -- resume next time the loop
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
Schedule()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- End LIFO
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
end
|
||||
@@ -809,7 +809,7 @@ function UTILS.BeaufortScale(speed)
|
||||
return bn,bd
|
||||
end
|
||||
|
||||
--- Split string at seperators. C.f. http://stackoverflow.com/questions/1426954/split-string-in-lua
|
||||
--- Split string at seperators. C.f. [split-string-in-lua](http://stackoverflow.com/questions/1426954/split-string-in-lua).
|
||||
-- @param #string str Sting to split.
|
||||
-- @param #string sep Speparator for split.
|
||||
-- @return #table Split text.
|
||||
@@ -1447,6 +1447,23 @@ function UTILS.GetModulationName(Modulation)
|
||||
|
||||
end
|
||||
|
||||
--- Get the NATO reporting name of a unit type name
|
||||
-- @param #number Typename The type name.
|
||||
-- @return #string The Reporting name or "Bogey".
|
||||
function UTILS.GetReportingName(Typename)
|
||||
|
||||
local typename = string.lower(Typename)
|
||||
|
||||
for name, value in pairs(ENUMS.ReportingName.NATO) do
|
||||
local svalue = string.lower(value)
|
||||
if string.find(typename,svalue,1,true) then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
return "Bogey"
|
||||
end
|
||||
|
||||
--- Get the callsign name from its enumerator value
|
||||
-- @param #number Callsign The enumerator callsign.
|
||||
-- @return #string The callsign name or "Ghostrider".
|
||||
@@ -1475,7 +1492,49 @@ function UTILS.GetCallsignName(Callsign)
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for name, value in pairs(CALLSIGN.B1B) do
|
||||
if value==Callsign then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
for name, value in pairs(CALLSIGN.B52) do
|
||||
if value==Callsign then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
for name, value in pairs(CALLSIGN.F15E) do
|
||||
if value==Callsign then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
for name, value in pairs(CALLSIGN.F16) do
|
||||
if value==Callsign then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
for name, value in pairs(CALLSIGN.F18) do
|
||||
if value==Callsign then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
for name, value in pairs(CALLSIGN.FARP) do
|
||||
if value==Callsign then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
for name, value in pairs(CALLSIGN.TransportAircraft) do
|
||||
if value==Callsign then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
return "Ghostrider"
|
||||
end
|
||||
|
||||
@@ -2402,493 +2461,3 @@ function UTILS.ToStringBRAANATO(FromGrp,ToGrp)
|
||||
end
|
||||
return BRAANATO
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- FIFO
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
do
|
||||
--- **UTILS** - FiFo Stack.
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Build a simple multi-purpose FiFo (First-In, First-Out) stack for generic data.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **applevangelist**
|
||||
|
||||
--- FIFO class.
|
||||
-- @type FIFO
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field #string version Version of FiFo
|
||||
-- @field #number counter
|
||||
-- @field #number pointer
|
||||
-- @field #table stackbypointer
|
||||
-- @field #table stackbyid
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
---
|
||||
-- @type FIFO.IDEntry
|
||||
-- @field #number pointer
|
||||
-- @field #table data
|
||||
-- @field #table uniqueID
|
||||
|
||||
---
|
||||
-- @field #FIFO
|
||||
FIFO = {
|
||||
ClassName = "FIFO",
|
||||
lid = "",
|
||||
version = "0.0.1",
|
||||
counter = 0,
|
||||
pointer = 0,
|
||||
stackbypointer = {},
|
||||
stackbyid = {}
|
||||
}
|
||||
|
||||
--- Instantiate a new FIFO Stack
|
||||
-- @param #FIFO self
|
||||
-- @return #FIFO self
|
||||
function FIFO:New()
|
||||
-- Inherit everything from BASE class.
|
||||
local self=BASE:Inherit(self, BASE:New())
|
||||
self.pointer = 0
|
||||
self.counter = 0
|
||||
self.stackbypointer = {}
|
||||
self.stackbyid = {}
|
||||
self.uniquecounter = 0
|
||||
-- Set some string id for output to DCS.log file.
|
||||
self.lid=string.format("%s (%s) | ", "FiFo", self.version)
|
||||
self:I(self.lid .."Created.")
|
||||
return self
|
||||
end
|
||||
|
||||
--- FIFO Push Object to Stack
|
||||
-- @param #FIFO self
|
||||
-- @param #table Object
|
||||
-- @param #string UniqueID (optional) - will default to current pointer + 1
|
||||
-- @return #FIFO self
|
||||
function FIFO:Push(Object,UniqueID)
|
||||
self:T(self.lid.."Push")
|
||||
self:T({Object,UniqueID})
|
||||
self.pointer = self.pointer + 1
|
||||
self.counter = self.counter + 1
|
||||
local uniID = UniqueID
|
||||
if not UniqueID then
|
||||
self.uniquecounter = self.uniquecounter + 1
|
||||
uniID = self.uniquecounter
|
||||
end
|
||||
self.stackbyid[uniID] = { pointer = self.pointer, data = Object, uniqueID = uniID }
|
||||
self.stackbypointer[self.pointer] = { pointer = self.pointer, data = Object, uniqueID = uniID }
|
||||
return self
|
||||
end
|
||||
|
||||
--- FIFO Pull Object from Stack
|
||||
-- @param #FIFO self
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function FIFO:Pull()
|
||||
self:T(self.lid.."Pull")
|
||||
if self.counter == 0 then return nil end
|
||||
--local object = self.stackbypointer[self.pointer].data
|
||||
--self.stackbypointer[self.pointer] = nil
|
||||
local object = self.stackbypointer[1].data
|
||||
self.stackbypointer[1] = nil
|
||||
self.counter = self.counter - 1
|
||||
--self.pointer = self.pointer - 1
|
||||
self:Flatten()
|
||||
return object
|
||||
end
|
||||
|
||||
--- FIFO Pull Object from Stack by Pointer
|
||||
-- @param #FIFO self
|
||||
-- @param #number Pointer
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function FIFO:PullByPointer(Pointer)
|
||||
self:T(self.lid.."PullByPointer " .. tostring(Pointer))
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbypointer[Pointer] -- #FIFO.IDEntry
|
||||
self.stackbypointer[Pointer] = nil
|
||||
self.stackbyid[object.uniqueID] = nil
|
||||
self.counter = self.counter - 1
|
||||
self:Flatten()
|
||||
return object.data
|
||||
end
|
||||
|
||||
--- FIFO Pull Object from Stack by UniqueID
|
||||
-- @param #FIFO self
|
||||
-- @param #tableUniqueID
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function FIFO:PullByID(UniqueID)
|
||||
self:T(self.lid.."PullByID " .. tostring(UniqueID))
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbyid[UniqueID] -- #FIFO.IDEntry
|
||||
--self.stackbyid[UniqueID] = nil
|
||||
return self:PullByPointer(object.pointer)
|
||||
end
|
||||
|
||||
--- FIFO Housekeeping
|
||||
-- @param #FIFO self
|
||||
-- @return #FIFO self
|
||||
function FIFO:Flatten()
|
||||
self:T(self.lid.."Flatten")
|
||||
-- rebuild stacks
|
||||
local pointerstack = {}
|
||||
local idstack = {}
|
||||
local counter = 0
|
||||
for _ID,_entry in pairs(self.stackbypointer) do
|
||||
counter = counter + 1
|
||||
pointerstack[counter] = { pointer = counter, data = _entry.data, uniqueID = _entry.uniqueID}
|
||||
end
|
||||
for _ID,_entry in pairs(pointerstack) do
|
||||
idstack[_entry.uniqueID] = { pointer = _entry.pointer , data = _entry.data, uniqueID = _entry.uniqueID}
|
||||
end
|
||||
self.stackbypointer = nil
|
||||
self.stackbypointer = pointerstack
|
||||
self.stackbyid = nil
|
||||
self.stackbyid = idstack
|
||||
self.counter = counter
|
||||
self.pointer = counter
|
||||
return self
|
||||
end
|
||||
|
||||
--- FIFO Check Stack is empty
|
||||
-- @param #FIFO self
|
||||
-- @return #boolean empty
|
||||
function FIFO:IsEmpty()
|
||||
self:T(self.lid.."IsEmpty")
|
||||
return self.counter == 0 and true or false
|
||||
end
|
||||
|
||||
--- FIFO Get stack size
|
||||
-- @param #FIFO self
|
||||
-- @return #number size
|
||||
function FIFO:GetSize()
|
||||
self:T(self.lid.."GetSize")
|
||||
return self.counter
|
||||
end
|
||||
|
||||
--- FIFO Check Stack is NOT empty
|
||||
-- @param #FIFO self
|
||||
-- @return #boolean notempty
|
||||
function FIFO:IsNotEmpty()
|
||||
self:T(self.lid.."IsNotEmpty")
|
||||
return not self:IsEmpty()
|
||||
end
|
||||
|
||||
--- FIFO Get the data stack by pointer
|
||||
-- @param #FIFO self
|
||||
-- @return #table Table of #FIFO.IDEntry entries
|
||||
function FIFO:GetPointerStack()
|
||||
self:T(self.lid.."GetPointerStack")
|
||||
return self.stackbypointer
|
||||
end
|
||||
|
||||
--- FIFO Check if a certain UniqeID exists
|
||||
-- @param #FIFO self
|
||||
-- @return #boolean exists
|
||||
function FIFO:HasUniqueID(UniqueID)
|
||||
self:T(self.lid.."HasUniqueID")
|
||||
return self.stackbyid[UniqueID] and true or false
|
||||
end
|
||||
|
||||
--- FIFO Get the data stack by UniqueID
|
||||
-- @param #FIFO self
|
||||
-- @return #table Table of #FIFO.IDEntry entries
|
||||
function FIFO:GetIDStack()
|
||||
self:T(self.lid.."GetIDStack")
|
||||
return self.stackbyid
|
||||
end
|
||||
|
||||
--- FIFO Get table of UniqueIDs sorthed smallest to largest
|
||||
-- @param #FIFO self
|
||||
-- @return #table Table of #FIFO.IDEntry entries
|
||||
function FIFO:GetIDStackSorted()
|
||||
self:T(self.lid.."GetIDStackSorted")
|
||||
|
||||
local stack = self:GetIDStack()
|
||||
local idstack = {}
|
||||
for _id,_entry in pairs(stack) do
|
||||
idstack[#idstack+1] = _id
|
||||
|
||||
self:T({"pre",_id})
|
||||
end
|
||||
|
||||
local function sortID(a, b)
|
||||
return a < b
|
||||
end
|
||||
|
||||
table.sort(idstack)
|
||||
|
||||
return idstack
|
||||
end
|
||||
|
||||
--- FIFO Print stacks to dcs.log
|
||||
-- @param #FIFO self
|
||||
-- @return #FIFO self
|
||||
function FIFO:Flush()
|
||||
self:T(self.lid.."FiFo Flush")
|
||||
self:I("FIFO Flushing Stack by Pointer")
|
||||
for _id,_data in pairs (self.stackbypointer) do
|
||||
local data = _data -- #FIFO.IDEntry
|
||||
self:I(string.format("Pointer: %s | Entry: Number = %s Data = %s UniqueID = %s",tostring(_id),tostring(data.pointer),tostring(data.data),tostring(data.uniqueID)))
|
||||
end
|
||||
self:I("FIFO Flushing Stack by ID")
|
||||
for _id,_data in pairs (self.stackbyid) do
|
||||
local data = _data -- #FIFO.IDEntry
|
||||
self:I(string.format("ID: %s | Entry: Number = %s Data = %s UniqueID = %s",tostring(_id),tostring(data.pointer),tostring(data.data),tostring(data.uniqueID)))
|
||||
end
|
||||
self:I("Counter = " .. self.counter)
|
||||
self:I("Pointer = ".. self.pointer)
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- End FIFO
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- LIFO
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
do
|
||||
--- **UTILS** - LiFo Stack.
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Build a simple multi-purpose LiFo (Last-In, First-Out) stack for generic data.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **applevangelist**
|
||||
|
||||
--- LIFO class.
|
||||
-- @type LIFO
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field #string version Version of LiFo
|
||||
-- @field #number counter
|
||||
-- @field #number pointer
|
||||
-- @field #table stackbypointer
|
||||
-- @field #table stackbyid
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
---
|
||||
-- @type LIFO.IDEntry
|
||||
-- @field #number pointer
|
||||
-- @field #table data
|
||||
-- @field #table uniqueID
|
||||
|
||||
---
|
||||
-- @field #LIFO
|
||||
LIFO = {
|
||||
ClassName = "LIFO",
|
||||
lid = "",
|
||||
version = "0.0.1",
|
||||
counter = 0,
|
||||
pointer = 0,
|
||||
stackbypointer = {},
|
||||
stackbyid = {}
|
||||
}
|
||||
|
||||
--- Instantiate a new LIFO Stack
|
||||
-- @param #LIFO self
|
||||
-- @return #LIFO self
|
||||
function LIFO:New()
|
||||
-- Inherit everything from BASE class.
|
||||
local self=BASE:Inherit(self, BASE:New())
|
||||
self.pointer = 0
|
||||
self.counter = 0
|
||||
self.uniquecounter = 0
|
||||
self.stackbypointer = {}
|
||||
self.stackbyid = {}
|
||||
-- Set some string id for output to DCS.log file.
|
||||
self.lid=string.format("%s (%s) | ", "LiFo", self.version)
|
||||
self:I(self.lid .."Created.")
|
||||
return self
|
||||
end
|
||||
|
||||
--- LIFO Push Object to Stack
|
||||
-- @param #LIFO self
|
||||
-- @param #table Object
|
||||
-- @param #string UniqueID (optional) - will default to current pointer + 1
|
||||
-- @return #LIFO self
|
||||
function LIFO:Push(Object,UniqueID)
|
||||
self:T(self.lid.."Push")
|
||||
self:T({Object,UniqueID})
|
||||
self.pointer = self.pointer + 1
|
||||
self.counter = self.counter + 1
|
||||
local uniID = UniqueID
|
||||
if not UniqueID then
|
||||
self.uniquecounter = self.uniquecounter + 1
|
||||
uniID = self.uniquecounter
|
||||
end
|
||||
self.stackbyid[uniID] = { pointer = self.pointer, data = Object, uniqueID = uniID }
|
||||
self.stackbypointer[self.pointer] = { pointer = self.pointer, data = Object, uniqueID = uniID }
|
||||
return self
|
||||
end
|
||||
|
||||
--- LIFO Pull Object from Stack
|
||||
-- @param #LIFO self
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function LIFO:Pull()
|
||||
self:T(self.lid.."Pull")
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbypointer[self.pointer].data
|
||||
self.stackbypointer[self.pointer] = nil
|
||||
--local object = self.stackbypointer[1].data
|
||||
--self.stackbypointer[1] = nil
|
||||
self.counter = self.counter - 1
|
||||
self.pointer = self.pointer - 1
|
||||
self:Flatten()
|
||||
return object
|
||||
end
|
||||
|
||||
--- LIFO Pull Object from Stack by Pointer
|
||||
-- @param #LIFO self
|
||||
-- @param #number Pointer
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function LIFO:PullByPointer(Pointer)
|
||||
self:T(self.lid.."PullByPointer " .. tostring(Pointer))
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbypointer[Pointer] -- #LIFO.IDEntry
|
||||
self.stackbypointer[Pointer] = nil
|
||||
self.stackbyid[object.uniqueID] = nil
|
||||
self.counter = self.counter - 1
|
||||
self:Flatten()
|
||||
return object.data
|
||||
end
|
||||
|
||||
--- LIFO Pull Object from Stack by UniqueID
|
||||
-- @param #LIFO self
|
||||
-- @param #tableUniqueID
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function LIFO:PullByID(UniqueID)
|
||||
self:T(self.lid.."PullByID " .. tostring(UniqueID))
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbyid[UniqueID] -- #LIFO.IDEntry
|
||||
--self.stackbyid[UniqueID] = nil
|
||||
return self:PullByPointer(object.pointer)
|
||||
end
|
||||
|
||||
--- LIFO Housekeeping
|
||||
-- @param #LIFO self
|
||||
-- @return #LIFO self
|
||||
function LIFO:Flatten()
|
||||
self:T(self.lid.."Flatten")
|
||||
-- rebuild stacks
|
||||
local pointerstack = {}
|
||||
local idstack = {}
|
||||
local counter = 0
|
||||
for _ID,_entry in pairs(self.stackbypointer) do
|
||||
counter = counter + 1
|
||||
pointerstack[counter] = { pointer = counter, data = _entry.data, uniqueID = _entry.uniqueID}
|
||||
end
|
||||
for _ID,_entry in pairs(pointerstack) do
|
||||
idstack[_entry.uniqueID] = { pointer = _entry.pointer , data = _entry.data, uniqueID = _entry.uniqueID}
|
||||
end
|
||||
self.stackbypointer = nil
|
||||
self.stackbypointer = pointerstack
|
||||
self.stackbyid = nil
|
||||
self.stackbyid = idstack
|
||||
self.counter = counter
|
||||
self.pointer = counter
|
||||
return self
|
||||
end
|
||||
|
||||
--- LIFO Check Stack is empty
|
||||
-- @param #LIFO self
|
||||
-- @return #boolean empty
|
||||
function LIFO:IsEmpty()
|
||||
self:T(self.lid.."IsEmpty")
|
||||
return self.counter == 0 and true or false
|
||||
end
|
||||
|
||||
--- LIFO Get stack size
|
||||
-- @param #LIFO self
|
||||
-- @return #number size
|
||||
function LIFO:GetSize()
|
||||
self:T(self.lid.."GetSize")
|
||||
return self.counter
|
||||
end
|
||||
|
||||
--- LIFO Check Stack is NOT empty
|
||||
-- @param #LIFO self
|
||||
-- @return #boolean notempty
|
||||
function LIFO:IsNotEmpty()
|
||||
self:T(self.lid.."IsNotEmpty")
|
||||
return not self:IsEmpty()
|
||||
end
|
||||
|
||||
--- LIFO Get the data stack by pointer
|
||||
-- @param #LIFO self
|
||||
-- @return #table Table of #LIFO.IDEntry entries
|
||||
function LIFO:GetPointerStack()
|
||||
self:T(self.lid.."GetPointerStack")
|
||||
return self.stackbypointer
|
||||
end
|
||||
|
||||
--- LIFO Get the data stack by UniqueID
|
||||
-- @param #LIFO self
|
||||
-- @return #table Table of #LIFO.IDEntry entries
|
||||
function LIFO:GetIDStack()
|
||||
self:T(self.lid.."GetIDStack")
|
||||
return self.stackbyid
|
||||
end
|
||||
|
||||
--- LIFO Get table of UniqueIDs sorthed smallest to largest
|
||||
-- @param #LIFO self
|
||||
-- @return #table Table of #LIFO.IDEntry entries
|
||||
function LIFO:GetIDStackSorted()
|
||||
self:T(self.lid.."GetIDStackSorted")
|
||||
|
||||
local stack = self:GetIDStack()
|
||||
local idstack = {}
|
||||
for _id,_entry in pairs(stack) do
|
||||
idstack[#idstack+1] = _id
|
||||
|
||||
self:T({"pre",_id})
|
||||
end
|
||||
|
||||
local function sortID(a, b)
|
||||
return a < b
|
||||
end
|
||||
|
||||
table.sort(idstack)
|
||||
|
||||
return idstack
|
||||
end
|
||||
|
||||
--- LIFO Check if a certain UniqeID exists
|
||||
-- @param #LIFO self
|
||||
-- @return #boolean exists
|
||||
function LIFO:HasUniqueID(UniqueID)
|
||||
self:T(self.lid.."HasUniqueID")
|
||||
return self.stackbyid[UniqueID] and true or false
|
||||
end
|
||||
|
||||
--- LIFO Print stacks to dcs.log
|
||||
-- @param #LIFO self
|
||||
-- @return #LIFO self
|
||||
function LIFO:Flush()
|
||||
self:T(self.lid.."FiFo Flush")
|
||||
self:I("LIFO Flushing Stack by Pointer")
|
||||
for _id,_data in pairs (self.stackbypointer) do
|
||||
local data = _data -- #LIFO.IDEntry
|
||||
self:I(string.format("Pointer: %s | Entry: Number = %s Data = %s UniqueID = %s",tostring(_id),tostring(data.pointer),tostring(data.data),tostring(data.uniqueID)))
|
||||
end
|
||||
self:I("LIFO Flushing Stack by ID")
|
||||
for _id,_data in pairs (self.stackbyid) do
|
||||
local data = _data -- #LIFO.IDEntry
|
||||
self:I(string.format("ID: %s | Entry: Number = %s Data = %s UniqueID = %s",tostring(_id),tostring(data.pointer),tostring(data.data),tostring(data.uniqueID)))
|
||||
end
|
||||
self:I("Counter = " .. self.counter)
|
||||
self:I("Pointer = ".. self.pointer)
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- End LIFO
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
end
|
||||
Reference in New Issue
Block a user