-
Notifications
You must be signed in to change notification settings - Fork 0
/
_.PRG
266 lines (183 loc) · 5.65 KB
/
_.PRG
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
**************************************************************
*
* Marco Plaza, nfTools 2018. @vfp2nfox
*
* https://github.com/nfTools
*
*************************************************************
*
* usage ( see _sample.prg )
*
*
* with _( object , [ cNewPropertyName ] )
*
* .property1 = any valid vfp expression
*
* .property2 = any valid vfp expression
*
* with _( .<newObjectPropertyName> [,cNewpropertyName] )
*
* endwith
*
* .myCollection = .newCollection( [Item1,Item2,... Item20 ])
*
* .myList = .newList( [ Item1,Item2,... Item20 ] )
*
* .additems( "< collection/array name >" , item1,item2,.. item20 )
*
* with .newItemFor("< collection/array name >" [, collectionItemkey] )
*
* .itemproperty1 = value
*
* .itemproperty2 = value
*
* endwith
*
* endwith
*
*
**************************************************************
Parameters __otarget__, newpropname
Private All
Try
emessage = ''
Do Case
Case Vartype(__otarget__) # 'O'
Error 'nfTools: Invalid parameter type - must supply an object '+Chr(13)
result = .Null.
Case Pcount() = 2 And Vartype(m.newpropname ) = 'C'
tact = Type( '__oTarget__.'+newpropname )
Do Case
Case m.tact = 'U'
AddProperty( __otarget__ , newpropname, Createobject('empty') )
Case m.tact # 'O'
__otarget__.&newpropname = Createobject('empty')
Endcase
result = Createobject('nfset',__otarget__.&newpropname)
Otherwise
result = Createobject('nfset',m.__otarget__)
Endcase
Catch To oerr
emessage = emessage( oerr)
Endtry
If !Empty(m.emessage)
Error m.emessage
Return .Null.
Endif
Return m.result
******************************************
Define Class nfset As Custom
******************************************
__otarget__ = .F.
__lastproperty__ = ''
__passitems__ = .F.
*----------------------------------------
Procedure Init( __otarget__ )
*----------------------------------------
This.__otarget__ = m.__otarget__
AddProperty(This,'__acache__(1)')
*---------------------------------------------
Procedure this_access( pname As String )
*---------------------------------------------
If Lower(m.pname) $ '__apush__,__otarget__,__lastproperty__,newitemfor,newlist,newcollection,additems,__acache__,__passitems__,__copycache__'
Return This
Endif
This.__copycache__()
This.__lastproperty__ = m.pname
If !Pemstatus(This.__otarget__,m.pname,5)
AddProperty(This.__otarget__,m.pname, Createobject('empty') )
Endif
Return This.__otarget__
*---------------------------------------
Function additems( pname, p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20 )
*---------------------------------------
If Not Type( 'this.__oTarget__.'+m.pname,1) $ 'C,A'
Error pname + ' is not a Collection / Array '
Endif
isarray = Type( 'this.__oTarget__.'+m.pname,1) = 'A'
ot = This.__otarget__
For nn = 1 To Pcount()-1
If m.isarray
this.__apush__( m.ot,m.pname, Evaluate('p'+Transform(m.nn)) )
Else
m.ot.&pname..Add( Evaluate('p'+Transform(m.nn)) )
Endif
Endfor
*---------------------------------------
Function newitemfor( pname , Key )
*---------------------------------------
If Type('pName') # 'C'
Error ' newItemFor() invalid parameter Type '+calledfrom()
Endif
ot = This.__otarget__
tvar = Type( 'oT.'+m.pname , 1 )
Do Case
Case m.tvar = 'C'
onew = create('empty')
If Pcount() = 2
m.ot.&pname..Add( m.onew, m.key )
Else
m.ot.&pname..Add( m.onew )
Endif
Return Createobject('nfset',m.onew )
Case m.tvar = 'A'
onew = create('empty')
this.__apush__( m.ot,m.pname, m.onew )
Return Createobject('nfset',m.onew)
Otherwise
Error pname + ' is not a Collection / Array ' &&+calledfrom()
Endcase
*-------------------------------------------------------------------------------------------------------
Procedure newlist( p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20 )
*-------------------------------------------------------------------------------------------------------
ot = This.__otarget__
lp = This.__lastproperty__
Removeproperty(m.ot,m.lp)
AddProperty(m.ot,m.lp+'(1)')
If Pcount() > 0
Dimension This.__acache__( Pcount() )
For np = 1 To Pcount()
This.__acache__(m.np) = Evaluate('p'+Transform(m.np,'@b 99'))
Endfor
This.__passitems__ = .T.
Else
Dimension This.__acache__(1)
This.__acache__(1) = .Null.
This.__passitems__ = .F.
Endif
Return .Null.
*-------------------------------
Procedure Destroy
*-------------------------------
This.__copycache__()
*------------------------------------------
Procedure __copycache__
*------------------------------------------
If !This.__passitems__
Return
Endif
This.__passitems__ = .F.
aname = This.__lastproperty__
Acopy( This.__acache__,This.__otarget__.&aname )
This.__acache__ = .Null.
*--------------------------------------
Procedure newcollection( p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20 )
*--------------------------------------
Local ocol
ocol = Createobject('collection')
For nn = 1 To Pcount()
ocol.Add( Evaluate('p'+Transform(m.nn,'@b 99') ))
Endfor
Return m.ocol
*-----------------------------------------
Function __apush__( o, pname , vvalue )
*-----------------------------------------
uel = Alen( m.o.&pname )
If !Isnull( m.o.&pname )
m.uel = m.uel+1
Dimension m.o.&pname( m.uel )
Endif
m.o.&pname( m.uel ) = m.vvalue
**********************************************
Enddefine
**********************************************