-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathClass_Permissions.ahk
147 lines (143 loc) · 5.05 KB
/
Class_Permissions.ahk
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Classes to stop inadvertent errors in AHK_L
;; Copyright (C) 2012 Adrian Hawryluk
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Miscleanious Classes to Stop Inadvertent Errors
;; - by Adrian Hawryluk November 2012
;; - Tested under AHK_L v1.1.08.01
;;
;; These classes are to make inadvertent errors a thing of the past. These
;; classes do not stop deliberate actions on the part of the programmer, they
;; are to stop errors not intended by the programmer.
;;
;; const
;; This class makes the member variables of the class constant by putting all
;; members that are constant in a separate member called _vals. Write attempts
;; to the vars through the object will be caught so long as there is no member
;; variable by that name already in the object.
;;
;; checkExistence
;; This class checks the existence of a member variable in the class and catch
;; if there is an attempt to get or set a variable that isn't already in the
;; object or in the object member _vals.
;;
;; checkExistenceConst
;; This class allows the getting of members located in _vals, but doesn't allow
;; the setting of them. This doesn't stop the setting of vars that are
;; directly in the object.
;;
;; You can either inherit using extends or possibly assign the __Get/__Set to
;; the base class (which I am not going to show here). I.e.
;;
;; class foo extends const
;; {
;; __new()
;; {
;; _vals := {}
;; _vals.bar := "foofoo"
;; ObjInsert(this, "_vals", _vals) ; have to insert this way to avoid the __Set() function.
;; }
;; }
;;
;; x := new foo
;; x.boo := 3 ; fails since constant
;; x.bar := 4 ; fails since constant
;; MsgBox % "x.boo: '" x.boo "'`nx.bar: '" x.bar "'"
;;
;; class foo2 extends checkExistence
;; {
;; __New()
;; {
;; _vals := {}
;; _vals.bar := "foofoo"
;; ObjInsert(this, "_vals", _vals) ; have to insert this way to avoid the __Set() function.
;; }
;; }
;; x := new foo2
;; x.boo := 3 ; fails since doesn't already exist
;; x.bar := 4 ; succeeds
;; MsgBox % "x.boo: '" x.boo "'`nx.bar: '" x.bar "'" ; x.boo warns since it checks existence
;;
;; class foo3 extends checkExistenceConst
;; {
;; __New()
;; {
;; _vals := {}
;; _vals.bar := "foofoo"
;; ObjInsert(this, "_vals", _vals) ; have to insert this way to avoid the __Set() function.
;; }
;; }
;; x := new foo3
;; x.boo := 3 ; fails since constant
;; x.bar := 4 ; fails since constant
;; MsgBox % "x.boo: '" x.boo "'`nx.bar: '" x.bar "'" ; x.boo warns since it checks existence
;;
;; LOG
;; Nov 30/2012
;; - Moved the inclusion of the object.ahk file to the bottom of the script
;; as it caused an order problem.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
class const
{
__Get(key)
{
if (ObjHasKey(this, "_vals") and ObjHasKey(this._vals, key))
return this._vals[key]
else if (ObjHasKey(object_getBase(this), "_vals"))
return object_getBase(this).__Get(key)
}
__Set(key, val)
{
MsgBox Error: Attempt to set to key '%key%' to value '%val%' when object is a constant.
return ; a return means not to let default __Set() handle call.
}
}
class checkExistence
{
__Get(key)
{
if (ObjHasKey(this, "_vals") and ObjHasKey(this._vals, key))
return this._vals[key]
else if (ObjHasKey(object_getBase(this), "_vals"))
return object_getBase(this).__Get(key)
else
MsgBox Warning: Key '%key%' doesn't exist in object.
}
__Set(key, ByRef val)
{
if (ObjHasKey(this, "_vals") and ObjHasKey(this._vals, key))
return this._vals[key] := val
else
{
MsgBox Error: Attempt to assign to key '%key%', which doesn't exist in object, to value '%val%'.
return
}
}
}
class checkExistenceConst extends const
{
__Get(key)
{
if (ObjHasKey(this, "_vals") and ObjHasKey(this._vals, key))
return this._vals[key]
else if (ObjHasKey(object_getBase(this), "_vals"))
return object_getBase(this).__Get(key)
else
MsgBox Warning: Key '%key%' doesn't exist in object.
}
}
#include <object>