25 typedef map<string,strVec> mapofvec;
30 logger = Logger::getLogger(
"AfcUtil");
36 static map<string,string> doneMap;
37 string AfcUtil::generateJsObjectsAll(vector<string> obj,strVec files,vector<bool> stat,
string &headers,
string &objs,
string &infjs,vector<string> pv,
38 string& ajaxret,
string& typrefs,map<string, string> ajintpthMap)
41 string ttem =
"Date readDate(JSONElement& obj){DateFormat formt(\"yyyy-mm-dd hh:mi:ss\");\nreturn *formt.parse(obj.getValue());}";
42 ttem +=
"Date* readDateP(JSONElement& obj){DateFormat formt(\"yyyy-mm-dd hh:mi:ss\");\nreturn formt.parse(obj.getValue());}";
43 ttem +=
"\nstring fromDateToJSON(Date d){DateFormat formt(\"yyyy-mm-dd hh:mi:ss\");\nreturn formt.format(d);}";
44 ttem +=
"\nstring fromDateVPToJSON(Date *d){DateFormat formt(\"yyyy-mm-dd hh:mi:ss\");\nreturn formt.format(*d);}";
45 ttem +=
"BinaryData readBinaryData(JSONElement& obj){BinaryData bd;return bd;}";
46 ttem +=
"BinaryData* readBinaryDataP(JSONElement& obj){return new BinaryData;}";
47 ttem +=
"\nstring fromBinaryDataToJSON(BinaryData d){return \"\";}";
48 ttem +=
"\nstring fromBinaryDataVPToJSON(BinaryData *d){return \"\";}";
49 ajaxret = ttem + typrefs + ajaxret;
50 string ret =
"#include \"AfcInclude.h\"\n\nextern \"C\"\n{\n" + ajaxret;
51 headers +=
"#include \"CastUtil.h\"\n#include \"JSONUtil.h\"\n#include \"sstream\"\n#include <algorithm>\n#include \"JSONSerialize.h\"\n";
52 headers +=
"#include \"set\"\n#include \"list\"\n#include \"queue\"\n#include \"deque\"\n#include \"DateFormat.h\"\n";
53 if(obj.size()==0)
return ret +
"}";
55 for (
unsigned int var = 0; var < obj.size(); ++var)
69 bool isOpForSet =
false;
70 strVec info = ref.getAfcObjectData(obj.at(var)+files.at(var)+
".h",
false,pinfo,isOpForSet);
71 ret += generateJsInterfaces(info,files.at(var),headers,obj.at(var),infjs,pv.at(var),ajintpthMap);
75 ret = (ret +
"\n}\n");
80 string AfcUtil::generateJsObjects(strVec obj,
string claz,
string &headers,
string path,
string &objs,strVec pobj,
bool isOpForSet,
string& typrefs,strVec minfo)
82 if(doneMap.find(claz)==doneMap.end())
83 doneMap[claz] =
"done";
86 string tes,tes1,fres,fres1;
89 string test =
"function _"+claz+
"()\n{\n";
90 tes +=
"JSONElement* _node;\n";
91 tes1 +=
"JSONElement* _node;\n";
92 fres =
"string json=\"{\";\n";
93 fres1 =
"string json=\"{\";\n";
98 map<string, int> fldstat;
99 for (
unsigned int i = 0; i < pobj.size(); i++)
101 if(((tess=pobj.at(i).find(
"("))==string::npos && (tess=pobj.at(i).find(
")"))==string::npos && pobj.at(i).find(
"~")==string::npos))
103 string fld = pobj.at(i);
104 StringUtil::replaceFirst(fld,
";",
"");
105 RegexUtil::replace(fld,
"[\t]+",
" ");
106 RegexUtil::replace(fld,
"[ ]+",
" ");
108 StringUtil::split(fldp, fld, (
" "));
111 string nam = fldp.at(1);
112 fldnames.push_back(fldp.at(0));
113 fldnames.push_back(nam);
118 for(
unsigned int i=0;i<minfo.size();i++)
120 if((tess=minfo.at(i).find(
"("))!=string::npos && (tess=minfo.at(i).find(
")"))!=string::npos && minfo.at(i).find(
"~")==string::npos
121 && fldnames.size()>0)
124 StringUtil::replaceFirst(meth,
";",
"");
125 RegexUtil::replace(meth,
"[\t]+",
" ");
126 RegexUtil::replace(meth,
"[ ]+",
" ");
127 RegexUtil::replace(meth,
"[ ?, ?]+",
",");
129 if(meth.find(
"*")!=string::npos)
132 StringUtil::replaceFirst(meth,
"*",
"");
135 string argts = meth.substr(meth.find(
"("),meth.find(
")")-meth.find(
"("));
136 StringUtil::replaceFirst(argts,
"(",
"");
137 StringUtil::replaceAll(argts,
")",
"");
138 meth = meth.substr(0,meth.find(
"("));
140 if(meth.find(
"operator")!=string::npos)
145 strVec methp,methpm,argp,argpm;
146 StringUtil::split(argp, argts, (
","));
147 StringUtil::split(methp, meth, (
" "));
148 for(
unsigned int j = 0; j < methp.size(); j++)
151 methpm.push_back(methp.at(j));
153 for(
unsigned int j = 0; j < argp.size(); j++)
155 if(argp.at(j)!=
"" && argp.at(j)!=
"(")
157 string tty = argp.at(j);
158 StringUtil::trim(tty);
159 if(tty.find(
" ")!=string::npos)
161 vector<string> temargt = StringUtil::split(tty,
" ");
162 argpm.push_back(temargt.at(0));
166 argpm.push_back(tty);
171 if(methpm.at(0)!=claz)
173 for(
unsigned int k = 0; k < fldnames.size(); k=k+2)
175 string cam = AfcUtil::camelCased(fldnames.at(k+1));
176 if(
"set"+cam==methpm.at(1) && argpm.size()==1 && argpm.at(0)==fldnames.at(k) && methpm.at(0)==
"void")
178 fldstat[fldnames.at(k+1)]++;
180 else if(
"get"+cam==methpm.at(1) && argpm.size()==0 && methpm.at(0)==fldnames.at(k))
182 fldstat[fldnames.at(k+1)]++;
190 for(
unsigned int k = 0; k < fldnames.size(); k=k+2)
192 if(fldstat[fldnames.at(k+1)]==2)
194 string data = fldnames.at(k) +
" " + fldnames.at(k+1) +
";";
196 pobj.push_back(data);
199 for(
unsigned int i=0;i<pobj.size();i++)
201 obj.push_back(pobj.at(i));
204 for(
unsigned int i=0;i<obj.size();i++)
207 string data = obj.at(i);
209 if(data.find(
"*")!=string::npos)
212 StringUtil::replaceFirst(data,
"*",
"");
214 StringUtil::replaceFirst(data,
";",
"");
215 StringUtil::split(vemp, data, (
" "));
222 tobj.push_back(obj.at(i));
226 for(
unsigned int i=0;i<obj.size();i++)
229 string data = obj.at(i);
231 if(data.find(
"*")!=string::npos)
234 StringUtil::replaceFirst(data,
"*",
"");
236 StringUtil::replaceFirst(data,
";",
"");
237 StringUtil::split(vemp, data, (
" "));
244 priv = (fldstat[vemp.at(1)]==2?
true:
false);
246 test +=
"this." + vemp.at(1) +
"= null;\n";
247 tes += generateReadObjects(vemp.at(0), vemp.at(1), priv, ptr,
".");
248 tes1 += generateReadObjects(vemp.at(0), vemp.at(1), priv, ptr,
"->");
249 fres += generateToJSONObjects(vemp.at(0), vemp.at(1), priv, obj, i, retu, headers, path, objs,
".", ptr);
250 fres1 += generateToJSONObjects(vemp.at(0), vemp.at(1), priv, obj, i, retu, headers, path, objs,
"->", ptr);
278 fres +=
"\njson += \"}\";";
279 fres1 +=
"\njson += \"}\";";
284 headers +=
"#include \""+claz+
".h\"\n";
286 typrefs += claz +
" read"+claz+
"(JSONElement& obj);\n" + claz +
"* read"+claz+
"P(JSONElement& obj);\n";
287 typrefs +=
"\nstring from"+claz+
"ToJSON("+claz+
" _obj);\nstring from"+claz+
"VPToJSON("+claz+
"* _obj);\n";
288 typrefs += claz +
" to"+claz+
"(string s);\n" + claz +
"* to"+claz+
"P(string s);\n";
289 typrefs +=
"vector<"+claz +
"> to"+claz+
"Vec(string s);\nvector<" + claz +
">* to"+claz+
"VecVP(string s);\n";
290 typrefs +=
"list<"+claz +
"> to"+claz+
"Lis(string s);\nlist<" + claz +
">* to"+claz+
"LisVP(string s);\n";
291 typrefs +=
"deque<"+claz +
"> to"+claz+
"Dq(string s);\ndeque<" + claz +
">* to"+claz+
"DqVP(string s);\n";
292 typrefs +=
"std::queue<"+claz +
"> to"+claz+
"Q(string s);\nstd::queue<" + claz +
">* to"+claz+
"QVP(string s);\n";
295 typrefs +=
"set<"+claz +
"> to"+claz+
"Set(string s);\nset<" + claz +
">* to"+claz+
"SetVP(string s);\n";
296 typrefs +=
"multiset<"+claz +
"> to"+claz+
"MulSet(string s);\nmultiset<" + claz +
">* to"+claz+
"MulSetVP(string s);\n";
298 typrefs +=
"\nstring from"+claz+
"VecToJSON(vector<"+claz+
"> _obj);\nstring from"+claz+
"VecVPToJSON(vector<"+claz+
">* _obj);\n";
299 typrefs +=
"\nstring from"+claz+
"LisToJSON(list<"+claz+
"> _obj);\nstring from"+claz+
"LisVPToJSON(list<"+claz+
">* _obj);\n";
300 typrefs +=
"\nstring from"+claz+
"DqToJSON(deque<"+claz+
"> _obj);\nstring from"+claz+
"DqVPToJSON(deque<"+claz+
">* _obj);\n";
301 typrefs +=
"\nstring from"+claz+
"QToJSON(std::queue<"+claz+
"> _obj);\nstring from"+claz+
"QVPToJSON(std::queue<"+claz+
">* _obj);\n";
304 typrefs +=
"\nstring from"+claz+
"SetToJSON(set<"+claz+
"> _obj);\nstring from"+claz+
"SetVPToJSON(set<"+claz+
">* _obj);\n";
305 typrefs +=
"\nstring from"+claz+
"MulSetToJSON(multiset<"+claz+
"> _obj);\nstring from"+claz+
"MulSetVPToJSON(multiset<"+claz+
">* _obj);\n";
308 test = retu+
"\n\n" + claz +
" read"+claz+
"(JSONElement& obj)\n{\n"+claz+
" _obj;\n";
309 test += tes +
"\nreturn _obj;\n}\n";
310 test +=
"\n\n" + claz +
"* read"+claz+
"P(JSONElement& obj)\n{\n"+claz+
"* _obj = new "+claz+
";\n";
311 test += tes1 +
"\nreturn _obj;\n}\n";
312 test += claz +
" to"+claz+
"(string s)\n{\nJSONElement element = JSONUtil::getDocument(s);\n"+ claz +
" _obj = read"+claz+
"(element);\nreturn _obj;\n}\n";
313 test +=
"vector<"+claz+
"> to"+claz+
"Vec(string s)\n{\nJSONElement element = JSONUtil::getDocument(s);\n" +
314 "vector<"+claz+
"> vec;\nfor(int i=0;i<(int)element.getChildren().size();i++){\n" +
315 claz +
" _obj = read"+claz+
"(*element.getChildren().at(i));\nvec.push_back(_obj);\n" +
316 "}\nreturn vec;\n}\n";
317 test +=
"list<"+claz+
"> to"+claz+
"Lis(string s)\n{\nvector<"+claz+
"> vec = to"+claz+
"Vec(s);\n" +
318 "list<"+claz+
"> tt;\nstd::copy(vec.begin(), vec.end(), std::back_inserter(tt));\n" +
322 test +=
"set<"+claz+
"> to"+claz+
"Set(string s)\n{\nvector<"+claz+
"> vec = to"+claz+
"Vec(s);\n" +
323 "set<"+claz+
"> tt;\nstd::copy(vec.begin(), vec.end(), std::inserter(tt, tt.begin()));\n" +
325 test +=
"multiset<"+claz+
"> to"+claz+
"MulSet(string s)\n{\nvector<"+claz+
"> vec = to"+claz+
"Vec(s);\n" +
326 "multiset<"+claz+
"> tt;\nstd::copy(vec.begin(), vec.end(), std::inserter(tt, tt.begin()));\n" +
329 test +=
"deque<"+claz+
"> to"+claz+
"Dq(string s)\n{\nvector<"+claz+
"> vec = to"+claz+
"Vec(s);\n" +
330 "deque<"+claz+
"> tt;\nstd::copy(vec.begin(), vec.end(), std::inserter(tt, tt.begin()));\n" +
332 test +=
"std::queue<"+claz+
"> to"+claz+
"Q(string s)\n{\nvector<"+claz+
"> vec = to"+claz+
"Vec(s);\n" +
333 "std::queue<"+claz+
"> tt;for (int var = 0; var < (int)vec.size(); ++var) {\ntt.push(vec.at(var));\n}\n" +
335 test +=
"vector<"+claz+
">* to"+claz+
"VecVP(string s)\n{\nJSONElement element = JSONUtil::getDocument(s);\n" +
336 "vector<"+claz+
">* vec = new vector<"+claz+
">;\nfor(int i=0;i<element.getChildren().size();i++){\n" +
337 claz +
" _obj = read"+claz+
"(*element.getChildren().at(i));\nvec->push_back(_obj);\n" +
338 "}\nreturn vec;\n}\n";
339 test +=
"list<"+claz+
">* to"+claz+
"LisVP(string s)\n{\nvector<"+claz+
"> vec = to"+claz+
"Vec(s);\n" +
340 "list<"+claz+
">* tt = new list<"+claz+
">;\nstd::copy(vec.begin(), vec.end(), std::back_inserter(*tt));\n" +
344 test +=
"set<"+claz+
">* to"+claz+
"SetVP(string s)\n{\nvector<"+claz+
"> vec = to"+claz+
"Vec(s);\n" +
345 "set<"+claz+
">* tt = new set<"+claz+
">;\nstd::copy(vec.begin(), vec.end(), std::inserter(*tt, tt->begin()));\n" +
347 test +=
"multiset<"+claz+
">* to"+claz+
"MulSetVP(string s)\n{\nvector<"+claz+
"> vec = to"+claz+
"Vec(s);\n" +
348 "multiset<"+claz+
">* tt = new multiset<"+claz+
">;\nstd::copy(vec.begin(), vec.end(), std::inserter(*tt, tt->begin()));\n" +
351 test +=
"deque<"+claz+
">* to"+claz+
"DqVP(string s)\n{\nvector<"+claz+
"> vec = to"+claz+
"Vec(s);\n" +
352 "deque<"+claz+
">* tt = new deque<"+claz+
">;\nstd::copy(vec.begin(), vec.end(), std::inserter(*tt, tt->begin()));\n" +
354 test +=
"std::queue<"+claz+
">* to"+claz+
"QVP(string s)\n{\nvector<"+claz+
"> vec = to"+claz+
"Vec(s);\n" +
355 "std::queue<"+claz+
">* tt = new std::queue<"+claz+
">;for (int var = 0; var < (int)vec.size(); ++var) {\ntt->push(vec.at(var));\n}\n" +
357 test +=
"void* toVoidP"+claz+
"(string s)\n{\nJSONElement element = JSONUtil::getDocument(s);\n"+ claz +
" *_obj = new "+claz+
";\n*_obj = read"+claz+
"(element);\nreturn _obj;\n}\n";
358 test +=
"\nstring from"+claz+
"ToJSON("+claz+
" _obj)\n{\n"+fres+
"\nreturn json;\n}\n";
359 test +=
"\nstring from"+claz+
"VPToJSON("+claz+
"* _obj)\n{\n"+fres1+
"\nreturn json;\n}\n";
360 test +=
"\nstring from"+claz+
"VecToJSON(vector<"+claz+
"> _vecobj)\n{\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
361 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
362 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
363 "\n}\njson += \"]\";\nreturn json;\n}\n";
364 test +=
"\nstring from"+claz+
"LisToJSON(list<"+claz+
"> _lisobj)\n{\nvector<"+claz+
"> _vecobj;\nstd::copy(_lisobj.begin(), _lisobj.end(), std::back_inserter(_vecobj));" +
365 "\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
366 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
367 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
368 "\n}\njson += \"]\";\nreturn json;\n}\n";
371 test +=
"\nstring from"+claz+
"SetToJSON(set<"+claz+
"> _lisobj)\n{\nvector<"+claz+
"> _vecobj;\nstd::copy(_lisobj.begin(), _lisobj.end(), std::back_inserter(_vecobj));" +
372 "\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
373 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
374 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
375 "\n}\njson += \"]\";\nreturn json;\n}\n";
376 test +=
"\nstring from"+claz+
"MulSetToJSON(multiset<"+claz+
"> _lisobj)\n{\nvector<"+claz+
"> _vecobj;\nstd::copy(_lisobj.begin(), _lisobj.end(), std::back_inserter(_vecobj));" +
377 "\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
378 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
379 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
380 "\n}\njson += \"]\";\nreturn json;\n}\n";
382 test +=
"\nstring from"+claz+
"DqToJSON(deque<"+claz+
"> _lisobj)\n{\nvector<"+claz+
"> _vecobj;\nstd::copy(_lisobj.begin(), _lisobj.end(), std::back_inserter(_vecobj));" +
383 "\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
384 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
385 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
386 "\n}\njson += \"]\";\nreturn json;\n}\n";
387 test +=
"\nstring from"+claz+
"QToJSON(std::queue<"+claz+
"> _lisobj)\n{\nvector<"+claz+
"> _vecobj;" +
388 "std::queue<"+claz+
"> qq = _lisobj;\nfor (int var = 0; var < (int)qq.size(); ++var)\n{" +
389 "_vecobj.push_back(qq.front());\nqq.pop();\n}\n" +
390 "\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
391 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
392 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
393 "\n}\njson += \"]\";\nreturn json;\n}\n";
394 test +=
"\nstring from"+claz+
"VecVPToJSON(vector<"+claz+
">* _vecobj)\n{\nstring json = \"[\";\nfor(int i=0;i<_vecobj->size();i++){\n" +
395 "json += from"+claz+
"ToJSON(_vecobj->at(i));\n" +
396 "if(i!=_vecobj->size()-1)json += \",\";\n" +
397 "\n}\njson += \"]\";\nreturn json;\n}\n";
398 test +=
"\nstring from"+claz+
"LisVPToJSON(list<"+claz+
">* _lisobj)\n{\nvector<"+claz+
"> _vecobj;\nstd::copy(_lisobj->begin(), _lisobj->end(), std::back_inserter(_vecobj));" +
399 "\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
400 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
401 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
402 "\n}\njson += \"]\";\nreturn json;\n}\n";
405 test +=
"\nstring from"+claz+
"SetVPToJSON(set<"+claz+
">* _lisobj)\n{\nvector<"+claz+
"> _vecobj;\nstd::copy(_lisobj->begin(), _lisobj->end(), std::back_inserter(_vecobj));" +
406 "\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
407 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
408 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
409 "\n}\njson += \"]\";\nreturn json;\n}\n";
410 test +=
"\nstring from"+claz+
"MulSetVPToJSON(multiset<"+claz+
">* _lisobj)\n{\nvector<"+claz+
"> _vecobj;\nstd::copy(_lisobj->begin(), _lisobj->end(), std::back_inserter(_vecobj));" +
411 "\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
412 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
413 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
414 "\n}\njson += \"]\";\nreturn json;\n}\n";
416 test +=
"\nstring from"+claz+
"DqVPToJSON(deque<"+claz+
">* _lisobj)\n{\nvector<"+claz+
"> _vecobj;\nstd::copy(_lisobj->begin(), _lisobj->end(), std::back_inserter(_vecobj));" +
417 "\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
418 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
419 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
420 "\n}\njson += \"]\";\nreturn json;\n}\n";
421 test +=
"\nstring from"+claz+
"QVPToJSON(std::queue<"+claz+
">* _lisobj)\n{\nvector<"+claz+
"> _vecobj;\n" +
422 "std::queue<"+claz+
"> qq = *_lisobj;\nfor (int var = 0; var < (int)qq.size(); ++var)\n{" +
423 "_vecobj.push_back(qq.front());\nqq.pop();\n}\n" +
424 "\nstring json = \"[\";\nfor(int i=0;i<(int)_vecobj.size();i++){\n" +
425 "json += from"+claz+
"ToJSON(_vecobj.at(i));\n" +
426 "if(i!=(int)_vecobj.size()-1)json += \",\";\n" +
427 "\n}\njson += \"]\";\nreturn json;\n}\n";
432 string AfcUtil::generateReadObjects(
string type,
string name,
bool priv,
bool ptr,
string typ)
435 if(type==
"int" || type==
"short" || type==
"long" || type==
"double" || type==
"float" || type==
"string" || type==
"bool")
437 tes +=
"_node = obj.getNode(\""+name+
"\");\n";
440 if(!priv)tes +=
"if(_node!=NULL)_obj"+typ + name +
"= CastUtil::lexical_cast<"+type+
">(_node->getValue());\n";
441 else tes +=
"if(_node!=NULL)_obj"+typ+
"set"+camelCased(name)+
"(CastUtil::lexical_cast<"+type+
">(_node->getValue()));\n";
445 if(!priv)tes +=
"if(_node!=NULL)_obj"+typ + name +
"= new "+type+
"(CastUtil::lexical_cast<"+type+
">(_node->getValue()));\n";
446 else tes +=
"if(_node!=NULL)_obj"+typ+
"set"+camelCased(name)+
"(new "+type+
"(CastUtil::lexical_cast<"+type+
">(_node->getValue())));\n";
451 tes +=
"_node = obj.getNode(\""+name+
"\");\n";
452 string tempp = StringUtil::replaceAllCopy(type,
" ",
"");
453 if(tempp.find(
"vector<")!=string::npos || tempp.find(
"list<")!=string::npos || tempp.find(
"set<")!=string::npos
454 || tempp.find(
"multiset<")!=string::npos || tempp.find(
"queue<")!=string::npos || tempp.find(
"deque<")!=string::npos)
457 if(tempp.find(
"vector")!=string::npos)
458 stlcnttyp =
"vector";
459 else if(tempp.find(
"queue")!=string::npos)
460 stlcnttyp =
"std::queue";
461 else if(tempp.find(
"deque")!=string::npos)
463 else if(tempp.find(
"list")!=string::npos)
465 else if(tempp.find(
"multiset")!=string::npos)
466 stlcnttyp =
"multiset";
469 tempp = StringUtil::replaceAllCopy(tempp,
"vector<",
"");
470 tempp = StringUtil::replaceAllCopy(tempp,
"multiset<",
"");
471 tempp = StringUtil::replaceAllCopy(tempp,
"set<",
"");
472 tempp = StringUtil::replaceAllCopy(tempp,
"queue<",
"");
473 tempp = StringUtil::replaceAllCopy(tempp,
"deque<",
"");
474 tempp = StringUtil::replaceAllCopy(tempp,
"list<",
"");
475 tempp = StringUtil::replaceAllCopy(tempp,
"std::",
"");
476 tempp = StringUtil::replaceAllCopy(tempp,
">",
"");
477 tes +=
"if(_node!=NULL){\n";
478 tes +=
"for(int i=0;i<_node->getChildren().size();i++)\n{\n";
479 tes +=
"JSONElement* __node = _node->getChildren().at(i);\n";
480 tes += generateReadVectorObjects(tempp, name, priv, ptr, typ, stlcnttyp);
484 else if(Reflection::isValidClass(tempp))
488 if(!priv)tes +=
"if(_node!=NULL)_obj"+typ + name +
"= read"+tempp+
"(*_node);\n";
489 else tes +=
"if(_node!=NULL)_obj"+typ+
"set"+camelCased(name)+
"(read"+tempp+
"(*_node));\n";
493 if(!priv)tes +=
"if(_node!=NULL)_obj"+typ + name +
"= read"+tempp+
"P(*_node);\n";
494 else tes +=
"if(_node!=NULL)_obj"+typ+
"set"+camelCased(name)+
"(read"+tempp+
"P(*_node));\n";
502 string AfcUtil::generateReadVectorObjects(
string type,
string name,
bool priv,
bool ptr,
string typ,
string conttype)
505 string act = ((conttype==
"set" || conttype==
"multiset")?
"insert":(conttype==
"std::queue"?
"push":
"push_back"));
506 if(type==
"int" || type==
"short" || type==
"long" || type==
"double" || type==
"float" || type==
"string" || type==
"bool")
510 if(!priv)tes +=
"if(__node!=NULL)_obj"+typ + name +
"."+act+
"(CastUtil::lexical_cast<"+type+
">(__node->getValue()));\n";
511 else tes +=
"if(__node!=NULL)_obj"+typ+
"get"+camelCased(name)+
"()."+act+
"(CastUtil::lexical_cast<"+type+
">(__node->getValue()));\n";
515 if(!priv)tes +=
"if(__node!=NULL){_obj"+typ + name +
" = new "+conttype+
"<"+type+
">;\n_obj"+typ + name +
"->"+act+
"(CastUtil::lexical_cast<"+type+
">(__node->getValue()));\n}\n";
516 else tes +=
"if(__node!=NULL){_obj"+typ +
"set"+camelCased(name)+
"(new "+conttype+
"<"+type+
">);\n_obj"+typ+
"get"+camelCased(name)+
"()->"+act+
"(CastUtil::lexical_cast<"+type+
">(__node->getValue()));\n}\n";
519 else if(Reflection::isValidClass(type))
523 if(!priv)tes +=
"if(__node!=NULL)_obj"+typ + name +
"."+act+
"(read"+type+
"(*__node));\n";
524 else tes +=
"if(__node!=NULL)_obj"+typ+
"get"+camelCased(name)+
"()."+act+
"(read"+type+
"(*__node));\n";
528 if(!priv)tes +=
"if(__node!=NULL){_obj"+typ + name +
" = new "+conttype+
"<"+type+
">;\n_obj"+typ + name +
"->"+act+
"(read"+type+
"(*__node));\n}\n";
529 else tes +=
"if(__node!=NULL){_obj"+typ +
"set"+camelCased(name)+
"(new "+conttype+
"<"+type+
">);\n_obj"+typ+
"get"+camelCased(name)+
"()->"+act+
"(read"+type+
"(*__node));\n}\n";
535 string AfcUtil::generateToJSONObjects(
string type,
string name,
bool priv, strVec obj,
int i,
string &retu,
string &headers,
string path,
string &objs,
string typ,
bool ptr)
538 if(type==
"int" || type==
"short" || type==
"long" || type==
"double" || type==
"float" || type==
"string" || type==
"bool")
544 if(!priv)fres +=
"json += \"\\\""+name+
"\\\" : \\\"\"+_obj"+typ+name+
"+\"\\\"\";";
545 else fres +=
"json += \"\\\""+name+
"\\\" : \\\"\"+_obj"+typ+
"get"+camelCased(name)+
"()+\"\\\"\";";
549 if(!priv)fres +=
"if(_obj"+typ+name+
"!=NULL)json += \"\\\""+name+
"\\\" : \\\"\"+*_obj"+typ+name+
"+\"\\\"\";\nelse json += \"null\";\n";
550 else fres +=
"if(_obj"+typ+
"get"+camelCased(name)+
"()!=NULL)json += \"\\\""+name+
"\\\" : \\\"\"+*_obj"+typ+
"get"+camelCased(name)+
"()+\"\\\"\";\nelse json += \"null\";\n";
557 if(!priv)fres +=
"json += \"\\\""+name+
"\\\" : \"+CastUtil::lexical_cast<string>(_obj"+typ+name+
");";
558 else fres +=
"json += \"\\\""+name+
"\\\" : \"+CastUtil::lexical_cast<string>(_obj"+typ+
"get"+camelCased(name)+
"());";
562 if(!priv)fres +=
"if(_obj"+typ+name+
"!=NULL)json += \"\\\""+name+
"\\\" : \"+CastUtil::lexical_cast<string>(*_obj"+typ+name+
");\nelse json += \"null\";\n";
563 else fres +=
"if(_obj"+typ+
"get"+camelCased(name)+
"()!=NULL)json += \"\\\""+name+
"\\\" : \"+CastUtil::lexical_cast<string>(*_obj"+typ+
"get"+camelCased(name)+
"());\nelse json += \"null\";\n";
567 if(i!=((
int)obj.size()-1))
569 fres +=
"\njson += \",\";\n";
574 string tempp = StringUtil::replaceAllCopy(type,
" ",
"");
575 if(tempp.find(
"vector<")!=string::npos || tempp.find(
"list<")!=string::npos || tempp.find(
"set<")!=string::npos
576 || tempp.find(
"multiset<")!=string::npos || tempp.find(
"queue<")!=string::npos || tempp.find(
"deque<")!=string::npos)
579 if(tempp.find(
"vector")!=string::npos)
580 stlcnttyp =
"vector";
581 else if(tempp.find(
"queue")!=string::npos)
582 stlcnttyp =
"std::queue";
583 else if(tempp.find(
"deque")!=string::npos)
585 else if(tempp.find(
"list")!=string::npos)
587 else if(tempp.find(
"multiset")!=string::npos)
588 stlcnttyp =
"multiset";
591 tempp = StringUtil::replaceAllCopy(tempp,
"vector<",
"");
592 tempp = StringUtil::replaceAllCopy(tempp,
"multiset<",
"");
593 tempp = StringUtil::replaceAllCopy(tempp,
"set<",
"");
594 tempp = StringUtil::replaceAllCopy(tempp,
"queue<",
"");
595 tempp = StringUtil::replaceAllCopy(tempp,
"deque<",
"");
596 tempp = StringUtil::replaceAllCopy(tempp,
"list<",
"");
597 tempp = StringUtil::replaceAllCopy(tempp,
"std::",
"");
598 tempp = StringUtil::replaceAllCopy(tempp,
">",
"");
600 fres +=
"json += \"\\\""+name+
"\\\" : \";\n";
605 fres +=
"if(_obj"+typ+name+
"!=NULL)\n";
606 fres +=
"json += JSONSerialize::serialize<"+stlcnttyp+
"<"+tempp+
"> >(*_obj"+typ+name+
");\n";
609 fres +=
"json += JSONSerialize::serialize<"+stlcnttyp+
"<"+tempp+
"> >(_obj"+typ+name+
");\n";
615 fres +=
"if(_obj"+typ+
"get"+camelCased(name)+
"()!=NULL)\n";
616 fres +=
"json += JSONSerialize::serialize<"+stlcnttyp+
"<"+tempp+
"> >(*_obj"+typ+
"get"+camelCased(name)+
"());\n";
619 fres +=
"json += JSONSerialize::serialize<"+stlcnttyp+
"<"+tempp+
"> >(_obj"+typ+
"get"+camelCased(name)+
"());\n";
623 else if(Reflection::isValidClass(type))
627 if(!priv)fres +=
"json += \"\\\""+name+
"\\\" : \"+from"+type+
"ToJSON(_obj"+typ+name+
");";
628 else fres +=
"json += \"\\\""+name+
"\\\" : \"+from"+type+
"ToJSON(_obj"+typ+
"get"+camelCased(name)+
"());";
632 if(!priv)fres +=
"if(_obj"+typ+name+
"!=NULL)json += \"\\\""+name+
"\\\" : \"+from"+type+
"ToJSON(*_obj"+typ+name+
");\nelse json += \"null\";\n";
633 else fres +=
"if(_obj"+typ+
"get"+camelCased(name)+
"()!=NULL)json += \"\\\""+name+
"\\\" : \"+from"+type+
"ToJSON(*_obj"+typ+
"get"+camelCased(name)+
"());\nelse json += \"null\";\n";
636 if(i!=((
int)obj.size()-1))
638 fres +=
"json += \",\";\n";
644 string AfcUtil::generateToJSONVectorObjects(
string type,
string name,
bool priv,
string &retu,
string &headers,
string path,
string &objs,
string typ,
bool ptr,
string stlcnttyp)
646 string fres =
"json += \"\\\""+name+
"\\\" : [\";\n";
652 if(ptr)fres +=
"if(_obj"+typ+name+
"!=NULL)\n";
655 if(stlcnttyp==
"vector")
656 fres +=
"for(int j=0;j<_obj"+typ+name+vtyp+
"size();j++)\n{\n";
657 else if(stlcnttyp==
"list" || stlcnttyp==
"set" || stlcnttyp==
"multiset" || stlcnttyp==
"deque")
658 fres += stlcnttyp+
"<"+type+
">::iterator it"+name+
";\nint j"+name+
" = 0;\nfor(it"+name+
"=_obj"+typ+name+vtyp+
"begin();it"+name+
"!=_obj"+typ+name+vtyp+
"end();it"+name+
"++,j"+name+
"++)\n{\n";
662 fres +=
"std::queue<"+type+
"> tt"+name+
" = _obj"+typ+name+
";\nif(!tt"+name+vtyp+
"empty()){\n" +
663 "for(int j=0;j<(int)tt"+name+vtyp+
"size();j++)\n{\n";
665 fres +=
"std::queue<"+type+
">* tt"+name+
" = _obj"+typ+name+
";\nif(!tt"+name+
"->empty()){\n" +
666 "for(int j=0;j<(int)tt"+name+
"->size();j++)\n{\n";
671 if(stlcnttyp==
"vector")
672 fres +=
"for(int j=0;j<_obj"+typ+
"get"+camelCased(name)+
"()"+vtyp+
"size();j++)\n{\n";
673 else if(stlcnttyp==
"list" || stlcnttyp==
"set" || stlcnttyp==
"multiset" || stlcnttyp==
"deque")
674 fres += stlcnttyp+
"<"+type+
">::iterator it"+name+
";\nint j"+name+
" = 0;\nfor(it"+name+
"=_obj"+typ+
"get"+camelCased(name)+
"()"+vtyp+
"begin();it"+name+
"!=_obj"+typ+
"get"+camelCased(name)+
"()"+vtyp+
"end();it"+name+
"++,j"+name+
"++)\n{\n";
678 fres +=
"std::queue<"+type+
"> tt"+name+
" = _obj"+typ+
"get"+camelCased(name)+
"();\nif(!tt"+name+vtyp+
"empty()){\n" +
679 "for(int j=0;j<(int)tt"+name+vtyp+
"size();j++)\n{\n";
681 fres +=
"std::queue<"+type+
">* tt"+name+
" = _obj"+typ+
"get"+camelCased(name)+
"();\nif(!tt"+name+
"!=NULL && !tt"+name+
"->empty()){\n" +
682 "for(int j=0;j<(int)tt"+name+
"->size();j++)\n{\n";
685 if(type==
"int" || type==
"short" || type==
"long" || type==
"double" || type==
"float" || type==
"string" || type==
"bool")
691 if(stlcnttyp==
"vector")
693 if(!priv)fres +=
"json += \"\\\"\"+_obj"+typ+name+
".at(j)+\"\\\"\";";
694 else fres +=
"json += \"\\\"\"+_obj"+typ+
"get"+camelCased(name)+
"().at(j)+\"\\\"\";";
696 else if(stlcnttyp==
"list" || stlcnttyp==
"set" || stlcnttyp==
"multiset" || stlcnttyp==
"deque")
698 fres +=
"json += \"\\\"\";json += *it"+name+
";json += \"\\\"\";";
703 fres +=
"json += \"\\\"\";json += tt"+name+
".front();json +=\"\\\"\";\ntt"+name+
".pop();\n";
705 fres +=
"json += \"\\\"\";json += tt"+name+
"->front();json +=\"\\\"\";\ntt"+name+
"->pop();\n";
710 if(stlcnttyp==
"vector")
712 if(!priv)fres +=
"json += \"\\\"\"+_obj"+typ+name+
"->at(j)+\"\\\"\";";
713 else fres +=
"json += \"\\\"\"+_obj"+typ+
"get"+camelCased(name)+
"()->at(j)+\"\\\"\";";
715 else if(stlcnttyp==
"list" || stlcnttyp==
"set" || stlcnttyp==
"multiset" || stlcnttyp==
"deque")
717 fres +=
"json += \"\\\"\"+*it"+name+
"+\"\\\"\";";
722 fres +=
"json += \"\\\"\"+tt"+name+
".front()+\"\\\"\";\ntt"+name+
".pop();\n";
724 fres +=
"json += \"\\\"\"+tt"+name+
"->front()+\"\\\"\";\ntt"+name+
"->pop();\n";
732 if(stlcnttyp==
"vector")
734 if(!priv)fres +=
"json += CastUtil::lexical_cast<string>(_obj"+typ+name+
".at(j));";
735 else fres +=
"json += CastUtil::lexical_cast<string>(_obj"+typ+
"get"+camelCased(name)+
"().at(j));";
737 else if(stlcnttyp==
"list" || stlcnttyp==
"set" || stlcnttyp==
"multiset" || stlcnttyp==
"deque")
739 fres +=
"json += CastUtil::lexical_cast<string>(*it"+name+
");";
744 fres +=
"json += CastUtil::lexical_cast<string>(tt"+name+
".front());\ntt"+name+
".pop();\n";
746 fres +=
"json += CastUtil::lexical_cast<string>(tt"+name+
"->front());\ntt"+name+
"->pop();\n";
751 if(stlcnttyp==
"vector")
753 if(!priv)fres +=
"json += CastUtil::lexical_cast<string>(_obj"+typ+name+
"->at(j));";
754 else fres +=
"json += CastUtil::lexical_cast<string>(_obj"+typ+
"get"+camelCased(name)+
"()->at(j));";
756 else if(stlcnttyp==
"list" || stlcnttyp==
"set" || stlcnttyp==
"multiset" || stlcnttyp==
"deque")
758 fres +=
"json += CastUtil::lexical_cast<string>(*it"+name+
");";
763 fres +=
"json += CastUtil::lexical_cast<string>(tt"+name+
".front());\ntt"+name+
".pop();\n";
765 fres +=
"json += CastUtil::lexical_cast<string>(tt"+name+
"->front());\ntt"+name+
"->pop();\n";
770 else if(Reflection::isValidClass(type))
774 if(stlcnttyp==
"vector")
776 if(!priv)fres +=
"json += from"+type+
"ToJSON(_obj"+typ+name+
".at(j));";
777 else fres +=
"json += from"+type+
"ToJSON(_obj"+typ+
"get"+camelCased(name)+
"().at(j));";
779 else if(stlcnttyp==
"list" || stlcnttyp==
"set" || stlcnttyp==
"multiset" || stlcnttyp==
"deque")
781 if(!priv)fres +=
"json += from"+type+
"ToJSON(*it"+name+
");";
782 else fres +=
"json += from"+type+
"ToJSON(*it"+name+
");";
788 if(!priv)fres +=
"json += from"+type+
"ToJSON(tt"+name+
".front());\ntt"+name+
".pop();\n";
789 else fres +=
"json += from"+type+
"ToJSON(tt"+name+
".front());\ntt"+name+
".pop();\n";
793 if(!priv)fres +=
"json += from"+type+
"ToJSON(tt"+name+
"->front());\ntt"+name+
"->pop();\n";
794 else fres +=
"json += from"+type+
"ToJSON(tt"+name+
"->front());\ntt"+name+
"->pop();\n";
800 if(stlcnttyp==
"vector")
802 if(!priv)fres +=
"json += from"+type+
"ToJSON(_obj"+typ+name+
"->at(j));";
803 else fres +=
"json += from"+type+
"ToJSON(_obj"+typ+
"get"+camelCased(name)+
"()->at(j));";
805 else if(stlcnttyp==
"list" || stlcnttyp==
"set" || stlcnttyp==
"multiset" || stlcnttyp==
"deque")
807 if(!priv)fres +=
"json += from"+type+
"ToJSON(*it"+name+
");";
808 else fres +=
"json += from"+type+
"ToJSON(*it"+name+
");";
814 if(!priv)fres +=
"json += from"+type+
"ToJSON(tt"+name+
".front());\ntt"+name+
".pop();\n";
815 else fres +=
"json += from"+type+
"ToJSON(tt"+name+
".front());\ntt"+name+
".pop();\n";
819 if(!priv)fres +=
"json += from"+type+
"ToJSON(tt"+name+
"->front());\ntt"+name+
"->pop();\n";
820 else fres +=
"json += from"+type+
"ToJSON(tt"+name+
"->front());\ntt"+name+
"->pop();\n";
827 if(stlcnttyp==
"list" || stlcnttyp==
"set" || stlcnttyp==
"multiset" || stlcnttyp==
"deque")
828 fres +=
"\nif(j"+name+
"!=_obj"+typ+name+vtyp+
"size()-1)json += \",\";\n";
830 fres +=
"\nif(j!=_obj"+typ+name+vtyp+
"size()-1)json += \",\";\n";
834 if(stlcnttyp==
"list" || stlcnttyp==
"set" || stlcnttyp==
"multiset" || stlcnttyp==
"deque")
835 fres +=
"\nif(j"+name+
"!=_obj"+typ+
"get"+camelCased(name)+
"()"+vtyp+
"size()-1)json += \",\";\n";
837 fres +=
"\nif(j!=_obj"+typ+
"get"+camelCased(name)+
"()"+vtyp+
"size()-1)json += \",\";\n";
839 if(stlcnttyp==
"std::queue")
841 fres +=
"}\njson += \"]\";\n";
845 string AfcUtil::generateJsInterfaces(strVec obj,
string claz,
string &headers,
string path,
string &infjs,
string pv,map<string, string> ajintpthMap)
847 string test,intf,intff,inc;
848 headers +=
"#include \"" + claz +
".h\"\n";
852 test = (
"var " + claz +
"= {\n");
853 for(
unsigned int i=0;i<obj.size();i++)
856 string data = obj.at(i);
857 StringUtil::replaceFirst(data,
";",
"");
858 vector<string> delimiters;
859 delimiters.push_back(
" ");
860 delimiters.push_back(
",");
861 delimiters.push_back(
")");
862 delimiters.push_back(
"(");
863 StringUtil::split(vemp, data, delimiters);
864 for(
unsigned int k=0;k<vemp.size();k++)
867 emp.push_back(vemp.at(k));
873 size_t te = emp.at(1).find(
"~");
876 string pars,parswt,types,jsonstr;
879 test += emp.at(1) +
": function(_cb,_url,_cntxt){\n";
880 test +=
"AfcCall(\""+claz+
"\",\""+emp.at(1)+
"\",new Array("+jsonstr+
"),_cb,(_url==null?\""+ajintpthMap[claz]+
"\":_url),_cntxt);\n";
884 test += emp.at(1) +
": function(";
885 for(
unsigned int j=2;j<emp.size();j++)
887 stringstream st,st1,st2;
900 parswt += (
"string " + h);
905 if(emp.at(j)==
"string" || emp.at(j)==
"int" || emp.at(j)==
"float" || emp.at(j)==
"double")
907 types.append(emp.at(j).c_str());
912 types.append(h1.c_str());
913 types.append(
"=CastUtil::lexical_cast<");
914 types.append(emp.at(j).c_str());
915 types.append(
">(_inp.at(");
918 types.append(h1.c_str());
919 types.append(
").c_str());\n");
923 types.append(emp.at(j).c_str());
927 jsonstr +=
"JSON.stringify(_"+h1+
")";
928 types.append(h1.c_str());
929 types.append(
"=to"+emp.at(j)+
"(_inp.at(");
932 types.append(h1.c_str());
933 types.append(
"));\n");
944 test +=
",_cb,_url,_cntxt){\n";
945 test +=
"AfcCall(\""+claz+
"\",\""+emp.at(1)+
"\",new Array("+jsonstr+
"),_cb,(_url==null?\""+pv+
"\":_url),_cntxt);\n";
947 inc += updateAjaxInterface(emp,claz,pars,parswt,types);
967 string AfcUtil::updateAjaxInterface(strVec emp,
string claz,
string pars,
string parswt,
string types)
970 string retType = emp.at(0);
971 string funcName = emp.at(1);
973 test += (
"string invokeAjaxMethodFor" + claz + funcName +
"(strVec _inp");
974 test +=
")\n{\n" + types;
975 test += (claz +
" _obj;\n");
978 test +=
"return \"\";\n}\n";
980 else if(retType==
"string")
982 test +=
"return _obj."+funcName+
"("+pars+
");\n}\n";
984 else if(retType==
"int" || retType==
"float" || retType==
"double")
986 test +=
"string outp = CastUtil::lexical_cast<string>(_obj."+funcName+
"("+pars+
"));\nreturn outp;\n}\n";
989 test +=
"return from"+retType+
"ToJSON(_obj."+funcName+
"("+pars+
"));\n}\n";
997 logger <<
"Inside Ajax Interface Execute" << endl;
999 string methName = req.getRequestParam(
"method");
1002 res->setHTTPResponseStatus(HTTPResponseStatus::InternalServerError);
1005 string temp = req.getRequestParam(
"paramsize");
1010 paramSize = CastUtil::lexical_cast<
int>(temp.c_str());
1012 res->setHTTPResponseStatus(HTTPResponseStatus::InternalServerError);
1016 logger <<
"Reading Ajax params" << endl;
1017 for(
int i=0;i<paramSize;i++)
1025 string tem = req.getRequestParam(ss);
1026 vemp.push_back(tem);
1028 string libName = Constants::INTER_LIB_FILE;
1029 void *dlib = dlopen(libName.c_str(), RTLD_NOW);
1031 cerr << dlerror() << endl;
1036 metn =
"invokeAjaxMethodFor"+claz+methName;
1037 void *mkr = dlsym(dlib, metn.c_str());
1040 typedef string (*Funptr2) (strVec);
1041 Funptr2 f2 = (Funptr2)mkr;
1042 logger << (
"Calling method " + metn) << endl;
1044 logger <<
"Completed method call" << endl;
1045 res->setHTTPResponseStatus(HTTPResponseStatus::Ok);
1046 res->setContent_type(
"text/plain");
1047 res->setContent_str(re);
1052 res->setHTTPResponseStatus(HTTPResponseStatus::InternalServerError);
1058 void AfcUtil::writeTofile(
string fileName,
string data,
bool trunc)
1062 myfile1.open(fileName.c_str(),ios::trunc | ios::binary);
1064 myfile1.open(fileName.c_str(),ios::app | ios::binary);
1065 if (myfile1.is_open())
1067 myfile1.write(data.c_str(),data.length());
1073 string AfcUtil::camelCased(
const string& s)
1076 str[0] = toupper(str[0]);
1080 string AfcUtil::reverseCamelCased(
const string& s)
1083 str[0] = tolower(str[0]);