summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/include/GlobalAPI/iterable.inc
blob: 585873b308f0390162d6ebb6172fbc63722fb2c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ================== DOUBLE INCLUDE ========================= //

#if defined _GlobalAPI_Iterable_included_
#endinput
#endif
#define _GlobalAPI_Iterable_included_

// =========================================================== //

#include <json>

// =========================================================== //

/*
	Helper methodmap for JSON_Object arrays
*/
methodmap APIIterable < JSON_Object
{
   /**
 	* Creates a new APIIterable
 	*
 	* @param hItems				JSON_Object array handle
 	* @return					A new APIIterable handle
 	*/
	public APIIterable(JSON_Object hItems)
	{
		if (hItems.HasKey("result"))
		{
			return view_as<APIIterable>(hItems.GetObject("result"));
		}
		return view_as<APIIterable>(hItems);
	}
	
	/*
		Gets count of the items in the array
	*/
	property int Count
	{
		public get() { return this.Length; }
	}
	
   /**
 	* Gets an object from the array by index
 	*
 	* @note						This is an alias to GetObjectIndexed
 	* @param index				Index of the object we want to retrieve
 	* @return					JSON_Object handle to the object retrieved
 	*/
	public JSON_Object GetById(int index)
	{
		return this.GetObjectIndexed(index);
	}
}

// =========================================================== //