membergroup.cpp 11 KB
Newer Older
1 2
/******************************************************************************
 *
3
 * 
4
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5
 * Copyright (C) 1997-2013 by Dimitri van Heesch.
6 7 8 9 10 11 12
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
13 14
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
15 16 17 18 19 20 21 22 23 24 25
 *
 */

#include "membergroup.h"
#include "memberlist.h"
#include "outputlist.h"
#include "util.h"
#include "classdef.h"
#include "namespacedef.h"
#include "filedef.h"
#include "language.h"
26
#include "groupdef.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
27
#include "doxygen.h"
28
#include "docparser.h"
29
#include "marshal.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
30 31
#include "entry.h"
#include "md5.h"
32

33 34 35 36 37 38
//static QCString idToName(int id)
//{
//  QCString result;
//  result.sprintf("mgroup_%d",id);
//  return result;
//}
39

40 41 42 43
MemberGroup::MemberGroup()
{
}

44
MemberGroup::MemberGroup(Definition *parent,
45
      int id,const char *hdr,const char *d,const char *docFile) 
46
{
47
  //printf("New member group id=%d header=%s desc=%s\n",id,hdr,d);
48
  memberList      = new MemberList(MemberListType_memberGroup);
49 50 51 52 53 54
  grpId           = id;
  grpHeader       = hdr;
  doc             = d;
  scope           = 0;
  inSameSection   = TRUE;
  inDeclSection   = 0;
55
  m_numDecMembers = -1;
56
  m_numDocMembers = -1;
57
  m_parent        = parent;
58
  m_docFile       = docFile;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
59
  m_xrefListItems = 0;
60
  //printf("Member group docs=`%s'\n",doc.data());
61 62 63 64 65 66 67
}

MemberGroup::~MemberGroup()
{
  delete memberList;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
68
void MemberGroup::insertMember(MemberDef *md)
69
{
70
  //printf("MemberGroup::insertMember m_parent=%s memberList=%p count=%d"
71
  //       " member section list: %p: md=%p:%s\n",
72 73
  //       m_parent ? m_parent->name().data() : "<null>",
  //       memberList->first() ? memberList->first()->getSectionList(m_parent) : 0,
74
  //       memberList->count(),
75 76 77
  //       md->getSectionList(m_parent),
  //       md,md->name().data());

78
  MemberDef *firstMd = memberList->getFirst();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
79
  if (inSameSection && memberList->count()>0 && 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
80
      firstMd->getSectionList(m_parent)!=md->getSectionList(m_parent))
Dimitri van Heesch's avatar
Dimitri van Heesch committed
81 82 83 84 85
  {
    inSameSection=FALSE;
  }
  else if (inDeclSection==0)
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
86
    inDeclSection = md->getSectionList(m_parent);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
87
    //printf("inDeclSection=%p type=%d\n",inDeclSection,inDeclSection->listType());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
88
  }
89
  memberList->append(md);
90 91 92 93 94

  // copy the group of the first member in the memberGroup
  GroupDef *gd;
  if (firstMd && (gd=firstMd->getGroupDef()))
  {
95 96 97
    md->setGroupDef(gd, firstMd->getGroupPri(), 
                    firstMd->getGroupFileName(), firstMd->getGroupStartLine(), 
                    firstMd->getGroupHasDocs());
98 99
    gd->insertMember(md);
  }
100 101 102
}


103
void MemberGroup::setAnchors()
104
{
105
  ::setAnchors(memberList);
106
}
107 108

void MemberGroup::writeDeclarations(OutputList &ol,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
109 110
               ClassDef *cd,NamespaceDef *nd,FileDef *fd,GroupDef *gd,
               bool showInline)
111
{
112
  //printf("MemberGroup::writeDeclarations() %s\n",grpHeader.data());
113
  QCString ldoc = doc;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
114
  if (!ldoc.isEmpty()) ldoc.prepend("<a name=\""+anchor()+"\" id=\""+anchor()+"\"></a>");
115
  memberList->writeDeclarations(ol,cd,nd,fd,gd,grpHeader,ldoc,DefinitionIntf::TypeGroup,FALSE,showInline);
116 117
}

118
void MemberGroup::writePlainDeclarations(OutputList &ol,
119
               ClassDef *cd,NamespaceDef *nd,FileDef *fd,GroupDef *gd,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
120
               ClassDef *inheritedFrom,const char *inheritId
121
              )
122
{
123
  //printf("MemberGroup::writePlainDeclarations() memberList->count()=%d\n",memberList->count());
124
  memberList->writePlainDeclarations(ol,cd,nd,fd,gd,DefinitionIntf::TypeGroup,inheritedFrom,inheritId);
125 126 127
}

void MemberGroup::writeDocumentation(OutputList &ol,const char *scopeName,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
128
               Definition *container,bool showEnumValues,bool showInline)
129
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
130
  memberList->writeDocumentation(ol,scopeName,container,0,showEnumValues,showInline);
131
}
132

133 134 135 136 137 138
void MemberGroup::writeDocumentationPage(OutputList &ol,const char *scopeName,
               Definition *container)
{
  memberList->writeDocumentationPage(ol,scopeName,container);
}

139
void MemberGroup::addGroupedInheritedMembers(OutputList &ol,ClassDef *cd,
140
               MemberListType lt,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
141
               ClassDef *inheritedFrom,const QCString &inheritId)
142 143 144 145 146 147 148 149 150 151 152
{
  //printf("** addGroupedInheritedMembers()\n");
  MemberListIterator li(*memberList);
  MemberDef *md;
  for (li.toFirst();(md=li.current());++li)
  {
    //printf("matching %d == %d\n",lt,md->getSectionList(m_parent)->listType());
    if (lt==md->getSectionList(m_parent)->listType())
    {
      MemberList ml(lt);
      ml.append(md);
153
      ml.writePlainDeclarations(ol,cd,0,0,0,DefinitionIntf::TypeGroup,inheritedFrom,inheritId);
154 155 156 157
    }
  }
}

158
int MemberGroup::countGroupedInheritedMembers(MemberListType lt)
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
{
  //printf("** countGroupedInheritedMembers()\n");
  int count=0;
  MemberListIterator li(*memberList);
  MemberDef *md;
  for (li.toFirst();(md=li.current());++li)
  {
    //printf("matching %d == %d\n",lt,md->getSectionList(m_parent)->listType());
    if (lt==md->getSectionList(m_parent)->listType())
    {
      count++;
    }
  }
  return count;
}


Dimitri van Heesch's avatar
Dimitri van Heesch committed
176 177 178 179 180 181 182
/*! Add this group as a subsection of the declaration section, instead
 *  of rendering it in its own section
 */
void MemberGroup::addToDeclarationSection()
{
  if (inDeclSection)
  {
183 184
    //printf("Adding group %p to list %p (type=%d)\n",this,
    //                              inDeclSection,inDeclSection->listType());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
185 186 187 188
    inDeclSection->addMemberGroup(this);
  }
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
189
int MemberGroup::countDecMembers(GroupDef *gd)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
190
{
191
  if (m_numDecMembers==-1) /* number of member not cached */
Dimitri van Heesch's avatar
Dimitri van Heesch committed
192
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
193
    memberList->countDecMembers(gd);
194
    m_numDecMembers = memberList->numDecMembers();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
195
  }
196
  return m_numDecMembers;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
197
}
198

199 200 201 202 203 204 205 206 207 208
int MemberGroup::countDocMembers()
{
  if (m_numDocMembers==-1)
  {
    memberList->countDocMembers();
    m_numDocMembers = memberList->numDocMembers();
  }
  return m_numDocMembers;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
209 210 211 212 213 214
int MemberGroup::countInheritableMembers(ClassDef *inheritedFrom) const
{
  return memberList->countInheritableMembers(inheritedFrom);
}


215 216
void MemberGroup::distributeMemberGroupDocumentation()
{
217
  //printf("MemberGroup::distributeMemberGroupDocumentation() %s\n",grpHeader.data());
218 219 220
  MemberListIterator li(*memberList);
  MemberDef *md;
  for (li.toFirst();(md=li.current());++li)
221
  {
222 223 224 225 226 227 228 229 230 231 232 233 234 235
    //printf("checking md=%s\n",md->name().data());
    // find the first member of the group with documentation
    if (!md->documentation().isEmpty()       ||
        !md->briefDescription().isEmpty()    ||
        !md->inbodyDocumentation().isEmpty()
       )
    {
      //printf("found it!\n");
      break;
    }
  }
  if (md) // distribute docs of md to other members of the list
  {
    //printf("Member %s has documentation!\n",md->name().data());
236 237
    MemberDef *omd;
    for (li.toFirst();(omd=li.current());++li)
238
    {
239 240
      if (md!=omd && omd->documentation().isEmpty() &&
                     omd->briefDescription().isEmpty() &&
241 242
                     omd->inbodyDocumentation().isEmpty()
         )
243
      {
244
        //printf("Copying documentation to member %s\n",omd->name().data());
245 246
        omd->setBriefDescription(md->briefDescription(),md->briefFile(),md->briefLine());
        omd->setDocumentation(md->documentation(),md->docFile(),md->docLine());
247
        omd->setInbodyDocumentation(md->inbodyDocumentation(),md->inbodyFile(),md->inbodyLine());
248 249 250 251
      }
    }
  }
}
252

Dimitri van Heesch's avatar
Dimitri van Heesch committed
253 254 255
int MemberGroup::varCount() const
{
  return memberList->varCount();
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
}

int MemberGroup::funcCount() const      
{ 
  return memberList->funcCount(); 
}

int MemberGroup::enumCount() const      
{ 
  return memberList->enumCount(); 
}

int MemberGroup::enumValueCount() const 
{ 
  return memberList->enumValueCount(); 
}

int MemberGroup::typedefCount() const   
{ 
  return memberList->typedefCount(); 
}

int MemberGroup::protoCount() const     
{ 
  return memberList->protoCount(); 
}

int MemberGroup::defineCount() const    
{ 
  return memberList->defineCount(); 
}

int MemberGroup::friendCount() const    
{ 
  return memberList->friendCount(); 
}

int MemberGroup::numDecMembers() const  
{ 
  return memberList->numDecMembers(); 
}

int MemberGroup::numDocMembers() const  
{ 
  return memberList->numDocMembers(); 
}

void MemberGroup::setInGroup(bool b)
{
  memberList->setInGroup(b);
}
307

Dimitri van Heesch's avatar
Dimitri van Heesch committed
308 309 310 311
QCString MemberGroup::anchor() const
{
  uchar md5_sig[16];
  QCString sigStr(33);
312 313 314
  QCString locHeader = grpHeader;
  if (locHeader.isEmpty()) locHeader="[NOHEADER]";
  MD5Buffer((const unsigned char *)locHeader.data(),locHeader.length(),md5_sig);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
315 316 317 318
  MD5SigToString(md5_sig,sigStr.data(),33);
  return "amgrp"+sigStr;
}

319 320 321
void MemberGroup::addListReferences(Definition *def)
{
  memberList->addListReferences(def);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
322 323
  if (m_xrefListItems && def)
  {
324 325 326 327 328 329
    QCString name = def->getOutputFileBase()+"#"+anchor();
    addRefItem(m_xrefListItems,
        name,
        theTranslator->trGroup(TRUE,TRUE),
        name,
        grpHeader,0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
330
  }
331
}
332 333 334

void MemberGroup::findSectionsInDocumentation()
{
335
  docFindSections(doc,0,this,m_docFile);
336 337 338
  memberList->findSectionsInDocumentation();
}

339 340 341 342 343 344 345 346 347 348 349 350 351 352
void MemberGroup::marshal(StorageIntf *s)
{
  marshalMemberList(s,memberList);
  marshalObjPointer(s,inDeclSection); // reference only
  marshalInt(s,grpId);
  marshalQCString(s,grpHeader);
  marshalQCString(s,fileName);
  marshalObjPointer(s,scope);
  marshalQCString(s,doc);
  marshalBool(s,inSameSection);
  marshalInt(s,m_numDecMembers);
  marshalInt(s,m_numDocMembers);
  marshalObjPointer(s,m_parent);
  marshalQCString(s,m_docFile);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
353
  marshalItemInfoList (Doxygen::symbolStorage,m_xrefListItems);
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
}

void MemberGroup::unmarshal(StorageIntf *s)
{
  memberList      = unmarshalMemberList(s);
  inDeclSection   = (MemberList *)unmarshalObjPointer(s); 
  grpId           = unmarshalInt(s);
  grpHeader       = unmarshalQCString(s);
  fileName        = unmarshalQCString(s);
  scope           = (Definition *)unmarshalObjPointer(s);
  doc             = unmarshalQCString(s);
  inSameSection   = unmarshalBool(s);
  m_numDecMembers = unmarshalInt(s);
  m_numDocMembers = unmarshalInt(s);
  m_parent        = (Definition *)unmarshalObjPointer(s);
  m_docFile       = unmarshalQCString(s);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
370
  m_xrefListItems = unmarshalItemInfoList (Doxygen::symbolStorage);
371 372
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
void MemberGroup::setRefItems(const QList<ListItemInfo> *sli)
{
  if (sli)
  {
    // deep copy the list
    if (m_xrefListItems==0) 
    {
      m_xrefListItems=new QList<ListItemInfo>;
      m_xrefListItems->setAutoDelete(TRUE);
    }
    QListIterator<ListItemInfo> slii(*sli);
    ListItemInfo *lii;
    for (slii.toFirst();(lii=slii.current());++slii)
    {
      m_xrefListItems->append(new ListItemInfo(*lii));
    } 
  }
}
//--------------------------------------------------------------------------

void MemberGroupInfo::setRefItems(const QList<ListItemInfo> *sli)
{
  if (!sli) return;
  if (m_sli==0)
  {
    m_sli = new QList<ListItemInfo>;
    m_sli->setAutoDelete(TRUE);
  }
  QListIterator<ListItemInfo> slii(*sli);
  ListItemInfo *ili;
  for (slii.toFirst();(ili=slii.current());++slii)
  {
    m_sli->append(new ListItemInfo(*ili));
  }
}