TableField

Scripts

14 years
edited 8 years
Code (jass) Select
1
library TableField /* v1.0.0.1
2
************************************************************************************
3
*
4
*	*/ uses /*
5
*
6
*		*/ Table	/*
7
*		*/ Init		/*
8
*
9
************************************************************************************
10
*
11
*	//! textmacro CREATE_TABLE_FIELD takes ACCESS_MODIFIER, TYPE, NAME, RETURN_TYPE
12
*		-	creates a table field surrounded by method operators
13
*
14
*	//! textmacro INITIALIZE_TABLE_FIELD takes NAME
15
*		-	initializes table field
16
*		-	used in onInit
17
*
18
*	//! textmacro CREATE_TABLE_FIELD_ARRAY takes TYPE, NAME, RETURN_TYPE
19
*		-	creates a struct that acts as an array
20
*		-	not used in a struct
21
*
22
*	//! textmacro USE_TABLE_FIELD_ARRAY takes ACCESS_MODIFIER, NAME
23
*		-	creates a field of a struct array
24
*		-	used in a struct
25
*
26
************************************************************************************/
27
	//! textmacro CREATE_TABLE_FIELD takes ACCESS_MODIFIER, TYPE, NAME, RETURN_TYPE
28
		private static Table t$NAME$
29
			
30
		$ACCESS_MODIFIER$ method operator $NAME$ takes nothing returns $RETURN_TYPE$
31
			return t$NAME$.$TYPE$[this]
32
		endmethod
33
		$ACCESS_MODIFIER$ method operator $NAME$= takes $RETURN_TYPE$ value returns nothing
34
			set t$NAME$.$TYPE$[this] = value
35
		endmethod
36
		$ACCESS_MODIFIER$ method $NAME$_clear takes nothing returns nothing
37
			call t$NAME$.$TYPE$.remove(this)
38
		endmethod
39
	//! endtextmacro
40
	
41
	//! textmacro CREATE_TABLE_FIELD_ARRAY takes TYPE, NAME, RETURN_TYPE
42
		private struct T$NAME$ extends array
43
			private static Table table
44
			
45
			method operator [] takes integer index returns $RETURN_TYPE$
46
				return table.$TYPE$[index]
47
			endmethod
48
			method operator []= takes integer index, $RETURN_TYPE$ value returns nothing
49
				set table.$TYPE$[index] = value
50
			endmethod
51
			static method remove takes integer index returns nothing
52
				call table.$TYPE$.remove(index)
53
			endmethod
54
			static method clear takes nothing returns nothing
55
				call table.flush()
56
			endmethod
57
			
58
			private static method init takes nothing returns nothing
59
				set table = Table.create()
60
			endmethod
61
			
62
			implement Init
63
		endstruct
64
	//! endtextmacro
65
	
66
	//! textmacro USE_TABLE_FIELD_ARRAY takes ACCESS_MODIFIER, NAME
67
		$ACCESS_MODIFIER$ static T$NAME$ $NAME$ = 0
68
	//! endtextmacro
69
	
70
	//! textmacro INITIALIZE_TABLE_FIELD takes NAME
71
		set t$NAME$ = Table.create()
72
	//! endtextmacro
73
endlibrary