Skip to content

Commit 648e61a

Browse files
committed
Add subvalue conditions/expressions & bookmarks
1 parent 7fd9145 commit 648e61a

7 files changed

+694
-28
lines changed

Actions.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@ void Extension::LoadJSON(TCHAR const *JSON, int flags)
3434
json_value_free(root);
3535
}
3636
current = root = temp;
37+
bookmarks.clear();
3738
}
3839

3940
void Extension::EnterObject(TCHAR const *Name)
4041
{
41-
if(IsObject())
42+
if(IsObject() && ObjExists(Name))
4243
{
43-
json_value const*temp = &((*current)[UTF8fromUnicode(Name).c_str()]);
44-
if(temp)
45-
{
46-
current = temp;
47-
}
44+
current = &((*current)[UTF8fromUnicode(Name).c_str()]);
4845
}
4946
}
5047

@@ -70,6 +67,18 @@ void Extension::GotoRoot()
7067
current = root;
7168
}
7269

70+
void Extension::SetBookmark(TCHAR const *Name)
71+
{
72+
bookmarks[Name] = current;
73+
}
74+
void Extension::GotoBookmark(TCHAR const *Name)
75+
{
76+
if(bookmarks.find(Name) != bookmarks.end())
77+
{
78+
current = bookmarks[Name];
79+
}
80+
}
81+
7382
void Extension::DebugWindow()
7483
{
7584
std::basic_ostringstream<TCHAR> oss;

Conditions.cpp

+162
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,165 @@ bool Extension::IsTrue()
4949
}
5050
return false;
5151
}
52+
53+
bool Extension::ObjExists(TCHAR const *Name)
54+
{
55+
if(IsObject())
56+
{
57+
std::string n = UTF8fromUnicode(Name);
58+
for(unsigned i = 0; i < current->u.object.length; ++i)
59+
{
60+
if(current->u.object.values[i].name == n)
61+
{
62+
return true;
63+
}
64+
}
65+
}
66+
return false;
67+
}
68+
69+
bool Extension::IsObjString(TCHAR const *Name)
70+
{
71+
if(ObjExists(Name))
72+
{
73+
TempDelve td (*this, Name);
74+
return IsString();
75+
}
76+
return false;
77+
}
78+
bool Extension::IsObjInteger(TCHAR const *Name)
79+
{
80+
if(ObjExists(Name))
81+
{
82+
TempDelve td (*this, Name);
83+
return IsInteger();
84+
}
85+
return false;
86+
}
87+
bool Extension::IsObjDouble(TCHAR const *Name)
88+
{
89+
if(ObjExists(Name))
90+
{
91+
TempDelve td (*this, Name);
92+
return IsDouble();
93+
}
94+
return false;
95+
}
96+
bool Extension::IsObjObject(TCHAR const *Name)
97+
{
98+
if(ObjExists(Name))
99+
{
100+
TempDelve td (*this, Name);
101+
return IsObject();
102+
}
103+
return false;
104+
}
105+
bool Extension::IsObjArray(TCHAR const *Name)
106+
{
107+
if(ObjExists(Name))
108+
{
109+
TempDelve td (*this, Name);
110+
return IsArray();
111+
}
112+
return false;
113+
}
114+
bool Extension::IsObjBoolean(TCHAR const *Name)
115+
{
116+
if(ObjExists(Name))
117+
{
118+
TempDelve td (*this, Name);
119+
return IsBoolean();
120+
}
121+
return false;
122+
}
123+
bool Extension::IsObjNull(TCHAR const *Name)
124+
{
125+
if(ObjExists(Name))
126+
{
127+
TempDelve td (*this, Name);
128+
return IsNull();
129+
}
130+
return false;
131+
}
132+
bool Extension::IsObjTrue(TCHAR const *Name)
133+
{
134+
if(ObjExists(Name))
135+
{
136+
TempDelve td (*this, Name);
137+
return IsTrue();
138+
}
139+
return false;
140+
}
141+
142+
bool Extension::IsArrString(unsigned index)
143+
{
144+
if(IsArray() && index < current->u.array.length)
145+
{
146+
TempDelve td (*this, index);
147+
return IsString();
148+
}
149+
return false;
150+
}
151+
bool Extension::IsArrInteger(unsigned index)
152+
{
153+
if(IsArray() && index < current->u.array.length)
154+
{
155+
TempDelve td (*this, index);
156+
return IsInteger();
157+
}
158+
return false;
159+
}
160+
bool Extension::IsArrDouble(unsigned index)
161+
{
162+
if(IsArray() && index < current->u.array.length)
163+
{
164+
TempDelve td (*this, index);
165+
return IsDouble();
166+
}
167+
return false;
168+
}
169+
bool Extension::IsArrObject(unsigned index)
170+
{
171+
if(IsArray() && index < current->u.array.length)
172+
{
173+
TempDelve td (*this, index);
174+
return IsObject();
175+
}
176+
return false;
177+
}
178+
bool Extension::IsArrArray(unsigned index)
179+
{
180+
if(IsArray() && index < current->u.array.length)
181+
{
182+
TempDelve td (*this, index);
183+
return IsArray();
184+
}
185+
return false;
186+
}
187+
bool Extension::IsArrBoolean(unsigned index)
188+
{
189+
if(IsArray() && index < current->u.array.length)
190+
{
191+
TempDelve td (*this, index);
192+
return IsBoolean();
193+
}
194+
return false;
195+
}
196+
bool Extension::IsArrNull(unsigned index)
197+
{
198+
if(IsArray() && index < current->u.array.length)
199+
{
200+
TempDelve td (*this, index);
201+
return IsNull();
202+
}
203+
return false;
204+
}
205+
bool Extension::IsArrTrue(unsigned index)
206+
{
207+
if(IsArray() && index < current->u.array.length)
208+
{
209+
TempDelve td (*this, index);
210+
return IsTrue();
211+
}
212+
return false;
213+
}

Expressions.cpp

+129
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ TCHAR const *Extension::GetError()
44
{
55
return Runtime.CopyString(error.c_str());
66
}
7+
78
TCHAR const *Extension::GetString()
89
{
910
if(IsString())
@@ -166,3 +167,131 @@ unsigned Extension::GetBoolNum()
166167
}
167168
return 0;
168169
}
170+
171+
TCHAR const *Extension::GetObjString(TCHAR const *Name)
172+
{
173+
if(IsObject())
174+
{
175+
TempDelve td (*this, Name);
176+
return GetString();
177+
}
178+
return _T("");
179+
}
180+
int Extension::GetObjInteger(TCHAR const *Name)
181+
{
182+
if(IsObject())
183+
{
184+
TempDelve td (*this, Name);
185+
return GetInteger();
186+
}
187+
return 0;
188+
}
189+
TCHAR const *Extension::GetObjLong(TCHAR const *Name)
190+
{
191+
if(IsObject())
192+
{
193+
TempDelve td (*this, Name);
194+
return GetLong();
195+
}
196+
return _T("0");
197+
}
198+
float Extension::GetObjFloat(TCHAR const *Name)
199+
{
200+
if(IsObject())
201+
{
202+
TempDelve td (*this, Name);
203+
return GetFloat();
204+
}
205+
return 0.0f;
206+
}
207+
TCHAR const *Extension::GetObjDouble(TCHAR const *Name)
208+
{
209+
if(IsObject())
210+
{
211+
TempDelve td (*this, Name);
212+
return GetDouble();
213+
}
214+
return _T("0.0");
215+
}
216+
unsigned Extension::GetObjNumValues(TCHAR const *Name)
217+
{
218+
if(IsObject())
219+
{
220+
TempDelve td (*this, Name);
221+
return GetNumValues();
222+
}
223+
return 0;
224+
}
225+
unsigned Extension::GetObjBoolNum(TCHAR const *Name)
226+
{
227+
if(IsObject())
228+
{
229+
TempDelve td (*this, Name);
230+
return GetBoolNum();
231+
}
232+
return 0;
233+
}
234+
235+
TCHAR const *Extension::GetArrString(unsigned index)
236+
{
237+
if(IsArray() && index < current->u.array.length)
238+
{
239+
TempDelve td (*this, index);
240+
return GetString();
241+
}
242+
return _T("");
243+
}
244+
int Extension::GetArrInteger(unsigned index)
245+
{
246+
if(IsArray() && index < current->u.array.length)
247+
{
248+
TempDelve td (*this, index);
249+
return GetInteger();
250+
}
251+
return 0;
252+
}
253+
TCHAR const *Extension::GetArrLong(unsigned index)
254+
{
255+
if(IsArray() && index < current->u.array.length)
256+
{
257+
TempDelve td (*this, index);
258+
return GetLong();
259+
}
260+
return _T("0");
261+
}
262+
float Extension::GetArrFloat(unsigned index)
263+
{
264+
if(IsArray() && index < current->u.array.length)
265+
{
266+
TempDelve td (*this, index);
267+
return GetFloat();
268+
}
269+
return 0.0f;
270+
}
271+
TCHAR const *Extension::GetArrDouble(unsigned index)
272+
{
273+
if(IsArray() && index < current->u.array.length)
274+
{
275+
TempDelve td (*this, index);
276+
return GetDouble();
277+
}
278+
return _T("0.0");
279+
}
280+
unsigned Extension::GetArrNumValues(unsigned index)
281+
{
282+
if(IsArray() && index < current->u.array.length)
283+
{
284+
TempDelve td (*this, index);
285+
return GetNumValues();
286+
}
287+
return 0;
288+
}
289+
unsigned Extension::GetArrBoolNum(unsigned index)
290+
{
291+
if(IsArray() && index < current->u.array.length)
292+
{
293+
TempDelve td (*this, index);
294+
return GetBoolNum();
295+
}
296+
return 0;
297+
}

0 commit comments

Comments
 (0)