Skip to content

Commit 671c704

Browse files
committed
Un-inline functions
1 parent 5b4b26b commit 671c704

5 files changed

Lines changed: 203 additions & 157 deletions

File tree

Actions.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "Common.h"
2+
3+
4+
void Extension::LoadJSON(TCHAR const *JSON, int flags)
5+
{
6+
json_settings settings = {0};
7+
settings.settings = (flags ? json_relaxed_commas : 0);
8+
char Error[128];
9+
#ifdef UNICODE
10+
std::string json = UTF8fromUnicode(JSON);
11+
if(json.empty())
12+
{
13+
error = L"Could not convert Unicode JSON to UTF8";
14+
Runtime.GenerateEvent(0);
15+
error.clear();
16+
return;
17+
}
18+
json_value *temp = json_parse_ex(&settings, json.c_str(), json.length(), Error);
19+
#else
20+
json_value *temp = json_parse_ex(&settings, JSON, strlen(JSON), Error);
21+
#endif
22+
if(!temp)
23+
{
24+
TCHAR *t = 0;
25+
error = (t = Edif::ConvertString(Error));
26+
Edif::FreeString(t), t = 0;
27+
Runtime.GenerateEvent(0);
28+
error.clear();
29+
return;
30+
}
31+
if(root)
32+
{
33+
current = 0;
34+
json_value_free(root);
35+
}
36+
current = root = temp;
37+
}
38+
39+
void Extension::EnterObject(TCHAR const *Name)
40+
{
41+
if(IsObject())
42+
{
43+
json_value const*temp = &((*current)[UTF8fromUnicode(Name).c_str()]);
44+
if(temp)
45+
{
46+
current = temp;
47+
}
48+
}
49+
}
50+
51+
void Extension::EnterArray(unsigned index)
52+
{
53+
if(IsArray())
54+
{
55+
json_value const*temp = &((*current)[index]);
56+
if(temp)
57+
{
58+
current = temp;
59+
}
60+
}
61+
}
62+
63+
void Extension::GoUp()
64+
{
65+
current = current->parent ? current->parent : current;
66+
}
67+
68+
void Extension::GotoRoot()
69+
{
70+
current = root;
71+
}

Conditions.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "Common.h"
2+
3+
4+
bool Extension::OnError()
5+
{
6+
return true;
7+
}
8+
bool Extension::IsString()
9+
{
10+
return current->type == json_string;
11+
}
12+
bool Extension::IsInteger()
13+
{
14+
return current->type == json_integer;
15+
}
16+
bool Extension::IsDouble()
17+
{
18+
return current->type == json_double;
19+
}
20+
bool Extension::IsObject()
21+
{
22+
return current->type == json_object;
23+
}
24+
bool Extension::IsArray()
25+
{
26+
return current->type == json_array;
27+
}
28+
bool Extension::IsBoolean()
29+
{
30+
return current->type == json_boolean;
31+
}
32+
bool Extension::IsNull()
33+
{
34+
return current->type == json_null;
35+
}
36+
bool Extension::IsTrue()
37+
{
38+
return IsBoolean() && current->u.boolean;
39+
}

Expressions.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "Common.h"
2+
3+
4+
TCHAR const *Extension::GetError()
5+
{
6+
return Runtime.CopyString(error.c_str());
7+
}
8+
TCHAR const *Extension::GetString()
9+
{
10+
if(!IsString()) return _T("");
11+
TCHAR *t = Edif::ConvertString(current->u.string.ptr);
12+
TCHAR *c = Runtime.CopyString(t);
13+
Edif::FreeString(t);
14+
return c;
15+
}
16+
int Extension::GetInteger()
17+
{
18+
return IsInteger() ? static_cast<int>(current->u.integer) : 0;
19+
}
20+
TCHAR const *Extension::GetLong()
21+
{
22+
if(IsInteger())
23+
{
24+
std::basic_ostringstream<TCHAR> ss;
25+
ss << current->u.integer;
26+
return Runtime.CopyString(ss.str().c_str());
27+
}
28+
return _T("0");
29+
}
30+
float Extension::GetFloat()
31+
{
32+
return IsDouble() ? static_cast<float>(current->u.dbl) : 0.0f;
33+
}
34+
TCHAR const *Extension::GetDouble()
35+
{
36+
if(IsDouble())
37+
{
38+
std::basic_ostringstream<TCHAR> ss;
39+
ss << std::setprecision(20) << current->u.dbl;
40+
return Runtime.CopyString(ss.str().c_str());
41+
}
42+
return _T("0.0");
43+
}
44+
unsigned Extension::GetNumValues()
45+
{
46+
if(IsObject())
47+
{
48+
return current->u.object.length;
49+
}
50+
else if(IsArray())
51+
{
52+
return current->u.array.length;
53+
}
54+
return 0;
55+
}
56+
unsigned Extension::GetBoolNum()
57+
{
58+
return IsBoolean() ? (current->u.boolean ? 1 : 0) : 0;
59+
}

Extension.hpp

Lines changed: 22 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -94,167 +94,32 @@ class Extension
9494
#endif
9595

9696
//Actions
97-
void LoadJSON(TCHAR const*JSON, int flags)
98-
{
99-
json_settings settings = {0};
100-
settings.settings = (flags ? json_relaxed_commas : 0);
101-
char Error[128];
102-
#ifdef UNICODE
103-
std::string json = UTF8fromUnicode(JSON);
104-
if(json.empty())
105-
{
106-
error = L"Could not convert Unicode JSON to UTF8";
107-
Runtime.GenerateEvent(0);
108-
error.clear();
109-
return;
110-
}
111-
json_value *temp = json_parse_ex(&settings, json.c_str(), json.length(), Error);
112-
#else
113-
json_value *temp = json_parse_ex(&settings, JSON, strlen(JSON), Error);
114-
#endif
115-
if(!temp)
116-
{
117-
TCHAR *t = 0;
118-
error = (t = Edif::ConvertString(Error));
119-
Edif::FreeString(t), t = 0;
120-
Runtime.GenerateEvent(0);
121-
error.clear();
122-
return;
123-
}
124-
if(root)
125-
{
126-
current = 0;
127-
json_value_free(root);
128-
}
129-
current = root = temp;
130-
}
131-
void EnterObject(TCHAR const*Name)
132-
{
133-
if(IsObject())
134-
{
135-
json_value const*temp = &((*current)[UTF8fromUnicode(Name).c_str()]);
136-
if(temp)
137-
{
138-
current = temp;
139-
}
140-
}
141-
}
142-
void EnterArray(unsigned index)
143-
{
144-
if(IsArray())
145-
{
146-
json_value const*temp = &((*current)[index]);
147-
if(temp)
148-
{
149-
current = temp;
150-
}
151-
}
152-
}
153-
void GoUp()
154-
{
155-
current = current->parent ? current->parent : current;
156-
}
157-
void GotoRoot()
158-
{
159-
current = root;
160-
}
97+
void LoadJSON(TCHAR const *JSON, int flags);
98+
void EnterObject(TCHAR const *Name);
99+
void EnterArray(unsigned index);
100+
void GoUp();
101+
void GotoRoot();
161102

162103
//Conditions
163-
bool OnError() //0
164-
{
165-
return true;
166-
}
167-
bool IsString()
168-
{
169-
return current->type == json_string;
170-
}
171-
bool IsInteger()
172-
{
173-
return current->type == json_integer;
174-
}
175-
bool IsDouble()
176-
{
177-
return current->type == json_double;
178-
}
179-
bool IsObject()
180-
{
181-
return current->type == json_object;
182-
}
183-
bool IsArray()
184-
{
185-
return current->type == json_array;
186-
}
187-
bool IsBoolean()
188-
{
189-
return current->type == json_boolean;
190-
}
191-
bool IsNull()
192-
{
193-
return current->type == json_null;
194-
}
195-
bool IsTrue()
196-
{
197-
return IsBoolean() && current->u.boolean;
198-
}
104+
bool OnError(); //0
105+
bool IsString();
106+
bool IsInteger();
107+
bool IsDouble();
108+
bool IsObject();
109+
bool IsArray();
110+
bool IsBoolean();
111+
bool IsNull();
112+
bool IsTrue();
199113

200114
//Expressions
201-
TCHAR const*GetError()
202-
{
203-
return Runtime.CopyString(error.c_str());
204-
}
205-
TCHAR const*GetString()
206-
{
207-
if(!IsString()) return _T("");
208-
TCHAR *t = Edif::ConvertString(current->u.string.ptr);
209-
TCHAR *c = Runtime.CopyString(t);
210-
Edif::FreeString(t);
211-
return c;
212-
}
213-
int GetInteger()
214-
{
215-
return IsInteger() ? static_cast<int>(current->u.integer) : 0;
216-
}
217-
TCHAR const*GetLong()
218-
{
219-
if(IsInteger())
220-
{
221-
std::basic_ostringstream<TCHAR> ss;
222-
ss << current->u.integer;
223-
return Runtime.CopyString(ss.str().c_str());
224-
}
225-
return _T("0");
226-
}
227-
float GetFloat()
228-
{
229-
return IsDouble() ? static_cast<float>(current->u.dbl) : 0.0f;
230-
}
231-
TCHAR const*GetDouble()
232-
{
233-
if(IsDouble())
234-
{
235-
std::basic_ostringstream<TCHAR> ss;
236-
ss << std::setprecision(20) << current->u.dbl;
237-
return Runtime.CopyString(ss.str().c_str());
238-
}
239-
return _T("0.0");
240-
}
241-
unsigned GetNumValues()
242-
{
243-
if(IsObject())
244-
{
245-
return current->u.object.length;
246-
}
247-
else if(IsArray())
248-
{
249-
return current->u.array.length;
250-
}
251-
return 0;
252-
}
253-
unsigned GetBoolNum()
254-
{
255-
return IsBoolean() ? (current->u.boolean ? 1 : 0) : 0;
256-
}
257-
115+
TCHAR const *GetError();
116+
TCHAR const *GetString();
117+
int GetInteger();
118+
TCHAR const *GetLong();
119+
float GetFloat();
120+
TCHAR const *GetDouble();
121+
unsigned GetNumValues();
122+
unsigned GetBoolNum();
258123

259124

260125
short Handle(); //defined & documented in Extension.cpp

Template.vcproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,18 @@
13501350
<Filter
13511351
Name="The Extension Class"
13521352
>
1353+
<File
1354+
RelativePath=".\Actions.cpp"
1355+
>
1356+
</File>
1357+
<File
1358+
RelativePath=".\Conditions.cpp"
1359+
>
1360+
</File>
1361+
<File
1362+
RelativePath=".\Expressions.cpp"
1363+
>
1364+
</File>
13531365
<File
13541366
RelativePath=".\Extension.cpp"
13551367
>

0 commit comments

Comments
 (0)