My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
marshal.cpp
Go to the documentation of this file.
1 #include <qfile.h>
2 #include <assert.h>
3 
4 #include "sortdict.h"
5 #include "marshal.h"
6 #include "entry.h"
7 #include "section.h"
8 #include "memberlist.h"
9 #include "definition.h"
10 #include "groupdef.h"
11 #include "example.h"
12 #include "arguments.h"
13 
14 #define HEADER ('D'<<24)+('O'<<16)+('X'<<8)+'!'
15 
16 void marshalInt(StorageIntf *s,int v)
17 {
18  uchar b[4];
19  b[0]=((uint)v)>>24;
20  b[1]=(((uint)v)>>16)&0xff;
21  b[2]=(((uint)v)>>8)&0xff;
22  b[3]=v&0xff;
23  s->write((const char *)b,4);
24 }
25 
26 void marshalUInt(StorageIntf *s,uint v)
27 {
28  uchar b[4];
29  b[0]=v>>24;
30  b[1]=(v>>16)&0xff;
31  b[2]=(v>>8)&0xff;
32  b[3]=v&0xff;
33  s->write((const char *)b,4);
34 }
35 
36 void marshalUInt64(StorageIntf *s,uint64 v)
37 {
38  marshalUInt(s, uint(v>>32));
39  marshalUInt(s, uint(v&0xFFFFFFFF));
40 }
41 
42 void marshalBool(StorageIntf *s,bool b)
43 {
44  char c = b;
45  s->write(&c,sizeof(char));
46 }
47 
48 void marshalQCString(StorageIntf *s,const QCString &str)
49 {
50  uint l=str.length();
51  marshalUInt(s,l);
52  if (l>0) s->write(str.data(),l);
53 }
54 
55 void marshalQGString(StorageIntf *s,const QGString &str)
56 {
57  uint l=str.length();
58  marshalUInt(s,l);
59  if (l>0) s->write(str.data(),l);
60 }
61 
63 {
64  ArgumentList::marshal(s,argList);
65 }
66 
67 void marshalArgumentLists(StorageIntf *s,QList<ArgumentList> *argLists)
68 {
69  if (argLists==0)
70  {
71  marshalUInt(s,NULL_LIST); // null pointer representation
72  }
73  else
74  {
75  marshalUInt(s,argLists->count());
76  QListIterator<ArgumentList> ali(*argLists);
77  ArgumentList *al;
78  for (ali.toFirst();(al=ali.current());++ali)
79  {
80  marshalArgumentList(s,al);
81  }
82  }
83 }
84 
85 void marshalBaseInfoList(StorageIntf *s, QList<BaseInfo> *baseList)
86 {
87  if (baseList==0)
88  {
89  marshalUInt(s,NULL_LIST); // null pointer representation
90  }
91  else
92  {
93  marshalUInt(s,baseList->count());
94  QListIterator<BaseInfo> bli(*baseList);
95  BaseInfo *bi;
96  for (bli.toFirst();(bi=bli.current());++bli)
97  {
98  marshalQCString(s,bi->name);
99  marshalInt(s,(int)bi->prot);
100  marshalInt(s,(int)bi->virt);
101  }
102  }
103 }
104 
105 void marshalGroupingList(StorageIntf *s, QList<Grouping> *groups)
106 {
107  if (groups==0)
108  {
109  marshalUInt(s,NULL_LIST); // null pointer representation
110  }
111  else
112  {
113  marshalUInt(s,groups->count());
114  QListIterator<Grouping> gli(*groups);
115  Grouping *g;
116  for (gli.toFirst();(g=gli.current());++gli)
117  {
119  marshalInt(s,(int)g->pri);
120  }
121  }
122 }
123 
124 void marshalSectionInfoList(StorageIntf *s, QList<SectionInfo> *anchors)
125 {
126  if (anchors==0)
127  {
128  marshalUInt(s,NULL_LIST); // null pointer representation
129  }
130  else
131  {
132  marshalUInt(s,anchors->count());
133  QListIterator<SectionInfo> sli(*anchors);
134  SectionInfo *si;
135  for (sli.toFirst();(si=sli.current());++sli)
136  {
137  marshalQCString(s,si->label);
138  marshalQCString(s,si->title);
139  marshalQCString(s,si->ref);
140  marshalInt(s,(int)si->type);
141  marshalQCString(s,si->fileName);
142  marshalInt(s,si->lineNr);
143  marshalInt(s,si->level);
144  }
145  }
146 }
147 
148 void marshalItemInfoList(StorageIntf *s, QList<ListItemInfo> *sli)
149 {
150  if (sli==0)
151  {
152  marshalUInt(s,NULL_LIST); // null pointer representation
153  }
154  else
155  {
156  marshalUInt(s,sli->count());
157  QListIterator<ListItemInfo> liii(*sli);
158  ListItemInfo *lii;
159  for (liii.toFirst();(lii=liii.current());++liii)
160  {
161  marshalQCString(s,lii->type);
162  marshalInt(s,lii->itemId);
163  }
164  }
165 }
166 
167 void marshalObjPointer(StorageIntf *s,void *obj)
168 {
169  char *b = (char *)&obj;
170  s->write(b,sizeof(void *));
171 }
172 
174 {
175  if (sections==0)
176  {
177  marshalUInt(s,NULL_LIST); // null pointer representation
178  }
179  else
180  {
181  marshalUInt(s,sections->count());
182  SDict<SectionInfo>::IteratorDict sli(*sections);
183  SectionInfo *si;
184  for (sli.toFirst();(si=sli.current());++sli)
185  {
186  marshalQCString(s,sli.currentKey());
187  marshalObjPointer(s,si);
188  }
189  }
190 }
191 
193 {
194  if (memberSDict==0)
195  {
196  marshalUInt(s,NULL_LIST); // null pointer representation
197  }
198  else
199  {
200  marshalUInt(s,memberSDict->count());
201  //printf(" marshalMemberSDict: items=%d\n",memberSDict->count());
202  SDict<MemberDef>::IteratorDict mdi(*memberSDict);
203  MemberDef *md;
204  int count=0;
205  for (mdi.toFirst();(md=mdi.current());++mdi)
206  {
207  //printf(" marshalMemberSDict: %d: key=%s value=%p\n",count,mdi.currentKey().data(),md);
208  marshalQCString(s,mdi.currentKey());
209  marshalObjPointer(s,md);
210  count++;
211  }
212  assert(count==memberSDict->count());
213  }
214 }
215 
217 {
218  if (docInfo==0)
219  {
220  marshalUInt(s,NULL_LIST); // null pointer representation
221  }
222  else
223  {
224  marshalUInt(s,1);
225  marshalQCString(s,docInfo->doc);
226  marshalInt(s,docInfo->line);
227  marshalQCString(s,docInfo->file);
228  }
229 }
230 
232 {
233  if (briefInfo==0)
234  {
235  marshalUInt(s,NULL_LIST); // null pointer representation
236  }
237  else
238  {
239  marshalUInt(s,1);
240  marshalQCString(s,briefInfo->doc);
241  marshalQCString(s,briefInfo->tooltip);
242  marshalInt(s,briefInfo->line);
243  marshalQCString(s,briefInfo->file);
244  }
245 }
246 
248 {
249  if (bodyInfo==0)
250  {
251  marshalUInt(s,NULL_LIST); // null pointer representation
252  }
253  else
254  {
255  marshalUInt(s,1);
256  marshalInt(s,bodyInfo->startLine);
257  marshalInt(s,bodyInfo->endLine);
258  marshalObjPointer(s,bodyInfo->fileDef);
259  }
260 }
261 
263 {
264  if (groupList==0)
265  {
266  marshalUInt(s,NULL_LIST); // null pointer representation
267  }
268  else
269  {
270  marshalUInt(s,groupList->count());
271  QListIterator<GroupDef> gli(*groupList);
272  GroupDef *gd=0;
273  for (gli.toFirst();(gd=gli.current());++gli)
274  {
275  marshalObjPointer(s,gd);
276  }
277  }
278 }
279 
281 {
282  if (ml==0)
283  {
284  marshalUInt(s,NULL_LIST); // null pointer representation
285  }
286  else
287  {
288  marshalUInt(s,ml->count());
289  MemberListIterator mli(*ml);
290  MemberDef *md;
291  uint count=0;
292  for (mli.toFirst();(md=mli.current());++mli)
293  {
294  marshalObjPointer(s,md);
295  count++;
296  }
297  assert(count==ml->count());
298 
299  ml->marshal(s);
300  }
301 }
302 
304 {
305  if (ed==0)
306  {
307  marshalUInt(s,NULL_LIST); // null pointer representation
308  }
309  else
310  {
311  marshalUInt(s,ed->count());
312  //printf(" marshalMemberSDict: items=%d\n",memberSDict->count());
314  Example *e;
315  for (edi.toFirst();(e=edi.current());++edi)
316  {
317  //printf(" marshalMemberSDict: %d: key=%s value=%p\n",count,mdi.currentKey().data(),md);
318  marshalQCString(s,edi.currentKey());
319  marshalQCString(s,e->anchor);
320  marshalQCString(s,e->name);
321  marshalQCString(s,e->file);
322  }
323  }
324 }
325 
327 {
328  if (mls==0)
329  {
330  marshalUInt(s,NULL_LIST); // null pointer representation
331  }
332  else
333  {
334  marshalUInt(s,mls->count());
335  //printf(" marshalMemberSDict: items=%d\n",memberSDict->count());
337  MemberList *ml;
338  for (mli.toFirst();(ml=mli.current());++mli)
339  {
340  //printf(" marshalMemberSDict: %d: key=%s value=%p\n",count,mdi.currentKey().data(),md);
341  marshalQCString(s,mli.currentKey());
342  marshalObjPointer(s,ml); // assume we are not owner of the list
343  }
344  }
345 }
346 
348 {
349  marshalUInt(s,HEADER);
350  marshalQCString(s,e->name);
351  marshalQCString(s,e->type);
352  marshalInt(s,e->section);
353  marshalInt(s,(int)e->protection);
354  marshalInt(s,(int)e->mtype);
355  marshalUInt64(s,e->spec);
356  marshalInt(s,e->initLines);
357  marshalBool(s,e->stat);
359  marshalBool(s,e->proto);
360  marshalBool(s,e->subGrouping);
361  marshalBool(s,e->callGraph);
362  marshalBool(s,e->callerGraph);
363  marshalInt(s,(int)e->virt);
364  marshalQCString(s,e->args);
368  marshalQGString(s,e->program);
372  marshalQCString(s,e->doc);
373  marshalInt(s,e->docLine);
374  marshalQCString(s,e->docFile);
375  marshalQCString(s,e->brief);
376  marshalInt(s,e->briefLine);
379  marshalInt(s,e->inbodyLine);
381  marshalQCString(s,e->relates);
382  marshalInt(s,e->relatesType);
383  marshalQCString(s,e->read);
384  marshalQCString(s,e->write);
385  marshalQCString(s,e->inside);
388  marshalInt(s,e->bodyLine);
389  marshalInt(s,e->endBodyLine);
390  marshalInt(s,e->mGrpId);
395  marshalInt(s,e->startLine);
396  marshalItemInfoList(s,e->sli);
397  marshalInt(s,(int)e->lang);
398  marshalBool(s,e->hidden);
399  marshalBool(s,e->artificial);
400  marshalInt(s,(int)e->groupDocType);
401  marshalQCString(s,e->id);
402 }
403 
405 {
406  marshalEntry(s,e);
407  marshalUInt(s,e->children()->count());
408  QListIterator<Entry> eli(*e->children());
409  Entry *child;
410  for (eli.toFirst();(child=eli.current());++eli)
411  {
412  marshalEntryTree(s,child);
413  }
414 }
415 
416 //------------------------------------------------------------------
417 
419 {
420  uchar b[4];
421  s->read((char *)b,4);
422  int result=(int)((((uint)b[0])<<24)+((uint)b[1]<<16)+((uint)b[2]<<8)+(uint)b[3]);
423  //printf("unmarshalInt: %x %x %x %x: %x offset=%llx\n",b[0],b[1],b[2],b[3],result,f.pos());
424  return result;
425 }
426 
428 {
429  uchar b[4];
430  s->read((char *)b,4);
431  uint result=(((uint)b[0])<<24)+((uint)b[1]<<16)+((uint)b[2]<<8)+(uint)b[3];
432  //printf("unmarshalUInt: %x %x %x %x: %x offset=%llx\n",b[0],b[1],b[2],b[3],result,f.pos());
433  return result;
434 }
435 
437 {
438  uint64 result=uint64(unmarshalUInt(s))<<32;
439  result|=unmarshalUInt(s);
440  return result;
441 }
442 
444 {
445  char result;
446  s->read(&result,sizeof(result));
447  //printf("unmarshalBool: %x offset=%llx\n",result,f.pos());
448  return result;
449 }
450 
452 {
453  uint len = unmarshalUInt(s);
454  //printf("unmarshalQCString: len=%d offset=%llx\n",len,f.pos());
455  QCString result(len+1);
456  result.at(len)='\0';
457  if (len>0)
458  {
459  s->read(result.rawData(),len);
460  }
461  //printf("unmarshalQCString: result=%s\n",result.data());
462  return result;
463 }
464 
466 {
467  uint len = unmarshalUInt(s);
468  //printf("unmarshalQCString: len=%d offset=%llx\n",len,f.pos());
469  QGString result(len+1);
470  result.at(len)='\0';
471  if (len>0)
472  {
473  s->read(result.data(),len);
474  }
475  //printf("unmarshalQCString: result=%s\n",result.data());
476  return result;
477 }
478 
480 {
481  return ArgumentList::unmarshal(s);
482 }
483 
484 QList<ArgumentList> *unmarshalArgumentLists(StorageIntf *s)
485 {
486  uint i;
487  uint count = unmarshalUInt(s);
488  if (count==NULL_LIST) return 0; // null list
489  QList<ArgumentList> *result = new QList<ArgumentList>;
490  result->setAutoDelete(TRUE);
491  assert(count<1000000);
492  //printf("unmarshalArgumentLists: %d\n",count);
493  for (i=0;i<count;i++)
494  {
495  result->append(unmarshalArgumentList(s));
496  }
497  return result;
498 }
499 
500 QList<BaseInfo> *unmarshalBaseInfoList(StorageIntf *s)
501 {
502  uint i;
503  uint count = unmarshalUInt(s);
504  if (count==NULL_LIST) return 0; // null list
505  QList<BaseInfo> *result = new QList<BaseInfo>;
506  result->setAutoDelete(TRUE);
507  assert(count<1000000);
508  for (i=0;i<count;i++)
509  {
510  QCString name = unmarshalQCString(s);
512  Specifier virt = (Specifier)unmarshalInt(s);
513  result->append(new BaseInfo(name,prot,virt));
514  }
515  return result;
516 }
517 
518 QList<Grouping> *unmarshalGroupingList(StorageIntf *s)
519 {
520  uint i;
521  uint count = unmarshalUInt(s);
522  if (count==NULL_LIST) return 0; // null list
523  QList<Grouping> *result = new QList<Grouping>;
524  result->setAutoDelete(TRUE);
525  assert(count<1000000);
526  for (i=0;i<count;i++)
527  {
528  QCString name = unmarshalQCString(s);
530  result->append(new Grouping(name,prio));
531  }
532  return result;
533 }
534 
535 QList<SectionInfo> *unmarshalSectionInfoList(StorageIntf *s)
536 {
537  uint i;
538  uint count = unmarshalUInt(s);
539  if (count==NULL_LIST) return 0; // null list
540  QList<SectionInfo> *result = new QList<SectionInfo>;
541  result->setAutoDelete(TRUE);
542  assert(count<1000000);
543  for (i=0;i<count;i++)
544  {
545  QCString label = unmarshalQCString(s);
546  QCString title = unmarshalQCString(s);
547  QCString ref = unmarshalQCString(s);
549  QCString fileName = unmarshalQCString(s);
550  int lineNr = unmarshalInt(s);
551  int level = unmarshalInt(s);
552  result->append(new SectionInfo(fileName,lineNr,label,title,type,level,ref));
553  }
554  return result;
555 }
556 
557 QList<ListItemInfo> *unmarshalItemInfoList(StorageIntf *s)
558 {
559  uint i;
560  uint count = unmarshalUInt(s);
561  if (count==NULL_LIST) return 0; // null list
562  QList<ListItemInfo> *result = new QList<ListItemInfo>;
563  result->setAutoDelete(TRUE);
564  assert(count<1000000);
565  for (i=0;i<count;i++)
566  {
567  ListItemInfo *lii = new ListItemInfo;
568  lii->type = unmarshalQCString(s);
569  lii->itemId = unmarshalInt(s);
570  result->append(lii);
571  }
572  return result;
573 }
574 
576 {
577  void *result;
578  s->read((char *)&result,sizeof(void*));
579  return result;
580 }
581 
583 {
584  uint i;
585  uint count = unmarshalUInt(s);
586  //printf("unmarshalSectionDict count=%d\n",count);
587  if (count==NULL_LIST) return 0; // null list
588  SectionDict *result = new SectionDict(17);
589  assert(count<1000000);
590  for (i=0;i<count;i++)
591  {
592  QCString key = unmarshalQCString(s);
594  //printf(" unmarshalSectionDict i=%d key=%s si=%s\n",count,key.data(),si->label.data());
595  result->append(key,si);
596  }
597  return result;
598 }
599 
601 {
602  uint i;
603  uint count = unmarshalUInt(s);
604  //printf("--- unmarshalMemberSDict count=%d\n",count);
605  if (count==NULL_LIST)
606  {
607  //printf("--- end unmarshalMemberSDict\n");
608  return 0; // null list
609  }
610  MemberSDict *result = new MemberSDict;
611  assert(count<1000000);
612  //printf("Reading %d key-value pairs\n",count);
613  for (i=0;i<count;i++)
614  {
615  //printf(" unmarshaling pair %d\n",i);
616  QCString key = unmarshalQCString(s);
617  //printf(" unmarshaling key %s\n",key.data());
619  //printf(" unmarshalMemberSDict i=%d key=%s md=%p\n",i,key.data(),md);
620  result->append(key,md);
621  }
622 
623  //printf("--- end unmarshalMemberSDict\n");
624  return result;
625 }
626 
628 {
629  uint count = unmarshalUInt(s);
630  if (count==NULL_LIST) return 0;
631  DocInfo *result = new DocInfo;
632  result->doc = unmarshalQCString(s);
633  result->line = unmarshalInt(s);
634  result->file = unmarshalQCString(s);
635  return result;
636 }
637 
639 {
640  uint count = unmarshalUInt(s);
641  if (count==NULL_LIST) return 0;
642  BriefInfo *result = new BriefInfo;
643  result->doc = unmarshalQCString(s);
644  result->tooltip = unmarshalQCString(s);
645  result->line = unmarshalInt(s);
646  result->file = unmarshalQCString(s);
647  return result;
648 }
649 
651 {
652  uint count = unmarshalUInt(s);
653  if (count==NULL_LIST) return 0;
654  BodyInfo *result = new BodyInfo;
655  result->startLine = unmarshalInt(s);
656  result->endLine = unmarshalInt(s);
657  result->fileDef = (FileDef*)unmarshalObjPointer(s);
658  return result;
659 }
660 
662 {
663  uint i;
664  uint count = unmarshalUInt(s);
665  if (count==NULL_LIST) return 0; // null list
666  assert(count<1000000);
667  GroupList *result = new GroupList;
668  for (i=0;i<count;i++)
669  {
671  result->append(gd);
672  }
673  return result;
674 }
675 
677 {
678  uint i;
679  uint count = unmarshalUInt(s);
680  if (count==NULL_LIST) return 0;
681  MemberList *result = new MemberList;
682  assert(count<1000000);
683  for (i=0;i<count;i++)
684  {
686  result->append(md);
687  }
688  result->unmarshal(s);
689  return result;
690 }
691 
693 {
694  uint i;
695  uint count = unmarshalUInt(s);
696  if (count==NULL_LIST) return 0;
697  ExampleSDict *result = new ExampleSDict;
698  assert(count<1000000);
699  for (i=0;i<count;i++)
700  {
701  QCString key = unmarshalQCString(s);
702  Example *e = new Example;
703  e->anchor = unmarshalQCString(s);
704  e->name = unmarshalQCString(s);
705  e->file = unmarshalQCString(s);
706  result->inSort(key,e);
707  }
708  return result;
709 }
710 
712 {
713  uint i;
714  uint count = unmarshalUInt(s);
715  if (count==NULL_LIST) return 0;
716  SDict<MemberList> *result = new SDict<MemberList>(7);
717  assert(count<1000000);
718  for (i=0;i<count;i++)
719  {
720  QCString key = unmarshalQCString(s);
722  result->append(key,ml);
723  }
724  return result;
725 }
726 
728 {
729  Entry *e = new Entry;
730  uint header=unmarshalUInt(s);
731  ASSERT(header==HEADER);
732  e->name = unmarshalQCString(s);
733  e->type = unmarshalQCString(s);
734  e->section = unmarshalInt(s);
736  e->mtype = (MethodTypes)unmarshalInt(s);
737  e->spec = unmarshalUInt64(s);
738  e->initLines = unmarshalInt(s);
739  e->stat = unmarshalBool(s);
741  e->proto = unmarshalBool(s);
742  e->subGrouping = unmarshalBool(s);
743  e->callGraph = unmarshalBool(s);
744  e->callerGraph = unmarshalBool(s);
745  e->virt = (Specifier)unmarshalInt(s);
746  e->args = unmarshalQCString(s);
748  delete e->argList;
751  e->program = unmarshalQGString(s);
755  e->doc = unmarshalQCString(s);
756  e->docLine = unmarshalInt(s);
757  e->docFile = unmarshalQCString(s);
758  e->brief = unmarshalQCString(s);
759  e->briefLine = unmarshalInt(s);
762  e->inbodyLine = unmarshalInt(s);
764  e->relates = unmarshalQCString(s);
766  e->read = unmarshalQCString(s);
767  e->write = unmarshalQCString(s);
768  e->inside = unmarshalQCString(s);
771  e->bodyLine = unmarshalInt(s);
772  e->endBodyLine = unmarshalInt(s);
773  e->mGrpId = unmarshalInt(s);
774  delete e->extends;
776  delete e->groups;
778  delete e->anchors;
780  e->fileName = unmarshalQCString(s);
781  e->startLine = unmarshalInt(s);
782  e->sli = unmarshalItemInfoList(s);
783  e->lang = (SrcLangExt)unmarshalInt(s);
784  e->hidden = unmarshalBool(s);
785  e->artificial = unmarshalBool(s);
787  e->id = unmarshalQCString(s);
788  return e;
789 }
790 
792 {
793  Entry *e = unmarshalEntry(s);
794  uint count = unmarshalUInt(s);
795  uint i;
796  for (i=0;i<count;i++)
797  {
799  }
800  return e;
801 }