ffead.server.doc
Serialize.cpp
1 /*
2  Copyright 2009-2012, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  * Serialize.cpp
18  *
19  * Created on: Apr 2, 2010
20  * Author: sumeet
21  */
22 
23 #include "Serialize.h"
24 
25 string Serialize::demangle(const char *mangled)
26 {
27  int status; char *demangled;
28  using namespace abi;
29  demangled = __cxa_demangle(mangled, NULL, 0, &status);
30  string s(demangled);
31  delete demangled;
32  return s;
33 }
34 string Serialize::getClassName(void* instance)
35 {
36  const char *mangled = typeid(instance).name();
37  return demangle(mangled);
38 }
39 
40 string Serialize::_handleAllSerialization(string className,void *t)
41 {
42  string objXml;
43  AMEFEncoder enc;
44  AMEFObject object;
45 
46  if(className=="std::string" || className=="string")
47  {
48  string tem = *(string*)t;
49  object.setName(className);
50  object.addPacket(tem);
51  objXml = enc.encodeB(&object, false);
52  //objXml = CastUtil::lexical_cast<string>(tem);
53  }
54  else if(className=="int")
55  {
56  int tem = *(int*)t;
57  object.addPacket(tem, className);
58  objXml = enc.encodeB(&object, false);
59  //objXml = CastUtil::lexical_cast<string>(tem);
60  }
61  else if(className=="short")
62  {
63  short tem = *(short*)t;
64  object.addPacket(tem, className);
65  objXml = enc.encodeB(&object, false);
66  //objXml = CastUtil::lexical_cast<string>(tem);
67  }
68  else if(className=="long")
69  {
70  long tem = *(long*)t;
71  object.addPacket(tem, className);
72  objXml = enc.encodeB(&object, false);
73  //objXml = CastUtil::lexical_cast<string>(tem);
74  }
75  else if(className=="float")
76  {
77  float tem = *(float*)t;
78  object.addPacket(tem, className);
79  objXml = enc.encodeB(&object, false);
80  //objXml = CastUtil::lexical_cast<string>(tem);
81  }
82  else if(className=="double")
83  {
84  double tem = *(double*)t;
85  object.addPacket(tem, className);
86  objXml = enc.encodeB(&object, false);
87  //objXml = CastUtil::lexical_cast<string>(tem);
88  }
89  else if(className=="bool")
90  {
91  bool tem = *(bool*)t;
92  object.addPacket(tem, className);
93  objXml = enc.encodeB(&object, false);
94  //objXml = CastUtil::lexical_cast<string>(tem);
95  }
96  else if(className=="Date")
97  {
98  DateFormat formt("yyyy-mm-dd hh:mi:ss");
99  object.addPacket(formt.format(*(Date*)t), className);
100  objXml = enc.encodeB(&object, false);
101  //objXml = formt.format(*(Date*)t);
102  }
103  else if(className=="BinaryData")
104  {
105  object.addPacket(BinaryData::serilaize(*(BinaryData*)t), className);
106  objXml = enc.encodeB(&object, false);
107  //objXml = BinaryData::serilaize(*(BinaryData*)t);
108  }
109  else if(className.find("std::vector<std::string,")!=string::npos || className.find("std::vector<string,")!=string::npos)
110  {
111  vector<string> *tt = (vector<string>*)t;
112  objXml = serializevec<string>(*tt);
113  }
114  else if(className.find("std::vector<int,")!=string::npos)
115  {
116  vector<int> *tt = (vector<int>*)t;
117  objXml = serializevec<int>(*tt);
118  }
119  else if(className.find("std::vector<short,")!=string::npos)
120  {
121  vector<short> *tt = (vector<short>*)t;
122  objXml = serializevec<short>(*tt);
123  }
124  else if(className.find("std::vector<long,")!=string::npos)
125  {
126  vector<long> *tt = (vector<long>*)t;
127  objXml = serializevec<long>(*tt);
128  }
129  else if(className.find("std::vector<double,")!=string::npos)
130  {
131  vector<double> *tt = (vector<double>*)t;
132  objXml = serializevec<double>(*tt);
133  }
134  else if(className.find("std::vector<float,")!=string::npos)
135  {
136  vector<float> *tt = (vector<float>*)t;
137  objXml = serializevec<float>(*tt);
138  }
139  else if(className.find("std::vector<bool,")!=string::npos)
140  {
141  vector<bool> *tt = (vector<bool>*)t;
142  objXml = serializevec<bool>(*tt);
143  }
144  else if(className.find("std::vector<")!=string::npos)
145  {
146  StringUtil::replaceFirst(className,"std::vector<","");
147  string vtyp = className.substr(0,className.find(","));
148  return _servec(t,vtyp);
149  }
150  else if(className.find("std::list<std::string,")!=string::npos || className.find("std::list<string,")!=string::npos)
151  {
152  list<string> *tt = (list<string>*)t;
153  objXml = serializelist<string>(*tt);
154  }
155  else if(className.find("std::list<int,")!=string::npos)
156  {
157  list<int> *tt = (list<int>*)t;
158  objXml = serializelist<int>(*tt);
159  }
160  else if(className.find("std::list<long,")!=string::npos)
161  {
162  list<long> *tt = (list<long>*)t;
163  objXml = serializelist<long>(*tt);
164  }
165  else if(className.find("std::list<short,")!=string::npos)
166  {
167  list<short> *tt = (list<short>*)t;
168  objXml = serializelist<short>(*tt);
169  }
170  else if(className.find("std::list<double,")!=string::npos)
171  {
172  list<double> *tt = (list<double>*)t;
173  objXml = serializelist<double>(*tt);
174  }
175  else if(className.find("std::list<float,")!=string::npos)
176  {
177  list<float> *tt = (list<float>*)t;
178  objXml = serializelist<float>(*tt);
179  }
180  else if(className.find("std::list<bool,")!=string::npos)
181  {
182  list<bool> *tt = (list<bool>*)t;
183  objXml = serializelist<bool>(*tt);
184  }
185  else if(className.find("std::list<")!=string::npos)
186  {
187  StringUtil::replaceFirst(className,"std::list<","");
188  string vtyp = className.substr(0,className.find(","));
189  return _serlis(t,vtyp);
190  }
191  else if(className.find("std::set<std::string,")!=string::npos || className.find("std::set<string,")!=string::npos)
192  {
193  set<string> *tt = (set<string>*)t;
194  objXml = serializeset<string>(*tt);
195  }
196  else if(className.find("std::set<int,")!=string::npos)
197  {
198  set<int> *tt = (set<int>*)t;
199  objXml = serializeset<int>(*tt);
200  }
201  else if(className.find("std::set<short,")!=string::npos)
202  {
203  set<short> *tt = (set<short>*)t;
204  objXml = serializeset<short>(*tt);
205  }
206  else if(className.find("std::set<long,")!=string::npos)
207  {
208  set<long> *tt = (set<long>*)t;
209  objXml = serializeset<long>(*tt);
210  }
211  else if(className.find("std::set<double,")!=string::npos)
212  {
213  set<double> *tt = (set<double>*)t;
214  objXml = serializeset<double>(*tt);
215  }
216  else if(className.find("std::set<float,")!=string::npos)
217  {
218  set<float> *tt = (set<float>*)&t;
219  objXml = serializeset<float>(*tt);
220  }
221  else if(className.find("std::set<bool,")!=string::npos)
222  {
223  set<bool> *tt = (set<bool>*)&t;
224  objXml = serializeset<bool>(*tt);
225  }
226  else if(className.find("std::set<")!=string::npos)
227  {
228  StringUtil::replaceFirst(className,"std::set<","");
229  string vtyp = className.substr(0,className.find(","));
230  return _serset(t,vtyp);
231  }
232  else if(className.find("std::multiset<std::string,")!=string::npos || className.find("std::multiset<string,")!=string::npos)
233  {
234  multiset<string> *tt = (multiset<string>*)t;
235  objXml = serializemultiset<string>(*tt);
236  }
237  else if(className.find("std::multiset<int,")!=string::npos)
238  {
239  multiset<int> *tt = (multiset<int>*)t;
240  objXml = serializemultiset<int>(*tt);
241  }
242  else if(className.find("std::multiset<long,")!=string::npos)
243  {
244  multiset<long> *tt = (multiset<long>*)t;
245  objXml = serializemultiset<long>(*tt);
246  }
247  else if(className.find("std::multiset<short,")!=string::npos)
248  {
249  multiset<short> *tt = (multiset<short>*)t;
250  objXml = serializemultiset<short>(*tt);
251  }
252  else if(className.find("std::multiset<double,")!=string::npos)
253  {
254  multiset<double> *tt = (multiset<double>*)t;
255  objXml = serializemultiset<double>(*tt);
256  }
257  else if(className.find("std::multiset<float,")!=string::npos)
258  {
259  multiset<float> *tt = (multiset<float>*)t;
260  objXml = serializemultiset<float>(*tt);
261  }
262  else if(className.find("std::multiset<bool,")!=string::npos)
263  {
264  multiset<bool> *tt = (multiset<bool>*)t;
265  objXml = serializemultiset<bool>(*tt);
266  }
267  else if(className.find("std::multiset<")!=string::npos)
268  {
269  StringUtil::replaceFirst(className,"std::multiset<","");
270  string vtyp = className.substr(0,className.find(","));
271  return _sermultiset(t,vtyp);
272  }
273  else if(className.find("std::queue<std::string,")!=string::npos || className.find("std::queue<string,")!=string::npos)
274  {
275  std::queue<string> *tt = (std::queue<string>*)t;
276  objXml = serializeq<string>(*tt);
277  }
278  else if(className.find("std::queue<int,")!=string::npos)
279  {
280  std::queue<int> *tt = (std::queue<int>*)t;
281  objXml = serializeq<int>(*tt);
282  }
283  else if(className.find("std::queue<short,")!=string::npos)
284  {
285  std::queue<short> *tt = (std::queue<short>*)t;
286  objXml = serializeq<short>(*tt);
287  }
288  else if(className.find("std::queue<long,")!=string::npos)
289  {
290  std::queue<long> *tt = (std::queue<long>*)t;
291  objXml = serializeq<long>(*tt);
292  }
293  else if(className.find("std::queue<double,")!=string::npos)
294  {
295  std::queue<double> *tt = (std::queue<double>*)t;
296  objXml = serializeq<double>(*tt);
297  }
298  else if(className.find("std::queue<float,")!=string::npos)
299  {
300  std::queue<float> *tt = (std::queue<float>*)t;
301  objXml = serializeq<float>(*tt);
302  }
303  else if(className.find("std::queue<bool,")!=string::npos)
304  {
305  std::queue<bool> *tt = (std::queue<bool>*)t;
306  objXml = serializeq<bool>(*tt);
307  }
308  else if(className.find("std::queue<")!=string::npos)
309  {
310  StringUtil::replaceFirst(className,"std::queue<","");
311  string vtyp = className.substr(0,className.find(","));
312  return _serq(t,vtyp);
313  }
314  else if(className.find("std::deque<std::string,")!=string::npos || className.find("std::deque<string,")!=string::npos)
315  {
316  deque<string> *tt = (deque<string>*)t;
317  objXml = serializedq<string>(*tt);
318  }
319  else if(className.find("std::deque<int,")!=string::npos)
320  {
321  deque<int> *tt = (deque<int>*)t;
322  objXml = serializedq<int>(*tt);
323  }
324  else if(className.find("std::deque<long,")!=string::npos)
325  {
326  deque<long> *tt = (deque<long>*)t;
327  objXml = serializedq<long>(*tt);
328  }
329  else if(className.find("std::deque<short,")!=string::npos)
330  {
331  deque<short> *tt = (deque<short>*)t;
332  objXml = serializedq<short>(*tt);
333  }
334  else if(className.find("std::deque<double,")!=string::npos)
335  {
336  deque<double> *tt = (deque<double>*)t;
337  objXml = serializedq<double>(*tt);
338  }
339  else if(className.find("std::deque<float,")!=string::npos)
340  {
341  deque<float> *tt = (deque<float>*)t;
342  objXml = serializedq<float>(*tt);
343  }
344  else if(className.find("std::deque<bool,")!=string::npos)
345  {
346  deque<bool> *tt = (deque<bool>*)t;
347  objXml = serializedq<bool>(*tt);
348  }
349  else if(className.find("std::deque<")!=string::npos)
350  {
351  StringUtil::replaceFirst(className,"std::deque<","");
352  string vtyp = className.substr(0,className.find(","));
353  return _serdq(t,vtyp);
354  }
355  else
356  {
357  return _ser(t,className);
358  }
359  return objXml;
360 }
361 
362 string Serialize::_servec(void* t,string className)
363 {
364  string objXml;
365  string libName = Constants::INTER_LIB_FILE;
366  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
367  if(dlib == NULL)
368  {
369  cerr << dlerror() << endl;
370  exit(-1);
371  }
372  string methodname = "binarySerialize"+className+"Vec";
373  void *mkr = dlsym(dlib, methodname.c_str());
374  typedef string (*RfPtr) (void*);
375  RfPtr f = (RfPtr)mkr;
376  if(f!=NULL)
377  objXml = f(t);
378  return objXml;
379 }
380 
381 string Serialize::_serlis(void* t,string className)
382 {
383  string objXml;
384  string libName = Constants::INTER_LIB_FILE;
385  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
386  if(dlib == NULL)
387  {
388  cerr << dlerror() << endl;
389  exit(-1);
390  }
391  string methodname = "binarySerialize"+className+"Lis";
392  void *mkr = dlsym(dlib, methodname.c_str());
393  typedef string (*RfPtr) (void*);
394  RfPtr f = (RfPtr)mkr;
395  if(f!=NULL)
396  objXml = f(t);
397  return objXml;
398 }
399 string Serialize::_serset(void* t,string className)
400 {
401  string objXml;
402  string libName = Constants::INTER_LIB_FILE;
403  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
404  if(dlib == NULL)
405  {
406  cerr << dlerror() << endl;
407  exit(-1);
408  }
409  string methodname = "binarySerialize"+className+"Set";
410  void *mkr = dlsym(dlib, methodname.c_str());
411  typedef string (*RfPtr) (void*);
412  RfPtr f = (RfPtr)mkr;
413  if(f!=NULL)
414  objXml = f(t);
415  return objXml;
416 }
417 string Serialize::_sermultiset(void* t,string className)
418 {
419  string objXml;
420  string libName = Constants::INTER_LIB_FILE;
421  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
422  if(dlib == NULL)
423  {
424  cerr << dlerror() << endl;
425  exit(-1);
426  }
427  string methodname = "binarySerialize"+className+"MulSet";
428  void *mkr = dlsym(dlib, methodname.c_str());
429  typedef string (*RfPtr) (void*);
430  RfPtr f = (RfPtr)mkr;
431  if(f!=NULL)
432  objXml = f(t);
433  return objXml;
434 }
435 string Serialize::_serq(void* t,string className)
436 {
437  string objXml;
438  string libName = Constants::INTER_LIB_FILE;
439  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
440  if(dlib == NULL)
441  {
442  cerr << dlerror() << endl;
443  exit(-1);
444  }
445  string methodname = "binarySerialize"+className+"Q";
446  void *mkr = dlsym(dlib, methodname.c_str());
447  typedef string (*RfPtr) (void*);
448  RfPtr f = (RfPtr)mkr;
449  if(f!=NULL)
450  objXml = f(t);
451  return objXml;
452 }
453 string Serialize::_serdq(void* t,string className)
454 {
455  string objXml;
456  string libName = Constants::INTER_LIB_FILE;
457  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
458  if(dlib == NULL)
459  {
460  cerr << dlerror() << endl;
461  exit(-1);
462  }
463  string methodname = "binarySerialize"+className+"Dq";
464  void *mkr = dlsym(dlib, methodname.c_str());
465  typedef string (*RfPtr) (void*);
466  RfPtr f = (RfPtr)mkr;
467  if(f!=NULL)
468  objXml = f(t);
469  return objXml;
470 }
471 
472 string Serialize::_ser(void* t,string className)
473 {
474  string objXml;
475  string libName = Constants::INTER_LIB_FILE;
476  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
477  if(dlib == NULL)
478  {
479  cerr << dlerror() << endl;
480  exit(-1);
481  }
482  string methodname = "binarySerialize"+className;
483  void *mkr = dlsym(dlib, methodname.c_str());
484  typedef string (*RfPtr) (void*);
485  RfPtr f = (RfPtr)mkr;
486  if(f!=NULL)
487  objXml = f(t);
488  return objXml;
489 }
490 
491 string Serialize::_ser(Object t)
492 {
493  return _ser(t.getVoidPointer(),t.getTypeName());
494 }
495 
496 
497 void* Serialize::_handleAllUnSerialization(string objXml,string className)
498 {
499  AMEFDecoder dec;
500  AMEFObject* root = dec.decodeB(objXml, true, false);
501  if(root==NULL || root->getNameStr()=="")
502  return NULL;
503  if(root->getNameStr()==className &&
504  (className=="std::string" || className=="string" || className=="int" || className=="short" ||
505  className=="bool" || className=="long" || className=="float" || className=="double"))
506  {
507  if(className=="int")
508  {
509  int *vt = new int;
510  *vt = root->getIntValue();
511  return vt;
512  }
513  else if(className=="short")
514  {
515  short *vt = new short;
516  *vt = root->getShortValue();
517  return vt;
518  }
519  else if(className=="long")
520  {
521  long *vt = new long;
522  *vt = root->getLongValue();
523  return vt;
524  }
525  else if(className=="Date")
526  {
527  DateFormat formt("yyyy-mm-dd hh:mi:ss");
528  return formt.parse(root->getValueStr());
529  }
530  else if(className=="BinaryData")
531  {
532  return BinaryData::unSerilaize(root->getValueStr());
533  }
534  else if(className=="float")
535  {
536  float *vt = new float;
537  *vt = root->getFloatValue();
538  return vt;
539  }
540  else if(className=="double")
541  {
542  double *vt = new double;
543  *vt = root->getDoubleValue();
544  return vt;
545  }
546  else if(className=="bool")
547  {
548  bool *vt = new bool;
549  *vt = root->getBoolValue();
550  return vt;
551  }
552  else if(className=="std::string" || className=="string")
553  {
554  string *vt = new string;
555  *vt = root->getValueStr();
556  return vt;
557  }
558  }
559  if(root->getNameStr().find("vector<")==0)
560  {
561  return unserializevec(root, objXml);
562  }
563  else if(root->getNameStr().find("set<")==0)
564  {
565  return unserializeset(root, objXml);
566  }
567  else if(root->getNameStr().find("multiset<")==0)
568  {
569  return unserializemultiset(root, objXml);
570  }
571  else if(root->getNameStr().find("list<")==0)
572  {
573  return unserializelist(root, objXml);
574  }
575  else if(root->getNameStr().find("std::queue<")==0 || root->getNameStr().find("queue<")==0)
576  {
577  return unserializeq(root, objXml);
578  }
579  else if(root->getNameStr().find("deque<")==0)
580  {
581  return unserializedq(root, objXml);
582  }
583  return _unser(objXml,className);
584 }
585 
586 void* Serialize::unserializeset(AMEFObject* root, string objXml)
587 {
588  AMEFDecoder dec;
589  string stlclassName = root->getNameStr();
590  string className = stlclassName.substr(4,stlclassName.find(">")-4);
591  void* t = NULL;
592  if(className=="std::string" || className=="string")
593  t = new set<string>();
594  else if(className=="int")
595  t = new set<int>();
596  else if(className=="short")
597  t = new set<short>();
598  else if(className=="long")
599  t = new set<long>();
600  else if(className=="float")
601  t = new set<float>();
602  else if(className=="double")
603  t = new set<double>();
604  else if(className=="bool")
605  t = new set<bool>();
606  else
607  {
608  return _unserSet(objXml,className);
609  }
610  if(t!=NULL)
611  {
612  for (int var = 0; var < (int)root->getPackets().size(); var++)
613  {
614  AMEFObject* root2 = dec.decodeB(root->getPackets().at(var)->getValue(), true, false);
615  if(className=="std::string" || className=="string")
616  ((set<string>*)t)->insert(root2->getPackets().at(0)->getValueStr());
617  else if(className=="int")
618  ((set<int>*)t)->insert(root2->getPackets().at(0)->getIntValue());
619  else if(className=="short")
620  ((set<short>*)t)->insert(root2->getPackets().at(0)->getShortValue());
621  else if(className=="long")
622  ((set<long>*)t)->insert(root2->getPackets().at(0)->getNumericValue());
623  else if(className=="float")
624  ((set<float>*)t)->insert(root2->getPackets().at(0)->getFloatValue());
625  else if(className=="double")
626  ((set<double>*)t)->insert(root2->getPackets().at(0)->getDoubleValue());
627  else if(className=="bool")
628  ((set<bool>*)t)->insert(root2->getPackets().at(0)->getBoolValue());
629  }
630  return t;
631  }
632  return NULL;
633 }
634 
635 void* Serialize::unserializelist(AMEFObject* root, string objXml)
636 {
637  AMEFDecoder dec;
638  string stlclassName = root->getNameStr();
639  string className = stlclassName.substr(5,stlclassName.find(">")-5);
640  void* t = NULL;
641  if(className=="std::string" || className=="string")
642  t = new list<string>();
643  else if(className=="int")
644  t = new list<int>();
645  else if(className=="short")
646  t = new list<short>();
647  else if(className=="long")
648  t = new list<long>();
649  else if(className=="float")
650  t = new list<float>();
651  else if(className=="double")
652  t = new list<double>();
653  else if(className=="bool")
654  t = new list<bool>();
655  else
656  {
657  return _unserLis(objXml,className);
658  }
659  if(t!=NULL)
660  {
661  for (int var = 0; var < (int)root->getPackets().size(); var++)
662  {
663  AMEFObject* root2 = dec.decodeB(root->getPackets().at(var)->getValue(), true, false);
664  if(className=="std::string" || className=="string")
665  ((list<string>*)t)->push_back(root2->getPackets().at(0)->getValueStr());
666  else if(className=="int")
667  ((list<int>*)t)->push_back(root2->getPackets().at(0)->getIntValue());
668  else if(className=="short")
669  ((list<short>*)t)->push_back(root2->getPackets().at(0)->getShortValue());
670  else if(className=="long")
671  ((list<long>*)t)->push_back(root2->getPackets().at(0)->getNumericValue());
672  else if(className=="float")
673  ((list<float>*)t)->push_back(root2->getPackets().at(0)->getFloatValue());
674  else if(className=="double")
675  ((list<double>*)t)->push_back(root2->getPackets().at(0)->getDoubleValue());
676  else if(className=="bool")
677  ((list<bool>*)t)->push_back(root2->getPackets().at(0)->getBoolValue());
678  }
679  return t;
680  }
681  return NULL;
682 }
683 
684 void* Serialize::unserializeq(AMEFObject* root, string objXml)
685 {
686  AMEFDecoder dec;
687  string stlclassName = root->getNameStr();
688  string className = stlclassName.substr(6,stlclassName.find(">")-6);
689  void* t = NULL;
690  if(className=="std::string" || className=="string")
691  t = new std::queue<string>();
692  else if(className=="int")
693  t = new std::queue<int>();
694  else if(className=="short")
695  t = new std::queue<short>();
696  else if(className=="long")
697  t = new std::queue<long>();
698  else if(className=="float")
699  t = new std::queue<float>();
700  else if(className=="double")
701  t = new std::queue<double>();
702  else if(className=="bool")
703  t = new std::queue<bool>();
704  else
705  {
706  return _unserQ(objXml,className);
707  }
708  if(t!=NULL)
709  {
710  for (int var = 0; var < (int)root->getPackets().size(); var++)
711  {
712  AMEFObject* root2 = dec.decodeB(root->getPackets().at(var)->getValue(), true, false);
713  if(className=="std::string" || className=="string")
714  ((std::queue<string>*)t)->push(root2->getPackets().at(0)->getValueStr());
715  else if(className=="int")
716  ((std::queue<int>*)t)->push(root2->getPackets().at(0)->getIntValue());
717  else if(className=="short")
718  ((std::queue<short>*)t)->push(root2->getPackets().at(0)->getShortValue());
719  else if(className=="long")
720  ((std::queue<long>*)t)->push(root2->getPackets().at(0)->getNumericValue());
721  else if(className=="float")
722  ((std::queue<float>*)t)->push(root2->getPackets().at(0)->getFloatValue());
723  else if(className=="double")
724  ((std::queue<double>*)t)->push(root2->getPackets().at(0)->getDoubleValue());
725  else if(className=="bool")
726  ((std::queue<bool>*)t)->push(root2->getPackets().at(0)->getBoolValue());
727  }
728  return t;
729  }
730  return NULL;
731 }
732 
733 void* Serialize::unserializevec(AMEFObject* root, string objXml)
734 {
735  AMEFDecoder dec;
736  string stlclassName = root->getNameStr();
737  string className = stlclassName.substr(7,stlclassName.find(">")-7);
738  void* t = NULL;
739  if(className=="std::string" || className=="string")
740  t = new vector<string>();
741  else if(className=="int")
742  t = new vector<int>();
743  else if(className=="short")
744  t = new vector<short>();
745  else if(className=="long")
746  t = new vector<long>();
747  else if(className=="float")
748  t = new vector<float>();
749  else if(className=="double")
750  t = new vector<double>();
751  else if(className=="bool")
752  t = new vector<bool>();
753  else
754  {
755  return _unserVec(objXml,className);
756  }
757  if(t!=NULL)
758  {
759  for (int var = 0; var < (int)root->getPackets().size(); var++)
760  {
761  AMEFObject* root2 = dec.decodeB(root->getPackets().at(var)->getValue(), true, false);
762  if(className=="std::string" || className=="string")
763  ((vector<string>*)t)->push_back(root2->getPackets().at(0)->getValueStr());
764  else if(className=="int")
765  ((vector<int>*)t)->push_back(root2->getPackets().at(0)->getIntValue());
766  else if(className=="short")
767  ((vector<short>*)t)->push_back(root2->getPackets().at(0)->getShortValue());
768  else if(className=="long")
769  ((vector<long>*)t)->push_back(root2->getPackets().at(0)->getNumericValue());
770  else if(className=="float")
771  ((vector<float>*)t)->push_back(root2->getPackets().at(0)->getFloatValue());
772  else if(className=="double")
773  ((vector<double>*)t)->push_back(root2->getPackets().at(0)->getDoubleValue());
774  else if(className=="bool")
775  ((vector<bool>*)t)->push_back(root2->getPackets().at(0)->getBoolValue());
776  }
777  return t;
778  }
779  return NULL;
780 }
781 
782 void* Serialize::unserializedq(AMEFObject* root, string objXml)
783 {
784  AMEFDecoder dec;
785  string stlclassName = root->getNameStr();
786  string className = stlclassName.substr(6,stlclassName.find(">")-6);
787  void* t = NULL;
788  if(className=="std::string" || className=="string")
789  t = new deque<string>();
790  else if(className=="int")
791  t = new deque<int>();
792  else if(className=="short")
793  t = new deque<short>();
794  else if(className=="long")
795  t = new deque<long>();
796  else if(className=="float")
797  t = new deque<float>();
798  else if(className=="double")
799  t = new deque<double>();
800  else if(className=="bool")
801  t = new deque<bool>();
802  else
803  {
804  return _unserDq(objXml,className);
805  }
806  if(t!=NULL)
807  {
808  for (int var = 0; var < (int)root->getPackets().size(); var++)
809  {
810  AMEFObject* root2 = dec.decodeB(root->getPackets().at(var)->getValue(), true, false);
811  if(className=="std::string" || className=="string")
812  ((deque<string>*)t)->push_back(root2->getPackets().at(0)->getValueStr());
813  else if(className=="int")
814  ((deque<int>*)t)->push_back(root2->getPackets().at(0)->getIntValue());
815  else if(className=="short")
816  ((deque<short>*)t)->push_back(root2->getPackets().at(0)->getShortValue());
817  else if(className=="long")
818  ((deque<long>*)t)->push_back(root2->getPackets().at(0)->getNumericValue());
819  else if(className=="float")
820  ((deque<float>*)t)->push_back(root2->getPackets().at(0)->getFloatValue());
821  else if(className=="double")
822  ((deque<double>*)t)->push_back(root2->getPackets().at(0)->getDoubleValue());
823  else if(className=="bool")
824  ((deque<bool>*)t)->push_back(root2->getPackets().at(0)->getBoolValue());
825  }
826  return t;
827  }
828  return NULL;
829 }
830 
831 void* Serialize::unserializemultiset(AMEFObject* root, string objXml)
832 {
833  AMEFDecoder dec;
834  string stlclassName = root->getNameStr();
835  string className = stlclassName.substr(9,stlclassName.find(">")-9);
836  void* t = NULL;
837  if(className=="std::string" || className=="string")
838  t = new multiset<string>();
839  else if(className=="int")
840  t = new multiset<int>();
841  else if(className=="short")
842  t = new multiset<short>();
843  else if(className=="long")
844  t = new multiset<long>();
845  else if(className=="float")
846  t = new multiset<float>();
847  else if(className=="double")
848  t = new multiset<double>();
849  else if(className=="bool")
850  t = new multiset<bool>();
851  else
852  {
853  return _unserMulSet(objXml,className);
854  }
855  if(t!=NULL)
856  {
857  for (int var = 0; var < (int)root->getPackets().size(); var++)
858  {
859  AMEFObject* root2 = dec.decodeB(root->getPackets().at(var)->getValue(), true, false);
860  if(className=="std::string" || className=="string")
861  ((multiset<string>*)t)->insert(root2->getPackets().at(0)->getValueStr());
862  else if(className=="int")
863  ((multiset<int>*)t)->insert(root2->getPackets().at(0)->getIntValue());
864  else if(className=="short")
865  ((multiset<short>*)t)->insert(root2->getPackets().at(0)->getShortValue());
866  else if(className=="long")
867  ((multiset<long>*)t)->insert(root2->getPackets().at(0)->getNumericValue());
868  else if(className=="float")
869  ((multiset<float>*)t)->insert(root2->getPackets().at(0)->getFloatValue());
870  else if(className=="double")
871  ((multiset<double>*)t)->insert(root2->getPackets().at(0)->getDoubleValue());
872  else if(className=="bool")
873  ((multiset<bool>*)t)->insert(root2->getPackets().at(0)->getBoolValue());
874  }
875  return t;
876  }
877  return NULL;
878 }
879 
880 void* Serialize::_unserSet(string objXml,string className)
881 {
882  void* obj = NULL;
883  string libName = Constants::INTER_LIB_FILE;
884  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
885  if(dlib == NULL)
886  {
887  cerr << dlerror() << endl;
888  exit(-1);
889  }
890  string methodname = "binaryUnSerialize"+className+"Set";
891  void *mkr = dlsym(dlib, methodname.c_str());
892  typedef void* (*RfPtr) (string);
893  RfPtr f = (RfPtr)mkr;
894  if(f!=NULL)
895  {
896  obj = f(objXml);
897  }
898  return obj;
899 }
900 
901 void* Serialize::_unserMulSet(string objXml,string className)
902 {
903  void* obj = NULL;
904  string libName = Constants::INTER_LIB_FILE;
905  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
906  if(dlib == NULL)
907  {
908  cerr << dlerror() << endl;
909  exit(-1);
910  }
911  string methodname = "binaryUnSerialize"+className+"MulSet";
912  void *mkr = dlsym(dlib, methodname.c_str());
913  typedef void* (*RfPtr) (string);
914  RfPtr f = (RfPtr)mkr;
915  if(f!=NULL)
916  {
917  obj = f(objXml);
918  }
919  return obj;
920 }
921 
922 void* Serialize::_unserQ(string objXml,string className)
923 {
924  void* obj = NULL;
925  string libName = Constants::INTER_LIB_FILE;
926  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
927  if(dlib == NULL)
928  {
929  cerr << dlerror() << endl;
930  exit(-1);
931  }
932  string methodname = "binaryUnSerialize"+className+"Q";
933  void *mkr = dlsym(dlib, methodname.c_str());
934  typedef void* (*RfPtr) (string);
935  RfPtr f = (RfPtr)mkr;
936  if(f!=NULL)
937  {
938  obj = f(objXml);
939  }
940  return obj;
941 }
942 
943 void* Serialize::_unserDq(string objXml,string className)
944 {
945  void* obj = NULL;
946  string libName = Constants::INTER_LIB_FILE;
947  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
948  if(dlib == NULL)
949  {
950  cerr << dlerror() << endl;
951  exit(-1);
952  }
953  string methodname = "binaryUnSerialize"+className+"Dq";
954  void *mkr = dlsym(dlib, methodname.c_str());
955  typedef void* (*RfPtr) (string);
956  RfPtr f = (RfPtr)mkr;
957  if(f!=NULL)
958  {
959  obj = f(objXml);
960  }
961  return obj;
962 }
963 
964 void* Serialize::_unserLis(string objXml,string className)
965 {
966  void* obj = NULL;
967  string libName = Constants::INTER_LIB_FILE;
968  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
969  if(dlib == NULL)
970  {
971  cerr << dlerror() << endl;
972  exit(-1);
973  }
974  string methodname = "binaryUnSerialize"+className+"Lis";
975  void *mkr = dlsym(dlib, methodname.c_str());
976  typedef void* (*RfPtr) (string);
977  RfPtr f = (RfPtr)mkr;
978  if(f!=NULL)
979  {
980  obj = f(objXml);
981  }
982  return obj;
983 }
984 
985 void* Serialize::_unserVec(string objXml,string className)
986 {
987  void* obj = NULL;
988  string libName = Constants::INTER_LIB_FILE;
989  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
990  if(dlib == NULL)
991  {
992  cerr << dlerror() << endl;
993  exit(-1);
994  }
995  string methodname = "binaryUnSerialize"+className+"Vec";
996  void *mkr = dlsym(dlib, methodname.c_str());
997  typedef void* (*RfPtr) (string);
998  RfPtr f = (RfPtr)mkr;
999  if(f!=NULL)
1000  {
1001  obj = f(objXml);
1002  }
1003  return obj;
1004 }
1005 
1006 
1007 void* Serialize::_unser(string objXml,string className)
1008 {
1009  void* obj = NULL;
1010  string libName = Constants::INTER_LIB_FILE;
1011  void *dlib = dlopen(libName.c_str(), RTLD_NOW);
1012  if(dlib == NULL)
1013  {
1014  cerr << dlerror() << endl;
1015  exit(-1);
1016  }
1017  string methodname = "binaryUnSerialize"+className;
1018  void *mkr = dlsym(dlib, methodname.c_str());
1019  typedef void* (*RfPtr) (string);
1020  RfPtr f = (RfPtr)mkr;
1021  if(f!=NULL)
1022  {
1023  obj = f(objXml);
1024  }
1025  return obj;
1026 }