-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added 4 New Array Functions #131
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3adfb0e
Add 3 New Array Functions to Find First Entry of TypeOf, Null or Nil …
jokoho48 058409d
rename Files and Fix Documentation
jokoho48 e1f58c3
fix missing Renames
jokoho48 1a9ae13
Add TypeName
jokoho48 232a7e6
Fix Spelling Issues
jokoho48 52d47a0
Improved code stability and improved tests along with a bunch of bug …
MikeMatrix 9129ce8
Better alternative to counting empty arrays
MikeMatrix 0dfc4a2
Merge pull request #2 from MikeMatrix/NewArrayFunctions
jokoho48 50c75f6
Some more Improvements
jokoho48 43e8ec4
Typo fixes
MikeMatrix f4d2a80
Merge pull request #3 from MikeMatrix/NewArrayFunctions
jokoho48 6816ee4
More typo fixes
MikeMatrix aa136b5
Merge pull request #4 from MikeMatrix/NewArrayFunctions
jokoho48 1f22847
fix Spelling
jokoho48 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_findNil | ||
|
||
Description: | ||
A function that returns the index of the first empty (nil) entry in an array. | ||
|
||
Parameters: | ||
The array to search in. | ||
|
||
Example: | ||
(begin example) | ||
_index = ["", Player, "test", nil, VARIABLE, nil] call CBA_fnc_findNil | ||
(end) | ||
|
||
Returns: | ||
Index of the first nil entry in the array. If there is no nil entry, the function returns -1 | ||
|
||
Author: | ||
joko // Jonas | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
if !(IS_ARRAY(_this)) exitWith {-1}; | ||
|
||
scopeName "main"; | ||
|
||
{ | ||
if (isNil "_x") then { | ||
_forEachIndex breakOut "main"; | ||
}; | ||
} forEach _this; | ||
|
||
-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_findNull | ||
|
||
Description: | ||
A function that returns the index of the first null entry in an array. | ||
|
||
Parameters: | ||
The array to search in. | ||
|
||
Example: | ||
(begin example) | ||
_index = ["", Player, "test", objNull, VARIABLE] call CBA_fnc_findNull | ||
(end) | ||
|
||
Returns: | ||
Index of the first null entry in the array. If there is no null entry, the function returns -1 | ||
|
||
Author: | ||
joko // Jonas | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
if !(IS_ARRAY(_this)) exitWith {-1}; | ||
|
||
scopeName "main"; | ||
|
||
private "_checkableTypes"; | ||
|
||
_checkableTypes = ["OBJECT", "CONTROL", "DISPLAY", "GROUP", "LOCATION", "TASK", "SCRIPT"]; | ||
|
||
{ | ||
if (typeName _x in _checkableTypes && {isNull _x}) then { | ||
_forEachIndex breakOut "main"; | ||
}; | ||
} forEach _this; | ||
|
||
-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_findTypeName | ||
|
||
Description: | ||
A function that returns the index of the first entry of the given type in an array. | ||
|
||
Parameters: | ||
0: Array | ||
1: TypeName, if parameter is a string, that contains a case insensitive typename, it will be used. Otherwise typename of the variable will be used. | ||
|
||
Example: | ||
(begin example) | ||
_index = ["OBJECT",["", Player, "test", nil, VARIABLE, nil]] call CBA_fnc_findTypeName | ||
(end) | ||
|
||
Returns: | ||
Index of the first entry of the indicated type in the array or -1 if no entry of the type could be found. | ||
|
||
Author: | ||
joko // Jonas | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
#define TYPENAMES ["ARRAY", "BOOL", "CODE", "CONFIG", "CONTROL", "DISPLAY", "GROUP", "LOCATION", "OBJECT", "SCALAR", "SCRIPT", "SIDE", "STRING", "TASK", "TEXT", "TEAM_MEMBER", "NAMESPACE"] | ||
|
||
scopeName "main"; | ||
|
||
params [["_array", [], [[]]], "_typeName"]; | ||
|
||
if (isNil "_typeName" || {_array isEqualTo []}) exitWith {-1}; | ||
|
||
// If a string is given, tansform to uppercase for type matching | ||
if (IS_STRING(_typeName)) then { | ||
_typeName = toUpper _typeName; | ||
}; | ||
|
||
// If _typeName is not a typename description, use the type of that value | ||
if !(_typeName in TYPENAMES) then { | ||
_typeName = typeName _typeName; | ||
}; | ||
|
||
{ | ||
if (typeName _x == _typeName) then { | ||
_forEachIndex breakOut "main"; | ||
}; | ||
} forEach _array; | ||
|
||
-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_findTypeOf | ||
|
||
Description: | ||
A function that returns the index of the first entry (either object or class name string) of the given type in an array. | ||
|
||
Parameters: | ||
0: Array | ||
1: Entry type, can be either Object or class name string (as returned by typeOf) | ||
|
||
Example: | ||
(begin example) | ||
_index = [["", Player, "test", nil, VARIABLE, nil], player] call CBA_fnc_findTypeOf | ||
(end) | ||
|
||
Returns: | ||
Index of the first entry of the indicated type in the array or -1 if no entry of the type could be found. | ||
|
||
Author: | ||
joko // Jonas | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
scopeName "main"; | ||
|
||
params [["_array", [], [[]]], ["_typeOf", nil, [objNull, ""]]]; | ||
|
||
if (isNil "_typeOf" || {_array isEqualTo []}) exitWith {-1}; | ||
|
||
if (IS_OBJECT(_typeOf)) then { | ||
_typeOf = typeOf _typeOf; | ||
}; | ||
|
||
{ | ||
if (IS_OBJECT(_x) && {typeOf _x == _typeOf}) then { | ||
_forEachIndex breakOut "main"; | ||
}; | ||
if (IS_STRING(_x) && {_x == _typeOf}) then { | ||
_forEachIndex breakOut "main"; | ||
}; | ||
} forEach _array; | ||
|
||
-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// ---------------------------------------------------------------------------- | ||
#define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
|
||
SCRIPT(test_findNil); | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
private ["_expected", "_result", "_fn"]; | ||
|
||
_fn = "CBA_fnc_findNil"; | ||
LOG("Testing " + _fn); | ||
|
||
TEST_DEFINED("CBA_fnc_findNil",""); | ||
|
||
// Use of embedded nil | ||
_result = ["", 5, objNull, nil, player] call CBA_fnc_findNil; | ||
_expected = 3; | ||
TEST_OP(_result,==,_expected,_fn); | ||
|
||
// Only find the first nil | ||
_result = ["", 5, objNull, player, nil, nil] call CBA_fnc_findNil; | ||
_expected = 4; | ||
TEST_OP(_result,==,_expected,_fn); | ||
|
||
// Return a not found when there is no nil | ||
_result = ["", 5, objNull, displayNull, player] call CBA_fnc_findNil; | ||
_expected = -1; | ||
TEST_OP(_result,==,_expected,_fn); | ||
|
||
// Return a not found when empty array is given | ||
_result = [] call CBA_fnc_findNil; | ||
_expected = -1; | ||
TEST_OP(_result,==,_expected,_fn); | ||
|
||
// Return a not found when a non array is given | ||
_result = "not an array" call CBA_fnc_findNil; | ||
_expected = -1; | ||
TEST_OP(_result,==,_expected,_fn); | ||
|
||
nil; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// ---------------------------------------------------------------------------- | ||
#define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
|
||
SCRIPT(test_findNull); | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
private ["_original", "_expected", "_result", "_fn"]; | ||
|
||
_fn = "CBA_fnc_findNull"; | ||
LOG("Testing " + _fn); | ||
|
||
TEST_DEFINED("CBA_fnc_findNull",""); | ||
|
||
// Use of embedded null | ||
_result = ["", objNull, player, 3] call CBA_fnc_findNull; | ||
_expected = 1; | ||
TEST_OP(_result,==,_expected,_fn); | ||
|
||
// Only find first null | ||
_result = ["", player, objNull, displayNull, 4] call CBA_fnc_findNull; | ||
_expected = 2; | ||
TEST_OP(_result,==,_expected,_fn); | ||
|
||
// Return not found if there is no null | ||
_result = ["", player, 5] call CBA_fnc_findNull; | ||
_expected = -1; | ||
TEST_OP(_result,==,_expected,_fn); | ||
|
||
// Return a not found if empty array is given | ||
_result = [] call CBA_fnc_findNull; | ||
_expected = -1; | ||
TEST_OP(_result,==,_expected,_fn); | ||
|
||
// Return a not found when a non array is given | ||
_result = "not an array" call CBA_fnc_findNull; | ||
_expected = -1; | ||
TEST_OP(_result,==,_expected,_fn); | ||
|
||
nil; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"transform"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better word for "transform" in this context is to use "convert"